@@ -29,8 +29,8 @@ export function getPackageJson(packageName: string, version = '0.0.0') {
2929 devDependencies : {
3030 '@codeshift/cli' : `^${ cliVersion } ` ,
3131 '@codeshift/test-utils' : `^${ testUtilVersion } ` ,
32- '@types/node' : '^16.11.0' ,
3332 '@types/jest' : '^26.0.15' ,
33+ '@types/node' : '^16.11.0' ,
3434 jest : '^26.6.0' ,
3535 parcel : '^2.8.3' ,
3636 prettier : '^2.0.0' ,
@@ -59,9 +59,9 @@ function getConfig(packageName: string, transform?: string, preset?: string) {
5959 targets: [],
6060 description: 'Codemods for ${ packageName } ',
6161 transforms: {${
62- transform ? `'${ transform } ': resolve ('./${ transform } /transform'),` : ''
62+ transform ? `'${ transform } ': require ('./${ transform } /transform'),` : ''
6363 } },
64- presets: {${ preset ? `'${ preset } ': resolve ('./${ preset } /transform'),` : '' } },
64+ presets: {${ preset ? `'${ preset } ': require ('./${ preset } /transform'),` : '' } },
6565};
6666` ;
6767}
@@ -139,20 +139,26 @@ export function initDirectory(
139139 targetPath = './' ,
140140 isReduced = false ,
141141) {
142+ const sourcePath = path . join ( targetPath , 'src' ) ;
143+
142144 fs . copySync (
143145 path . join ( TEMPLATE_PATH , isReduced ? 'codemods' : '' ) ,
144- targetPath ,
146+ sourcePath ,
145147 {
146148 filter : src => ! src . includes ( 'codemods/codemod' ) ,
147149 } ,
148150 ) ;
149151
150- if ( ! isReduced ) {
151- fs . writeFileSync (
152- path . join ( targetPath , 'package.json' ) ,
153- getPackageJson ( packageName ) ,
154- ) ;
152+ fs . writeFileSync (
153+ path . join ( targetPath , 'package.json' ) ,
154+ getPackageJson (
155+ isReduced
156+ ? `@codeshift/mod-${ packageName . replace ( '/' , '__' ) . replace ( '@' , '' ) } `
157+ : packageName ,
158+ ) ,
159+ ) ;
155160
161+ if ( ! isReduced ) {
156162 fs . writeFileSync ( path . join ( targetPath , '.npmignore' ) , getNpmIgnore ( ) ) ;
157163
158164 const readmeFilePath = path . join ( targetPath , 'README.md' ) ;
@@ -163,7 +169,7 @@ export function initDirectory(
163169 fs . writeFileSync ( readmeFilePath , readmeFile ) ;
164170 }
165171
166- initConfig ( packageName , targetPath ) ;
172+ initConfig ( packageName , sourcePath ) ;
167173}
168174
169175export function initTransform (
@@ -177,7 +183,8 @@ export function initTransform(
177183 throw new Error ( `Provided version ${ id } is not a valid semver version` ) ;
178184 }
179185
180- const transformPath = path . join ( targetPath , ! isReduced ? 'codemods' : '' , id ) ;
186+ const sourcePath = path . join ( targetPath , 'src' ) ;
187+ const transformPath = path . join ( sourcePath , id ) ;
181188
182189 if ( fs . existsSync ( transformPath ) ) {
183190 throw new Error ( `Codemod for ${ type } "${ id } " already exists` ) ;
@@ -213,5 +220,5 @@ export function initTransform(
213220
214221 fs . writeFileSync ( readmeFilePath , readmeFile ) ;
215222
216- updateConfig ( targetPath , packageName , id || '' , type , isReduced ) ;
223+ updateConfig ( sourcePath , packageName , id || '' , type , isReduced ) ;
217224}
0 commit comments