@@ -5,6 +5,42 @@ const paths = require('path');
55const fs = require ( 'fs' ) ;
66const figlet = require ( 'figlet' ) ;
77const chalk = require ( 'chalk' ) ;
8+ const execSync = require ( 'child_process' ) . execSync ;
9+ const spawn = require ( 'cross-spawn' ) ;
10+
11+ function shouldUseYarn ( ) {
12+ try {
13+ execSync ( 'yarnpkg --version' , { stdio : 'ignore' } ) ;
14+ return true ;
15+ } catch ( e ) {
16+ return false ;
17+ }
18+ }
19+
20+ const installPackages = ( ) => {
21+ console . log ( chalk . white . bold ( 'Installing Packages' ) ) ;
22+ return new Promise ( ( resolve , reject ) => {
23+ let command ;
24+ let args = [ 'install' ] ;
25+
26+ if ( shouldUseYarn ( ) ) {
27+ command = 'yarn' ;
28+ } else {
29+ command = 'npm' ;
30+ }
31+
32+ const child = spawn ( command , args , { stdio : 'inherit' } ) ;
33+ child . on ( 'close' , code => {
34+ if ( code !== 0 ) {
35+ reject ( {
36+ command : `${ command } ${ args . join ( ' ' ) } `
37+ } ) ;
38+ return ;
39+ }
40+ resolve ( ) ;
41+ } )
42+ } )
43+ }
844
945const build = ( appName ) => {
1046 cp ( '-r' , __dirname + '/../node_modules/rxapp/.' , appName ) ;
@@ -19,21 +55,27 @@ const build = (appName) => {
1955 console . log ( '----------------------------------------------------------' ) ;
2056 console . log ( chalk . green . bold ( 'Welcome to ReactXP' ) ) ;
2157 console . log ( '----------------------------------------------------------' ) ;
22- console . log ( chalk . white . bold ( 'Let\'s get started' ) ) ;
23- console . log ( chalk . green ( 'Step 1: cd into the newly created ' + appName + ' directory' ) ) ;
24- console . log ( chalk . green ( 'Step 2: install dependencies using yarn or npm' ) ) ;
25- console . log ( '----------------------------------------------------------' ) ;
26- console . log ( chalk . white . bold ( 'For Web' ) ) ;
27- console . log ( chalk . green ( 'Step 1. npm run web-watch' ) ) ;
28- console . log ( chalk . black . bold ( 'This compiles the TypeScript code and recompiles it whenever any files are changed.' ) )
29- console . log ( chalk . green ( 'Step 2. Open index.html in your browser to view the result.' ) ) ;
30- console . log ( '----------------------------------------------------------' ) ;
31- console . log ( chalk . white . bold ( 'For React Native' ) ) ;
32- console . log ( chalk . green ( 'Step 1. run npm run rn-watch' ) ) ;
33- console . log ( chalk . black . bold ( 'This compiles the TypeScript code and recompiles it whenever any files are changed.' ) ) ;
34- console . log ( chalk . green ( 'Step 2. run npm start' ) ) ;
35- console . log ( chalk . black . bold ( 'This starts the React Native Packager.' ) ) ;
36- console . log ( '----------------------------------------------------------' ) ;
58+ cd ( appName ) ;
59+ installPackages ( ) . then ( ( ) => {
60+ console . log ( chalk . white . bold ( 'Let\'s get started' ) ) ;
61+ console . log ( chalk . green ( 'Step 1: cd into the newly created ' + appName + ' directory' ) ) ;
62+ console . log ( '----------------------------------------------------------' ) ;
63+ console . log ( chalk . white . bold ( 'For Web' ) ) ;
64+ console . log ( chalk . green ( 'Step 1. npm run web-watch' ) ) ;
65+ console . log ( chalk . black . bold ( 'This compiles the TypeScript code and recompiles it whenever any files are changed.' ) )
66+ console . log ( chalk . green ( 'Step 2. Open index.html in your browser to view the result.' ) ) ;
67+ console . log ( '----------------------------------------------------------' ) ;
68+ console . log ( chalk . white . bold ( 'For React Native' ) ) ;
69+ console . log ( chalk . green ( 'Step 1. run npm run rn-watch' ) ) ;
70+ console . log ( chalk . black . bold ( 'This compiles the TypeScript code and recompiles it whenever any files are changed.' ) ) ;
71+ console . log ( chalk . green ( 'Step 2. run npm start' ) ) ;
72+ console . log ( chalk . black . bold ( 'This starts the React Native Packager.' ) ) ;
73+ console . log ( '----------------------------------------------------------' ) ;
74+ } )
75+ . catch ( error => {
76+ console . log ( chalk . red ( 'An unexpected error occurred' ) )
77+ console . log ( chalk . red ( error ) ) ;
78+ } ) ;
3779 } ) ;
3880}
3981
0 commit comments