@@ -13,24 +13,24 @@ var path = require('path');
13
13
var prompt = require ( 'react-dev-utils/prompt' ) ;
14
14
var rimrafSync = require ( 'rimraf' ) . sync ;
15
15
var spawnSync = require ( 'cross-spawn' ) . sync ;
16
+ var chalk = require ( 'chalk' ) ;
17
+ var green = chalk . green ;
18
+ var cyan = chalk . cyan ;
16
19
17
20
prompt (
18
21
'Are you sure you want to eject? This action is permanent.' ,
19
22
false
20
23
) . then ( shouldEject => {
21
24
if ( ! shouldEject ) {
22
- console . log ( 'Close one! Eject aborted.' ) ;
25
+ console . log ( cyan ( 'Close one! Eject aborted.' ) ) ;
23
26
process . exit ( 1 ) ;
24
27
}
25
28
26
29
console . log ( 'Ejecting...' ) ;
27
- console . log ( ) ;
28
30
29
31
var ownPath = path . join ( __dirname , '..' ) ;
30
32
var appPath = path . join ( ownPath , '..' , '..' ) ;
31
33
var files = [
32
- '.babelrc' ,
33
- '.eslintrc' ,
34
34
path . join ( 'config' , 'env.js' ) ,
35
35
path . join ( 'config' , 'paths.js' ) ,
36
36
path . join ( 'config' , 'polyfills.js' ) ,
@@ -61,8 +61,10 @@ prompt(
61
61
fs . mkdirSync ( path . join ( appPath , 'config' , 'jest' ) ) ;
62
62
fs . mkdirSync ( path . join ( appPath , 'scripts' ) ) ;
63
63
64
+ console . log ( ) ;
65
+ console . log ( 'Copying files to ' + cyan ( appPath ) ) ;
64
66
files . forEach ( function ( file ) {
65
- console . log ( 'Copying ' + file + ' to ' + appPath ) ;
67
+ console . log ( ' Copying ' + cyan ( file ) ) ;
66
68
var content = fs
67
69
. readFileSync ( path . join ( ownPath , file ) , 'utf8' )
68
70
// Remove dead code from .js files on eject
@@ -76,48 +78,68 @@ prompt(
76
78
77
79
var ownPackage = require ( path . join ( ownPath , 'package.json' ) ) ;
78
80
var appPackage = require ( path . join ( appPath , 'package.json' ) ) ;
81
+ var babelConfig = JSON . parse ( fs . readFileSync ( path . join ( ownPath , '.babelrc' ) , 'utf8' ) ) ;
82
+ var eslintConfig = JSON . parse ( fs . readFileSync ( path . join ( ownPath , '.eslintrc' ) , 'utf8' ) ) ;
79
83
84
+ console . log ( cyan ( 'Updating dependencies...' ) ) ;
80
85
var ownPackageName = ownPackage . name ;
81
- console . log ( 'Removing dependency: ' + ownPackageName ) ;
86
+ console . log ( ' Removing dependency: ' + cyan ( ownPackageName ) ) ;
82
87
delete appPackage . devDependencies [ ownPackageName ] ;
83
88
84
89
Object . keys ( ownPackage . dependencies ) . forEach ( function ( key ) {
85
90
// For some reason optionalDependencies end up in dependencies after install
86
91
if ( ownPackage . optionalDependencies [ key ] ) {
87
92
return ;
88
93
}
89
- console . log ( 'Adding dependency: ' + key ) ;
94
+ console . log ( ' Adding dependency: ' + cyan ( key ) ) ;
90
95
appPackage . devDependencies [ key ] = ownPackage . dependencies [ key ] ;
91
96
} ) ;
92
-
93
- console . log ( 'Updating scripts' ) ;
97
+ console . log ( ) ;
98
+ console . log ( cyan ( 'Updating scripts...' ) ) ;
94
99
delete appPackage . scripts [ 'eject' ] ;
95
100
Object . keys ( appPackage . scripts ) . forEach ( function ( key ) {
96
101
appPackage . scripts [ key ] = appPackage . scripts [ key ]
97
102
. replace ( / r e a c t - s c r i p t s ( \w + ) / g, 'node scripts/$1.js' ) ;
103
+ console . log (
104
+ ' Replacing ' +
105
+ cyan ( '\"react-scripts ' + key + '\"' ) +
106
+ ' with ' +
107
+ cyan ( '\"' + appPackage . scripts [ key ] + '\"' )
108
+ ) ;
98
109
} ) ;
99
110
111
+ console . log ( ) ;
112
+ console . log ( cyan ( 'Adding configuration to ' ) + 'package.json' + cyan ( '...' ) ) ;
100
113
// Add Jest config
114
+ console . log ( ' Adding ' + cyan ( 'Jest' ) + ' configuration' ) ;
101
115
appPackage . jest = createJestConfig (
102
116
filePath => path . join ( '<rootDir>' , filePath ) ,
103
117
null ,
104
118
true
105
119
) ;
106
120
107
- console . log ( 'Writing package.json' ) ;
121
+ // Add Babel config
122
+
123
+ console . log ( ' Adding ' + cyan ( 'Babel' ) + ' preset' ) ;
124
+ appPackage . babel = babelConfig ;
125
+
126
+ // Add ESlint config
127
+ console . log ( ' Adding ' + cyan ( 'ESLint' ) + ' configuration' ) ;
128
+ appPackage . eslintConfig = eslintConfig ;
129
+
108
130
fs . writeFileSync (
109
131
path . join ( appPath , 'package.json' ) ,
110
132
JSON . stringify ( appPackage , null , 2 )
111
133
) ;
112
134
console . log ( ) ;
113
135
114
- console . log ( 'Running npm install...' ) ;
136
+ console . log ( cyan ( 'Running npm install...' ) ) ;
115
137
rimrafSync ( ownPath ) ;
116
138
spawnSync ( 'npm' , [ 'install' ] , { stdio : 'inherit' } ) ;
117
- console . log ( 'Ejected successfully!' ) ;
139
+ console . log ( green ( 'Ejected successfully!' ) ) ;
118
140
console . log ( ) ;
119
141
120
- console . log ( 'Please consider sharing why you ejected in this survey:' ) ;
121
- console . log ( ' http://goo.gl/forms/Bi6CZjk1EqsdelXk1' ) ;
122
- console . log ( ) ;
123
- } ) ;
142
+ console . log ( green ( 'Please consider sharing why you ejected in this survey:' ) ) ;
143
+ console . log ( green ( ' http://goo.gl/forms/Bi6CZjk1EqsdelXk1' ) ) ;
144
+ console . log ( )
145
+ } )
0 commit comments