Skip to content

Commit e73606a

Browse files
authored
Merge pull request #1 from ConnectedHomes/v3-modes
V3 mods
2 parents 2f3b222 + 62ede02 commit e73606a

File tree

9 files changed

+168
-18
lines changed

9 files changed

+168
-18
lines changed

packages/react-scripts/config/jest/babelTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ const babelJest = require('babel-jest');
1212

1313
module.exports = babelJest.createTransformer({
1414
presets: [require.resolve('babel-preset-react-app')],
15-
babelrc: false,
15+
babelrc: true,
1616
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const paths = require('./paths');
6+
7+
const DEFAULT_LOCALE = 'en-gb';
8+
const LOCALE_DIR = paths.appIntl;
9+
10+
// By looking at our `i18n` we can get an idea of which languages and locales we need to be
11+
// concerned with. As we add translations for different languages we'll automatically have
12+
// the right data to help with whitelisting those languages/locales in npm modules.
13+
14+
const locales = [
15+
DEFAULT_LOCALE,
16+
...fs.readdirSync(LOCALE_DIR).map(f => path.basename(f, path.extname(f))) // fr-ca.json -> fr-ca
17+
];
18+
19+
module.exports = {
20+
locales,
21+
languages: locales.map(l => l.replace(/(-.*)$/, '')) // en-gb -> en
22+
};

packages/react-scripts/config/paths.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ module.exports = {
5555
appPublic: resolveApp('public'),
5656
appHtml: resolveApp('public/index.html'),
5757
appIndexJs: resolveApp('src/index.js'),
58+
appBrowserUpdateHtml: resolveApp('public/browser-update.html'),
59+
appBrowserUpdateJs: resolveApp('src/assets/scripts/browser-detect.js'),
5860
appPackageJson: resolveApp('package.json'),
5961
appSrc: resolveApp('src'),
62+
appEnv: resolveApp('env'),
63+
appIntl: resolveApp('src/i18n'),
6064
yarnLockFile: resolveApp('yarn.lock'),
6165
testsSetup: resolveApp('src/setupTests.js'),
6266
appNodeModules: resolveApp('node_modules'),
@@ -75,8 +79,12 @@ module.exports = {
7579
appPublic: resolveApp('public'),
7680
appHtml: resolveApp('public/index.html'),
7781
appIndexJs: resolveApp('src/index.js'),
82+
appBrowserUpdateHtml: resolveApp('public/browser-update.html'),
83+
appBrowserUpdateJs: resolveApp('src/assets/scripts/browser-detect.js'),
7884
appPackageJson: resolveApp('package.json'),
7985
appSrc: resolveApp('src'),
86+
appEnv: resolveApp('env'),
87+
appIntl: resolveApp('src/i18n'),
8088
yarnLockFile: resolveApp('yarn.lock'),
8189
testsSetup: resolveApp('src/setupTests.js'),
8290
appNodeModules: resolveApp('node_modules'),

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
// @remove-on-eject-end
1111
'use strict';
1212

13-
const autoprefixer = require('autoprefixer');
13+
const cssnext = require('postcss-cssnext');
14+
const cssimport = require('postcss-import');
15+
const cssFluidGrid = require('postcss-grid-fluid');
16+
17+
const HivehomeWebappFaviconsWebpackPlugin = require('@connected-home/hivehome-webapp-favicons-webpack-plugin');
18+
1419
const path = require('path');
1520
const webpack = require('webpack');
1621
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -22,6 +27,8 @@ const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2227
const getClientEnvironment = require('./env');
2328
const paths = require('./paths');
2429

30+
const { languages, locales } = require('./locales');
31+
2532
// Webpack uses `publicPath` to determine where the app is being served from.
2633
// In development, we always serve from the root. This makes config easier.
2734
const publicPath = '/';
@@ -60,6 +67,7 @@ module.exports = {
6067
require.resolve('react-error-overlay'),
6168
// Finally, this is your app's code:
6269
paths.appIndexJs,
70+
paths.appBrowserUpdateJs,
6371
// We include the app code last so that if there is a runtime error during
6472
// initialization, it doesn't blow up the WebpackDevServer client, and
6573
// changing JS code would still trigger a refresh.
@@ -173,7 +181,7 @@ module.exports = {
173181
loader: require.resolve('babel-loader'),
174182
options: {
175183
// @remove-on-eject-begin
176-
babelrc: false,
184+
babelrc: true,
177185
presets: [require.resolve('babel-preset-react-app')],
178186
// @remove-on-eject-end
179187
// This is a feature of `babel-loader` for webpack (not Babel itself).
@@ -204,16 +212,22 @@ module.exports = {
204212
// https://github.com/facebookincubator/create-react-app/issues/2677
205213
ident: 'postcss',
206214
plugins: () => [
207-
require('postcss-flexbugs-fixes'),
208-
autoprefixer({
215+
cssimport({
216+
path: [paths.appSrc + '/assets/stylesheets/common'],
217+
onImport: function(files) {
218+
files.forEach(this.addDependency);
219+
}.bind(this),
220+
}),
221+
cssnext({
209222
browsers: [
210223
'>1%',
211224
'last 4 versions',
212225
'Firefox ESR',
213226
'not ie < 9', // React doesn't support IE8 anyway
214227
],
215-
flexbox: 'no-2009',
216228
}),
229+
cssFluidGrid(),
230+
require('postcss-flexbugs-fixes'),
217231
],
218232
},
219233
},
@@ -256,7 +270,39 @@ module.exports = {
256270
new webpack.NamedModulesPlugin(),
257271
// Makes some environment variables available to the JS code, for example:
258272
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
259-
new webpack.DefinePlugin(env.stringified),
273+
new webpack.DefinePlugin(
274+
Object.assign({}, env.stringified, {
275+
'process.locales': JSON.stringify(locales),
276+
})
277+
),
278+
// Favicons and tile icons etc
279+
new HivehomeWebappFaviconsWebpackPlugin({
280+
title: 'Hive Home',
281+
prefix: 'static/media/[hash]-',
282+
platforms: {
283+
generic: {
284+
source: path.join(paths.appSrc, 'assets/icons', 'favicon.png'),
285+
},
286+
ios: {
287+
source: path.join(paths.appSrc, 'assets/icons', 'app-icon.png'),
288+
statusBar: 'black-translucent',
289+
},
290+
android: {
291+
source: path.join(paths.appSrc, 'assets/icons', 'app-icon.png'),
292+
themeColor: '#ff8600',
293+
backgroundColor: '#ffffff',
294+
},
295+
windows: {
296+
source: path.join(paths.appSrc, 'assets/icons', 'app-icon.png'),
297+
tileColor: '#ff8600',
298+
},
299+
},
300+
}),
301+
// Whitelist `react-intl` language files we know we'll need
302+
new webpack.ContextReplacementPlugin(
303+
/react-intl[/\\]locale-data$/,
304+
new RegExp(`^\\.[/\\\\](${languages.join('|')})$`)
305+
),
260306
// This is necessary to emit hot updates (currently CSS only):
261307
new webpack.HotModuleReplacementPlugin(),
262308
// Watcher doesn't work well if you mistype casing in a path so we use

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
// @remove-on-eject-end
1111
'use strict';
1212

13-
const autoprefixer = require('autoprefixer');
13+
const cssnext = require('postcss-cssnext');
14+
const cssimport = require('postcss-import');
15+
const cssFluidGrid = require('postcss-grid-fluid');
16+
17+
const { languages, locales } = require('./locales');
18+
19+
const HivehomeWebappFaviconsWebpackPlugin = require('@connected-home/hivehome-webapp-favicons-webpack-plugin');
20+
1421
const path = require('path');
1522
const webpack = require('webpack');
1623
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -66,7 +73,11 @@ module.exports = {
6673
// You can exclude the *.map files from the build during deployment.
6774
devtool: shouldUseSourceMap ? 'source-map' : false,
6875
// In production, we only want to load the polyfills and the app code.
69-
entry: [require.resolve('./polyfills'), paths.appIndexJs],
76+
entry: [
77+
require.resolve('./polyfills'),
78+
paths.appIndexJs,
79+
paths.appBrowserUpdateJs,
80+
],
7081
output: {
7182
// The build folder.
7283
path: paths.appBuild,
@@ -176,7 +187,7 @@ module.exports = {
176187
loader: require.resolve('babel-loader'),
177188
options: {
178189
// @remove-on-eject-begin
179-
babelrc: false,
190+
babelrc: true,
180191
presets: [require.resolve('babel-preset-react-app')],
181192
// @remove-on-eject-end
182193
compact: true,
@@ -216,16 +227,22 @@ module.exports = {
216227
// https://github.com/facebookincubator/create-react-app/issues/2677
217228
ident: 'postcss',
218229
plugins: () => [
219-
require('postcss-flexbugs-fixes'),
220-
autoprefixer({
230+
cssimport({
231+
path: [paths.appSrc + '/assets/stylesheets/common'],
232+
onImport: function(files) {
233+
files.forEach(this.addDependency);
234+
}.bind(this),
235+
}),
236+
cssnext({
221237
browsers: [
222238
'>1%',
223239
'last 4 versions',
224240
'Firefox ESR',
225241
'not ie < 9', // React doesn't support IE8 anyway
226242
],
227-
flexbox: 'no-2009',
228243
}),
244+
cssFluidGrid(),
245+
require('postcss-flexbugs-fixes'),
229246
],
230247
},
231248
},
@@ -285,7 +302,39 @@ module.exports = {
285302
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
286303
// It is absolutely essential that NODE_ENV was set to production here.
287304
// Otherwise React will be compiled in the very slow development mode.
288-
new webpack.DefinePlugin(env.stringified),
305+
new webpack.DefinePlugin(
306+
Object.assign({}, env.stringified, {
307+
'process.locales': JSON.stringify(locales),
308+
})
309+
),
310+
// Favicons and tile icons etc
311+
new HivehomeWebappFaviconsWebpackPlugin({
312+
title: 'Hive Home',
313+
prefix: 'static/media/[hash]-',
314+
platforms: {
315+
generic: {
316+
source: path.join(paths.appSrc, 'assets/icons', 'favicon.png'),
317+
},
318+
ios: {
319+
source: path.join(paths.appSrc, 'assets/icons', 'app-icon.png'),
320+
statusBar: 'black-translucent',
321+
},
322+
android: {
323+
source: path.join(paths.appSrc, 'assets/icons', 'app-icon.png'),
324+
themeColor: '#ff8600',
325+
backgroundColor: '#ffffff',
326+
},
327+
windows: {
328+
source: path.join(paths.appSrc, 'assets/icons', 'app-icon.png'),
329+
tileColor: '#ff8600',
330+
},
331+
},
332+
}),
333+
// Whitelist `react-intl` language files we know we'll need
334+
new webpack.ContextReplacementPlugin(
335+
/react-intl[/\\]locale-data$/,
336+
new RegExp(`^\\.[/\\\\](${languages.join('|')})$`)
337+
),
289338
// Minify the code.
290339
new webpack.optimize.UglifyJsPlugin({
291340
compress: {

packages/react-scripts/config/webpackDevServer.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ const paths = require('./paths');
1818
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
1919
const host = process.env.HOST || '0.0.0.0';
2020

21+
function envMiddleware(req, res) {
22+
const options = {
23+
root: paths.appEnv
24+
};
25+
26+
const fileName = `${process.env.DIST_ENV}.js`;
27+
res.sendFile(fileName, options, err => {
28+
if (err) {
29+
console.log(err);
30+
res.status(err.status).end();
31+
}
32+
});
33+
}
34+
2135
module.exports = function(proxy, allowedHost) {
2236
return {
2337
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
@@ -97,6 +111,8 @@ module.exports = function(proxy, allowedHost) {
97111
// it used the same host and port.
98112
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
99113
app.use(noopServiceWorkerMiddleware());
114+
115+
app.use('/env.js', envMiddleware);
100116
},
101117
};
102118
};

packages/react-scripts/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "react-scripts",
3-
"version": "1.0.11",
2+
"name": "@connected-home/react-scripts",
3+
"version": "1.0.11-4",
44
"description": "Configuration and scripts for Create React App.",
55
"repository": "facebookincubator/create-react-app",
66
"license": "BSD-3-Clause",
@@ -21,10 +21,11 @@
2121
"react-scripts": "./bin/react-scripts.js"
2222
},
2323
"dependencies": {
24+
"@connected-home/hivehome-webapp-favicons-webpack-plugin": "^3.0.0",
2425
"autoprefixer": "7.1.2",
2526
"babel-core": "6.25.0",
2627
"babel-eslint": "7.2.3",
27-
"babel-jest": "20.0.3",
28+
"babel-jest": "^16.0.0",
2829
"babel-loader": "7.1.1",
2930
"babel-preset-react-app": "^3.0.2",
3031
"babel-runtime": "6.23.0",
@@ -43,9 +44,12 @@
4344
"file-loader": "0.11.2",
4445
"fs-extra": "3.0.1",
4546
"html-webpack-plugin": "2.29.0",
46-
"jest": "20.0.4",
47+
"jest": "^16.0.1",
4748
"object-assign": "4.1.1",
49+
"postcss-cssnext": "^3.0.2",
4850
"postcss-flexbugs-fixes": "3.2.0",
51+
"postcss-grid-fluid": "^0.1.17",
52+
"postcss-import": "^10.0.0",
4953
"postcss-loader": "2.0.6",
5054
"promise": "8.0.1",
5155
"react-dev-utils": "^3.1.0",

packages/react-scripts/scripts/start.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// Do this as the first thing so that any code reading it knows the right env.
1414
process.env.BABEL_ENV = 'development';
1515
process.env.NODE_ENV = 'development';
16+
process.env.DIST_ENV = process.env.DIST_ENV ? process.env.DIST_ENV : 'local-dev';
1617

1718
// Makes the script crash on unhandled rejections instead of silently
1819
// ignoring them. In the future, promise rejections that are not handled will

packages/react-scripts/scripts/utils/createJestConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
2626
collectCoverageFrom: ['src/**/*.{js,jsx}'],
2727
setupFiles: [resolve('config/polyfills.js')],
2828
setupTestFrameworkScriptFile: setupTestsFile,
29+
testRegex: 'jest\\.js$',
2930
testMatch: [
3031
'<rootDir>/src/**/__tests__/**/*.js?(x)',
3132
'<rootDir>/src/**/?(*.)(spec|test).js?(x)',
@@ -42,6 +43,9 @@ module.exports = (resolve, rootDir, isEjecting) => {
4243
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
4344
moduleNameMapper: {
4445
'^react-native$': 'react-native-web',
46+
'^.+\\.css$': '<rootDir>/scripts/utils/css-stub.js',
47+
'^.+\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$':
48+
'<rootDir>/scripts/utils/file-stub.js',
4549
},
4650
moduleFileExtensions: ['web.js', 'js', 'json', 'web.jsx', 'jsx', 'node'],
4751
};

0 commit comments

Comments
 (0)