Skip to content

Commit f477c9b

Browse files
committed
Init Lot2
1 parent 7f190c2 commit f477c9b

40 files changed

+6580
-0
lines changed

conf/env.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (C) 2017-2017 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
7+
// injected into the application via DefinePlugin in Webpack configuration.
8+
9+
const REACT_APP = /^REACT_APP_/i;
10+
11+
function getClientEnvironment() {
12+
return Object.keys(process.env).filter(key => REACT_APP.test(key)).reduce((env, key) => {
13+
env['process.env.' + key] = JSON.stringify(process.env[key]);
14+
return env;
15+
}, {
16+
// Useful for determining whether we’re running in production mode.
17+
// Most importantly, it switches React into the correct mode.
18+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
19+
});
20+
}
21+
22+
module.exports = getClientEnvironment;

conf/jest/CSSStub.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (C) 2017-2017 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
module.exports = {};

conf/jest/FileStub.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (C) 2017-2017 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
module.exports = 'test-file-stub';

conf/jest/SetupTestEnvironment.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (C) 2017-2017 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
window.baseUrl = '';
7+
8+
window.t = (window.tp = function() {
9+
const args = Array.prototype.slice.call(arguments, 0);
10+
return args.join('.');
11+
});

conf/webpack/webpack.config.dev.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2017-2017 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
const webpack = require('webpack');
7+
const config = require('./webpack.config');
8+
9+
config.devtool = 'eval';
10+
11+
config.output.publicPath = '/static/icode/';
12+
13+
config.output.pathinfo = true;
14+
15+
Object.keys(config.entry).forEach(key => {
16+
config.entry[key].unshift(require.resolve('react-dev-utils/webpackHotDevClient'));
17+
});
18+
19+
config.plugins = [new webpack.HotModuleReplacementPlugin()];
20+
21+
module.exports = config;

conf/webpack/webpack.config.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2017-2017 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
const path = require('path');
7+
const autoprefixer = require('autoprefixer');
8+
9+
const autoprefixerOptions = {
10+
browsers: [
11+
'last 3 Chrome versions',
12+
'last 3 Firefox versions',
13+
'Safari >= 8',
14+
'Edge >= 12',
15+
'IE 11'
16+
]
17+
};
18+
19+
const output = path.join(__dirname, '../../target/classes/static');
20+
21+
module.exports = {
22+
entry: {
23+
'icode_metrics_summary': ['./src/main/js/app-metrics_summary.js'],
24+
},
25+
output: {
26+
path: output,
27+
filename: '[name].js'
28+
},
29+
resolve: {
30+
root: path.join(__dirname, 'src/main/js')
31+
},
32+
externals: {
33+
lodash: '_',
34+
react: 'React',
35+
'react-dom': 'ReactDOM',
36+
'react-redux': 'ReactRedux',
37+
'react-router': 'ReactRouter',
38+
'sonar-request': 'SonarRequest',
39+
'sonar-measures': 'SonarMeasures',
40+
'sonar-components': 'SonarComponents'
41+
},
42+
module: {
43+
loaders: [
44+
{
45+
test: /\.js$/,
46+
loader: 'babel',
47+
exclude: /(node_modules)/
48+
},
49+
{
50+
test: /\.css/,
51+
loader: 'style-loader!css-loader!postcss-loader'
52+
},
53+
{ test: /\.json$/, loader: 'json' }
54+
]
55+
},
56+
postcss() {
57+
return [autoprefixer(autoprefixerOptions)];
58+
}
59+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2017-2017 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
const webpack = require('webpack');
7+
const config = require('./webpack.config');
8+
const getClientEnvironment = require('../env');
9+
10+
// Get environment variables to inject into our app.
11+
const env = getClientEnvironment();
12+
13+
// Assert this just to be safe.
14+
// Development builds of React are slow and not intended for production.
15+
if (env['process.env.NODE_ENV'] !== '"production"') {
16+
throw new Error('Production builds must have NODE_ENV=production.');
17+
}
18+
19+
const noUglify = process.argv.some(arg => arg.indexOf('--no-uglify') > -1);
20+
21+
// Don't attempt to continue if there are any errors.
22+
config.bail = true;
23+
24+
config.plugins = [
25+
// Makes some environment variables available to the JS code, for example:
26+
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
27+
// It is absolutely essential that NODE_ENV was set to production here.
28+
// Otherwise React will be compiled in the very slow development mode.
29+
new webpack.DefinePlugin(env),
30+
31+
// This helps ensure the builds are consistent if source hasn't changed:
32+
new webpack.optimize.OccurrenceOrderPlugin(),
33+
34+
// Try to dedupe duplicated modules, if any:
35+
new webpack.optimize.DedupePlugin()
36+
];
37+
38+
if (!noUglify) {
39+
config.plugins.push(
40+
new webpack.optimize.UglifyJsPlugin({
41+
compress: {
42+
screw_ie8: true, // React doesn't support IE8
43+
warnings: false
44+
},
45+
mangle: {
46+
screw_ie8: true
47+
},
48+
output: {
49+
comments: false,
50+
screw_ie8: true
51+
}
52+
})
53+
);
54+
}
55+
56+
module.exports = config;

package.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"name": "icode",
3+
"version": "0.0.1",
4+
"devDependencies": {
5+
"autoprefixer": "6.2.2",
6+
"babel-core": "6.14.0",
7+
"babel-jest": "18.0.0",
8+
"babel-jest": "18.0.0",
9+
"babel-loader": "6.2.5",
10+
"babel-preset-react-app": "0.2.1",
11+
"cross-env": "2.0.0",
12+
"cross-spawn": "4.0.0",
13+
"css-loader": "0.23.1",
14+
"detect-port": "1.0.0",
15+
"dotenv": "2.0.0",
16+
"enzyme": "2.6.0",
17+
"enzyme-to-json": "1.4.5",
18+
"expose-loader": "0.7.1",
19+
"express": "4.13.4",
20+
"express-http-proxy": "0.6.0",
21+
"filesize": "3.3.0",
22+
"find-cache-dir": "0.1.1",
23+
"gzip-size": "3.0.0",
24+
"imports-loader": "0.6.5",
25+
"jest": "18.0.0",
26+
"json-loader": "0.5.4",
27+
"path-exists": "2.1.0",
28+
"postcss-loader": "0.8.0",
29+
"prettier": "0.22.0",
30+
"react": "15.6.2",
31+
"react-addons-shallow-compare": "15.6.2",
32+
"react-addons-test-utils": "15.6.2",
33+
"react-dev-utils": "0.2.1",
34+
"react-dom": "15.6.2",
35+
"react-router": "3.0.2",
36+
"react-transform-hmr": "1.0.4",
37+
"recursive-readdir": "2.1.0",
38+
"rimraf": "2.5.4",
39+
"script-loader": "0.6.1",
40+
"strip-ansi": "3.0.1",
41+
"style-loader": "0.13.0",
42+
"webpack": "1.13.2",
43+
"webpack-dev-server": "1.16.1"
44+
},
45+
"scripts": {
46+
"build": "node scripts/build.js",
47+
"start": "node scripts/start.js",
48+
"test": "node scripts/test.js"
49+
},
50+
"babel": {
51+
"presets": [
52+
"react-app"
53+
]
54+
},
55+
"jest": {
56+
"coverageDirectory": "<rootDir>/target/coverage",
57+
"coveragePathIgnorePatterns": [
58+
"<rootDir>/node_modules",
59+
"<rootDir>/tests"
60+
],
61+
"moduleFileExtensions": [
62+
"jsx",
63+
"js",
64+
"json"
65+
],
66+
"moduleNameMapper": {
67+
"^.+\\.(hbs|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/conf/jest/FileStub.js",
68+
"^.+\\.css$": "<rootDir>/conf/jest/CSSStub.js"
69+
},
70+
"setupFiles": [
71+
"<rootDir>/conf/jest/SetupTestEnvironment.js"
72+
],
73+
"snapshotSerializers": [
74+
"enzyme-to-json/serializer"
75+
],
76+
"testPathIgnorePatterns": [
77+
"<rootDir>/node_modules",
78+
"<rootDir>/scripts",
79+
"<rootDir>/conf"
80+
]
81+
}
82+
}

scripts/build.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (C) 2017-2017 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
/* eslint-disable no-console */
7+
process.env.NODE_ENV = 'production';
8+
9+
const chalk = require('chalk');
10+
const webpack = require('webpack');
11+
const config = require('../conf/webpack/webpack.config.prod.js');
12+
13+
function formatSize(bytes) {
14+
if (bytes === 0) {
15+
return '0';
16+
}
17+
const k = 1000; // or 1024 for binary
18+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
19+
const i = Math.floor(Math.log(bytes) / Math.log(k));
20+
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
21+
}
22+
23+
function build() {
24+
console.log(chalk.cyan.bold('Creating optimized production build...'));
25+
console.log();
26+
27+
webpack(config, (err, stats) => {
28+
if (err) {
29+
console.log(chalk.red.bold('Failed to create a production build!'));
30+
console.log(chalk.red(err.message || err));
31+
process.exit(1);
32+
}
33+
34+
if (stats.compilation.errors && stats.compilation.errors.length) {
35+
console.log(chalk.red.bold('Failed to create a production build!'));
36+
stats.compilation.errors.forEach(err => console.log(chalk.red(err.message || err)));
37+
process.exit(1);
38+
}
39+
40+
const jsonStats = stats.toJson();
41+
42+
console.log('Assets:');
43+
const assets = jsonStats.assets.slice();
44+
assets.sort((a, b) => b.size - a.size);
45+
assets.forEach(asset => {
46+
let sizeLabel = formatSize(asset.size);
47+
const leftPadding = ' '.repeat(Math.max(0, 8 - sizeLabel.length));
48+
sizeLabel = leftPadding + sizeLabel;
49+
console.log('', chalk.yellow(sizeLabel), asset.name);
50+
});
51+
console.log();
52+
53+
const seconds = jsonStats.time / 1000;
54+
console.log('Duration: ' + seconds.toFixed(2) + 's');
55+
console.log();
56+
57+
console.log(chalk.green.bold('Compiled successfully!'));
58+
});
59+
}
60+
61+
build();

0 commit comments

Comments
 (0)