@travetto/cli 3.0.0-rc.20 → 3.0.0-rc.22

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 CHANGED
@@ -21,12 +21,13 @@ $ trv --help
21
21
  Usage: [options] [command]
22
22
 
23
23
  Options:
24
- -V, --version output the version number
25
- -h, --help display help for command
24
+ -V, --version output the version number
25
+ -h, --help display help for command
26
26
 
27
27
  Commands:
28
28
  echo [options] [args...]
29
- help [command] display help for command
29
+ main <fileOrImport> [args...]
30
+ help [command] display help for command
30
31
  ```
31
32
 
32
33
  This will show all the available options/choices that are exposed given the currently installed modules.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "3.0.0-rc.20",
3
+ "version": "3.0.0-rc.22",
4
4
  "description": "CLI infrastructure for travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -24,9 +24,9 @@
24
24
  "directory": "module/cli"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/base": "^3.0.0-rc.17",
27
+ "@travetto/base": "^3.0.0-rc.19",
28
28
  "@travetto/terminal": "^3.0.0-rc.10",
29
- "@travetto/worker": "^3.0.0-rc.17",
29
+ "@travetto/worker": "^3.0.0-rc.19",
30
30
  "commander": "^10.0.0"
31
31
  },
32
32
  "travetto": {
package/src/execute.ts CHANGED
@@ -1,9 +1,7 @@
1
- import fs from 'fs/promises';
2
1
  import { program as commander } from 'commander';
3
2
 
4
- import { PackageUtil, path, RootIndex } from '@travetto/manifest';
3
+ import { PackageUtil } from '@travetto/manifest';
5
4
  import { GlobalTerminal } from '@travetto/terminal';
6
- import { ShutdownManager } from '@travetto/base';
7
5
 
8
6
  import { CliCommandManager } from './command-manager';
9
7
  import { HelpUtil } from './help';
@@ -43,28 +41,6 @@ export class ExecutionManager {
43
41
  }
44
42
  }
45
43
 
46
- /**
47
- * Run file expecting a main method
48
- */
49
- static async runMain(file: string, args: string[]): Promise<void> {
50
- try {
51
- // If referenced file exists
52
- if (await (fs.stat(path.resolve(file)).then(() => true, () => false))) {
53
- file = path.join(RootIndex.manifest.mainModule, file);
54
- }
55
-
56
- const imp = RootIndex.getFromImport(file)?.import;
57
- if (!imp) {
58
- throw new Error(`Unknown file: ${file}`);
59
- }
60
-
61
- const mod = await import(imp);
62
- await ShutdownManager.exitWithResponse(await mod.main(...args));
63
- } catch (err) {
64
- await ShutdownManager.exitWithResponse(err, true);
65
- }
66
- }
67
-
68
44
  /**
69
45
  * Execute the command line
70
46
  * @param args
@@ -83,10 +59,7 @@ export class ExecutionManager {
83
59
  await init();
84
60
 
85
61
  const [, , cmd, ...args] = argv;
86
- if (cmd === 'main') {
87
- const [file, ...rest] = args;
88
- await this.runMain(file, rest);
89
- } else if (cmd && !cmd.startsWith('-')) {
62
+ if (cmd && !cmd.startsWith('-')) {
90
63
  await this.runCommand(cmd, args);
91
64
  } else {
92
65
  // Load all commands
@@ -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
+ }