Skip to content

Commit

Permalink
Make the end to end install flow work :))
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeux committed Jul 18, 2016
1 parent 714971c commit 6987b80
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "create-react-app-scripts",
"version": "0.0.1",
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js"
"start": "node scripts/start.js local",
"build": "node scripts/build.js local"
},
"dependencies": {
"autoprefixer": "^6.3.7",
Expand Down
4 changes: 3 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ var spawnSync = require('child_process').spawnSync;
var webpack = require('webpack');
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) {
if (err) {
console.error(err);
Expand Down
10 changes: 7 additions & 3 deletions scripts/init.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var fs = require('fs');

module.exports = function(hostPath, appName) {
var selfPath = hostPath + '/node_modules/create-react-app-scripts';

Expand All @@ -11,14 +13,16 @@ module.exports = function(hostPath, appName) {

// Setup the script rules
hostPackage.scripts = {};
['start', 'build', 'publish-gh-pages'].forEach(function(command) {
hostPackage.scripts[command] = 'node node_modules/create-react-app-scripts/' + command + '.js';
['start', 'build'].forEach(function(command) {
hostPackage.scripts[command] = 'node node_modules/create-react-app-scripts/scripts/' + command + '.js';
});

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
fs.renameSync(selfPackage + '/src', hostPackage + '/src');
fs.renameSync(selfPath + '/src', hostPath + '/src');

console.log('Creating the app', appName, 'at', hostPath);
};
10 changes: 6 additions & 4 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

var relative = process.argv[2] === 'local' ? '.' : '../..';

module.exports = {
devtool: 'eval',
entry: [
Expand All @@ -11,7 +13,7 @@ module.exports = {
],
output: {
// 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',
publicPath: '/'
},
Expand All @@ -20,18 +22,18 @@ module.exports = {
{
test: /\.js$/,
loader: 'eslint-loader',
include: path.resolve(__dirname, 'src')
include: path.resolve(__dirname, relative, 'src')
}
],
loaders: [
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
include: path.resolve(__dirname, relative, 'src'),
loader: 'babel'
},
{
test: /\.css$/,
include: path.resolve(__dirname, 'src'),
include: path.resolve(__dirname, relative, 'src'),
loader: 'style!css!postcss'
},
{
Expand Down
10 changes: 6 additions & 4 deletions webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

var relative = process.argv[2] === 'local' ? '.' : '../..';

module.exports = {
devtool: 'source-map',
entry: './src/index.js',
output: {
path: path.join(__dirname, 'build'),
path: path.resolve(__dirname, relative, 'build'),
filename: '[name].[hash].js',
// TODO: this wouldn't work for e.g. GH Pages.
// Good news: we can infer it from package.json :-)
Expand All @@ -18,18 +20,18 @@ module.exports = {
{
test: /\.js$/,
loader: 'eslint-loader',
include: path.resolve(__dirname, 'src')
include: path.resolve(__dirname, relative, 'src')
}
],
loaders: [
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
include: path.resolve(__dirname, relative, 'src'),
loader: 'babel'
},
{
test: /\.css$/,
include: path.resolve(__dirname, 'src'),
include: path.resolve(__dirname, relative, 'src'),
loader: 'style!css!postcss'
},
{
Expand Down

0 comments on commit 6987b80

Please sign in to comment.