Skip to content

Commit 9518bd4

Browse files
committed
Make it work outside its own directory
1 parent d592a6d commit 9518bd4

File tree

7 files changed

+58
-40
lines changed

7 files changed

+58
-40
lines changed

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

global-cli/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function run(root, appName, version, verbose) {
121121
'init.js'
122122
);
123123
var init = require(scriptsPath);
124-
init(root, appName);
124+
init(root, appName, verbose);
125125
});
126126
}
127127

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"babel-loader": "^6.2.4",
1818
"babel-plugin-transform-object-rest-spread": "^6.8.0",
1919
"babel-plugin-transform-react-constant-elements": "^6.9.1",
20-
"babel-plugin-transform-react-inline-elements": "^6.8.0",
2120
"babel-preset-es2015": "^6.9.0",
2221
"babel-preset-es2016": "^6.11.3",
2322
"babel-preset-react": "^6.11.1",

scripts/graduate.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ var files = [
2020
'scripts',
2121
'webpack.config.dev.js',
2222
'webpack.config.prod.js',
23-
'.babelrc',
24-
'.eslintrc',
23+
'.eslintrc'
2524
];
2625

2726
// Ensure that the host folder is clean and we won't override any files

scripts/init.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
var fs = require('fs');
1111
var path = require('path');
12+
var spawn = require('child_process').spawn;
1213

13-
module.exports = function(hostPath, appName) {
14+
module.exports = function(hostPath, appName, verbose) {
1415
var selfPath = path.join(hostPath, 'node_modules', 'create-react-app-scripts');
1516

1617
var hostPackage = require(path.join(hostPath, 'package.json'));
@@ -34,21 +35,34 @@ module.exports = function(hostPath, appName) {
3435
JSON.stringify(hostPackage, null, 2)
3536
);
3637

37-
// TODO: run npm install in hostPath, (not needed for npm 3 if we accept some hackery)
38-
3938
// Move the src folder
39+
// TODO: copying might be more correct?
4040
fs.renameSync(path.join(selfPath, 'src'), path.join(hostPath, 'src'));
4141

42-
console.log('Success! Created ' + appName + ' at ' + hostPath + '.');
43-
console.log();
44-
console.log('Inside that directory, you can run several commands:');
45-
console.log(' * npm start: Starts the development server.');
46-
console.log(' * npm run build: Builds the app for production.');
47-
console.log(' * npm run graduate: Removes this tool. If you do this, you can’t go back!');
48-
console.log();
49-
console.log('We suggest that you begin by typing:');
50-
console.log(' cd', appName);
51-
console.log(' npm start');
52-
console.log();
53-
console.log('Happy hacking!');
42+
// Run another npm install for react and react-dom
43+
// TODO: having to do two npm installs is bad, can we avoid it?
44+
var args = [
45+
'install',
46+
verbose && '--verbose'
47+
].filter(function(e) { return e; });
48+
var proc = spawn('npm', args, {stdio: 'inherit'});
49+
proc.on('close', function (code) {
50+
if (code !== 0) {
51+
console.error('`npm ' + args.join(' ') + '` failed');
52+
return;
53+
}
54+
55+
console.log('Success! Created ' + appName + ' at ' + hostPath + '.');
56+
console.log();
57+
console.log('Inside that directory, you can run several commands:');
58+
console.log(' * npm start: Starts the development server.');
59+
console.log(' * npm run build: Builds the app for production.');
60+
console.log(' * npm run graduate: Removes this tool. If you do this, you can’t go back!');
61+
console.log();
62+
console.log('We suggest that you begin by typing:');
63+
console.log(' cd', appName);
64+
console.log(' npm start');
65+
console.log();
66+
console.log('Happy hacking!');
67+
});
5468
};

webpack.config.dev.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ module.exports = {
3232
preLoaders: [
3333
{
3434
test: /\.js$/,
35-
loader: 'eslint-loader',
36-
include: path.resolve(__dirname, relative, 'src')
35+
loader: 'eslint',
36+
include: path.resolve(__dirname, relative, 'src'),
3737
}
3838
],
3939
loaders: [
4040
{
4141
test: /\.js$/,
4242
include: path.resolve(__dirname, relative, 'src'),
43-
loader: 'babel'
43+
loader: 'babel',
44+
query: {
45+
cacheDirectory: true,
46+
presets: ['es2015', 'es2016', 'react'],
47+
plugins: ['transform-object-rest-spread']
48+
}
4449
},
4550
{
4651
test: /\.css$/,
@@ -61,8 +66,11 @@ module.exports = {
6166
}
6267
]
6368
},
64-
postcss: function () {
65-
return [ autoprefixer ];
69+
eslint: {
70+
configFile: path.join(__dirname, '.eslintrc')
71+
},
72+
postcss: function() {
73+
return [autoprefixer];
6674
},
6775
plugins: [
6876
// TODO: infer from package.json?

webpack.config.prod.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,22 @@ module.exports = {
3030
preLoaders: [
3131
{
3232
test: /\.js$/,
33-
loader: 'eslint-loader',
33+
loader: 'eslint',
3434
include: path.resolve(__dirname, relative, 'src')
3535
}
3636
],
3737
loaders: [
3838
{
3939
test: /\.js$/,
4040
include: path.resolve(__dirname, relative, 'src'),
41-
loader: 'babel'
41+
loader: 'babel',
42+
query: {
43+
presets: ['es2015', 'es2016', 'react'],
44+
plugins: [
45+
'transform-object-rest-spread',
46+
'transform-react-constant-elements'
47+
]
48+
}
4249
},
4350
{
4451
test: /\.css$/,
@@ -59,8 +66,11 @@ module.exports = {
5966
}
6067
]
6168
},
62-
postcss: function () {
63-
return [ autoprefixer ];
69+
eslint: {
70+
configFile: path.join(__dirname, '.eslintrc')
71+
},
72+
postcss: function() {
73+
return [autoprefixer];
6474
},
6575
plugins: [
6676
// TODO: infer from package.json?

0 commit comments

Comments
 (0)