Make the end to end install flow work :))

This commit is contained in:
Christopher Chedeau
2016-07-15 15:19:55 -07:00
parent 714971cccc
commit 6987b80937
5 changed files with 24 additions and 14 deletions

View File

@@ -2,8 +2,8 @@
"name": "create-react-app-scripts", "name": "create-react-app-scripts",
"version": "0.0.1", "version": "0.0.1",
"scripts": { "scripts": {
"start": "node scripts/start.js", "start": "node scripts/start.js local",
"build": "node scripts/build.js" "build": "node scripts/build.js local"
}, },
"dependencies": { "dependencies": {
"autoprefixer": "^6.3.7", "autoprefixer": "^6.3.7",

View File

@@ -4,7 +4,9 @@ var spawnSync = require('child_process').spawnSync;
var webpack = require('webpack'); var webpack = require('webpack');
var config = require('../webpack.config.prod'); var config = require('../webpack.config.prod');
spawnSync('rm', ['-rf', 'build']); var relative = process.argv[2] === 'local' ? '.' : '../..';
spawnSync('rm', ['-rf', relative + '/build']);
webpack(config).run(function(err, stats) { webpack(config).run(function(err, stats) {
if (err) { if (err) {
console.error(err); console.error(err);

View File

@@ -1,3 +1,5 @@
var fs = require('fs');
module.exports = function(hostPath, appName) { module.exports = function(hostPath, appName) {
var selfPath = hostPath + '/node_modules/create-react-app-scripts'; var selfPath = hostPath + '/node_modules/create-react-app-scripts';
@@ -11,14 +13,16 @@ module.exports = function(hostPath, appName) {
// Setup the script rules // Setup the script rules
hostPackage.scripts = {}; hostPackage.scripts = {};
['start', 'build', 'publish-gh-pages'].forEach(function(command) { ['start', 'build'].forEach(function(command) {
hostPackage.scripts[command] = 'node node_modules/create-react-app-scripts/' + command + '.js'; hostPackage.scripts[command] = 'node node_modules/create-react-app-scripts/scripts/' + command + '.js';
}); });
fs.writeFileSync(hostPath + '/package.json', JSON.stringify(hostPackage, null, 2)); fs.writeFileSync(hostPath + '/package.json', 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
fs.renameSync(selfPackage + '/src', hostPackage + '/src'); fs.renameSync(selfPath + '/src', hostPath + '/src');
console.log('Creating the app', appName, 'at', hostPath); console.log('Creating the app', appName, 'at', hostPath);
}; };

View File

@@ -3,6 +3,8 @@ var autoprefixer = require('autoprefixer');
var webpack = require('webpack'); var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin'); var HtmlWebpackPlugin = require('html-webpack-plugin');
var relative = process.argv[2] === 'local' ? '.' : '../..';
module.exports = { module.exports = {
devtool: 'eval', devtool: 'eval',
entry: [ entry: [
@@ -11,7 +13,7 @@ module.exports = {
], ],
output: { output: {
// Next line is not used in dev but WebpackDevServer crashes without it: // Next line is not used in dev but WebpackDevServer crashes without it:
path: path.join(__dirname, 'build'), path: path.join(__dirname, relative, 'build'),
filename: 'bundle.js', filename: 'bundle.js',
publicPath: '/' publicPath: '/'
}, },
@@ -20,18 +22,18 @@ module.exports = {
{ {
test: /\.js$/, test: /\.js$/,
loader: 'eslint-loader', loader: 'eslint-loader',
include: path.resolve(__dirname, 'src') include: path.resolve(__dirname, relative, 'src')
} }
], ],
loaders: [ loaders: [
{ {
test: /\.js$/, test: /\.js$/,
include: path.resolve(__dirname, 'src'), include: path.resolve(__dirname, relative, 'src'),
loader: 'babel' loader: 'babel'
}, },
{ {
test: /\.css$/, test: /\.css$/,
include: path.resolve(__dirname, 'src'), include: path.resolve(__dirname, relative, 'src'),
loader: 'style!css!postcss' loader: 'style!css!postcss'
}, },
{ {

View File

@@ -3,11 +3,13 @@ var autoprefixer = require('autoprefixer');
var webpack = require('webpack'); var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin'); var HtmlWebpackPlugin = require('html-webpack-plugin');
var relative = process.argv[2] === 'local' ? '.' : '../..';
module.exports = { module.exports = {
devtool: 'source-map', devtool: 'source-map',
entry: './src/index.js', entry: './src/index.js',
output: { output: {
path: path.join(__dirname, 'build'), path: path.resolve(__dirname, relative, 'build'),
filename: '[name].[hash].js', filename: '[name].[hash].js',
// TODO: this wouldn't work for e.g. GH Pages. // TODO: this wouldn't work for e.g. GH Pages.
// Good news: we can infer it from package.json :-) // Good news: we can infer it from package.json :-)
@@ -18,18 +20,18 @@ module.exports = {
{ {
test: /\.js$/, test: /\.js$/,
loader: 'eslint-loader', loader: 'eslint-loader',
include: path.resolve(__dirname, 'src') include: path.resolve(__dirname, relative, 'src')
} }
], ],
loaders: [ loaders: [
{ {
test: /\.js$/, test: /\.js$/,
include: path.resolve(__dirname, 'src'), include: path.resolve(__dirname, relative, 'src'),
loader: 'babel' loader: 'babel'
}, },
{ {
test: /\.css$/, test: /\.css$/,
include: path.resolve(__dirname, 'src'), include: path.resolve(__dirname, relative, 'src'),
loader: 'style!css!postcss' loader: 'style!css!postcss'
}, },
{ {