2018-02-04 18:39:56 +00:00
|
|
|
require('require-yaml');
|
2018-02-03 19:14:44 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const runSequence = require('run-sequence');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
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');
|
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-03 21:53:02 +00:00
|
|
|
const 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-03 21:53:02 +00:00
|
|
|
const env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
const langs = ['es', 'en'];
|
|
|
|
const srcDir = './client';
|
|
|
|
const servicesDir = './services';
|
|
|
|
const nginxDir = `${servicesDir}/nginx`;
|
|
|
|
const buildDir = `${nginxDir}/static`;
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-04 18:39:56 +00:00
|
|
|
let proxyConf = require(`${nginxDir}/config.yml`);
|
|
|
|
let proxyEnvFile = `${nginxDir}/config.${env}.yml`;
|
2018-02-03 21:53:02 +00:00
|
|
|
|
|
|
|
if (fs.existsSync(proxyEnvFile))
|
|
|
|
Object.assign(proxyConf, require(proxyEnvFile));
|
|
|
|
|
|
|
|
const defaultService = proxyConf.main;
|
|
|
|
const defaultPort = proxyConf.defaultPort;
|
|
|
|
const devServerPort = proxyConf.devServerPort;
|
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
// Development
|
2017-05-16 10:37:48 +00:00
|
|
|
|
2018-01-29 11:37:54 +00:00
|
|
|
gulp.task('default', () => {
|
2017-06-02 13:23:19 +00:00
|
|
|
return gulp.start('services', 'client');
|
2017-05-16 10:37:48 +00:00
|
|
|
});
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('client', ['build-clean'], () => {
|
2017-05-16 10:37:48 +00:00
|
|
|
return gulp.start('watch', 'routes', 'locales', 'webpack-dev-server');
|
|
|
|
});
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('services', async () => {
|
|
|
|
await runSequenceP('docker-start', 'services-only', 'nginx');
|
2018-01-31 13:56:55 +00:00
|
|
|
});
|
2018-01-31 11:17:17 +00:00
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('services-only', async () => {
|
2018-02-03 19:14:44 +00:00
|
|
|
const services = await getServices();
|
|
|
|
for (let service of services)
|
|
|
|
require(service.index).start(service.port);
|
2017-06-02 13:23:19 +00:00
|
|
|
});
|
2018-01-11 07:12:21 +00:00
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('e2e', ['docker-rebuild'], async () => {
|
|
|
|
await runSequenceP('e2e-only');
|
2018-02-01 07:48:54 +00:00
|
|
|
});
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('e2e-only', () => {
|
2018-02-03 19:14:44 +00:00
|
|
|
const jasmine = require('gulp-jasmine');
|
2018-02-09 07:40:23 +00:00
|
|
|
return gulp.src('./e2e_tests.js')
|
2018-02-01 07:48:54 +00:00
|
|
|
.pipe(jasmine({reporter: 'none'}));
|
|
|
|
});
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('clean', ['build-clean', 'nginx-clean']);
|
2018-01-29 11:37:54 +00:00
|
|
|
|
2018-02-07 12:24:46 +00:00
|
|
|
gulp.task('i', ['install']);
|
|
|
|
|
2018-01-29 11:37:54 +00:00
|
|
|
gulp.task('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');
|
|
|
|
|
|
|
|
let packageFiles = [];
|
2018-02-03 21:53:02 +00:00
|
|
|
let services = fs.readdirSync(servicesDir);
|
2018-01-29 11:37:54 +00:00
|
|
|
services.push('..');
|
|
|
|
services.forEach(service => {
|
2018-02-09 07:40:23 +00:00
|
|
|
packageFiles.push(`${servicesDir}/${service}/package.json`);
|
2018-01-29 11:37:54 +00:00
|
|
|
});
|
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']
|
|
|
|
}));
|
2018-01-11 07:12:21 +00:00
|
|
|
});
|
2017-06-02 13:23:19 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
// Deployment
|
|
|
|
|
2018-02-12 12:16:49 +00:00
|
|
|
gulp.task('build', ['clean'], async () => {
|
|
|
|
await runSequenceP(['routes', 'locales', 'webpack', 'docker-compose', 'nginx-conf']);
|
2018-02-03 19:14:44 +00:00
|
|
|
});
|
|
|
|
|
2018-02-03 22:07:28 +00:00
|
|
|
gulp.task('docker-compose', async () => {
|
2018-02-03 19:14:44 +00:00
|
|
|
const yaml = require('js-yaml');
|
2018-02-09 07:40:23 +00:00
|
|
|
|
2018-02-05 18:34:04 +00:00
|
|
|
let compose = await fs.readFile('./docker-compose.tpl.yml', 'utf8');
|
2018-02-03 19:14:44 +00:00
|
|
|
let composeYml = yaml.safeLoad(compose);
|
|
|
|
let services = await getServices();
|
|
|
|
|
|
|
|
for (let service of services) {
|
2018-02-08 06:07:07 +00:00
|
|
|
let dockerFile = `${__dirname}/services/${service.name}/Dockerfile`;
|
2018-02-03 19:14:44 +00:00
|
|
|
|
2018-02-07 14:02:16 +00:00
|
|
|
// if (await fs.exists(`./services/${service.name}/Dockerfile`))
|
|
|
|
// dockerFile = 'Dockerfile';
|
2018-02-03 19:14:44 +00:00
|
|
|
|
|
|
|
composeYml.services[service.name] = {
|
|
|
|
environment: ['NODE_ENV=${NODE_ENV}'],
|
|
|
|
container_name: `\${BRANCH_NAME}-${service.name}`,
|
|
|
|
image: `${service.name}:\${TAG}`,
|
|
|
|
build: {
|
2018-02-07 13:45:39 +00:00
|
|
|
context: `./services`,
|
2018-02-03 19:14:44 +00:00
|
|
|
dockerfile: dockerFile
|
|
|
|
},
|
2018-02-08 06:51:24 +00:00
|
|
|
ports: [`${service.port}:${defaultPort}`]
|
2018-02-03 19:14:44 +00:00
|
|
|
};
|
|
|
|
composeYml.services.nginx.links.push(
|
|
|
|
`${service.name}:\${BRANCH_NAME}-${service.name}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let ymlString = yaml.safeDump(composeYml);
|
|
|
|
await fs.writeFile('./docker-compose.yml', ymlString);
|
2018-01-08 14:06:20 +00:00
|
|
|
});
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('build-clean', () => {
|
|
|
|
const del = require('del');
|
|
|
|
const files = [
|
|
|
|
`${buildDir}/*`,
|
|
|
|
`!${buildDir}/templates`,
|
|
|
|
`!${buildDir}/images`,
|
|
|
|
`docker-compose.yml`
|
|
|
|
];
|
|
|
|
return del(files, {force: true});
|
|
|
|
});
|
|
|
|
|
2018-02-03 22:07:28 +00:00
|
|
|
// Nginx & services
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-05 18:22:38 +00:00
|
|
|
let nginxConf = 'temp/nginx.conf';
|
|
|
|
let nginxTemp = `${nginxDir}/temp`;
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('nginx', async () => {
|
|
|
|
await runSequenceP('nginx-stop', 'nginx-start');
|
|
|
|
});
|
2018-02-05 18:22:38 +00:00
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('nginx-start', ['nginx-conf'], async () => {
|
2018-02-05 18:22:38 +00:00
|
|
|
let nginxBin = await nginxGetBin();
|
|
|
|
|
|
|
|
if (isWindows)
|
|
|
|
nginxBin = `start /B ${nginxBin}`;
|
|
|
|
|
2018-02-09 11:43:14 +00:00
|
|
|
log(`Application will be at http://${proxyConf.host}:${proxyConf.port}/`);
|
2018-02-09 07:40:23 +00:00
|
|
|
await execP(`${nginxBin} -c "${nginxConf}" -p "${nginxDir}"`);
|
2017-09-26 14:59:24 +00:00
|
|
|
});
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('nginx-stop', async () => {
|
2018-02-05 18:22:38 +00:00
|
|
|
try {
|
|
|
|
let nginxBin = await nginxGetBin();
|
|
|
|
await fs.stat(`${nginxTemp}/nginx.pid`);
|
2018-02-09 07:40:23 +00:00
|
|
|
await execP(`${nginxBin} -c "${nginxConf}" -p "${nginxDir}" -s stop`);
|
2018-02-05 18:22:38 +00:00
|
|
|
} catch (e) {}
|
|
|
|
});
|
|
|
|
|
2018-02-12 12:16:49 +00:00
|
|
|
gulp.task('nginx-conf', ['nginx-stop'], async () => {
|
2018-02-03 19:14:44 +00:00
|
|
|
const mustache = require('mustache');
|
|
|
|
|
2018-02-07 12:24:46 +00:00
|
|
|
if (!await fs.exists(nginxTemp))
|
|
|
|
await fs.mkdir(nginxTemp);
|
2018-02-07 08:51:51 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
let params = {
|
2018-02-03 21:53:02 +00:00
|
|
|
services: await getServices(),
|
2018-02-03 19:14:44 +00:00
|
|
|
defaultService: defaultService,
|
|
|
|
defaultPort: defaultPort,
|
2018-02-03 21:53:02 +00:00
|
|
|
devServerPort: devServerPort,
|
|
|
|
port: proxyConf.port,
|
|
|
|
host: proxyConf.host
|
2018-02-03 19:14:44 +00:00
|
|
|
};
|
2018-02-03 21:53:02 +00:00
|
|
|
|
|
|
|
let confFile = `${nginxDir}/nginx.${env}.mst`;
|
|
|
|
|
|
|
|
if (!await fs.exists(confFile))
|
|
|
|
confFile = `${nginxDir}/nginx.mst`;
|
|
|
|
|
|
|
|
let template = await fs.readFile(confFile, 'utf8');
|
2018-02-03 19:14:44 +00:00
|
|
|
let nginxConf = mustache.render(template, params);
|
|
|
|
|
2018-02-07 08:51:51 +00:00
|
|
|
await fs.writeFile(`${nginxTemp}/nginx.conf`, nginxConf);
|
2018-02-03 22:07:28 +00:00
|
|
|
});
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('nginx-clean', ['nginx-stop'], () => {
|
2018-02-04 18:39:56 +00:00
|
|
|
const del = require('del');
|
2018-02-07 08:51:51 +00:00
|
|
|
return del([`${nginxTemp}/*`], {force: true});
|
2018-02-04 18:39:56 +00:00
|
|
|
});
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
async function nginxGetBin() {
|
|
|
|
if (isWindows)
|
|
|
|
return 'nginx';
|
|
|
|
try {
|
|
|
|
let nginxBin = '/usr/sbin/nginx';
|
|
|
|
await fs.stat(nginxBin);
|
|
|
|
return nginxBin;
|
|
|
|
} catch (e) {
|
|
|
|
return 'nginx';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-03 22:07:28 +00:00
|
|
|
async function getServices() {
|
2018-02-07 12:24:46 +00:00
|
|
|
let services;
|
2018-02-03 22:07:28 +00:00
|
|
|
let startPort = defaultPort + 1;
|
|
|
|
services = [];
|
|
|
|
|
|
|
|
const serviceDirs = await fs.readdir(servicesDir);
|
|
|
|
const exclude = ['loopback'];
|
|
|
|
|
|
|
|
for (let service of serviceDirs) {
|
|
|
|
let index = `${servicesDir}/${service}/server/server.js`;
|
|
|
|
if (!await fs.exists(index) || exclude.indexOf(service) !== -1) continue;
|
|
|
|
|
|
|
|
let port = service == defaultService ? defaultPort : startPort++;
|
|
|
|
services.push({
|
|
|
|
name: service,
|
|
|
|
index: index,
|
|
|
|
port: port
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return services;
|
2018-02-03 19:14:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-31 13:13:06 +00:00
|
|
|
// Webpack
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('webpack', function(callback) {
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
const webpackConfig = require('./webpack.config.js');
|
2018-02-03 19:14:44 +00:00
|
|
|
let configCopy = Object.create(webpackConfig);
|
|
|
|
let compiler = webpack(configCopy);
|
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);
|
|
|
|
log('[webpack]', stats.toString({colors: true}));
|
|
|
|
callback();
|
2017-01-31 13:13:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-05 10:38:28 +00:00
|
|
|
gulp.task('webpack-dev-server', function() {
|
2018-02-09 07:40:23 +00:00
|
|
|
const WebpackDevServer = require('webpack-dev-server');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
const webpackConfig = require('./webpack.config.js');
|
2018-02-03 19:14:44 +00:00
|
|
|
let configCopy = Object.create(webpackConfig);
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
for (let entry in configCopy.entry) {
|
2017-01-31 13:13:06 +00:00
|
|
|
configCopy.entry[entry]
|
2018-02-03 19:14:44 +00:00
|
|
|
.unshift(`webpack-dev-server/client?http://127.0.0.1:${devServerPort}/`);
|
2017-03-01 08:55:17 +00:00
|
|
|
}
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
let compiler = webpack(configCopy);
|
2017-03-01 08:55:17 +00:00
|
|
|
new WebpackDevServer(compiler, {
|
2017-01-31 13:13:06 +00:00
|
|
|
publicPath: '/',
|
|
|
|
contentBase: buildDir,
|
|
|
|
quiet: false,
|
|
|
|
noInfo: false,
|
2017-10-24 06:56:18 +00:00
|
|
|
// hot: true,
|
2017-01-31 13:13:06 +00:00
|
|
|
stats: {
|
|
|
|
assets: true,
|
|
|
|
colors: true,
|
|
|
|
version: false,
|
|
|
|
hash: false,
|
|
|
|
timings: true,
|
|
|
|
chunks: false,
|
|
|
|
chunkModules: false
|
|
|
|
}
|
2018-02-03 19:14:44 +00:00
|
|
|
}).listen(devServerPort, '127.0.0.1', function(err) {
|
2018-02-09 07:40:23 +00:00
|
|
|
if (err) throw new PluginError('webpack-dev-server', err);
|
2017-01-31 13:13:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Locale
|
|
|
|
|
2018-02-07 12:24:46 +00:00
|
|
|
let localeFiles = `${srcDir}/**/locale/*.yml`;
|
2017-01-31 13:13:06 +00:00
|
|
|
|
|
|
|
gulp.task('locales', function() {
|
2018-02-03 19:14:44 +00:00
|
|
|
const extend = require('gulp-extend');
|
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');
|
2018-02-09 07:40:23 +00:00
|
|
|
const modules = require('./client/modules.yml');
|
2018-02-05 18:34:04 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
let streams = [];
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
for (let mod in modules)
|
|
|
|
for (let lang of langs) {
|
2018-02-04 14:46:46 +00:00
|
|
|
let localeFiles = `./client/${mod}/**/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())
|
2017-03-01 08:55:17 +00:00
|
|
|
.pipe(extend(`${lang}.json`))
|
|
|
|
.pipe(gulp.dest(`${buildDir}/locale/${mod}`)));
|
|
|
|
}
|
2017-01-31 13:13:06 +00:00
|
|
|
|
|
|
|
return merge(streams);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Routes
|
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
let routeFiles = `${srcDir}/**/routes.json`;
|
2017-01-31 13:13:06 +00:00
|
|
|
|
|
|
|
gulp.task('routes', function() {
|
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));
|
2017-01-31 13:13:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Watch
|
2018-01-29 11:37:54 +00:00
|
|
|
|
2017-01-31 13:13:06 +00:00
|
|
|
gulp.task('watch', function() {
|
|
|
|
gulp.watch(routeFiles, ['routes']);
|
|
|
|
gulp.watch(localeFiles, ['locales']);
|
|
|
|
});
|
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-09 07:40:23 +00:00
|
|
|
gulp.task('docker-rebuild', async () => {
|
|
|
|
try {
|
|
|
|
await execP('docker rm -f dblocal');
|
|
|
|
} catch (e) {}
|
|
|
|
try {
|
|
|
|
await execP('docker rmi dblocal:latest');
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
await runSequenceP('docker-run');
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('docker-start', async () => {
|
|
|
|
let result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
result = await execP('docker container inspect -f "{{json .State}}" dblocal');
|
|
|
|
} catch (err) {
|
|
|
|
return await runSequenceP('docker-run');
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (JSON.parse(result.stdout).Status) {
|
|
|
|
case 'running':
|
|
|
|
return;
|
|
|
|
case 'exited':
|
|
|
|
return await execP('docker start dblocal');
|
|
|
|
default:
|
|
|
|
throw new Error(`Unknown docker status: ${status}`);
|
|
|
|
}
|
2017-10-24 06:56:18 +00:00
|
|
|
});
|
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
gulp.task('docker-run', async () => {
|
|
|
|
try {
|
|
|
|
await execP('docker image inspect -f "{{json .Id}}" dblocal');
|
|
|
|
} catch (err) {
|
|
|
|
await execP('docker build -t dblocal:latest ./services/db');
|
|
|
|
}
|
|
|
|
|
|
|
|
await execP('docker run -d --name dblocal -p 3306:3306 dblocal');
|
|
|
|
await runSequenceP('docker-wait');
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('docker-wait', callback => {
|
2018-02-01 11:52:58 +00:00
|
|
|
let maxInterval = 30 * 60000;
|
2018-02-01 07:48:54 +00:00
|
|
|
let interval = 1000;
|
|
|
|
let timer = 0;
|
2018-02-09 07:40:23 +00:00
|
|
|
log('Waiting for MySQL init process...');
|
2018-02-01 07:48:54 +00:00
|
|
|
let waitForLocaldb = setInterval(() => {
|
|
|
|
if (timer < maxInterval) {
|
|
|
|
timer += interval;
|
2018-02-09 07:40:23 +00:00
|
|
|
exec('docker logs --tail 1 dblocal', (err, stdout, stderr) => {
|
|
|
|
if (stderr.includes('starting as process 1') || err) {
|
2018-02-01 07:48:54 +00:00
|
|
|
clearInterval(waitForLocaldb);
|
|
|
|
callback(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
clearInterval(waitForLocaldb);
|
2018-02-09 07:40:23 +00:00
|
|
|
callback(new Error(`MySQL not initialized whithin ${maxInterval / 1000} secs`));
|
2018-02-01 07:48:54 +00:00
|
|
|
}
|
|
|
|
}, interval);
|
|
|
|
});
|
2018-02-01 11:52:58 +00:00
|
|
|
|
2018-02-09 07:40:23 +00:00
|
|
|
// Helpers
|
2018-02-01 11:52:58 +00:00
|
|
|
|
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);
|
|
|
|
else
|
|
|
|
resolve({
|
|
|
|
stdout: stdout,
|
|
|
|
stderr: stderr
|
|
|
|
});
|
|
|
|
});
|
2018-02-01 11:52:58 +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
|
|
|
function runSequenceP() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let args = Array.prototype.slice.call(arguments);
|
|
|
|
args.push(err => {
|
|
|
|
if (err)
|
|
|
|
reject(err);
|
|
|
|
else
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
runSequence(...args);
|
2018-02-01 11:52:58 +00:00
|
|
|
});
|
2018-02-09 07:40:23 +00:00
|
|
|
}
|