@@ -17,6 +17,7 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
17
17
var ownPackageName = require ( path . join ( __dirname , '..' , 'package.json' ) ) . name ;
18
18
var ownPath = path . join ( appPath , 'node_modules' , ownPackageName ) ;
19
19
var appPackage = require ( path . join ( appPath , 'package.json' ) ) ;
20
+ var useYarn = pathExists . sync ( path . join ( appPath , 'yarn.lock' ) ) ;
20
21
21
22
// Copy over some of the devDependencies
22
23
appPackage . dependencies = appPackage . dependencies || { } ;
@@ -58,21 +59,31 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
58
59
}
59
60
} ) ;
60
61
61
- // Run another npm install for react and react-dom
62
- console . log ( 'Installing react and react-dom from npm...' ) ;
62
+ // Run yarn or npm for react and react-dom
63
+ // TODO: having to do two npm/yarn installs is bad, can we avoid it?
64
+ var command ;
65
+ var args ;
66
+
67
+ if ( useYarn ) {
68
+ command = 'yarn' ;
69
+ args = [ 'add' ] ;
70
+ } else {
71
+ command = 'npm' ;
72
+ args = [
73
+ 'install' ,
74
+ '--save' ,
75
+ verbose && '--verbose'
76
+ ] . filter ( function ( e ) { return e ; } ) ;
77
+ }
78
+ args . push ( 'react' , 'react-dom' ) ;
79
+
80
+ console . log ( 'Installing react and react-dom using ' + command + '...' ) ;
63
81
console . log ( ) ;
64
- // TODO: having to do two npm installs is bad, can we avoid it?
65
- var args = [
66
- 'install' ,
67
- 'react' ,
68
- 'react-dom' ,
69
- '--save' ,
70
- verbose && '--verbose'
71
- ] . filter ( function ( e ) { return e ; } ) ;
72
- var proc = spawn ( 'npm' , args , { stdio : 'inherit' } ) ;
82
+
83
+ var proc = spawn ( command , args , { stdio : 'inherit' } ) ;
73
84
proc . on ( 'close' , function ( code ) {
74
85
if ( code !== 0 ) {
75
- console . error ( '`npm ' + args . join ( ' ' ) + '` failed' ) ;
86
+ console . error ( '`' + command + ' ' + args . join ( ' ' ) + '` failed' ) ;
76
87
return ;
77
88
}
78
89
@@ -91,23 +102,23 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
91
102
console . log ( 'Success! Created ' + appName + ' at ' + appPath ) ;
92
103
console . log ( 'Inside that directory, you can run several commands:' ) ;
93
104
console . log ( ) ;
94
- console . log ( chalk . cyan ( ' npm start' ) ) ;
105
+ console . log ( chalk . cyan ( ' ' + command + ' start') ) ;
95
106
console . log ( ' Starts the development server.' ) ;
96
107
console . log ( ) ;
97
- console . log ( chalk . cyan ( ' npm run build' ) ) ;
108
+ console . log ( chalk . cyan ( ' ' + command + ' run build') ) ;
98
109
console . log ( ' Bundles the app into static files for production.' ) ;
99
110
console . log ( ) ;
100
- console . log ( chalk . cyan ( ' npm test' ) ) ;
111
+ console . log ( chalk . cyan ( ' ' + command + ' test') ) ;
101
112
console . log ( ' Starts the test runner.' ) ;
102
113
console . log ( ) ;
103
- console . log ( chalk . cyan ( ' npm run eject' ) ) ;
114
+ console . log ( chalk . cyan ( ' ' + command + ' run eject') ) ;
104
115
console . log ( ' Removes this tool and copies build dependencies, configuration files' ) ;
105
116
console . log ( ' and scripts into the app directory. If you do this, you can’t go back!' ) ;
106
117
console . log ( ) ;
107
118
console . log ( 'We suggest that you begin by typing:' ) ;
108
119
console . log ( ) ;
109
120
console . log ( chalk . cyan ( ' cd' ) , cdpath ) ;
110
- console . log ( ' ' + chalk . cyan ( 'npm start') ) ;
121
+ console . log ( ' ' + chalk . cyan ( command + ' start') ) ;
111
122
if ( readmeExists ) {
112
123
console . log ( ) ;
113
124
console . log ( chalk . yellow ( 'You had a `README.md` file, we renamed it to `README.old.md`' ) ) ;
0 commit comments