n8n/packages/cli/index.ts

59 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-06-23 03:35:23 -07:00
#!/usr/bin/env node
import { join as pathJoin } from 'path';
// Make sure that it also find the config folder when it
// did get started from another folder that the root one.
process.env.NODE_CONFIG_DIR = process.env.NODE_CONFIG_DIR || pathJoin(__dirname, 'config');
import Vorpal = require('vorpal');
import { GenericHelpers } from './src';
// Check if version should be displayed
const versionFlags = [
'-v',
'-V',
'--version'
];
if (versionFlags.includes(process.argv.slice(-1)[0])) {
console.log(require('../package').version);
process.exit(0);
}
if (process.argv.length === 2) {
// When no command is given choose by default start
process.argv.push('start');
}
const command = process.argv[2];
// Check if the command the user did enter is supported else stop
const supportedCommands = [
2019-06-23 23:28:24 -07:00
'execute',
2019-06-23 03:35:23 -07:00
'help',
'start',
];
if (!supportedCommands.includes(command)) {
GenericHelpers.logOutput(`The command "${command}" is not known!`);
process.argv.push('help');
}
const vorpal = new Vorpal();
vorpal
2019-06-23 23:28:24 -07:00
.use(require('./commands/execute.js'))
2019-06-23 03:35:23 -07:00
.use(require('./commands/start.js'))
.delimiter('')
.show()
.parse(process.argv);
process
.on('unhandledRejection', (reason, p) => {
console.error(reason, 'Unhandled Rejection at Promise', p);
})
.on('uncaughtException', err => {
console.error(err, 'Uncaught Exception thrown');
process.exit(1);
});