2018-02-04 18:39:56 +00:00
|
|
|
require('require-yaml');
|
2018-02-03 19:14:44 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const exec = require('child_process').exec;
|
2018-02-09 07:40:23 +00:00
|
|
|
const PluginError = require('plugin-error');
|
|
|
|
const argv = require('minimist')(process.argv.slice(2));
|
|
|
|
const log = require('fancy-log');
|
2019-07-04 07:34:36 +00:00
|
|
|
const request = require('request');
|
|
|
|
const e2eConfig = require('./e2e/helpers/config.js');
|
2017-10-18 04:41:17 +00:00
|
|
|
|
2017-01-31 13:13:06 +00:00
|
|
|
// Configuration
|
2018-01-29 11:37:54 +00:00
|
|
|
|
2018-02-13 21:40:02 +00:00
|
|
|
let isWindows = /^win/.test(process.platform);
|
2018-02-07 14:33:43 +00:00
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
if (argv.NODE_ENV)
|
|
|
|
process.env.NODE_ENV = argv.NODE_ENV;
|
2018-02-07 14:33:43 +00:00
|
|
|
|
2018-02-13 21:40:02 +00:00
|
|
|
let langs = ['es', 'en'];
|
2018-12-22 10:59:26 +00:00
|
|
|
let srcDir = './front';
|
2018-12-27 11:54:16 +00:00
|
|
|
let modulesDir = './modules';
|
2019-01-25 22:02:29 +00:00
|
|
|
let buildDir = 'dist';
|
2019-02-11 21:57:48 +00:00
|
|
|
let containerId = 'salix-db';
|
|
|
|
|
|
|
|
let dataSources = require('./loopback/server/datasources.json');
|
|
|
|
let dbConf = dataSources.vn;
|
|
|
|
|
2019-01-26 12:12:18 +00:00
|
|
|
let backSources = [
|
2019-01-28 08:07:46 +00:00
|
|
|
'!node_modules',
|
2019-01-26 12:12:18 +00:00
|
|
|
'loopback',
|
|
|
|
'modules/*/back/**',
|
2019-02-06 15:08:23 +00:00
|
|
|
'modules/*/back/*',
|
2019-01-28 08:07:46 +00:00
|
|
|
'back',
|
|
|
|
'print'
|
2019-01-26 12:12:18 +00:00
|
|
|
];
|
2019-01-26 01:30:46 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
// Development
|
2017-05-16 10:37:48 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
const localesRoutes = gulp.parallel(locales, routes);
|
|
|
|
localesRoutes.description = `Builds locales and routes`;
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2019-01-26 01:30:46 +00:00
|
|
|
const front = gulp.series(clean, gulp.parallel(localesRoutes, watch, webpackDevServer));
|
2019-01-09 09:02:56 +00:00
|
|
|
front.description = `Starts frontend service`;
|
2018-01-31 11:17:17 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
function backOnly(done) {
|
2018-12-27 11:54:16 +00:00
|
|
|
let app = require(`./loopback/server/server`);
|
2019-01-25 22:02:29 +00:00
|
|
|
app.start();
|
2019-01-09 09:02:56 +00:00
|
|
|
app.on('started', done);
|
|
|
|
}
|
|
|
|
backOnly.description = `Starts backend service`;
|
|
|
|
|
2019-01-26 12:12:18 +00:00
|
|
|
function backWatch(done) {
|
|
|
|
const nodemon = require('gulp-nodemon');
|
2019-01-28 11:14:22 +00:00
|
|
|
|
|
|
|
// XXX: Workaround to avoid nodemon bug
|
|
|
|
// https://github.com/remy/nodemon/issues/1346
|
2019-01-29 20:00:27 +00:00
|
|
|
let commands = ['node --inspect ./node_modules/gulp/bin/gulp.js'];
|
|
|
|
if (!isWindows) commands.unshift('sleep 1');
|
2019-01-26 12:12:18 +00:00
|
|
|
|
|
|
|
nodemon({
|
2019-01-29 20:00:27 +00:00
|
|
|
exec: commands.join(' && '),
|
2019-02-18 11:55:22 +00:00
|
|
|
ext: 'js html css json',
|
2019-01-26 12:12:18 +00:00
|
|
|
args: ['backOnly'],
|
|
|
|
watch: backSources,
|
|
|
|
done: done
|
|
|
|
});
|
|
|
|
}
|
|
|
|
backWatch.description = `Starts backend in waching mode`;
|
|
|
|
|
|
|
|
const back = gulp.series(dockerStart, backWatch);
|
|
|
|
back.description = `Starts backend and database service`;
|
|
|
|
|
|
|
|
const defaultTask = gulp.parallel(front, back);
|
|
|
|
defaultTask.description = `Starts all application services`;
|
|
|
|
|
|
|
|
// Backend tests
|
2019-01-21 16:01:01 +00:00
|
|
|
|
2019-02-13 09:00:56 +00:00
|
|
|
async function backTestOnce() {
|
2019-02-11 21:57:48 +00:00
|
|
|
let bootOptions;
|
|
|
|
|
|
|
|
if (argv['random'])
|
|
|
|
bootOptions = {dataSources};
|
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
let app = require(`./loopback/server/server`);
|
2019-02-11 21:57:48 +00:00
|
|
|
app.boot(bootOptions);
|
2019-01-09 09:02:56 +00:00
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
const jasmine = require('gulp-jasmine');
|
2018-01-11 07:12:21 +00:00
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
let options = {errorOnFail: false};
|
2019-01-21 16:01:01 +00:00
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
if (argv.junit) {
|
|
|
|
const reporters = require('jasmine-reporters');
|
|
|
|
options.reporter = new reporters.JUnitXmlReporter();
|
|
|
|
}
|
2019-01-21 16:01:01 +00:00
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
let backSpecFiles = [
|
|
|
|
'back/**/*.spec.js',
|
|
|
|
'loopback/**/*.spec.js',
|
|
|
|
'modules/*/back/**/*.spec.js'
|
|
|
|
];
|
|
|
|
|
|
|
|
gulp.src(backSpecFiles)
|
|
|
|
.pipe(jasmine(options))
|
|
|
|
.on('end', resolve)
|
|
|
|
.resume();
|
|
|
|
});
|
|
|
|
|
|
|
|
await app.disconnect();
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
2019-02-13 09:00:56 +00:00
|
|
|
backTestOnce.description = `Runs the backend tests once, can receive --junit arg to save reports on a xml file`;
|
|
|
|
|
|
|
|
async function backTestDockerOnce() {
|
|
|
|
let containerId = await docker();
|
2019-12-19 13:27:29 +00:00
|
|
|
try {
|
|
|
|
await backTestOnce();
|
|
|
|
} catch (e) {
|
|
|
|
throw e;
|
|
|
|
} finally {
|
|
|
|
if (argv['random'])
|
|
|
|
await execP(`docker rm -fv ${containerId}`);
|
|
|
|
}
|
2019-02-13 09:00:56 +00:00
|
|
|
}
|
|
|
|
backTestDockerOnce.description = `Runs backend tests using in site container once`;
|
2019-01-21 16:01:01 +00:00
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
async function backTestDocker() {
|
|
|
|
let containerId = await docker();
|
2019-12-19 13:27:29 +00:00
|
|
|
try {
|
|
|
|
await backTest();
|
|
|
|
} catch (e) {
|
|
|
|
throw e;
|
|
|
|
} finally {
|
|
|
|
if (argv['random'])
|
|
|
|
await execP(`docker rm -fv ${containerId}`);
|
|
|
|
}
|
2019-02-11 21:57:48 +00:00
|
|
|
}
|
2019-02-13 13:01:37 +00:00
|
|
|
backTestDocker.description = `Runs backend tests restoring fixtures first`;
|
2019-01-21 16:01:01 +00:00
|
|
|
|
2019-01-24 11:01:35 +00:00
|
|
|
function backTest(done) {
|
|
|
|
const nodemon = require('gulp-nodemon');
|
|
|
|
|
|
|
|
nodemon({
|
2019-02-11 21:57:48 +00:00
|
|
|
exec: ['node ./node_modules/gulp/bin/gulp.js'],
|
2019-02-13 09:00:56 +00:00
|
|
|
args: ['backTestOnce'],
|
2019-01-26 12:12:18 +00:00
|
|
|
watch: backSources,
|
2019-01-24 11:01:35 +00:00
|
|
|
done: done
|
|
|
|
});
|
|
|
|
}
|
|
|
|
backTest.description = `Watches for changes in modules to execute backTest task`;
|
2019-01-09 09:02:56 +00:00
|
|
|
|
2019-01-26 12:12:18 +00:00
|
|
|
// End to end tests
|
2019-01-09 09:02:56 +00:00
|
|
|
|
|
|
|
function e2eOnly() {
|
2019-02-06 15:08:23 +00:00
|
|
|
require('@babel/register')({presets: ['@babel/preset-env']});
|
|
|
|
require('@babel/polyfill');
|
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
const jasmine = require('gulp-jasmine');
|
2019-02-06 15:08:23 +00:00
|
|
|
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
|
|
|
|
const createNightmare = require('./e2e/helpers/nightmare');
|
2018-09-05 11:01:21 +00:00
|
|
|
|
|
|
|
if (argv.show || argv.s)
|
|
|
|
process.env.E2E_SHOW = true;
|
2019-05-23 07:30:29 +00:00
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
|
|
|
|
|
2018-09-05 11:01:21 +00:00
|
|
|
|
2019-02-06 15:08:23 +00:00
|
|
|
const specFiles = [
|
2019-06-19 07:03:45 +00:00
|
|
|
`${__dirname}/e2e/paths/01*/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/paths/02*/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/paths/03*/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/paths/04*/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/paths/05*/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/paths/06*/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/paths/07*/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/paths/08*/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/paths/09*/*[sS]pec.js`,
|
2019-02-06 15:08:23 +00:00
|
|
|
`${__dirname}/e2e/paths/**/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/helpers/extensions.js`
|
|
|
|
];
|
|
|
|
|
|
|
|
return gulp.src(specFiles).pipe(jasmine({
|
|
|
|
errorOnFail: false,
|
|
|
|
timeout: 10000,
|
|
|
|
reporter: [
|
|
|
|
new SpecReporter({
|
|
|
|
spec: {
|
|
|
|
displayStacktrace: 'summary',
|
|
|
|
displaySuccessful: true,
|
|
|
|
displayFailedSpec: true,
|
|
|
|
displaySpecDuration: true,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
.on('jasmineDone', function() {
|
|
|
|
const nightmare = createNightmare();
|
|
|
|
nightmare.end(() => {});
|
2019-11-12 07:51:50 +00:00
|
|
|
})
|
|
|
|
);
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
e2eOnly.description = `Runs the e2e tests only`;
|
2018-02-01 07:48:54 +00:00
|
|
|
|
2019-11-25 08:13:20 +00:00
|
|
|
function e2eSingleRun() {
|
|
|
|
require('@babel/register')({presets: ['@babel/preset-env']});
|
|
|
|
require('@babel/polyfill');
|
2019-12-12 07:37:35 +00:00
|
|
|
let getBrowser = require('./e2e/helpers/puppeteer').getBrowser;
|
2019-11-25 08:13:20 +00:00
|
|
|
|
|
|
|
const jasmine = require('gulp-jasmine');
|
|
|
|
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
|
|
|
|
|
|
|
|
const specFiles = [
|
|
|
|
`${__dirname}/e2e/paths/01*/*[sS]pec.js`,
|
2019-12-12 07:37:35 +00:00
|
|
|
`${__dirname}/e2e/paths/02*/*[sS]pec.js`,
|
2019-11-25 08:13:20 +00:00
|
|
|
// `${__dirname}/e2e/paths/03*/*[sS]pec.js`,
|
|
|
|
// `${__dirname}/e2e/paths/04*/*[sS]pec.js`,
|
|
|
|
// `${__dirname}/e2e/paths/05*/*[sS]pec.js`,
|
|
|
|
// `${__dirname}/e2e/paths/06*/*[sS]pec.js`,
|
|
|
|
// `${__dirname}/e2e/paths/07*/*[sS]pec.js`,
|
|
|
|
// `${__dirname}/e2e/paths/08*/*[sS]pec.js`,
|
|
|
|
// `${__dirname}/e2e/paths/09*/*[sS]pec.js`,
|
|
|
|
// `${__dirname}/e2e/paths/**/*[sS]pec.js`,
|
|
|
|
`${__dirname}/e2e/helpers/extensions.js`
|
|
|
|
];
|
|
|
|
|
|
|
|
return gulp.src(specFiles).pipe(jasmine({
|
|
|
|
errorOnFail: false,
|
|
|
|
timeout: 10000,
|
|
|
|
reporter: [
|
|
|
|
new SpecReporter({
|
|
|
|
spec: {
|
|
|
|
displayStacktrace: 'summary',
|
|
|
|
displaySuccessful: true,
|
|
|
|
displayFailedSpec: true,
|
|
|
|
displaySpecDuration: true,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
2019-12-12 07:37:35 +00:00
|
|
|
.on('jasmineDone', async function() {
|
|
|
|
await getBrowser().close();
|
|
|
|
})
|
2019-11-25 08:13:20 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
e2eSingleRun.description = `Runs the e2e tests just once`;
|
|
|
|
|
2019-07-04 07:34:36 +00:00
|
|
|
async function backendStatus() {
|
|
|
|
const milliseconds = 250;
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let timer;
|
|
|
|
let attempts = 1;
|
|
|
|
timer = setInterval(() => {
|
|
|
|
const url = `${e2eConfig.url}/api/Applications/status`;
|
|
|
|
request.get(url, (err, res) => {
|
2019-07-26 09:48:01 +00:00
|
|
|
if (err || attempts > 100) // 250ms * 100 => 25s timeout
|
|
|
|
throw new Error('Could not connect to backend');
|
|
|
|
else if (res && res.body == 'true') {
|
2019-07-04 07:34:36 +00:00
|
|
|
clearInterval(timer);
|
|
|
|
resolve(attempts);
|
|
|
|
} else
|
|
|
|
attempts++;
|
|
|
|
});
|
|
|
|
}, milliseconds);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
backendStatus.description = `Performs a simple requests to check the backend status`;
|
|
|
|
|
|
|
|
e2e = gulp.series(docker, async function isBackendReady() {
|
|
|
|
const attempts = await backendStatus();
|
|
|
|
log(`Backend ready after ${attempts} attempt(s)`);
|
|
|
|
|
|
|
|
return attempts;
|
2019-12-12 07:37:35 +00:00
|
|
|
}, e2eSingleRun);
|
2019-01-09 09:02:56 +00:00
|
|
|
e2e.description = `Restarts database and runs the e2e tests`;
|
|
|
|
|
|
|
|
function smokesOnly() {
|
2018-03-09 19:04:03 +00:00
|
|
|
const jasmine = require('gulp-jasmine');
|
2019-01-04 14:51:03 +00:00
|
|
|
return gulp.src('./e2e/smokes-tests.js')
|
2018-11-02 09:48:15 +00:00
|
|
|
.pipe(jasmine({reporter: 'none'}));
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
smokesOnly.description = `Runs the smokes tests only`;
|
2018-03-09 19:04:03 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
smokes = gulp.series(docker, smokesOnly);
|
|
|
|
smokes.description = `Restarts database and runs the smokes tests`;
|
2018-01-29 11:37:54 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
function install() {
|
2018-02-03 19:14:44 +00:00
|
|
|
const install = require('gulp-install');
|
2018-02-09 07:40:23 +00:00
|
|
|
const print = require('gulp-print');
|
|
|
|
|
2019-01-22 10:16:14 +00:00
|
|
|
let packageFiles = ['front/package.json', 'print/package.json'];
|
2018-02-09 07:40:23 +00:00
|
|
|
return gulp.src(packageFiles)
|
2018-01-29 11:37:54 +00:00
|
|
|
.pipe(print(filepath => {
|
|
|
|
return `Installing packages in ${filepath}`;
|
|
|
|
}))
|
|
|
|
.pipe(install({
|
|
|
|
npm: ['--no-package-lock']
|
|
|
|
}));
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
install.description = `Installs node dependencies in all directories`;
|
2018-06-12 09:24:43 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
const i = gulp.series(install);
|
|
|
|
i.description = `Alias for the 'install' task`;
|
2018-02-03 19:14:44 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
// Deployment
|
2018-06-12 09:24:43 +00:00
|
|
|
|
2019-01-25 22:02:29 +00:00
|
|
|
const build = gulp.series(clean, gulp.parallel(localesRoutes, webpack));
|
2019-01-09 09:02:56 +00:00
|
|
|
build.description = `Generates binaries and configuration files`;
|
2018-01-08 14:06:20 +00:00
|
|
|
|
2019-01-26 01:30:46 +00:00
|
|
|
function clean() {
|
2018-02-09 07:40:23 +00:00
|
|
|
const del = require('del');
|
|
|
|
const files = [
|
2018-12-27 15:10:55 +00:00
|
|
|
`${buildDir}/*`
|
2018-02-09 07:40:23 +00:00
|
|
|
];
|
|
|
|
return del(files, {force: true});
|
|
|
|
}
|
2019-01-26 01:30:46 +00:00
|
|
|
clean.description = `Cleans all files generated by the 'build' task`;
|
2018-02-09 07:40:23 +00:00
|
|
|
|
2017-01-31 13:13:06 +00:00
|
|
|
// Webpack
|
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
function webpack(done) {
|
|
|
|
const webpackCompile = require('webpack');
|
2018-12-20 13:37:29 +00:00
|
|
|
const merge = require('webpack-merge');
|
|
|
|
|
|
|
|
let wpConfig = require('./webpack.config.js');
|
|
|
|
wpConfig = merge(wpConfig, {});
|
2018-02-09 07:40:23 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
let compiler = webpackCompile(wpConfig);
|
2017-01-31 13:13:06 +00:00
|
|
|
|
|
|
|
compiler.run(function(err, stats) {
|
2018-02-09 07:40:23 +00:00
|
|
|
if (err) throw new PluginError('webpack', err);
|
2018-12-20 13:37:29 +00:00
|
|
|
log('[webpack]', stats.toString(wpConfig.stats));
|
2019-01-09 09:02:56 +00:00
|
|
|
done();
|
2017-01-31 13:13:06 +00:00
|
|
|
});
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
webpack.description = `Transpiles application into files`;
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
function webpackDevServer(done) {
|
2018-02-09 07:40:23 +00:00
|
|
|
const webpack = require('webpack');
|
2018-12-20 13:37:29 +00:00
|
|
|
const merge = require('webpack-merge');
|
|
|
|
const WebpackDevServer = require('webpack-dev-server');
|
2018-02-09 07:40:23 +00:00
|
|
|
|
2018-12-20 13:37:29 +00:00
|
|
|
let wpConfig = require('./webpack.config.js');
|
|
|
|
wpConfig = merge(wpConfig, {});
|
|
|
|
|
|
|
|
let devServer = wpConfig.devServer;
|
|
|
|
|
|
|
|
for (let entryName in wpConfig.entry) {
|
|
|
|
let entry = wpConfig.entry[entryName];
|
2019-01-26 12:12:18 +00:00
|
|
|
if (!Array.isArray(entry))
|
|
|
|
entry = [entry];
|
|
|
|
|
|
|
|
let wdsAssets = [
|
|
|
|
`webpack-dev-server/client?http://localhost:${devServer.port}/`,
|
|
|
|
`webpack/hot/dev-server`
|
|
|
|
];
|
|
|
|
wpConfig.entry[entryName] = wdsAssets.concat(entry);
|
2018-12-20 13:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let compiler = webpack(wpConfig);
|
|
|
|
new WebpackDevServer(compiler, wpConfig.devServer)
|
|
|
|
.listen(devServer.port, devServer.host, function(err) {
|
|
|
|
if (err) throw new PluginError('webpack-dev-server', err);
|
2019-10-14 10:01:19 +00:00
|
|
|
// XXX: Keep the server alive or continue?
|
2019-01-09 09:02:56 +00:00
|
|
|
done();
|
2018-12-20 13:37:29 +00:00
|
|
|
});
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
webpackDevServer.description = `Transpiles application into memory`;
|
2017-01-31 13:13:06 +00:00
|
|
|
|
|
|
|
// Locale
|
|
|
|
|
2018-12-27 11:54:16 +00:00
|
|
|
let localeFiles = [
|
|
|
|
`${srcDir}/**/locale/*.yml`,
|
|
|
|
`${modulesDir}/*/front/**/locale/*.yml`
|
|
|
|
];
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-13 21:40:02 +00:00
|
|
|
/**
|
|
|
|
* Mixes all locale files into one JSON file per module and language. It looks
|
|
|
|
* recursively in all project directories for locale folders with per language
|
|
|
|
* yaml translation files.
|
2019-01-09 09:02:56 +00:00
|
|
|
*
|
|
|
|
* @return {Stream} The merged gulp streams
|
2018-02-13 21:40:02 +00:00
|
|
|
*/
|
2019-01-09 09:02:56 +00:00
|
|
|
function locales() {
|
|
|
|
const mergeJson = require('gulp-merge-json');
|
2019-03-26 11:05:53 +00:00
|
|
|
const gulpFile = require('gulp-file');
|
2018-02-04 14:46:46 +00:00
|
|
|
const yaml = require('gulp-yaml');
|
2018-02-05 18:34:04 +00:00
|
|
|
const merge = require('merge-stream');
|
2019-01-26 12:12:18 +00:00
|
|
|
const fs = require('fs-extra');
|
2018-02-05 18:34:04 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
let streams = [];
|
2018-12-27 11:54:16 +00:00
|
|
|
let localePaths = [];
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2019-01-26 01:30:46 +00:00
|
|
|
let modules = fs.readdirSync(modulesDir);
|
|
|
|
for (let mod of modules)
|
2018-12-27 11:54:16 +00:00
|
|
|
localePaths[mod] = `${modulesDir}/${mod}`;
|
|
|
|
|
2019-01-25 22:02:29 +00:00
|
|
|
let baseMods = ['core', 'salix'];
|
2018-12-27 11:54:16 +00:00
|
|
|
for (let mod of baseMods)
|
|
|
|
localePaths[mod] = `${srcDir}/${mod}`;
|
|
|
|
|
|
|
|
for (let mod in localePaths) {
|
|
|
|
let path = localePaths[mod];
|
2018-02-03 19:14:44 +00:00
|
|
|
for (let lang of langs) {
|
2018-12-27 11:54:16 +00:00
|
|
|
let localeFiles = `${path}/**/locale/${lang}.yml`;
|
2017-03-01 08:55:17 +00:00
|
|
|
streams.push(gulp.src(localeFiles)
|
2018-02-04 14:46:46 +00:00
|
|
|
.pipe(yaml())
|
2019-01-09 09:02:56 +00:00
|
|
|
.pipe(mergeJson({fileName: `${lang}.json`}))
|
2017-03-01 08:55:17 +00:00
|
|
|
.pipe(gulp.dest(`${buildDir}/locale/${mod}`)));
|
|
|
|
}
|
2018-12-20 13:37:29 +00:00
|
|
|
}
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2019-03-26 11:05:53 +00:00
|
|
|
for (let mod in localePaths) {
|
|
|
|
for (let lang of langs) {
|
|
|
|
let file = `${buildDir}/locale/${mod}/${lang}.json`;
|
|
|
|
if (fs.existsSync(file)) continue;
|
|
|
|
streams.push(gulpFile('en.json', '{}', {src: true})
|
|
|
|
.pipe(gulp.dest(`${buildDir}/locale/${mod}`)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-31 13:13:06 +00:00
|
|
|
return merge(streams);
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
locales.description = `Generates client locale files`;
|
2017-01-31 13:13:06 +00:00
|
|
|
|
|
|
|
// Routes
|
|
|
|
|
2018-12-27 11:54:16 +00:00
|
|
|
let routeFiles = `${modulesDir}/*/front/routes.json`;
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
function routes() {
|
2018-02-05 18:34:04 +00:00
|
|
|
const concat = require('gulp-concat');
|
|
|
|
const wrap = require('gulp-wrap');
|
|
|
|
|
2017-01-31 13:13:06 +00:00
|
|
|
return gulp.src(routeFiles)
|
2017-10-24 06:56:18 +00:00
|
|
|
.pipe(concat('routes.js', {newLine: ','}))
|
|
|
|
.pipe(wrap('var routes = [<%=contents%>\n];'))
|
|
|
|
.pipe(gulp.dest(buildDir));
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
routes.description = 'Merges all module routes file into one file';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
|
|
|
// Watch
|
2018-01-29 11:37:54 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
function watch(done) {
|
|
|
|
gulp.watch(routeFiles, gulp.series(routes));
|
|
|
|
gulp.watch(localeFiles, gulp.series(locales));
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
watch.description = `Watches for changes in routes and locale files`;
|
2017-10-18 04:41:17 +00:00
|
|
|
|
2018-02-01 15:01:49 +00:00
|
|
|
// Docker
|
2018-01-29 11:37:54 +00:00
|
|
|
|
2018-02-13 21:40:02 +00:00
|
|
|
/**
|
2019-01-09 09:02:56 +00:00
|
|
|
* Builds the database image and runs a container. It only rebuilds the
|
|
|
|
* image when fixtures have been modified or when the day on which the
|
|
|
|
* image was built is different to today. Some workarounds have been used
|
|
|
|
* to avoid a bug with OverlayFS driver on MacOS.
|
2018-02-13 21:40:02 +00:00
|
|
|
*/
|
2019-01-09 09:02:56 +00:00
|
|
|
async function docker() {
|
|
|
|
let d = new Date();
|
|
|
|
let pad = v => v < 10 ? '0' + v : v;
|
|
|
|
let stamp = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
2019-03-04 07:13:09 +00:00
|
|
|
await execP(`docker build --build-arg STAMP=${stamp} -t salix-db ./db`);
|
2019-01-09 09:02:56 +00:00
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
let dockerArgs = `--name ${containerId} -p 3306:${dbConf.port}`;
|
|
|
|
|
|
|
|
if (argv['random'])
|
|
|
|
dockerArgs = '-p 3306';
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
await execP(`docker rm -fv ${containerId}`);
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
2019-01-09 12:04:49 +00:00
|
|
|
let runChown = process.platform != 'linux';
|
2019-01-26 19:30:45 +00:00
|
|
|
if (argv['run-chown']) runChown = true;
|
2019-01-26 19:26:14 +00:00
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
let result = await execP(`docker run --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`);
|
|
|
|
containerId = result.stdout;
|
|
|
|
|
|
|
|
if (argv['random']) {
|
2019-08-06 12:20:23 +00:00
|
|
|
let inspect = await execP(`docker inspect -f "{{json .NetworkSettings}}" ${containerId}`);
|
2019-08-06 12:31:25 +00:00
|
|
|
let netSettings = JSON.parse(inspect.stdout);
|
2019-08-06 12:18:15 +00:00
|
|
|
|
2019-08-06 12:45:45 +00:00
|
|
|
dbConf.host = netSettings.Gateway;
|
2019-08-06 12:18:15 +00:00
|
|
|
dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort'];
|
2019-02-11 21:57:48 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
if (runChown) await dockerWait();
|
2019-02-11 21:57:48 +00:00
|
|
|
return containerId;
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
docker.description = `Builds the database image and runs a container`;
|
2018-02-09 07:40:23 +00:00
|
|
|
|
2018-02-13 21:40:02 +00:00
|
|
|
/**
|
2019-01-09 09:02:56 +00:00
|
|
|
* Does the minium effort to start the database container, if it doesn't exists
|
|
|
|
* calls the 'docker' task, if it is started does nothing. Keep in mind that when
|
2018-02-13 21:40:02 +00:00
|
|
|
* you do not rebuild the docker you may be using an outdated version of it.
|
2018-03-12 08:19:50 +00:00
|
|
|
* See the 'docker' task for more info.
|
2018-02-13 21:40:02 +00:00
|
|
|
*/
|
2019-01-09 09:02:56 +00:00
|
|
|
async function dockerStart() {
|
2018-02-13 21:40:02 +00:00
|
|
|
let state;
|
2018-02-09 07:40:23 +00:00
|
|
|
try {
|
2019-02-11 21:57:48 +00:00
|
|
|
let result = await execP(`docker inspect -f "{{json .State}}" ${containerId}`);
|
2018-02-13 21:40:02 +00:00
|
|
|
state = JSON.parse(result.stdout);
|
2018-02-09 07:40:23 +00:00
|
|
|
} catch (err) {
|
2019-01-09 09:02:56 +00:00
|
|
|
return await docker();
|
2018-02-09 07:40:23 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 21:40:02 +00:00
|
|
|
switch (state.Status) {
|
2018-02-09 07:40:23 +00:00
|
|
|
case 'running':
|
|
|
|
return;
|
|
|
|
case 'exited':
|
2019-02-11 21:57:48 +00:00
|
|
|
await execP(`docker start ${containerId}`);
|
2019-01-09 09:02:56 +00:00
|
|
|
await dockerWait();
|
2019-01-04 12:32:04 +00:00
|
|
|
return;
|
2018-02-09 07:40:23 +00:00
|
|
|
default:
|
2019-01-07 07:41:54 +00:00
|
|
|
throw new Error(`Unknown docker status: ${state.Status}`);
|
2018-02-09 07:40:23 +00:00
|
|
|
}
|
2019-01-09 09:02:56 +00:00
|
|
|
}
|
|
|
|
dockerStart.description = `Starts the database container`;
|
|
|
|
|
|
|
|
function dockerWait() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const mysql = require('mysql2');
|
|
|
|
|
|
|
|
let interval = 100;
|
|
|
|
let elapsedTime = 0;
|
2019-02-11 23:44:39 +00:00
|
|
|
let maxInterval = 4 * 60 * 1000;
|
2019-01-09 09:02:56 +00:00
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
let myConf = {
|
|
|
|
user: dbConf.username,
|
|
|
|
password: dbConf.password,
|
|
|
|
host: dbConf.host,
|
2019-02-27 16:04:32 +00:00
|
|
|
port: dbConf.port
|
2019-02-11 21:57:48 +00:00
|
|
|
};
|
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
log('Waiting for MySQL init process...');
|
|
|
|
checker();
|
|
|
|
|
|
|
|
async function checker() {
|
|
|
|
elapsedTime += interval;
|
|
|
|
let state;
|
|
|
|
|
|
|
|
try {
|
2019-02-11 21:57:48 +00:00
|
|
|
let result = await execP(`docker container inspect -f "{{json .State}}" ${containerId}`);
|
2019-01-09 09:02:56 +00:00
|
|
|
state = JSON.parse(result.stdout);
|
|
|
|
} catch (err) {
|
|
|
|
return reject(new Error(err.message));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.Status === 'exited')
|
|
|
|
return reject(new Error('Docker exited, please see the docker logs for more info'));
|
|
|
|
|
2019-02-11 21:57:48 +00:00
|
|
|
let conn = mysql.createConnection(myConf);
|
2019-01-09 09:02:56 +00:00
|
|
|
conn.on('error', () => {});
|
|
|
|
conn.connect(err => {
|
|
|
|
conn.destroy();
|
2019-02-11 23:39:39 +00:00
|
|
|
if (!err) {
|
|
|
|
log('MySQL process ready.');
|
|
|
|
return resolve();
|
|
|
|
}
|
2019-01-09 09:02:56 +00:00
|
|
|
|
|
|
|
if (elapsedTime >= maxInterval)
|
2019-02-11 23:44:39 +00:00
|
|
|
reject(new Error(`MySQL not initialized whithin ${elapsedTime / 1000} secs`));
|
2019-01-09 09:02:56 +00:00
|
|
|
else
|
|
|
|
setTimeout(checker, interval);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
dockerWait.description = `Waits until database service is ready`;
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
// Helpers
|
2018-02-01 11:52:58 +00:00
|
|
|
|
2018-02-13 21:40:02 +00:00
|
|
|
/**
|
|
|
|
* Promisified version of exec().
|
|
|
|
*
|
|
|
|
* @param {String} command The exec command
|
|
|
|
* @return {Promise} The promise
|
|
|
|
*/
|
2018-02-09 07:40:23 +00:00
|
|
|
function execP(command) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
exec(command, (err, stdout, stderr) => {
|
|
|
|
if (err)
|
|
|
|
reject(err);
|
2018-12-20 13:37:29 +00:00
|
|
|
else {
|
2018-02-09 07:40:23 +00:00
|
|
|
resolve({
|
|
|
|
stdout: stdout,
|
|
|
|
stderr: stderr
|
|
|
|
});
|
2018-12-20 13:37:29 +00:00
|
|
|
}
|
2018-02-09 07:40:23 +00:00
|
|
|
});
|
2018-02-01 11:52:58 +00:00
|
|
|
});
|
2018-02-09 07:40:23 +00:00
|
|
|
}
|
2018-02-01 11:52:58 +00:00
|
|
|
|
2019-01-09 09:02:56 +00:00
|
|
|
module.exports = {
|
|
|
|
default: defaultTask,
|
|
|
|
front,
|
|
|
|
back,
|
|
|
|
backOnly,
|
2019-01-26 12:12:18 +00:00
|
|
|
backWatch,
|
2019-02-13 09:00:56 +00:00
|
|
|
backTestOnce,
|
|
|
|
backTestDockerOnce,
|
2019-01-21 16:01:01 +00:00
|
|
|
backTest,
|
2019-02-11 21:57:48 +00:00
|
|
|
backTestDocker,
|
2019-01-09 09:02:56 +00:00
|
|
|
e2e,
|
2019-02-11 21:57:48 +00:00
|
|
|
e2eOnly,
|
2019-01-09 09:02:56 +00:00
|
|
|
smokes,
|
2019-02-11 21:57:48 +00:00
|
|
|
smokesOnly,
|
2019-01-09 14:41:15 +00:00
|
|
|
i,
|
2019-02-11 21:57:48 +00:00
|
|
|
install,
|
2019-01-09 09:02:56 +00:00
|
|
|
build,
|
2019-01-26 01:30:46 +00:00
|
|
|
clean,
|
2019-01-09 09:02:56 +00:00
|
|
|
webpack,
|
|
|
|
webpackDevServer,
|
|
|
|
routes,
|
2019-02-11 21:57:48 +00:00
|
|
|
locales,
|
2019-01-09 09:02:56 +00:00
|
|
|
localesRoutes,
|
|
|
|
watch,
|
|
|
|
docker,
|
|
|
|
dockerStart,
|
2019-07-04 07:34:36 +00:00
|
|
|
dockerWait,
|
2019-12-12 07:37:35 +00:00
|
|
|
backendStatus,
|
|
|
|
e2eSingleRun
|
2019-01-09 09:02:56 +00:00
|
|
|
};
|