37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
const path = require('path');
|
|
const dotenv = require('dotenv');
|
|
const cwd = process.cwd();
|
|
['.common.env', '.dev.env', '.env'].forEach((filename) => {
|
|
dotenv.config({path: path.join(cwd, filename)});
|
|
});
|
|
|
|
const {spawn} = require('child_process');
|
|
|
|
const {servicesList} = require('@truss/core');
|
|
const {emitComposeFile} = require('@truss/docker');
|
|
|
|
const debug = require('debug')('truss:docker-dev');
|
|
|
|
debug('Ensuring dist directory exists...');
|
|
require('mkdirp').sync(path.join(cwd, 'dist', 'dev'));
|
|
// compose
|
|
const services = servicesList();
|
|
const composeFile = emitComposeFile(services);
|
|
debug('Compose file:');
|
|
debug(composeFile);
|
|
['down', 'up'].reduce((promise, op) => {
|
|
const args = ['-f', '-', op];
|
|
const options = {
|
|
stdio: ['pipe', 'inherit', 'inherit'],
|
|
};
|
|
const child = spawn('docker-compose', args, options);
|
|
child.stdin.write(composeFile);
|
|
// one after another
|
|
return promise.then(() => {
|
|
child.stdin.end();
|
|
return new Promise((resolve) => {
|
|
child.on('exit', resolve);
|
|
});
|
|
});
|
|
}, Promise.resolve());
|