forked from megahertz/electron-simple-publisher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·43 lines (35 loc) · 968 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/env node
'use strict';
const commands = require('./lib/commands');
const getOptionsFromCli = require('./lib/utils/get-options-from-cli');
const normalizeOptions = require('./lib/utils/normalize-options');
module.exports = run;
if (require.main === module) {
main();
}
function main() {
const cliOptions = getOptionsFromCli(process.argv.slice(2));
run(cliOptions)
.catch((e) => {
console.error(cliOptions.debug ? e : e.message);
process.exit(1);
});
}
async function run(options) {
let transport;
try {
options = normalizeOptions(options);
transport = options.transport.instance;
transport.init();
} catch (e) {
return Promise.reject(e);
}
const Command = commands[options.command];
if (!Command) {
throw new Error(`Unknown command ${options.command}`);
}
/** @type AbstractCommand */
const command = new Command(options);
await command.run();
await transport.close();
}