authelia/scripts/authelia-scripts-suites-start

60 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
var program = require('commander');
var spawn = require('child_process').spawn;
var fs = require('fs');
var ListSuites = require('./utils/ListSuites');
let suite;
program
.description(`Start the suite provided as argument. You can list the suites with the 'list' command.`)
.arguments('<suite>')
.action((suiteArg) => suite = suiteArg)
.parse(process.argv)
if (!suite) {
program.help();
}
if (ListSuites().indexOf(suite) == -1) {
console.log("[WARNING] This suite does not exist. Use 'list' command to check the existing suites.");
process.exit(1);
}
const ENVIRONMENT_FILENAME = '.suite';
let runEnvProcess;
// Sometime SIGINT is received twice, we make sure with this variable that we cleanup
// only once.
var alreadyCleaningUp = false;
// Properly cleanup server and client if ctrl-c is hit
process.on('SIGINT', function() {
if (alreadyCleaningUp) return;
alreadyCleaningUp = true;
console.log('Cleanup procedure is running...');
});
async function main() {
fs.writeFileSync(ENVIRONMENT_FILENAME, suite);
// Start the environment from ts-node process.
runEnvProcess = spawn('./node_modules/.bin/ts-node -P test/tsconfig.json -- ./scripts/run-environment.ts ' + suite, {
shell: true
});
runEnvProcess.stdout.pipe(process.stdout);
runEnvProcess.stderr.pipe(process.stderr);
runEnvProcess.on('exit', function(statusCode) {
fs.unlinkSync(ENVIRONMENT_FILENAME);
process.exit(statusCode);
});
}
main()
.catch((err) => {
console.error(err);
process.exit(1)
});