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) {
'init.js'
);
var init = require(scriptsPath);
init(root, appName);
init(root, appName, verbose);
});
}
......
......@@ -20,8 +20,7 @@ var files = [
'scripts',
'webpack.config.dev.js',
'webpack.config.prod.js',
'.babelrc',
'.eslintrc',
'.eslintrc'
];
// Ensure that the host folder is clean and we won't override any files
......
......@@ -9,8 +9,9 @@
var fs = require('fs');
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 hostPackage = require(path.join(hostPath, 'package.json'));
......@@ -34,21 +35,34 @@ module.exports = function(hostPath, appName) {
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
// TODO: copying might be more correct?
fs.renameSync(path.join(selfPath, 'src'), path.join(hostPath, 'src'));
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!');
// Run another npm install for react and react-dom
// TODO: having to do two npm installs is bad, can we avoid it?
var args = [
'install',
verbose && '--verbose'
].filter(function(e) { return e; });
var proc = spawn('npm', args, {stdio: 'inherit'});
proc.on('close', function (code) {
if (code !== 0) {
console.error('`npm ' + args.join(' ') + '` failed');
return;
}
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 = {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint-loader',
include: path.resolve(__dirname, relative, 'src')
loader: 'eslint',
include: path.resolve(__dirname, relative, 'src'),
}
],
loaders: [
{
test: /\.js$/,
include: path.resolve(__dirname, relative, 'src'),
loader: 'babel'
loader: 'babel',
query: {
cacheDirectory: true,
presets: ['es2015', 'es2016', 'react'],
plugins: ['transform-object-rest-spread']
}
},
{
test: /\.css$/,
......@@ -61,8 +66,11 @@ module.exports = {
}
]
},
postcss: function () {
return [ autoprefixer ];
eslint: {
configFile: path.join(__dirname, '.eslintrc')
},
postcss: function() {
return [autoprefixer];
},
plugins: [
// TODO: infer from package.json?
......
......@@ -30,7 +30,7 @@ module.exports = {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint-loader',
loader: 'eslint',
include: path.resolve(__dirname, relative, 'src')
}
],
......@@ -38,7 +38,14 @@ module.exports = {
{
test: /\.js$/,
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$/,
......@@ -59,8 +66,11 @@ module.exports = {
}
]
},
postcss: function () {
return [ autoprefixer ];
eslint: {
configFile: path.join(__dirname, '.eslintrc')
},
postcss: function() {
return [autoprefixer];
},
plugins: [
// 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