@@ -2,10 +2,6 @@ import fs from 'fs-extra';
22import semver from 'semver' ;
33import * as recast from 'recast' ;
44
5- function transformPackageName ( packageName : string ) {
6- return packageName . replace ( '/' , '__' ) ;
7- }
8-
95function 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 ) ;
0 commit comments