Commit cb0ada7a authored by Dan Abramov's avatar Dan Abramov Committed by Christopher Chedeau
Browse files

Make it work outside its own directory

parent 2987cc69
No related merge requests found
Showing with 58 additions and 40 deletions
+58 -40
{
"presets": ["es2015", "es2016", "react"],
"plugins": ["transform-object-rest-spread"],
"env": {
"production": {
"plugins": [
"transform-react-constant-elements",
"transform-react-inline-elements"
]
}
}
}
...@@ -121,7 +121,7 @@ function run(root, appName, version, verbose) { ...@@ -121,7 +121,7 @@ function run(root, appName, version, verbose) {
'init.js' 'init.js'
); );
var init = require(scriptsPath); var init = require(scriptsPath);
init(root, appName); init(root, appName, verbose);
}); });
} }
......
...@@ -20,8 +20,7 @@ var files = [ ...@@ -20,8 +20,7 @@ var files = [
'scripts', 'scripts',
'webpack.config.dev.js', 'webpack.config.dev.js',
'webpack.config.prod.js', 'webpack.config.prod.js',
'.babelrc', '.eslintrc'
'.eslintrc',
]; ];
// Ensure that the host folder is clean and we won't override any files // Ensure that the host folder is clean and we won't override any files
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var spawn = require('child_process').spawn;
module.exports = function(hostPath, appName) { module.exports = function(hostPath, appName, verbose) {
var selfPath = path.join(hostPath, 'node_modules', 'create-react-app-scripts'); var selfPath = path.join(hostPath, 'node_modules', 'create-react-app-scripts');
var hostPackage = require(path.join(hostPath, 'package.json')); var hostPackage = require(path.join(hostPath, 'package.json'));
...@@ -34,21 +35,34 @@ module.exports = function(hostPath, appName) { ...@@ -34,21 +35,34 @@ module.exports = function(hostPath, appName) {
JSON.stringify(hostPackage, null, 2) JSON.stringify(hostPackage, null, 2)
); );
// TODO: run npm install in hostPath, (not needed for npm 3 if we accept some hackery)
// Move the src folder // Move the src folder
// TODO: copying might be more correct?
fs.renameSync(path.join(selfPath, 'src'), path.join(hostPath, 'src')); fs.renameSync(path.join(selfPath, 'src'), path.join(hostPath, 'src'));
console.log('Success! Created ' + appName + ' at ' + hostPath + '.'); // Run another npm install for react and react-dom
console.log(); // TODO: having to do two npm installs is bad, can we avoid it?
console.log('Inside that directory, you can run several commands:'); var args = [
console.log(' * npm start: Starts the development server.'); 'install',
console.log(' * npm run build: Builds the app for production.'); verbose && '--verbose'
console.log(' * npm run graduate: Removes this tool. If you do this, you can’t go back!'); ].filter(function(e) { return e; });
console.log(); var proc = spawn('npm', args, {stdio: 'inherit'});
console.log('We suggest that you begin by typing:'); proc.on('close', function (code) {
console.log(' cd', appName); if (code !== 0) {
console.log(' npm start'); console.error('`npm ' + args.join(' ') + '` failed');
console.log(); return;
console.log('Happy hacking!'); }
console.log('Success! Created ' + appName + ' at ' + hostPath + '.');
console.log();
console.log('Inside that directory, you can run several commands:');
console.log(' * npm start: Starts the development server.');
console.log(' * npm run build: Builds the app for production.');
console.log(' * npm run graduate: Removes this tool. If you do this, you can’t go back!');
console.log();
console.log('We suggest that you begin by typing:');
console.log(' cd', appName);
console.log(' npm start');
console.log();
console.log('Happy hacking!');
});
}; };
...@@ -32,15 +32,20 @@ module.exports = { ...@@ -32,15 +32,20 @@ module.exports = {
preLoaders: [ preLoaders: [
{ {
test: /\.js$/, test: /\.js$/,
loader: 'eslint-loader', loader: 'eslint',
include: path.resolve(__dirname, relative, 'src') include: path.resolve(__dirname, relative, 'src'),
} }
], ],
loaders: [ loaders: [
{ {
test: /\.js$/, test: /\.js$/,
include: path.resolve(__dirname, relative, 'src'), include: path.resolve(__dirname, relative, 'src'),
loader: 'babel' loader: 'babel',
query: {
cacheDirectory: true,
presets: ['es2015', 'es2016', 'react'],
plugins: ['transform-object-rest-spread']
}
}, },
{ {
test: /\.css$/, test: /\.css$/,
...@@ -61,8 +66,11 @@ module.exports = { ...@@ -61,8 +66,11 @@ module.exports = {
} }
] ]
}, },
postcss: function () { eslint: {
return [ autoprefixer ]; configFile: path.join(__dirname, '.eslintrc')
},
postcss: function() {
return [autoprefixer];
}, },
plugins: [ plugins: [
// TODO: infer from package.json? // TODO: infer from package.json?
......
...@@ -30,7 +30,7 @@ module.exports = { ...@@ -30,7 +30,7 @@ module.exports = {
preLoaders: [ preLoaders: [
{ {
test: /\.js$/, test: /\.js$/,
loader: 'eslint-loader', loader: 'eslint',
include: path.resolve(__dirname, relative, 'src') include: path.resolve(__dirname, relative, 'src')
} }
], ],
...@@ -38,7 +38,14 @@ module.exports = { ...@@ -38,7 +38,14 @@ module.exports = {
{ {
test: /\.js$/, test: /\.js$/,
include: path.resolve(__dirname, relative, 'src'), include: path.resolve(__dirname, relative, 'src'),
loader: 'babel' loader: 'babel',
query: {
presets: ['es2015', 'es2016', 'react'],
plugins: [
'transform-object-rest-spread',
'transform-react-constant-elements'
]
}
}, },
{ {
test: /\.css$/, test: /\.css$/,
...@@ -59,8 +66,11 @@ module.exports = { ...@@ -59,8 +66,11 @@ module.exports = {
} }
] ]
}, },
postcss: function () { eslint: {
return [ autoprefixer ]; configFile: path.join(__dirname, '.eslintrc')
},
postcss: function() {
return [autoprefixer];
}, },
plugins: [ plugins: [
// TODO: infer from package.json? // TODO: infer from package.json?
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment