Skip to content

Commit ba0129f

Browse files
committed
Make the end to end install flow work :))
1 parent 96aae93 commit ba0129f

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "create-react-app-scripts",
33
"version": "0.0.1",
44
"scripts": {
5-
"start": "node scripts/start.js",
6-
"build": "node scripts/build.js"
5+
"start": "node scripts/start.js local",
6+
"build": "node scripts/build.js local"
77
},
88
"dependencies": {
99
"autoprefixer": "^6.3.7",

scripts/build.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ var spawnSync = require('child_process').spawnSync;
44
var webpack = require('webpack');
55
var config = require('../webpack.config.prod');
66

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

scripts/init.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var fs = require('fs');
2+
13
module.exports = function(hostPath, appName) {
24
var selfPath = hostPath + '/node_modules/create-react-app-scripts';
35

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

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

1820
fs.writeFileSync(hostPath + '/package.json', JSON.stringify(hostPackage, null, 2));
1921

22+
// TODO: run npm install in hostPath, (not needed for npm 3 if we accept some hackery)
23+
2024
// Move the src folder
21-
fs.renameSync(selfPackage + '/src', hostPackage + '/src');
25+
fs.renameSync(selfPath + '/src', hostPath + '/src');
2226

2327
console.log('Creating the app', appName, 'at', hostPath);
2428
};

webpack.config.dev.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var autoprefixer = require('autoprefixer');
33
var webpack = require('webpack');
44
var HtmlWebpackPlugin = require('html-webpack-plugin');
55

6+
var relative = process.argv[2] === 'local' ? '.' : '../..';
7+
68
module.exports = {
79
devtool: 'eval',
810
entry: [
@@ -11,7 +13,7 @@ module.exports = {
1113
],
1214
output: {
1315
// Next line is not used in dev but WebpackDevServer crashes without it:
14-
path: path.join(__dirname, 'build'),
16+
path: path.join(__dirname, relative, 'build'),
1517
filename: 'bundle.js',
1618
publicPath: '/'
1719
},
@@ -20,18 +22,18 @@ module.exports = {
2022
{
2123
test: /\.js$/,
2224
loader: 'eslint-loader',
23-
include: path.resolve(__dirname, 'src')
25+
include: path.resolve(__dirname, relative, 'src')
2426
}
2527
],
2628
loaders: [
2729
{
2830
test: /\.js$/,
29-
include: path.resolve(__dirname, 'src'),
31+
include: path.resolve(__dirname, relative, 'src'),
3032
loader: 'babel'
3133
},
3234
{
3335
test: /\.css$/,
34-
include: path.resolve(__dirname, 'src'),
36+
include: path.resolve(__dirname, relative, 'src'),
3537
loader: 'style!css!postcss'
3638
},
3739
{

webpack.config.prod.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ var autoprefixer = require('autoprefixer');
33
var webpack = require('webpack');
44
var HtmlWebpackPlugin = require('html-webpack-plugin');
55

6+
var relative = process.argv[2] === 'local' ? '.' : '../..';
7+
68
module.exports = {
79
devtool: 'source-map',
810
entry: './src/index.js',
911
output: {
10-
path: path.join(__dirname, 'build'),
12+
path: path.resolve(__dirname, relative, 'build'),
1113
filename: '[name].[hash].js',
1214
// TODO: this wouldn't work for e.g. GH Pages.
1315
// Good news: we can infer it from package.json :-)
@@ -18,18 +20,18 @@ module.exports = {
1820
{
1921
test: /\.js$/,
2022
loader: 'eslint-loader',
21-
include: path.resolve(__dirname, 'src')
23+
include: path.resolve(__dirname, relative, 'src')
2224
}
2325
],
2426
loaders: [
2527
{
2628
test: /\.js$/,
27-
include: path.resolve(__dirname, 'src'),
29+
include: path.resolve(__dirname, relative, 'src'),
2830
loader: 'babel'
2931
},
3032
{
3133
test: /\.css$/,
32-
include: path.resolve(__dirname, 'src'),
34+
include: path.resolve(__dirname, relative, 'src'),
3335
loader: 'style!css!postcss'
3436
},
3537
{

0 commit comments

Comments
 (0)