Skip to content

Commit 88be11b

Browse files
authored
Merge pull request #27 from combine/feature/cross-platform-support
Feature/cross platform support
2 parents 3ad0aec + 7ce1a11 commit 88be11b

File tree

7 files changed

+229
-140
lines changed

7 files changed

+229
-140
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v6.9.1
1+
v7.2.1

package.json

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,91 @@
1212
"url": "https://github.com/combine/universal-react-redux.git"
1313
},
1414
"engines": {
15-
"node": "6.2.1",
15+
"node": "7.x.x",
1616
"npm": "3.x.x"
1717
},
1818
"scripts": {
19-
"start": "yarn run dev:build && yarn run dev:start",
19+
"start": "better-npm-run dev:build && better-npm-run dev:start",
20+
"dev:start": "better-npm-run dev:start",
21+
"dev:start:server": "better-npm-run dev:start:server",
22+
"dev:start:client": "better-npm-run dev:start:client",
23+
"dev:build": "better-npm-run dev:build",
24+
"prod:build": "better-npm-run prod:build",
25+
"prod:start": "better-npm-run prod:start ",
26+
"test": "better-npm-run test",
27+
"test:all": "better-npm-run test:all",
28+
"test:watch": "better-npm-run test:watch",
29+
"test:all:watch": "better-npm-run test:all:watch",
30+
"lint": "better-npm-run lint",
31+
"postinstall": "node ./postinstall.js"
32+
},
33+
"betterScripts": {
2034
"dev:start": "yarn run dev:start:client & yarn run dev:start:server",
21-
"dev:start:server": "NODE_ENV=development yarn run nodemon server",
22-
"dev:start:client": "NODE_ENV=development yarn run babel-node webpack/development.hot",
23-
"dev:build": "NODE_ENV=development $(yarn bin)/babel-node $(yarn bin)/webpack --progress --colors --display-error-details --config webpack/development.js",
24-
"prod:build": "NODE_ENV=production $(yarn bin)/babel-node $(yarn bin)/webpack -p --optimize-dedupe --config webpack/production.js",
25-
"prod:start": "NODE_ENV=production pm2 start server --name='callai'",
26-
"test": "yarn run mocha --recursive --compilers js:babel-register",
27-
"test:all": "yarn run mocha --recursive --compilers js:babel-register $(find . -path ./node_modules -prune -o -name '*.test.js' -print)",
28-
"test:watch": "npm test -- --watch",
29-
"test:all:watch": "yarn run mocha --recursive --compilers js:babel-register $(find . -path ./node_modules -prune -o -name '*.test.js' -print) --watch",
30-
"lint": "yarn run eslint --ext .js,.jsx .",
31-
"postinstall": "if [ \"$NODE_ENV\" = \"production\" ]; then yarn run prod:build; fi"
35+
"dev:start:server": {
36+
"command": "yarn run nodemon server",
37+
"env": {
38+
"NODE_ENV": "development"
39+
}
40+
},
41+
"dev:start:client": {
42+
"command": "yarn run babel-node -- webpack/development.hot",
43+
"env": {
44+
"NODE_ENV": "development"
45+
}
46+
},
47+
"dev:build": {
48+
"command": "yarn run babel-node -- ./script/build webpack/development.js",
49+
"env": {
50+
"NODE_ENV": "development"
51+
}
52+
},
53+
"prod:build": {
54+
"command": "yarn run babel-node -- ./script/build webpack/production.js",
55+
"env": {
56+
"NODE_ENV": "production"
57+
}
58+
},
59+
"prod:start": {
60+
"command": "pm2 start server --name='universal-react-redux'",
61+
"env": {
62+
"NODE_ENV": "production"
63+
}
64+
},
65+
"test": {
66+
"command": "yarn run mocha --recursive --compilers js:babel-register",
67+
"env": {
68+
"NODE_ENV": "test"
69+
}
70+
},
71+
"test:all": {
72+
"command": "yarn run mocha --recursive --compilers js:babel-register $(find . -path ./node_modules -prune -o -name '*.test.js' -print)",
73+
"env": {
74+
"NODE_ENV": "test"
75+
}
76+
},
77+
"test:watch": {
78+
"command": "yarn run test -- --watch",
79+
"env": {
80+
"NODE_ENV": "test"
81+
}
82+
},
83+
"test:all:watch": {
84+
"command": "yarn run test:all -- --watch",
85+
"env": {
86+
"NODE_ENV": "test"
87+
}
88+
},
89+
"lint": {
90+
"command": "yarn run eslint --ext .js,.jsx .",
91+
"env": {
92+
"NODE_ENV": "test"
93+
}
94+
}
3295
},
3396
"devDependencies": {
3497
"babel-eslint": "7.1.1",
98+
"better-npm-run": "^0.0.13",
99+
"debug": "^2.6.0",
35100
"eslint": "3.11.1",
36101
"eslint-loader": "1.6.1",
37102
"eslint-plugin-react": "6.7.1",
@@ -95,7 +160,7 @@
95160
"serve-static": "1.11.1",
96161
"style-loader": "0.13.1",
97162
"url-loader": "0.5.7",
98-
"webpack": "2.1.0-beta.27",
163+
"webpack": "2.1.0-beta.28",
99164
"webpack-isomorphic-tools": "2.6.4"
100165
}
101166
}

postinstall.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const exec = require('child_process').exec;
2+
3+
// For cross-platform postinstalls, use a node script to execute any
4+
// post-install tasks rather than using a bash script since that wouldn't work
5+
// on Windows.
6+
if (process.env.NODE_ENV === 'production') {
7+
exec('yarn run prod:build', (error, stdout, stderr) => {
8+
if (error) {
9+
console.error(`exec error: ${error}`);
10+
return;
11+
}
12+
console.log(`stdout: ${stdout}`);
13+
console.log(`stderr: ${stderr}`);
14+
});
15+
}

script/build.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import webpack from 'webpack';
2+
import ProgressPlugin from 'webpack/lib/ProgressPlugin';
3+
4+
const args = process.argv.splice(2);
5+
const configFilePath = `${__dirname}/../${args[0]}`;
6+
const debug = require('debug')(args[0]);
7+
const configFile = require(configFilePath).default;
8+
const compiler = webpack(configFile);
9+
10+
const handleSoftErrors = (errors) => {
11+
debug('There were some errors with compilation.');
12+
debug(errors);
13+
};
14+
15+
const handleWarnings = (warnings) => {
16+
debug('There were some warnings with compilation.');
17+
debug(warnings);
18+
};
19+
20+
compiler.apply(new ProgressPlugin({ profile: true }));
21+
22+
compiler.run((err, stats) => {
23+
if (err || stats.hasErrors()) {
24+
debug('There was a fatal error with webpack.');
25+
debug(err);
26+
return;
27+
}
28+
29+
const jsonStats = stats.toJson();
30+
31+
if (jsonStats.errors.length > 0) {
32+
return handleSoftErrors(jsonStats.errors);
33+
}
34+
35+
if (jsonStats.warnings.length > 0) {
36+
return handleWarnings(jsonStats.warnings);
37+
}
38+
});

webpack/development.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export default {
4040
...baseConfig.plugins,
4141
...plugins
4242
],
43-
module: Object.assign({}, baseConfig.module, {
43+
module: { ...baseConfig.module, ...{
4444
rules: [
4545
...baseConfig.module.rules,
4646
...loaders
4747
]
48-
})
48+
}}
4949
};

webpack/production.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,25 @@ const loaders = [
3535
})
3636
},
3737
{
38-
test: /\.js$/,
38+
test: /\.jsx$|\.js$/,
3939
loader: 'babel-loader',
40-
rules: ['babel'],
4140
exclude: /node_modules/
4241
}
4342
];
4443

4544
export default {
4645
...baseConfig,
47-
output: Object.assign({}, baseConfig.output, {
46+
output: { ...baseConfig.output, ...{
4847
filename: '[name].[hash].js'
49-
}),
48+
}},
5049
plugins: [
5150
...baseConfig.plugins,
5251
...plugins
5352
],
54-
module: Object.assign({}, baseConfig.module, {
53+
module: { ...baseConfig.module, ...{
5554
rules: [
5655
...baseConfig.module.rules,
5756
...loaders
5857
]
59-
})
58+
}}
6059
};

0 commit comments

Comments
 (0)