Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f81cee1

Browse files
initial commit
1 parent bd8b666 commit f81cee1

File tree

11 files changed

+11682
-2
lines changed

11 files changed

+11682
-2
lines changed

‎.npmignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/
2+
codemods/
3+
**/__test__
4+
**/*.spec.(ts|js)
5+
.vscode
6+
jest.config.js

‎README.md‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
1-
# codeshift-examples
2-
Example stand-alone codeshift package
1+
# codeshift-community
2+
3+
This project was bootstrapped with [CodeshiftCommunity 🚚](https://www.codeshiftcommunity.com/). Please see the [external packages guide](https://www.codeshiftcommunity.com/docs/external-packages) for more information on how to work with this repo.
4+
5+
![CodeshiftCommunity logo](https://www.codeshiftcommunity.com/img/logo.svg)
6+
7+
## Scripts
8+
9+
### `npm run dev`
10+
11+
Runs the codeshift CLI useful for testing transform files as if they have been published
12+
13+
**example:** `npm run dev -t codemods/10.0.0/transform.ts`
14+
15+
Alternatively, you can run `npm run dev` to see an interactive list of codemods to choose from.
16+
17+
See the [cli reference](https://www.codeshiftcommunity.com/docs/cli) for more information.
18+
19+
### `npm run test`
20+
21+
Launches the test runner in interactive watch mode.
22+
23+
See the [testing guide](https://www.codeshiftcommunity.com/docs/testing) for more information.
24+
25+
### `npm run validate`
26+
27+
Checks the validity of your `codeshift.config.js` file.
28+
29+
See the [configuration options](https://www.codeshiftcommunity.com/docs/configuration) for more information.
30+
31+
### `npm run build`
32+
33+
Builds the app for production to the `dist` folder.
34+
35+
## Publishing
36+
37+
This package can be published to npm via the normal commands `npm version` and `npm publish`
38+
39+
## Build tooling
40+
41+
Feel free to replace the preinstalled build tooling & dependencies to suit your needs. The only requirement is that there is a valid `codeshift.config.js` in your project root, `/src` or `/codemods` directories.

‎codemods/10.0.0/README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# codeshift-community@10.0.0
2+
3+
Codemods for codeshift-community@10.0.0
4+
5+
```js
6+
/* INPUT */
7+
var foo = 'foo';
8+
9+
/* OUTPUT */
10+
let foo = 'foo';
11+
```

‎codemods/10.0.0/motions/.gitkeep‎

Whitespace-only changes.

‎codemods/10.0.0/transform.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { applyTransform } from "@codeshift/test-utils";
2+
import * as transformer from "./transform";
3+
4+
describe("codeshift-community@10.0.0 transform", () => {
5+
it("should transform correctly", async () => {
6+
const result = await applyTransform(
7+
transformer,
8+
`
9+
var foo = 'codeshift-community';
10+
console.log(foo);
11+
`,
12+
{ parser: "tsx" }
13+
);
14+
15+
expect(result).toMatchInlineSnapshot(`
16+
"var bar = 'codeshift-community';
17+
console.log(bar);"
18+
`);
19+
});
20+
});

‎codemods/10.0.0/transform.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { API, FileInfo, Options } from 'jscodeshift';
2+
3+
export default function transformer(
4+
file: FileInfo,
5+
{ jscodeshift: j }: API,
6+
options: Options,
7+
) {
8+
const source = j(file.source);
9+
10+
/**
11+
* Early exit condition
12+
* -----
13+
* It is often good practice to exit early and return the original source file
14+
* if it does not contain code relevant to the codemod.
15+
* See this page for more information:
16+
* https://codeshiftcommunity.github.io/CodeshiftCommunity/docs/your-first-codemod#output
17+
*/
18+
// if (/* Some condition here */ true) {
19+
// return file.source;
20+
// }
21+
22+
/**
23+
* Codemod logic goes here 👇
24+
* -----
25+
* This is where the core logic for your codemod will go,
26+
* consider grouping specific actions into 'motions' and running them in sequence
27+
*
28+
* See this page for more information:
29+
* https://codeshiftcommunity.github.io/CodeshiftCommunity/docs/authoring#motions
30+
*/
31+
source.findVariableDeclarators('foo').renameTo('bar');
32+
33+
/**
34+
* Return your modified AST here 👇
35+
* -----
36+
* This is where your modified AST will be transformed back into a string
37+
* and written back to the file.
38+
*/
39+
return source.toSource(options.printOptions);
40+
}

‎codemods/codeshift.config.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
maintainers: [],
3+
targets: [],
4+
description: "Codemods for codeshift-community",
5+
transforms: {
6+
"10.0.0": require("./10.0.0/transform"),
7+
},
8+
presets: {},
9+
};

‎jest.config.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
transform: {
3+
'^.+\\.ts$': 'ts-jest',
4+
},
5+
moduleFileExtensions: ['ts', 'tsx', 'js'],
6+
testRegex: '^.+\\.spec\\.(tsx|ts|js)$',
7+
globals: {
8+
'ts-jest': {
9+
tsconfig: 'tsconfig.json',
10+
},
11+
},
12+
testPathIgnorePatterns: ['/node_modules/'],
13+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /