@@ -2,6 +2,7 @@ import semver from 'semver';
22import fs from 'fs-extra' ;
33// @ts -ignore
44import RegClient from 'npm-registry-client' ;
5+ import { getPackageJson } from '@codeshift/initializer' ;
56
67const client = new RegClient ( ) ;
78const npmUri = 'https://registry.npmjs.org/' ;
@@ -26,62 +27,46 @@ function getPackageVersion(packageName: string) {
2627 ) ;
2728}
2829
29- function getPackageJson ( packageName : string , version : string ) {
30- return JSON . stringify (
31- {
32- name : packageName ,
33- version,
34- main : `dist/codeshift-${ packageName . replace ( '@codeshift/' , '' ) } .cjs.js` ,
35- license : 'MIT' ,
36- repository : 'https://github.com/CodeshiftCommunity/CodeshiftCommunity/' ,
37- scripts : { } ,
38- dependencies : {
39- jscodeshift : '^0.12.0' ,
40- '@codeshift/utils' : '*' ,
41- } ,
42- } ,
43- null ,
44- 2 ,
45- ) ;
46- }
47-
4830export default async function generatePackages (
4931 sourcePath : string ,
5032 targetPath : string ,
5133 changedPackages : string [ ] ,
5234) {
5335 await fs . mkdir ( targetPath ) ;
36+
5437 const directories = await fs . readdir ( sourcePath ) ;
5538
56- directories
57- . filter ( dir => changedPackages . includes ( dir ) )
58- . forEach ( async dir => {
59- const packageName = `@codeshift/mod-${ dir
60- . replace ( '@' , '' )
61- . replace ( '/' , '__' ) } `;
62- const packageVersion = await getPackageVersion ( packageName ) ;
63- // We need to manually patch bump the codemod
64- const nextPackageVersion = semver . inc ( packageVersion , 'patch' ) ;
39+ await Promise . all (
40+ directories
41+ . filter ( dir => changedPackages . includes ( dir ) )
42+ . map ( async dir => {
43+ const packageName = `@codeshift/mod-${ dir
44+ . replace ( '@' , '' )
45+ . replace ( '/' , '__' ) } `;
46+ const packageVersion = await getPackageVersion ( packageName ) ;
47+ // We need to manually patch bump the codemod
48+ const nextPackageVersion = semver . inc ( packageVersion , 'patch' ) ;
6549
66- const basePath = `${ targetPath } /${ dir } ` ;
67- await fs . copy ( `${ sourcePath } /${ dir } ` , `${ basePath } /src` ) ;
68- await fs . copyFile (
69- `${ __dirname } /../template/LICENSE` ,
70- `${ basePath } /LICENSE` ,
71- ) ;
72- await fs . copyFile (
73- `${ __dirname } /../template/.npmignore` ,
74- `${ basePath } /.npmignore` ,
75- ) ;
76- await fs . rename (
77- `${ basePath } /src/codeshift.config.js` ,
78- `${ basePath } /src/index.js` ,
79- ) ;
80- await fs . writeFile (
81- `${ basePath } /package.json` ,
82- getPackageJson ( packageName , nextPackageVersion ! ) ,
83- ) ;
84- } ) ;
50+ const basePath = `${ targetPath } /${ dir } ` ;
51+ await fs . copy ( `${ sourcePath } /${ dir } ` , `${ basePath } /src` ) ;
52+ await fs . copyFile (
53+ `${ __dirname } /../template/LICENSE` ,
54+ `${ basePath } /LICENSE` ,
55+ ) ;
56+ await fs . copyFile (
57+ `${ __dirname } /../template/.npmignore` ,
58+ `${ basePath } /.npmignore` ,
59+ ) ;
60+ await fs . copyFile (
61+ `${ __dirname } /../template/tsconfig.json` ,
62+ `${ basePath } /tsconfig.json` ,
63+ ) ;
64+ await fs . writeFile (
65+ `${ basePath } /package.json` ,
66+ getPackageJson ( packageName , nextPackageVersion ! ) ,
67+ ) ;
68+ } ) ,
69+ ) ;
8570}
8671
8772export function cleanTargetDir ( path : string ) {
0 commit comments