@@ -19,20 +19,36 @@ const addScriptsToPackageJson = async (packageJsonPath, scripts) => {
1919 await writeJson ( packageJsonPath , packageJson ) ;
2020} ;
2121
22- const createModule = async ( name , template , rootAppPath ) => {
23- const { execInPackages, execInApp } = createExecutionContext ( rootAppPath , name ) ;
22+ const createModule = async ( name , template , rootAppPath , isRootPath = false ) => {
23+ const { execInPackages, execInApp, execInRootApp , execInRoot } = createExecutionContext ( rootAppPath , name ) ;
2424
25- await execInPackages ( `npx create-react-app ${ name } ` ) ;
26- await appendFile ( `${ rootAppPath } /packages/${ name } /.gitignore` , [ 'build-lib' , 'public/meta.json' ] . join ( '\n' ) ) ;
27- await copyTemplateTo ( template , `${ rootAppPath } /packages/${ name } ` ) ;
25+ if ( isRootPath ) {
26+ await execInRoot ( `npx create-react-app ${ name } ` ) ;
2827
29- await execInApp ( 'yarn add @cmra/cli' ) ;
30- await execInApp ( 'yarn add @cmra/react' ) ;
28+ await appendFile ( ` ${ rootAppPath } /.gitignore` , [ 'build-lib' , 'public/meta.json' ] . join ( '\n' ) ) ;
29+ await copyTemplateTo ( template , rootAppPath ) ;
3130
32- await addScriptsToPackageJson (
33- `${ rootAppPath } /packages/${ name } /package.json` ,
34- getModuleScripts ( template === 'microfrontend' )
35- ) ;
31+ await execInRootApp ( 'yarn add @cmra/cli' ) ;
32+ await execInRootApp ( 'yarn add @cmra/react' ) ;
33+
34+ await addScriptsToPackageJson (
35+ `${ rootAppPath } /${ name } /package.json` ,
36+ getModuleScripts ( template === 'microfrontend' )
37+ ) ;
38+ } else {
39+ await execInPackages ( `npx create-react-app ${ name } ` ) ;
40+
41+ await appendFile ( `${ rootAppPath } /packages/${ name } /.gitignore` , [ 'build-lib' , 'public/meta.json' ] . join ( '\n' ) ) ;
42+ await copyTemplateTo ( template , `${ rootAppPath } /packages/${ name } ` ) ;
43+
44+ await execInApp ( 'yarn add @cmra/cli' ) ;
45+ await execInApp ( 'yarn add @cmra/react' ) ;
46+
47+ await addScriptsToPackageJson (
48+ `${ rootAppPath } /packages/${ name } /package.json` ,
49+ getModuleScripts ( template === 'microfrontend' )
50+ ) ;
51+ }
3652} ;
3753
3854module . exports = {
0 commit comments