@@ -3,35 +3,37 @@ const path = require('path');
3
3
const { execSync } = require ( 'child_process' ) ;
4
4
5
5
const packageJson = require ( './package.json' ) ;
6
- const jestJson = require ( './jest.json' ) ;
6
+ const jestConfig = require ( './jest.json' ) ;
7
7
const devDependencies = require ( './devDependencies.json' ) ;
8
8
9
9
const deleteFile = ( fileName ) => fs . unlinkSync ( path . join ( process . cwd ( ) , fileName ) ) ;
10
10
const writeFile = ( fileName , data ) => fs . writeFileSync ( path . join ( process . cwd ( ) , fileName ) , data ) ;
11
11
const isYarnAvailable = ( ) => {
12
12
try {
13
- execSync ( 'yarnpkg --version' , { stdio : 'ignore' } ) ;
13
+ execSync ( 'yarn --version' , { stdio : 'ignore' } ) ;
14
14
return true ;
15
- } catch ( e ) {
15
+ } catch ( exc ) {
16
16
return false ;
17
17
}
18
18
}
19
19
20
- const packager = isYarnAvailable ( ) ? 'yarn' : 'npm' ;
20
+ const packageManager = isYarnAvailable ( ) ? 'yarn' : 'npm' ;
21
21
const execOptions = { stdio : 'inherit' } ;
22
22
23
23
console . log ( '\n🔄 Please wait...\n' ) ;
24
24
25
25
packageJson . scripts . start = `${ packageJson . scripts . start } --config ../../../../rn-cli.config.js` ;
26
- packageJson . jest = Object . assign ( packageJson . jest , jestJson ) ;
26
+ packageJson . jest = Object . assign ( packageJson . jest , jestConfig ) ;
27
27
writeFile ( 'package.json' , JSON . stringify ( packageJson , null , 2 ) ) ;
28
28
29
- console . log ( `\n📦 Installing dependencies with ${ packager } ...\n` ) ;
29
+ console . log ( `\n📦 Installing dependencies with ${ packageManager } ...\n` ) ;
30
30
31
- if ( packager === 'yarn' ) {
32
- execSync ( `yarn add ${ devDependencies . join ( ' ' ) } --dev --exact` , execOptions ) ;
33
- } else {
34
- execSync ( `npm i ${ devDependencies . join ( ' ' ) } --save-dev --save-exact` , execOptions ) ;
31
+ switch ( packageManager ) {
32
+ case 'yarn' :
33
+ execSync ( `yarn add ${ devDependencies . join ( ' ' ) } --dev --exact` , execOptions ) ;
34
+ break ;
35
+ default :
36
+ execSync ( `npm i ${ devDependencies . join ( ' ' ) } --save-dev --save-exact` , execOptions ) ;
35
37
}
36
38
37
39
deleteFile ( 'App.js' ) ;
@@ -43,4 +45,4 @@ deleteFile('README.md');
43
45
deleteFile ( 'LICENSE' ) ;
44
46
deleteFile ( 'setup.js' ) ;
45
47
46
- console . log ( `\n✅ Setup completed! You can now start with: ${ packager } start\n` ) ;
48
+ console . log ( `\n✅ Setup completed! You can now start with: ${ packageManager } start\n` ) ;
0 commit comments