@@ -19,20 +19,36 @@ const addScriptsToPackageJson = async (packageJsonPath, scripts) => {
19
19
await writeJson ( packageJsonPath , packageJson ) ;
20
20
} ;
21
21
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 ) ;
24
24
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 } ` ) ;
28
27
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 ) ;
31
30
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
+ }
36
52
} ;
37
53
38
54
module . exports = {
0 commit comments