2016-08-22 15:29:35 +02:00
|
|
|
/*
|
|
|
|
* SonarQube
|
2020-01-06 15:01:53 +01:00
|
|
|
* Copyright (C) 2009-2020 SonarSource SA
|
2018-03-21 17:33:08 +01:00
|
|
|
* mailto:info AT sonarsource DOT com
|
2016-08-22 15:29:35 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2017-06-14 11:10:48 +02:00
|
|
|
/* eslint-disable no-console */
|
2016-08-22 15:29:35 +02:00
|
|
|
process.env.NODE_ENV = 'development';
|
|
|
|
|
2018-10-16 09:56:39 +02:00
|
|
|
const fs = require('fs');
|
2017-06-14 11:10:48 +02:00
|
|
|
const chalk = require('chalk');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const WebpackDevServer = require('webpack-dev-server');
|
|
|
|
const clearConsole = require('react-dev-utils/clearConsole');
|
|
|
|
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
2017-06-19 14:41:19 +02:00
|
|
|
const errorOverlayMiddleware = require('react-error-overlay/middleware');
|
2018-04-26 15:31:42 +02:00
|
|
|
const getMessages = require('./utils/getMessages');
|
2018-12-18 15:51:21 +01:00
|
|
|
const getConfigs = require('../config/webpack.config');
|
2017-06-14 11:10:48 +02:00
|
|
|
const paths = require('../config/paths');
|
2016-08-22 15:29:35 +02:00
|
|
|
|
2018-12-18 15:51:21 +01:00
|
|
|
const configs = getConfigs({ production: false });
|
|
|
|
const config = configs.find(config => config.name === 'modern');
|
2016-08-22 15:29:35 +02:00
|
|
|
|
2017-06-19 14:41:19 +02:00
|
|
|
const port = process.env.PORT || 3000;
|
|
|
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
|
|
const host = process.env.HOST || 'localhost';
|
2018-02-01 15:55:54 +01:00
|
|
|
const proxy = process.env.PROXY || 'http://localhost:9000';
|
2016-08-22 15:29:35 +02:00
|
|
|
|
2018-05-25 15:50:51 +02:00
|
|
|
// Force start script to proxy l10n request to the server (can be useful when working with plugins/extensions)
|
|
|
|
const l10nCompiledFlag = process.argv.findIndex(val => val === 'l10nCompiled') >= 0;
|
2018-11-28 09:48:16 +01:00
|
|
|
const l10nExtensions = process.argv.findIndex(val => val === 'l10nExtensions') >= 0;
|
2017-06-19 14:41:19 +02:00
|
|
|
|
2018-05-25 15:50:51 +02:00
|
|
|
const compiler = setupCompiler(host, port, protocol);
|
2017-06-19 14:41:19 +02:00
|
|
|
runDevServer(compiler, host, port, protocol);
|
2016-08-22 15:29:35 +02:00
|
|
|
|
2017-06-14 11:10:48 +02:00
|
|
|
function setupCompiler(host, port, protocol) {
|
2017-06-19 14:41:19 +02:00
|
|
|
const compiler = webpack(config);
|
2016-08-22 15:29:35 +02:00
|
|
|
|
2017-06-14 11:10:48 +02:00
|
|
|
compiler.plugin('invalid', () => {
|
2016-10-27 13:37:55 +02:00
|
|
|
clearConsole();
|
|
|
|
console.log('Compiling...');
|
2016-08-22 15:29:35 +02:00
|
|
|
});
|
|
|
|
|
2017-06-14 11:10:48 +02:00
|
|
|
compiler.plugin('done', stats => {
|
2016-10-27 13:37:55 +02:00
|
|
|
clearConsole();
|
2016-08-22 15:29:35 +02:00
|
|
|
|
2017-06-14 11:10:48 +02:00
|
|
|
const jsonStats = stats.toJson({}, true);
|
|
|
|
const messages = formatWebpackMessages(jsonStats);
|
|
|
|
const seconds = jsonStats.time / 1000;
|
2016-10-27 13:37:55 +02:00
|
|
|
if (!messages.errors.length && !messages.warnings.length) {
|
|
|
|
console.log(chalk.green('Compiled successfully!'));
|
2016-11-04 09:09:42 +01:00
|
|
|
console.log('Duration: ' + seconds.toFixed(2) + 's');
|
2016-10-27 13:37:55 +02:00
|
|
|
console.log();
|
|
|
|
console.log('The app is running at:');
|
|
|
|
console.log();
|
|
|
|
console.log(' ' + chalk.cyan(protocol + '://' + host + ':' + port + '/'));
|
|
|
|
console.log();
|
|
|
|
}
|
2016-08-22 15:29:35 +02:00
|
|
|
|
2016-10-27 13:37:55 +02:00
|
|
|
if (messages.errors.length) {
|
|
|
|
console.log(chalk.red('Failed to compile.'));
|
2016-08-22 15:29:35 +02:00
|
|
|
console.log();
|
2016-10-27 13:37:55 +02:00
|
|
|
messages.errors.forEach(message => {
|
2016-08-22 15:29:35 +02:00
|
|
|
console.log(message);
|
|
|
|
console.log();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-19 14:41:19 +02:00
|
|
|
return compiler;
|
2016-10-27 13:37:55 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:41:19 +02:00
|
|
|
function runDevServer(compiler, host, port, protocol) {
|
2017-06-14 11:10:48 +02:00
|
|
|
const devServer = new WebpackDevServer(compiler, {
|
2017-10-25 16:53:22 +02:00
|
|
|
before(app) {
|
|
|
|
app.use(errorOverlayMiddleware());
|
2018-05-25 15:50:51 +02:00
|
|
|
if (!l10nCompiledFlag) {
|
|
|
|
app.get('/api/l10n/index', (req, res) => {
|
2018-11-28 09:48:16 +01:00
|
|
|
getMessages(l10nExtensions)
|
2018-05-25 15:50:51 +02:00
|
|
|
.then(messages => res.json({ effectiveLocale: 'en', messages }))
|
|
|
|
.catch(() => res.status(500));
|
|
|
|
});
|
|
|
|
}
|
2017-10-25 16:53:22 +02:00
|
|
|
},
|
2016-11-28 18:13:00 +01:00
|
|
|
compress: true,
|
2016-10-27 13:37:55 +02:00
|
|
|
clientLogLevel: 'none',
|
2018-04-26 08:42:19 +02:00
|
|
|
contentBase: [paths.appPublic, paths.docRoot],
|
2017-10-10 14:46:39 +02:00
|
|
|
disableHostCheck: true,
|
2016-10-27 13:37:55 +02:00
|
|
|
hot: true,
|
|
|
|
publicPath: config.output.publicPath,
|
|
|
|
quiet: true,
|
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/
|
|
|
|
},
|
2017-06-14 11:10:48 +02:00
|
|
|
https: protocol === 'https',
|
2017-06-19 14:41:19 +02:00
|
|
|
host,
|
|
|
|
overlay: false,
|
|
|
|
historyApiFallback: {
|
|
|
|
disableDotRule: true
|
|
|
|
},
|
|
|
|
proxy: {
|
2018-06-11 17:16:04 +02:00
|
|
|
'/api': { target: proxy, changeOrigin: true },
|
|
|
|
'/static': { target: proxy, changeOrigin: true },
|
2018-07-20 16:57:23 +02:00
|
|
|
'/integration': { target: proxy, changeOrigin: true },
|
|
|
|
'/sessions/init': { target: proxy, changeOrigin: true },
|
2019-01-23 11:50:55 +01:00
|
|
|
'/oauth2': { target: proxy, changeOrigin: true },
|
|
|
|
'/batch': { target: proxy, changeOrigin: true }
|
2017-06-19 14:41:19 +02:00
|
|
|
}
|
2016-10-27 13:37:55 +02:00
|
|
|
});
|
|
|
|
|
2017-06-14 11:10:48 +02:00
|
|
|
devServer.listen(port, err => {
|
2016-08-22 15:29:35 +02:00
|
|
|
if (err) {
|
2017-10-25 16:53:22 +02:00
|
|
|
console.log(err);
|
|
|
|
return;
|
2016-08-22 15:29:35 +02:00
|
|
|
}
|
|
|
|
|
2016-10-27 13:37:55 +02:00
|
|
|
clearConsole();
|
|
|
|
console.log(chalk.cyan('Starting the development server...'));
|
2016-08-22 15:29:35 +02:00
|
|
|
console.log();
|
|
|
|
});
|
|
|
|
}
|