Skip to content

Commit cf5fd25

Browse files
committed
initial code generation
1 parent f668c19 commit cf5fd25

File tree

9 files changed

+114
-0
lines changed

9 files changed

+114
-0
lines changed

community/memoize-one/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

community/memoize-one/.npmignore

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

community/memoize-one/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+
};

community/memoize-one/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "memoize-one",
3+
"version": "0.0.0",
4+
"license": "MIT",
5+
"main": "dist/codeshift.config.js",
6+
"scripts": {
7+
"build": "tsc --build",
8+
"test": "jest"
9+
},
10+
"dependencies": {},
11+
"devDependencies": {
12+
"@codeshift/utils": "^0.1.2",
13+
"@codeshift/test-utils": "*",
14+
"@types/node": "^16.11.0",
15+
"@types/jest": "^26.0.15",
16+
"jest": "^26.6.0",
17+
"jscodeshift": "^0.12.0",
18+
"prettier": "^1.16.4",
19+
"ts-jest": "^26.4.4",
20+
"typescript": "^4.3.5"
21+
}
22+
}

community/memoize-one/src/5.0.0/motions/.gitkeep

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { applyTransform } from '@codeshift/test-utils';
2+
import * as transformer from './transform';
3+
4+
describe('memoize-one@5.0.0 transform', () => {
5+
it('should transform correctly', () => {
6+
const result = applyTransform(
7+
transformer,
8+
`
9+
import foo from '<% packageName %>';
10+
console.log(foo);
11+
`,
12+
{ parser: 'tsx' },
13+
);
14+
15+
expect(result).toMatchInlineSnapshot();
16+
});
17+
});
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
maintainers: [],
3+
target: [],
4+
description: 'Codemods for memoize-one',
5+
transforms: {'5.0.0': require.resolve('./5.0.0/transform'),},
6+
presets: {},
7+
};

community/memoize-one/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"include": ["src/**/*"],
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"esModuleInterop": true,
6+
"allowJs": true,
7+
"types": ["jest", "node"]
8+
}
9+
}

0 commit comments

Comments
 (0)