-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
33 lines (25 loc) · 1.01 KB
/
cli.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
import _ from 'lodash';
import { log, initializeLogger } from './lib/logger.js';
import { loadPluginFile } from './lib/model/plugin.js';
import { loadConfig } from './lib/config.js';
import supportedCommands, { validateCommands } from './controllers/commands.js';
const main = async( argv ) => {
const command = argv._[0];
const name = argv._[1]; // optional name
let version = argv.version; // optional version
// load and validate config
await loadConfig( name );
// need to initialize logger after loading config since it relies on config for logLevel
initializeLogger();
// validate command
validateCommands( command );
await loadPluginFile();
// route to the correct command code
await supportedCommands[command]({ version }).then(() => {
log.info( `${_.upperFirst( command )} command completed successfully.` );
}).catch(( error ) => {
log.error({ error: error.toString(), obj: error }, 'There has been an issue during the migration' );
throw error;
});
};
export default main;