@travetto/cli 3.0.0-rc.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/package.json +7 -9
- package/src/command-manager.ts +8 -3
- package/src/command.ts +22 -13
- package/src/execute.ts +15 -19
- package/src/help.ts +5 -4
- package/src/module.ts +12 -6
- package/src/scm.ts +2 -3
- package/support/cli.exec.ts +8 -4
- package/support/cli.list.ts +1 -1
- package/support/cli.main.ts +38 -0
- package/support/cli.ts +3 -0
- package/support/main.cli.ts +0 -8
package/README.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
<!-- This file was generated by @travetto/doc and should not be modified directly -->
|
|
2
2
|
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/cli/DOC.ts and execute "npx trv doc" to rebuild -->
|
|
3
3
|
# Command Line Interface
|
|
4
|
-
## CLI infrastructure for
|
|
4
|
+
## CLI infrastructure for Travetto framework
|
|
5
5
|
|
|
6
6
|
**Install: @travetto/cli**
|
|
7
7
|
```bash
|
|
8
8
|
npm install @travetto/cli
|
|
9
|
+
|
|
10
|
+
# or
|
|
11
|
+
|
|
12
|
+
yarn add @travetto/cli
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
The cli is the primary structure for interacting with the external requirements of the framework. This can range from running tests, to running applications, to generating email templates. The main executable can be installed globally or locally. If installed globally and locally, it will defer to the local installation for execution.
|
|
@@ -21,14 +25,13 @@ $ trv --help
|
|
|
21
25
|
Usage: [options] [command]
|
|
22
26
|
|
|
23
27
|
Options:
|
|
24
|
-
-V, --version
|
|
25
|
-
-h, --help
|
|
28
|
+
-V, --version output the version number
|
|
29
|
+
-h, --help display help for command
|
|
26
30
|
|
|
27
31
|
Commands:
|
|
28
32
|
echo [options] [args...]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[s[r[u
|
|
33
|
+
main <fileOrImport> [args...]
|
|
34
|
+
help [command] display help for command
|
|
32
35
|
```
|
|
33
36
|
|
|
34
37
|
This will show all the available options/choices that are exposed given the currently installed modules.
|
|
@@ -50,7 +53,7 @@ export class CliEchoCommand extends CliCommand {
|
|
|
50
53
|
name = 'echo';
|
|
51
54
|
|
|
52
55
|
getOptions() {
|
|
53
|
-
return { uppercase: this.boolOption({ desc: 'Upper case'
|
|
56
|
+
return { uppercase: this.boolOption({ desc: 'Upper case' }) };
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
getArgs() {
|
|
@@ -75,10 +78,8 @@ $ trv echo --help
|
|
|
75
78
|
Usage: echo [options] [args...]
|
|
76
79
|
|
|
77
80
|
Options:
|
|
78
|
-
-u, --uppercase Upper case
|
|
81
|
+
-u, --uppercase Upper case
|
|
79
82
|
-h, --help display help for command
|
|
80
|
-
|
|
81
|
-
[s[r[u
|
|
82
83
|
```
|
|
83
84
|
|
|
84
85
|
And actually using it:
|
|
@@ -88,5 +89,4 @@ And actually using it:
|
|
|
88
89
|
$ trv echo -u bOb rOb DRoP
|
|
89
90
|
|
|
90
91
|
[ 'BOB', 'ROB', 'DROP' ]
|
|
91
|
-
[s[r[u
|
|
92
92
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/cli",
|
|
3
|
-
"version": "3.0.0
|
|
4
|
-
"description": "CLI infrastructure for
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "CLI infrastructure for Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
7
7
|
"travetto",
|
|
@@ -16,20 +16,18 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"__index__.ts",
|
|
18
18
|
"src",
|
|
19
|
-
"support"
|
|
20
|
-
"bin"
|
|
19
|
+
"support"
|
|
21
20
|
],
|
|
22
|
-
"bin": "trv.js",
|
|
23
21
|
"main": "__index__.ts",
|
|
24
22
|
"repository": {
|
|
25
23
|
"url": "https://github.com/travetto/travetto.git",
|
|
26
24
|
"directory": "module/cli"
|
|
27
25
|
},
|
|
28
26
|
"dependencies": {
|
|
29
|
-
"@travetto/base": "^3.0.0
|
|
30
|
-
"@travetto/terminal": "^3.0.0
|
|
31
|
-
"@travetto/worker": "^3.0.0
|
|
32
|
-
"commander": "^
|
|
27
|
+
"@travetto/base": "^3.0.0",
|
|
28
|
+
"@travetto/terminal": "^3.0.0",
|
|
29
|
+
"@travetto/worker": "^3.0.0",
|
|
30
|
+
"commander": "^10.0.0"
|
|
33
31
|
},
|
|
34
32
|
"travetto": {
|
|
35
33
|
"displayName": "Command Line Interface"
|
package/src/command-manager.ts
CHANGED
|
@@ -24,8 +24,8 @@ export class CliCommandManager {
|
|
|
24
24
|
*/
|
|
25
25
|
static getCommandMapping(): Map<string, string> {
|
|
26
26
|
const all = new Map<string, string>();
|
|
27
|
-
for (const { output } of RootIndex.findSupport({ filter: /\/cli[.]/, checkProfile: false })) {
|
|
28
|
-
all.set(output.replace(/^.*\/cli[.](.*?)[.][^.]+$/, (_, f) => f),
|
|
27
|
+
for (const { outputFile: output, import: imp } of RootIndex.findSupport({ filter: /\/cli[.]/, checkProfile: false })) {
|
|
28
|
+
all.set(output.replace(/^.*\/cli[.](.*?)[.][^.]+$/, (_, f) => f), imp);
|
|
29
29
|
}
|
|
30
30
|
return all;
|
|
31
31
|
}
|
|
@@ -46,9 +46,14 @@ export class CliCommandManager {
|
|
|
46
46
|
const matchedCfg = COMMAND_PACKAGE.find(([re]) => re.test(cmd));
|
|
47
47
|
if (matchedCfg) {
|
|
48
48
|
const [, pkg, prod] = matchedCfg;
|
|
49
|
+
let install: string;
|
|
50
|
+
switch (RootIndex.manifest.packageManager) {
|
|
51
|
+
case 'npm': install = `npm i ${prod ? '' : '--save-dev '}@travetto/${pkg}`; break;
|
|
52
|
+
case 'yarn': install = `yarn add ${prod ? '' : '--dev '}@travetto/${pkg}`; break;
|
|
53
|
+
}
|
|
49
54
|
console.error!(cliTpl`
|
|
50
55
|
${{ title: 'Missing Package' }}\n${'-'.repeat(20)}\nTo use ${{ input: cmd }} please run:\n
|
|
51
|
-
${{ identifier:
|
|
56
|
+
${{ identifier: install }}
|
|
52
57
|
`);
|
|
53
58
|
await ShutdownManager.exit(1);
|
|
54
59
|
}
|
package/src/command.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { appendFile, mkdir } from 'fs/promises';
|
|
2
|
-
import type
|
|
2
|
+
import type commander from 'commander';
|
|
3
3
|
|
|
4
4
|
import { path } from '@travetto/manifest';
|
|
5
5
|
import { ConsoleManager, DataUtil, defineGlobalEnv, GlobalEnvConfig, ShutdownManager } from '@travetto/base';
|
|
@@ -74,7 +74,7 @@ export abstract class CliCommand<V extends OptionMap = OptionMap> {
|
|
|
74
74
|
/**
|
|
75
75
|
* Get args
|
|
76
76
|
*/
|
|
77
|
-
getArgs?(): string;
|
|
77
|
+
getArgs?(): string | undefined;
|
|
78
78
|
/**
|
|
79
79
|
* Initialization code for adding options
|
|
80
80
|
*/
|
|
@@ -135,8 +135,8 @@ export abstract class CliCommand<V extends OptionMap = OptionMap> {
|
|
|
135
135
|
boolOption(cfg: OptionConfig<boolean>): OptionConfig<boolean> {
|
|
136
136
|
return {
|
|
137
137
|
type: Boolean,
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
combine: (val, curr): boolean =>
|
|
139
|
+
(val !== undefined ? DataUtil.coerceType(val, Boolean, false) : undefined) ?? curr,
|
|
140
140
|
completion: true,
|
|
141
141
|
...cfg
|
|
142
142
|
};
|
|
@@ -217,22 +217,31 @@ export abstract class CliCommand<V extends OptionMap = OptionMap> {
|
|
|
217
217
|
if (this.init) {
|
|
218
218
|
cmd = await this.init?.(cmd);
|
|
219
219
|
}
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
const args = this.getArgs?.();
|
|
221
|
+
if (args) {
|
|
222
|
+
cmd = cmd.arguments(args);
|
|
222
223
|
}
|
|
224
|
+
|
|
223
225
|
for (const cfg of await this.finalizeOptions()) {
|
|
224
|
-
|
|
225
|
-
if (cfg.type
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
const pre = cfg.short ? `-${cfg.short}, ` : '';
|
|
227
|
+
if (cfg.type === Boolean) {
|
|
228
|
+
if (cfg.def) {
|
|
229
|
+
cmd = cmd.option(`${pre}--no-${cfg.name}`, `Disables: ${cfg.desc}`);
|
|
230
|
+
} else {
|
|
231
|
+
cmd = cmd.option(`${pre}--${cfg.name}`, cfg.desc);
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
const key = `${pre}--${cfg.name} <${cfg.name}>`;
|
|
229
235
|
// @ts-expect-error
|
|
230
|
-
cmd.option(key, cfg.desc, cfg.combine, cfg.def)
|
|
231
|
-
|
|
236
|
+
cmd = cmd.option(key, cfg.desc, cfg.combine ?? ((cur, acc): unknown => cur), cfg.def);
|
|
237
|
+
}
|
|
232
238
|
}
|
|
233
239
|
|
|
234
240
|
cmd = cmd.action(this.runAction.bind(this));
|
|
235
241
|
|
|
242
|
+
// @ts-expect-error, Do nothing
|
|
243
|
+
cmd.missingArgument = (): void => { };
|
|
244
|
+
|
|
236
245
|
return this.#cmd = cmd;
|
|
237
246
|
}
|
|
238
247
|
|
package/src/execute.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { program as commander } from 'commander';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { PackageUtil } from '@travetto/manifest';
|
|
4
4
|
import { GlobalTerminal } from '@travetto/terminal';
|
|
5
|
-
import { runMain } from '@travetto/base/support/init.main';
|
|
6
5
|
|
|
7
6
|
import { CliCommandManager } from './command-manager';
|
|
8
7
|
import { HelpUtil } from './help';
|
|
@@ -15,9 +14,7 @@ export class ExecutionManager {
|
|
|
15
14
|
/**
|
|
16
15
|
* Run command
|
|
17
16
|
*/
|
|
18
|
-
static async runCommand(args: string[]): Promise<void> {
|
|
19
|
-
const cmd = args[2];
|
|
20
|
-
|
|
17
|
+
static async runCommand(cmd: string, args: string[]): Promise<void> {
|
|
21
18
|
let command;
|
|
22
19
|
|
|
23
20
|
try {
|
|
@@ -32,7 +29,7 @@ export class ExecutionManager {
|
|
|
32
29
|
if (args.includes('-h') || args.includes('--help')) {
|
|
33
30
|
return command.showHelp();
|
|
34
31
|
} else {
|
|
35
|
-
await commander.parseAsync(args);
|
|
32
|
+
await commander.parseAsync([process.argv[0], process.argv[1], cmd, ...args]);
|
|
36
33
|
}
|
|
37
34
|
} catch (err) {
|
|
38
35
|
if (!(err instanceof Error)) {
|
|
@@ -48,23 +45,22 @@ export class ExecutionManager {
|
|
|
48
45
|
* Execute the command line
|
|
49
46
|
* @param args
|
|
50
47
|
*/
|
|
51
|
-
static async run(
|
|
52
|
-
|
|
48
|
+
static async run(argv: string[]): Promise<void> {
|
|
49
|
+
await GlobalTerminal.init();
|
|
50
|
+
|
|
53
51
|
commander
|
|
54
52
|
.version(PackageUtil.getFrameworkVersion())
|
|
55
|
-
.configureOutput({
|
|
53
|
+
.configureOutput({
|
|
54
|
+
getOutHelpWidth: () => GlobalTerminal.width,
|
|
55
|
+
getErrHelpWidth: () => GlobalTerminal.width
|
|
56
|
+
});
|
|
56
57
|
|
|
57
|
-
const
|
|
58
|
+
const { init } = await import('@travetto/base/support/init.js');
|
|
59
|
+
await init();
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
mainFile = path.join(RootIndex.manifest.mainModule, mainFile);
|
|
63
|
-
mainFile = RootIndex.resolveFileImport(mainFile);
|
|
64
|
-
}
|
|
65
|
-
await runMain((await import(mainFile)).main, process.argv.slice(4));
|
|
66
|
-
} else if (cmd && !cmd.startsWith('-')) {
|
|
67
|
-
await this.runCommand(args);
|
|
61
|
+
const [, , cmd, ...args] = argv;
|
|
62
|
+
if (cmd && !cmd.startsWith('-')) {
|
|
63
|
+
await this.runCommand(cmd, args);
|
|
68
64
|
} else {
|
|
69
65
|
// Load all commands
|
|
70
66
|
await CliCommandManager.loadAllCommands(x => x.setup(commander));
|
package/src/help.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type commander from 'commander';
|
|
2
2
|
|
|
3
3
|
import { cliTpl } from './color';
|
|
4
4
|
|
|
5
5
|
const TYPE_PATTERN = /(\[[^\]]+\])/g;
|
|
6
|
+
const REQ_TYPE_PATTERN = /(<[^>]+>)/g;
|
|
6
7
|
const TITLE_PATTERN = /^(\S[^:]+:)/gim;
|
|
7
8
|
|
|
8
9
|
const OPTIONS_PATTERN = new RegExp([
|
|
@@ -32,7 +33,7 @@ const COMMANDS_PATTERN = new RegExp([
|
|
|
32
33
|
'(?<space>[ ]+)',
|
|
33
34
|
'(?<name>\\S+)',
|
|
34
35
|
'(?<optionsSpace>[ ]+)?',
|
|
35
|
-
'(?<options
|
|
36
|
+
'(?<options>(?:\\[|<).*(?:\\]|>))?',
|
|
36
37
|
'((?<descriptionSpace>[ ]+)(?<description>[a-z][^\\n\\[]+))?',
|
|
37
38
|
'(?:[ ]+)?',
|
|
38
39
|
'$',
|
|
@@ -50,7 +51,7 @@ const USAGE_PATTERN = new RegExp([
|
|
|
50
51
|
'(?<space>[ ]+)?',
|
|
51
52
|
'(?<name>[^\\[ ]+)?',
|
|
52
53
|
'(?<nameSpace>[ ]+)?',
|
|
53
|
-
'(?<options
|
|
54
|
+
'(?<options>(?:\\[|<).*(?:\\]|>))?',
|
|
54
55
|
'(?:[ ]+)?',
|
|
55
56
|
'$',
|
|
56
57
|
].join(''), 'gim');
|
|
@@ -135,7 +136,7 @@ export class HelpUtil {
|
|
|
135
136
|
space,
|
|
136
137
|
cliTpl`${{ param: name }}`,
|
|
137
138
|
optionsSpace,
|
|
138
|
-
options?.replace(TYPE_PATTERN, input => cliTpl`${{ input }}`),
|
|
139
|
+
options?.replace(TYPE_PATTERN, input => cliTpl`${{ input }}`).replace(REQ_TYPE_PATTERN, type => cliTpl`${{ type }}`),
|
|
139
140
|
descriptionSpace,
|
|
140
141
|
cliTpl`${{ description }}`
|
|
141
142
|
]
|
package/src/module.ts
CHANGED
|
@@ -38,13 +38,13 @@ export class CliModuleUtil {
|
|
|
38
38
|
stdoutTerm: Terminal,
|
|
39
39
|
stderrTerm: Terminal
|
|
40
40
|
): ExecutionOptions {
|
|
41
|
-
const folder = mod.
|
|
41
|
+
const folder = mod.sourceFolder;
|
|
42
42
|
const opts: ExecutionOptions = {
|
|
43
43
|
stdio: ['ignore', 'pipe', 'pipe', 'ignore'],
|
|
44
44
|
outputMode: 'text',
|
|
45
45
|
catchAsResult: true,
|
|
46
46
|
cwd: folder,
|
|
47
|
-
env: { TRV_MANIFEST: '' },
|
|
47
|
+
env: { TRV_MANIFEST: '', TRV_MODULE: mod.name },
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
if (config.showStdout) {
|
|
@@ -62,7 +62,7 @@ export class CliModuleUtil {
|
|
|
62
62
|
* @returns
|
|
63
63
|
*/
|
|
64
64
|
static #buildPrefixes(mods: IndexedModule[]): Record<string, string> {
|
|
65
|
-
const folders = mods.map(x => x.
|
|
65
|
+
const folders = mods.map(x => x.sourceFolder);
|
|
66
66
|
const maxWidth = Math.max(...folders.map(x => x.length));
|
|
67
67
|
return Object.fromEntries(folders.map((x, i) => [x, colorize(x.padStart(maxWidth, ' ').padEnd(maxWidth + 1), i)]));
|
|
68
68
|
}
|
|
@@ -78,6 +78,10 @@ export class CliModuleUtil {
|
|
|
78
78
|
hash = await CliScmUtil.findLastRelease();
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
if (!hash) {
|
|
82
|
+
return RootIndex.getLocalModules();
|
|
83
|
+
}
|
|
84
|
+
|
|
81
85
|
const out = new Map<string, IndexedModule>();
|
|
82
86
|
for (const mod of await CliScmUtil.findChangedModulesSince(hash)) {
|
|
83
87
|
out.set(mod.name, mod);
|
|
@@ -102,14 +106,16 @@ export class CliModuleUtil {
|
|
|
102
106
|
return (mode === 'changed' ?
|
|
103
107
|
await this.findChangedModulesRecursive() :
|
|
104
108
|
[...RootIndex.getModuleList('all')].map(x => RootIndex.getModule(x)!)
|
|
105
|
-
).filter(x => x.
|
|
109
|
+
).filter(x => x.sourcePath !== RootIndex.manifest.workspacePath);
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
/**
|
|
109
113
|
* Synchronize all workspace modules to have the correct versions from the current packages
|
|
110
114
|
*/
|
|
111
|
-
static async synchronizeModuleVersions(): Promise<
|
|
112
|
-
|
|
115
|
+
static async synchronizeModuleVersions(): Promise<Record<string, string>> {
|
|
116
|
+
const versions = {};
|
|
117
|
+
await PackageUtil.syncVersions((await this.findModules('all')).map(x => x.sourcePath), versions);
|
|
118
|
+
return versions;
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
/**
|
package/src/scm.ts
CHANGED
|
@@ -32,13 +32,12 @@ export class CliScmUtil {
|
|
|
32
32
|
* Find the last code release
|
|
33
33
|
* @returns
|
|
34
34
|
*/
|
|
35
|
-
static async findLastRelease(): Promise<string> {
|
|
35
|
+
static async findLastRelease(): Promise<string | undefined> {
|
|
36
36
|
const root = await RootIndex.manifest;
|
|
37
37
|
const { result } = ExecUtil.spawn('git', ['log', '--pretty=oneline'], { cwd: root.workspacePath });
|
|
38
38
|
return (await result).stdout
|
|
39
39
|
.split(/\n/)
|
|
40
|
-
.find(x => /Publish /.test(x))
|
|
41
|
-
.split(/\s+/)[0]!;
|
|
40
|
+
.find(x => /Publish /.test(x))?.split(/\s+/)?.[0];
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
/**
|
package/support/cli.exec.ts
CHANGED
|
@@ -30,20 +30,24 @@ export class RepoExecCommand extends CliCommand<Options> {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
getArgs(): string {
|
|
33
|
-
return '
|
|
33
|
+
return '<command> [...args]';
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
envInit(): GlobalEnvConfig {
|
|
37
37
|
return { debug: false };
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
async action(): Promise<void> {
|
|
40
|
+
async action(cmd: string, args: string[]): Promise<void> {
|
|
41
|
+
if (!cmd) {
|
|
42
|
+
return this.showHelp('Command is a required field');
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
await CliModuleUtil.execOnModules(
|
|
42
46
|
this.cmd.changed ? 'changed' : 'all',
|
|
43
47
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
44
|
-
(mod, opts) => ExecUtil.spawn(
|
|
48
|
+
(mod, opts) => ExecUtil.spawn(cmd, args, opts),
|
|
45
49
|
{
|
|
46
|
-
progressMessage: mod => `Running '${this.args.join(' ')}' [%idx/%total] ${mod?.
|
|
50
|
+
progressMessage: mod => `Running '${this.args.join(' ')}' [%idx/%total] ${mod?.sourceFolder ?? ''}`,
|
|
47
51
|
showStdout: this.cmd.showStdout,
|
|
48
52
|
prefixOutput: this.cmd.prefixOutput,
|
|
49
53
|
workerCount: this.cmd.workers,
|
package/support/cli.list.ts
CHANGED
|
@@ -29,7 +29,7 @@ export class RepoListCommand extends CliCommand<Options> {
|
|
|
29
29
|
async action(...args: unknown[]): Promise<void> {
|
|
30
30
|
const mods = await CliModuleUtil.findModules(this.cmd.changed ? 'changed' : 'all');
|
|
31
31
|
if (!this.cmd.graph) {
|
|
32
|
-
for (const mod of mods.map(x => x.
|
|
32
|
+
for (const mod of mods.map(x => x.sourceFolder).sort()) {
|
|
33
33
|
console.log!(mod);
|
|
34
34
|
}
|
|
35
35
|
} else {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
|
|
3
|
+
import { ShutdownManager } from '@travetto/base';
|
|
4
|
+
import { CliCommand } from '@travetto/cli';
|
|
5
|
+
import { path, RootIndex } from '@travetto/manifest';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `npx trv main`
|
|
9
|
+
*
|
|
10
|
+
* Allows for running of main entry points
|
|
11
|
+
*/
|
|
12
|
+
export class MainCommand extends CliCommand {
|
|
13
|
+
|
|
14
|
+
name = 'main';
|
|
15
|
+
|
|
16
|
+
getArgs(): string {
|
|
17
|
+
return '<fileOrImport> [args...]';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async action(file: string, args: string[]): Promise<void> {
|
|
21
|
+
try {
|
|
22
|
+
// If referenced file exists
|
|
23
|
+
if (await (fs.stat(path.resolve(file)).then(() => true, () => false))) {
|
|
24
|
+
file = path.join(RootIndex.manifest.mainModule, file);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const imp = RootIndex.getFromImport(file)?.import;
|
|
28
|
+
if (!imp) {
|
|
29
|
+
throw new Error(`Unknown file: ${file}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const mod = await import(imp);
|
|
33
|
+
await ShutdownManager.exitWithResponse(await mod.main(...args));
|
|
34
|
+
} catch (err) {
|
|
35
|
+
await ShutdownManager.exitWithResponse(err, true);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/support/cli.ts
ADDED