@@ -6,6 +6,7 @@ import path from 'path';
6
6
import pathExists from 'path-exists' ;
7
7
import spawn from 'cross-spawn' ;
8
8
import log from '../util/log' ;
9
+ import install from '../util/install' ;
9
10
10
11
// UPDATE DEPENDENCY VERSIONS HERE
11
12
const DEFAULT_DEPENDENCIES = {
@@ -24,6 +25,7 @@ module.exports = async (appPath: string, appName: string, verbose: boolean, cwd:
24
25
const ownPackageName : string = require ( '../../package.json' ) . name ;
25
26
const ownPath : string = path . join ( appPath , 'node_modules' , ownPackageName ) ;
26
27
const useYarn : boolean = await pathExists ( path . join ( appPath , 'yarn.lock' ) ) ;
28
+ const npmOrYarn = useYarn ? 'yarn' : 'npm' ;
27
29
28
30
// FIXME(perry) remove when npm 5 is supported
29
31
if ( ! useYarn ) {
@@ -107,44 +109,24 @@ https://github.com/npm/npm/issues/16991
107
109
throw err ;
108
110
}
109
111
}
112
+ const { code, command, args } = await install ( appPath ) ;
113
+ if ( code !== 0 ) {
114
+ console . error ( 'Failed to install' ) ;
115
+ // console.error(`\`${command} ${args.join(' ')}\` failed`);
116
+ return ;
117
+ }
110
118
111
- // Run yarn or npm
112
- let command = '' ;
113
- let args = [ ] ;
114
-
115
- if ( useYarn ) {
116
- command = 'yarnpkg' ;
119
+ // display the cleanest way to get to the app dir
120
+ // if the cwd + appName is equal to the full path, then just cd into appName
121
+ let cdpath ;
122
+ if ( path . resolve ( cwd , appName ) === appPath ) {
123
+ cdpath = appName ;
117
124
} else {
118
- command = 'npm' ;
119
- args = [ 'install' , '--save' ] ;
120
-
121
- if ( verbose ) {
122
- args . push ( '--verbose' ) ;
123
- }
125
+ cdpath = appPath ;
124
126
}
125
127
126
- const npmOrYarn = useYarn ? 'yarn' : 'npm' ;
127
- log ( `Installing dependencies using ${ npmOrYarn } ...` ) ;
128
- log ( ) ; // why is this here
129
-
130
- const proc = spawn ( command , args , { stdio : 'inherit' } ) ;
131
- proc . on ( 'close' , code => {
132
- if ( code !== 0 ) {
133
- console . error ( `\`${ command } ${ args . join ( ' ' ) } \` failed` ) ;
134
- return ;
135
- }
136
-
137
- // display the cleanest way to get to the app dir
138
- // if the cwd + appName is equal to the full path, then just cd into appName
139
- let cdpath ;
140
- if ( path . resolve ( cwd , appName ) === appPath ) {
141
- cdpath = appName ;
142
- } else {
143
- cdpath = appPath ;
144
- }
145
-
146
- log (
147
- `
128
+ log (
129
+ `
148
130
149
131
Success! Created ${ appName } at ${ appPath }
150
132
Inside that directory, you can run several commands:
@@ -173,16 +155,15 @@ We suggest that you begin by typing:
173
155
174
156
${ chalk . cyan ( 'cd ' + cdpath ) }
175
157
${ chalk . cyan ( npmOrYarn + ' start' ) } `
176
- ) ;
158
+ ) ;
177
159
178
- if ( readmeExists ) {
179
- log (
180
- `
160
+ if ( readmeExists ) {
161
+ log (
162
+ `
181
163
${ chalk . yellow ( 'You had a `README.md` file, we renamed it to `README.old.md`' ) } `
182
- ) ;
183
- }
164
+ ) ;
165
+ }
184
166
185
- log ( ) ;
186
- log ( 'Happy hacking!' ) ;
187
- } ) ;
167
+ log ( ) ;
168
+ log ( 'Happy hacking!' ) ;
188
169
} ;
0 commit comments