@@ -17,6 +17,7 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
1717 var ownPackageName = require ( path . join ( __dirname , '..' , 'package.json' ) ) . name ;
1818 var ownPath = path . join ( appPath , 'node_modules' , ownPackageName ) ;
1919 var appPackage = require ( path . join ( appPath , 'package.json' ) ) ;
20+ var useYarn = pathExists . sync ( path . join ( appPath , 'yarn.lock' ) ) ;
2021
2122 // Copy over some of the devDependencies
2223 appPackage . dependencies = appPackage . dependencies || { } ;
@@ -58,21 +59,31 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
5859 }
5960 } ) ;
6061
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 + '...' ) ;
6381 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' } ) ;
7384 proc . on ( 'close' , function ( code ) {
7485 if ( code !== 0 ) {
75- console . error ( '`npm ' + args . join ( ' ' ) + '` failed' ) ;
86+ console . error ( '`' + command + ' ' + args . join ( ' ' ) + '` failed' ) ;
7687 return ;
7788 }
7889
@@ -91,23 +102,23 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
91102 console . log ( 'Success! Created ' + appName + ' at ' + appPath ) ;
92103 console . log ( 'Inside that directory, you can run several commands:' ) ;
93104 console . log ( ) ;
94- console . log ( chalk . cyan ( ' npm start' ) ) ;
105+ console . log ( chalk . cyan ( ' ' + command + ' start') ) ;
95106 console . log ( ' Starts the development server.' ) ;
96107 console . log ( ) ;
97- console . log ( chalk . cyan ( ' npm run build' ) ) ;
108+ console . log ( chalk . cyan ( ' ' + command + ' run build') ) ;
98109 console . log ( ' Bundles the app into static files for production.' ) ;
99110 console . log ( ) ;
100- console . log ( chalk . cyan ( ' npm test' ) ) ;
111+ console . log ( chalk . cyan ( ' ' + command + ' test') ) ;
101112 console . log ( ' Starts the test runner.' ) ;
102113 console . log ( ) ;
103- console . log ( chalk . cyan ( ' npm run eject' ) ) ;
114+ console . log ( chalk . cyan ( ' ' + command + ' run eject') ) ;
104115 console . log ( ' Removes this tool and copies build dependencies, configuration files' ) ;
105116 console . log ( ' and scripts into the app directory. If you do this, you can’t go back!' ) ;
106117 console . log ( ) ;
107118 console . log ( 'We suggest that you begin by typing:' ) ;
108119 console . log ( ) ;
109120 console . log ( chalk . cyan ( ' cd' ) , cdpath ) ;
110- console . log ( ' ' + chalk . cyan ( 'npm start') ) ;
121+ console . log ( ' ' + chalk . cyan ( command + ' start') ) ;
111122 if ( readmeExists ) {
112123 console . log ( ) ;
113124 console . log ( chalk . yellow ( 'You had a `README.md` file, we renamed it to `README.old.md`' ) ) ;
0 commit comments