@@ -2,21 +2,20 @@ import fs from 'fs-extra';
22import semver from 'semver' ;
33import * as recast from 'recast' ;
44
5- function main ( packageName : string , version : string ) {
6- if ( ! packageName ) throw new Error ( 'Package name was not provided' ) ;
7- if ( ! version ) throw new Error ( 'Version was not provided' ) ;
8-
5+ export function initDirectory (
6+ packageName : string ,
7+ version : string ,
8+ targetPath : string = './' ,
9+ ) {
910 if ( ! semver . valid ( version ) ) {
1011 throw new Error (
1112 `Provided version ${ version } is not a valid semver version` ,
1213 ) ;
1314 }
1415
15- const communityDirectoryPath = `${ __dirname } /../../../community` ;
16- const safePackageName = packageName . replace ( '/' , '__' ) ;
17- const codemodBasePath = `${ communityDirectoryPath } /${ safePackageName } ` ;
18- const codemodPath = `${ codemodBasePath } /${ version } ` ;
19- const configPath = `${ codemodBasePath } /codeshift.config.js` ;
16+ const basePath = `${ targetPath } /${ packageName . replace ( '/' , '__' ) } ` ;
17+ const codemodPath = `${ basePath } /${ version } ` ;
18+ const configPath = `${ basePath } /codeshift.config.js` ;
2019 const motionsPath = `${ codemodPath } /motions` ;
2120
2221 fs . mkdirSync ( codemodPath , { recursive : true } ) ;
@@ -88,10 +87,4 @@ function main(packageName: string, version: string) {
8887 recast . prettyPrint ( ast , { quote : 'single' , trailingComma : true } ) . code ,
8988 ) ;
9089 }
91-
92- console . log (
93- `🚚 New codemod package created at: community/${ safePackageName } /${ version } ` ,
94- ) ;
9590}
96-
97- main ( process . argv [ 2 ] , process . argv [ 3 ] ) ;
0 commit comments