Skip to content

Commit 6ef7d5f

Browse files
committed
🔨 Updates initialiser template
1 parent e832223 commit 6ef7d5f

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
2-
maintainers: [],
2+
maintainers: ['danieldelcore'],
33
transforms: {
44
'11.0.0': require('./11.0.0/transform'),
5-
}
5+
},
66
};

packages/initializer/src/index.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import fs from 'fs-extra';
22
import semver from 'semver';
33
import * as recast from 'recast';
44

5-
function transformPackageName(packageName: string) {
6-
return packageName.replace('/', '__');
7-
}
8-
95
function main(packageName: string, version: string) {
106
if (!packageName) throw new Error('Package name was not provided');
117
if (!version) throw new Error('Version was not provided');
@@ -17,23 +13,30 @@ function main(packageName: string, version: string) {
1713
}
1814

1915
const communityDirectoryPath = `${__dirname}/../../../community`;
20-
const safePackageName = transformPackageName(packageName);
16+
const safePackageName = packageName.replace('/', '__');
2117
const codemodBasePath = `${communityDirectoryPath}/${safePackageName}`;
2218
const codemodPath = `${codemodBasePath}/${version}`;
2319
const configPath = `${codemodBasePath}/codeshift.config.js`;
24-
const testsPath = `${codemodPath}/_tests_`;
2520
const motionsPath = `${codemodPath}/motions`;
2621

2722
fs.mkdirSync(codemodPath, { recursive: true });
23+
24+
fs.copyFileSync(
25+
`${__dirname}/../template/transform.spec.ts`,
26+
`${codemodPath}/transform.spec.ts`,
27+
);
28+
fs.copyFileSync(
29+
`${__dirname}/../template/transform.ts`,
30+
`${codemodPath}/transform.ts`,
31+
);
2832
fs.copySync(`${__dirname}/../template/motions`, motionsPath);
29-
fs.copySync(`${__dirname}/../template/_tests_`, testsPath);
3033

3134
const testFile = fs
32-
.readFileSync(`${testsPath}/transform.spec.ts`, 'utf8')
35+
.readFileSync(`${codemodPath}/transform.spec.ts`, 'utf8')
3336
.replace('<% packageName %>', packageName)
3437
.replace('<% version %>', version);
3538

36-
fs.writeFileSync(`${testsPath}/transform.spec.ts`, testFile);
39+
fs.writeFileSync(`${codemodPath}/transform.spec.ts`, testFile);
3740

3841
if (!fs.existsSync(configPath)) {
3942
fs.writeFileSync(
@@ -86,11 +89,6 @@ function main(packageName: string, version: string) {
8689
);
8790
}
8891

89-
fs.copyFileSync(
90-
`${__dirname}/../template/transform.ts`,
91-
`${codemodPath}/transform.ts`,
92-
);
93-
9492
console.log(
9593
`🚚 New codemod package created at: community/${safePackageName}/${version}`,
9694
);

packages/initializer/template/_tests_/transform.spec.ts renamed to packages/initializer/template/transform.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { applyTransform } from '@codeshift/test-utils';
2-
import * as transformer from '../transform';
2+
import * as transformer from './transform';
33

44
describe('<% packageName %>@<% version %> transform', () => {
55
it('should transform correctly', () => {

packages/initializer/template/transform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { API, FileInfo, Options } from 'jscodeshift';
22

33
export default function transformer(
4-
fileInfo: FileInfo,
4+
file: FileInfo,
55
{ jscodeshift: j }: API,
66
options: Options,
77
) {
8-
const source = j(fileInfo.source);
8+
const source = j(file.source);
99

1010
/**
1111
* Early exit condition
@@ -16,7 +16,7 @@ export default function transformer(
1616
* https://codeshiftcommunity.github.io/CodeshiftCommunity/docs/your-first-codemod#output
1717
*/
1818
if (/* Some condition here */ true) {
19-
return fileInfo.source;
19+
return file.source;
2020
}
2121

2222
/**

0 commit comments

Comments
 (0)