2016-11-23 01:03:33 +02:00
|
|
|
const cp = require('child_process');
|
2016-11-23 18:27:02 +02:00
|
|
|
const path = require('path');
|
2016-11-23 01:03:33 +02:00
|
|
|
|
|
|
|
const TYPE = process.env.TYPE;
|
|
|
|
const MODE = process.env.MODE;
|
|
|
|
|
|
|
|
if (!TYPE) {
|
|
|
|
console.error(`
|
|
|
|
Usage: TYPE={type} node start.js
|
|
|
|
TYPE=node node start.js
|
|
|
|
`.trim());
|
|
|
|
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const handler = ({
|
|
|
|
node: () => {
|
|
|
|
return cp.exec('node src/index.js', {
|
|
|
|
cwd: __dirname
|
|
|
|
})
|
|
|
|
},
|
|
|
|
artillery: () => {
|
2016-11-23 18:27:02 +02:00
|
|
|
const conf = path.join(__dirname, '../artillery/artillery-${MODE}.yml');
|
|
|
|
return cp.exec(`../node_modules/.bin/artillery run ${conf}`)
|
2016-11-23 01:03:33 +02:00
|
|
|
}
|
|
|
|
})[TYPE];
|
|
|
|
|
|
|
|
if (!handler) {
|
|
|
|
console.error(`No handler for ${TYPE}`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
handler().stdout.pipe(process.stdout);
|
|
|
|
handler().stderr.pipe(process.stderr);
|
|
|
|
process.stdin.pipe(handler().stdin);
|