-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin.ts
More file actions
51 lines (42 loc) · 1.16 KB
/
Copy pathbin.ts
File metadata and controls
51 lines (42 loc) · 1.16 KB
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
44
45
46
47
48
49
50
51
#!/usr/bin/env node
import { program } from 'commander';
import configYaml from 'config-yaml';
import {
bootstrap,
collections,
environments,
globals
} from '@cmd';
import { Configs } from '@pm-types/cmd';
import { version, checkUpdate } from '@helpers/version';
program.version(version, '-v --version');
const configFileFlags = ['-c', '--config'];
const configFileIndex =
process.argv.findIndex((argv) => {
return configFileFlags.includes(argv);
}) + 1;
const configFile: string = configFileIndex
? process.argv[configFileIndex]
: './.pm.yaml';
let config: Configs = {} as any;
try {
config = configFile ? configYaml(configFile) : config;
config.config = configFile;
} catch (err) {
if (err instanceof Error) {
if (err.message.includes('Unable to read file:')) {
console.error(err.message);
}
} else {
console.error('unknown error:', err);
}
}
bootstrap(program, config, config?.cmd?.bootstrap);
collections(program, config, config?.cmd?.collections);
environments(program, config, config?.cmd?.environments);
globals(program, config, config?.cmd?.globals);
async function init() {
await checkUpdate();
program.parse();
}
init();