aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/scripts
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-11-28 18:13:00 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-12-07 14:36:18 +0100
commit673b03c6f68593f4e27675e709f2ce20831e0d98 (patch)
tree30ee597d3a3e1a0bcf5eff9a7859d1084c32d435 /server/sonar-web/scripts
parenta2d0b4ee581e86b474a47e16095e7500c404e37d (diff)
downloadsonarqube-673b03c6f68593f4e27675e709f2ce20831e0d98.tar.gz
sonarqube-673b03c6f68593f4e27675e709f2ce20831e0d98.zip
SONAR-8448 generate index.html during the build
Diffstat (limited to 'server/sonar-web/scripts')
-rw-r--r--server/sonar-web/scripts/build.js93
-rw-r--r--server/sonar-web/scripts/start.js17
2 files changed, 59 insertions, 51 deletions
diff --git a/server/sonar-web/scripts/build.js b/server/sonar-web/scripts/build.js
index c73a5a9559f..8cc9bbef3c6 100644
--- a/server/sonar-web/scripts/build.js
+++ b/server/sonar-web/scripts/build.js
@@ -20,7 +20,7 @@
process.env.NODE_ENV = 'production';
var chalk = require('chalk');
-var fs = require('fs');
+var fs = require('fs-extra');
var path = require('path');
var rimrafSync = require('rimraf').sync;
var webpack = require('webpack');
@@ -33,54 +33,73 @@ var config = isFastBuild ?
require('../config/webpack/webpack.config.fast') :
require('../config/webpack/webpack.config.prod');
+function clean () {
// Remove all content but keep the directory so that
// if you're in it, you don't end up in Trash
-console.log(chalk.cyan.bold('Cleaning output directories...'));
+ console.log(chalk.cyan.bold('Cleaning output directories and files...'));
-console.log(paths.appBuild + '/*');
-rimrafSync(paths.appBuild + '/*');
+ console.log(paths.jsBuild + '/*');
+ rimrafSync(paths.jsBuild + '/*');
-console.log(paths.cssBuild + '/*');
-rimrafSync(paths.cssBuild + '/*');
+ console.log(paths.cssBuild + '/*');
+ rimrafSync(paths.cssBuild + '/*');
-console.log();
+ console.log(paths.htmlBuild);
+ rimrafSync(paths.htmlBuild);
-if (isFastBuild) {
- console.log(chalk.magenta.bold('Running fast build...'));
-} else {
- console.log(chalk.cyan.bold('Creating optimized production build...'));
+ console.log();
}
-console.log();
-webpack(config, (err, stats) => {
- if (err) {
- console.log(chalk.red.bold('Failed to create a production build!'));
- console.log(chalk.red(err.message || err));
- process.exit(1);
+function build () {
+ if (isFastBuild) {
+ console.log(chalk.magenta.bold('Running fast build...'));
+ } else {
+ console.log(chalk.cyan.bold('Creating optimized production build...'));
}
+ console.log();
- if (stats.compilation.errors && stats.compilation.errors.length) {
- console.log(chalk.red.bold('Failed to create a production build!'));
- stats.compilation.errors.forEach(err => console.log(chalk.red(err.message || err)));
- process.exit(1);
- }
+ webpack(config, (err, stats) => {
+ if (err) {
+ console.log(chalk.red.bold('Failed to create a production build!'));
+ console.log(chalk.red(err.message || err));
+ process.exit(1);
+ }
+
+ if (stats.compilation.errors && stats.compilation.errors.length) {
+ console.log(chalk.red.bold('Failed to create a production build!'));
+ stats.compilation.errors.forEach(err => console.log(chalk.red(err.message || err)));
+ process.exit(1);
+ }
+
+ var jsonStats = stats.toJson();
+
+ console.log('Assets:');
+ var assets = jsonStats.assets.slice();
+ assets.sort((a, b) => b.size - a.size);
+ assets.forEach(asset => {
+ var sizeLabel = formatSize(asset.size);
+ var leftPadding = ' '.repeat(Math.max(0, 8 - sizeLabel.length));
+ sizeLabel = leftPadding + sizeLabel;
+ console.log('', chalk.yellow(sizeLabel), asset.name);
+ });
+ console.log();
- var jsonStats = stats.toJson();
+ var seconds = jsonStats.time / 1000;
+ console.log('Duration: ' + seconds.toFixed(2) + 's');
+ console.log();
- console.log('Assets:');
- var assets = jsonStats.assets.slice();
- assets.sort((a, b) => b.size - a.size);
- assets.forEach(asset => {
- var sizeLabel = formatSize(asset.size);
- var leftPadding = ' '.repeat(8 - sizeLabel.length);
- sizeLabel = leftPadding + sizeLabel;
- console.log('', chalk.yellow(sizeLabel), asset.name);
+ console.log(chalk.green.bold('Compiled successfully!'));
});
- console.log();
+}
+
+function copyPublicFolder () {
+ fs.copySync(paths.appPublic, paths.appBuild, {
+ dereference: true,
+ filter: file => file !== paths.appHtml
+ });
+}
- var seconds = jsonStats.time / 1000;
- console.log('Duration: ' + seconds.toFixed(2) + 's');
- console.log();
- console.log(chalk.green.bold('Compiled successfully!'));
-});
+clean();
+build();
+copyPublicFolder();
diff --git a/server/sonar-web/scripts/start.js b/server/sonar-web/scripts/start.js
index 67b239a4739..c0ee1f90fe1 100644
--- a/server/sonar-web/scripts/start.js
+++ b/server/sonar-web/scripts/start.js
@@ -45,19 +45,6 @@ var handleCompile;
var PROXY_URL = 'http://localhost:9000';
-// You can safely remove this after ejecting.
-// We only use this block for testing of Create React App itself:
-var isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1);
-if (isSmokeTest) {
- handleCompile = function (err, stats) {
- if (err || stats.hasErrors() || stats.hasWarnings()) {
- process.exit(1);
- } else {
- process.exit(0);
- }
- };
-}
-
function setupCompiler (host, port, protocol) {
// "Compiler" is a low-level interface to Webpack.
// It lets us listen to some events and provide our own custom messages.
@@ -181,7 +168,7 @@ function addMiddleware (devServer) {
// - /*.hot-update.json (WebpackDevServer uses this too for hot reloading)
// - /sockjs-node/* (WebpackDevServer uses this for hot reloading)
// Tip: use https://jex.im/regulex/ to visualize the regex
- var mayProxy = /^(?!\/(.*\.hot-update\.json$|sockjs-node\/)).*$/;
+ var mayProxy = /^(?!\/(index\.html$|.*\.hot-update\.json$|sockjs-node\/)).*$/;
devServer.use(mayProxy,
// Pass the scope regex both to Express and to the middleware for proxying
// of both HTTP and WebSockets to work without false positives.
@@ -201,6 +188,8 @@ function addMiddleware (devServer) {
function runDevServer (host, port, protocol) {
var devServer = new WebpackDevServer(compiler, {
+ // Enable gzip compression of generated files.
+ compress: true,
// Silence WebpackDevServer's own logs since they're generally not useful.
// It will still show compile warnings and errors with this setting.
clientLogLevel: 'none',