Gulp refactor

This commit is contained in:
Juan Ferrer Toribio 2018-02-03 23:07:28 +01:00
parent 681310d9b6
commit 4a388f241c
2 changed files with 38 additions and 46 deletions

View File

@ -103,10 +103,10 @@ gulp.task('install', () => {
// Deployment
gulp.task('build', ['clean'], () => {
return gulp.start('routes', 'locales', 'webpack', 'build-conf');
return gulp.start('routes', 'locales', 'webpack', 'docker-compose', 'nginx-conf');
});
gulp.task('build-conf', async () => {
gulp.task('docker-compose', async () => {
let compose = await fs.readFile('./docker-compose.tpl.yml', 'utf8');
const yaml = require('js-yaml');
@ -136,11 +136,41 @@ gulp.task('build-conf', async () => {
let ymlString = yaml.safeDump(composeYml);
await fs.writeFile('./docker-compose.yml', ymlString);
await buildNginxConf();
});
// Services
// Nginx & services
gulp.task('nginx', ['nginx-conf'], callback => {
let command = isWindows ? 'start.cmd' : 'start.sh';
command = path.join(`${nginxDir}/${command}`);
exec(command, (err, stdout, stderr) => {
if (stderr) console.log(stderr);
callback(err);
});
});
gulp.task('nginx-conf', async () => {
const mustache = require('mustache');
let params = {
services: await getServices(),
defaultService: defaultService,
defaultPort: defaultPort,
devServerPort: devServerPort,
port: proxyConf.port,
host: proxyConf.host
};
let confFile = `${nginxDir}/nginx.${env}.mst`;
if (!await fs.exists(confFile))
confFile = `${nginxDir}/nginx.mst`;
let template = await fs.readFile(confFile, 'utf8');
let nginxConf = mustache.render(template, params);
await fs.writeFile(`${nginxDir}/temp/nginx.conf`, nginxConf);
});
let services;
@ -168,44 +198,6 @@ async function getServices() {
return services;
}
// Nginx
gulp.task('nginx', async () => {
await buildNginxConf();
let command = isWindows ? 'start.cmd' : 'start.sh';
command = path.join(`${nginxDir}/${command}`);
return new Promise((resolve, reject) => {
exec(command, (err, stdout, stderr) => {
if (stderr) console.log(stderr);
if (err) return reject(err);
resolve();
});
});
});
async function buildNginxConf() {
const mustache = require('mustache');
let params = {
services: await getServices(),
defaultService: defaultService,
defaultPort: defaultPort,
devServerPort: devServerPort,
port: proxyConf.port,
host: proxyConf.host
};
let confFile = `${nginxDir}/nginx.${env}.mst`;
if (!await fs.exists(confFile))
confFile = `${nginxDir}/nginx.mst`;
let template = await fs.readFile(confFile, 'utf8');
let nginxConf = mustache.render(template, params);
await fs.writeFile(`${nginxDir}/temp/nginx.conf`, nginxConf);
}
// Webpack
gulp.task('webpack', function(cb) {

View File

@ -1,7 +1,7 @@
{
"host": "localhost",
"port": 5000,
"main": "salix",
"defaultPort": 3000,
"devServerPort": 8081,
"host": "localhost",
"port": 5000
"devServerPort": 8081
}