33/* eslint-disable no-console */
44
55const fs = require ( 'fs' ) ;
6-
76const path = require ( 'path' ) ;
8-
97const execSync = require ( 'child_process' ) . execSync ;
108
119const requestedReactVersion = process . argv [ 2 ] ;
12-
1310if ( ! requestedReactVersion ) {
1411 throw new Error ( "React version is missing: '$ ./prepare 16.0.0'" ) ;
1512}
@@ -21,41 +18,53 @@ const deleteExistingDependencies = () => () => {
2118 if ( fs . existsSync ( nodeModulesPath ) ) {
2219 execSync ( `rm -r "${ nodeModulesPath } "` , {
2320 cwd : __dirname ,
24- stdio : 'inherit'
21+ stdio : 'inherit' ,
2522 } ) ;
2623 }
2724
2825 if ( fs . existsSync ( packageJsonPath ) ) {
2926 execSync ( `rm "${ packageJsonPath } "` , {
3027 cwd : __dirname ,
31- stdio : 'inherit'
28+ stdio : 'inherit' ,
3229 } ) ;
3330 }
3431} ;
3532
36- const preparePackageJson = reactVersion => ( ) => {
33+ const preparePackageJson = ( reactVersion ) => ( ) => {
3734 const packageJson = {
3835 name : 'smoke' ,
3936 version : '0.0.1' ,
4037 main : 'index.js' ,
4138 license : 'MIT' ,
4239 private : true ,
4340 dependencies : {
44- react : reactVersion
45- }
41+ react : reactVersion ,
42+ } ,
4643 } ;
47- fs . writeFileSync ( path . join ( __dirname , 'package.json' ) , JSON . stringify ( packageJson , null , 2 ) ) ;
44+
45+ fs . writeFileSync (
46+ path . join ( __dirname , 'package.json' ) ,
47+ JSON . stringify ( packageJson , null , 2 )
48+ ) ;
4849} ;
4950
50- const installDependencies = ( ) => ( ) => new Promise ( ( ) => {
51- if ( ! fs . existsSync ( packageJsonPath ) ) {
52- return ;
53- }
51+ const installDependencies = ( ) => ( ) =>
52+ new Promise ( ( ) => {
53+ if ( ! fs . existsSync ( packageJsonPath ) ) {
54+ return ;
55+ }
5456
55- execSync ( 'yarn install --no-lockfile' , {
56- cwd : __dirname ,
57- stdio : 'inherit'
57+ execSync ( 'yarn install --no-lockfile' , {
58+ cwd : __dirname ,
59+ stdio : 'inherit' ,
60+ } ) ;
5861 } ) ;
59- } ) ;
6062
61- Promise . resolve ( ) . then ( ( ) => console . log ( `Requested "react" version: "${ requestedReactVersion } "` ) ) . then ( deleteExistingDependencies ( ) ) . then ( preparePackageJson ( requestedReactVersion ) ) . then ( installDependencies ( ) ) . catch ( err => console . error ( err ) ) ;
63+ Promise . resolve ( )
64+ . then ( ( ) =>
65+ console . log ( `Requested "react" version: "${ requestedReactVersion } "` )
66+ )
67+ . then ( deleteExistingDependencies ( ) )
68+ . then ( preparePackageJson ( requestedReactVersion ) )
69+ . then ( installDependencies ( ) )
70+ . catch ( ( err ) => console . error ( err ) ) ;
0 commit comments