@travetto/cli 3.4.0-rc.0 → 3.4.0-rc.2

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
@@ -428,7 +428,7 @@ import { ServerHandle } from '../src/types';
428
428
  /**
429
429
  * Run a rest server as an application
430
430
  */
431
- @CliCommand({ runTarget: true, fields: ['module', 'env', 'profile'] })
431
+ @CliCommand({ runTarget: true, fields: ['module', 'env'] })
432
432
  export class RunRestCommand {
433
433
 
434
434
  /** IPC debug is enabled */
@@ -455,7 +455,7 @@ export class RunRestCommand {
455
455
  }
456
456
  ```
457
457
 
458
- As noted in the example above, `fields` is specified in this execution, with support for `module`, `env`, and `profile`. These env and profile flags are directly tied to the GlobalEnv flags defined in the [Base](https://github.com/travetto/travetto/tree/main/module/base#readme "Environment config and common utilities for travetto applications.") module.
458
+ As noted in the example above, `fields` is specified in this execution, with support for `module`, and `env`. These env flag is directly tied to the [GlobalEnv](https://github.com/travetto/travetto/tree/main/module/base/src/global-env.ts#L17) flags defined in the [Base](https://github.com/travetto/travetto/tree/main/module/base#readme "Environment config and common utilities for travetto applications.") module.
459
459
 
460
460
  The `module` field is slightly more complex, but is geared towards supporting commands within a monorepo context. This flag ensures that a module is specified if running from the root of the monorepo, and that the module provided is real, and can run the desired command. When running from an explicit module folder in the monorepo, the module flag is ignored.
461
461
 
package/__index__.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './src/types';
2
2
  export * from './src/decorators';
3
3
  export * from './src/execute';
4
+ export * from './src/error';
4
5
  export * from './src/schema';
5
6
  export * from './src/registry';
6
7
  export * from './src/help';
package/bin/trv.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // @ts-check
4
- import { withContext } from '@travetto/compiler/bin/common.js';
4
+ import { getEntry } from '@travetto/compiler/bin/common.js';
5
5
 
6
- withContext((ctx, compile) => compile(ctx, 'run')).then(load => load?.('@travetto/cli/support/entry.trv.js'));
6
+ getEntry().then(ops => ops.compile('run')).then(load => load('@travetto/cli/support/entry.trv.js'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "3.4.0-rc.0",
3
+ "version": "3.4.0-rc.2",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -29,7 +29,7 @@
29
29
  "directory": "module/cli"
30
30
  },
31
31
  "dependencies": {
32
- "@travetto/schema": "^3.4.0-rc.0",
32
+ "@travetto/schema": "^3.4.0-rc.1",
33
33
  "@travetto/terminal": "^3.4.0-rc.0"
34
34
  },
35
35
  "travetto": {
package/src/decorators.ts CHANGED
@@ -7,7 +7,7 @@ import { CliCommandRegistry, CliCommandConfigOptions } from './registry';
7
7
  import { CliModuleUtil } from './module';
8
8
  import { CliUtil } from './util';
9
9
 
10
- type ExtraFields = 'module' | 'profile' | 'env';
10
+ type ExtraFields = 'module' | 'env';
11
11
 
12
12
  const getName = (source: string): string => (source.match(/cli[.](.*)[.]tsx?$/)?.[1] ?? source).replaceAll('_', ':');
13
13
  const getMod = (cls: Class): string => RootIndex.getModuleFromSource(RootIndex.getFunctionMetadata(cls)!.source)!.name;
@@ -26,7 +26,6 @@ export function CliCommand({ fields, ...cfg }: { fields?: ExtraFields[] } & CliC
26
26
 
27
27
  const name = getName(meta.source);
28
28
  const addEnv = fields?.includes('env');
29
- const addProfile = fields?.includes('profile');
30
29
  const addModule = fields?.includes('module');
31
30
 
32
31
  CliCommandRegistry.registerClass({
@@ -35,12 +34,9 @@ export function CliCommand({ fields, ...cfg }: { fields?: ExtraFields[] } & CliC
35
34
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
36
35
  cls: target as ConcreteClass<T>,
37
36
  ...cfg,
38
- preMain: (cmd: CliCommandShape & { env?: string, profile?: string[], module?: string }) => {
39
- if (addEnv || addProfile) {
40
- defineGlobalEnv({
41
- ...addEnv ? { envName: cmd.env } : {},
42
- ...addProfile ? { profiles: cmd.profile } : {}
43
- });
37
+ preMain: (cmd: CliCommandShape & { env?: string, module?: string }) => {
38
+ if (addEnv) {
39
+ defineGlobalEnv({ envName: cmd.env });
44
40
  ConsoleManager.setDebug(GlobalEnv.debug, GlobalEnv.devMode);
45
41
  }
46
42
  if (addModule && cmd.module && cmd.module !== RootIndex.mainModuleName) { // Mono-repo support
@@ -59,14 +55,6 @@ export function CliCommand({ fields, ...cfg }: { fields?: ExtraFields[] } & CliC
59
55
  });
60
56
  }
61
57
 
62
- if (addProfile) {
63
- SchemaRegistry.registerPendingFieldConfig(target, 'profile', [String], {
64
- aliases: ['p'],
65
- description: 'Additional application profiles',
66
- required: { active: false }
67
- });
68
- }
69
-
70
58
  if (addModule) {
71
59
  SchemaRegistry.registerPendingFieldConfig(target, 'module', String, {
72
60
  aliases: ['m', 'env.TRV_MODULE'],
package/src/registry.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Class, ConcreteClass } from '@travetto/base';
1
+ import { Class, ConcreteClass, GlobalEnv } from '@travetto/base';
2
2
  import { RootIndex } from '@travetto/manifest';
3
3
 
4
4
  import { CliCommandShape } from './types';
@@ -37,8 +37,12 @@ class $CliCommandRegistry {
37
37
  getCommandMapping(): Map<string, string> {
38
38
  if (!this.#fileMapping) {
39
39
  const all = new Map<string, string>();
40
- for (const { outputFile: output, import: imp } of RootIndex.findSupport({ filter: CLI_REGEX, checkProfile: false })) {
41
- all.set(output.match(CLI_REGEX)![1].replace(/_/g, ':'), imp);
40
+ for (const e of RootIndex.find({
41
+ module: m => GlobalEnv.devMode || m.prod,
42
+ folder: f => f === 'support',
43
+ file: f => f.role === 'std' && CLI_REGEX.test(f.sourceFile)
44
+ })) {
45
+ all.set(e.outputFile.match(CLI_REGEX)![1].replace(/_/g, ':'), e.import);
42
46
  }
43
47
  this.#fileMapping = all;
44
48
  }
package/src/schema.ts CHANGED
@@ -5,6 +5,15 @@ import { CliCommandRegistry } from './registry';
5
5
  import { CliCommandInput, CliCommandSchema, CliCommandShape } from './types';
6
6
  import { CliValidationResultError } from './error';
7
7
 
8
+ function split(args: string[]): [core: string[], extra: string[]] {
9
+ const restIdx = args.indexOf('--');
10
+ if (restIdx >= 0) {
11
+ return [args.slice(0, restIdx), args.slice(restIdx + 1)];
12
+ } else {
13
+ return [args, []];
14
+ }
15
+ }
16
+
8
17
  function fieldToInput(x: FieldConfig): CliCommandInput {
9
18
  const type = x.type === Date ? 'date' :
10
19
  x.type === Boolean ? 'boolean' :
@@ -119,10 +128,7 @@ export class CliCommandSchemaUtil {
119
128
  static async bindArgs(cmd: CliCommandShape, args: string[]): Promise<[known: unknown[], unknown: string[]]> {
120
129
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
121
130
  const cls = cmd.constructor as Class<CliCommandShape>;
122
-
123
- const restIdx = args.indexOf('--');
124
- const copy = [...args.slice(0, restIdx < 0 ? args.length : restIdx)];
125
- const extra = restIdx < 0 ? [] : args.slice(restIdx);
131
+ const [copy, extra] = split(args);
126
132
  const schema = await this.getSchema(cmd);
127
133
  const out: unknown[] = [];
128
134
  const found: boolean[] = copy.map(x => false);
@@ -166,10 +172,8 @@ export class CliCommandSchemaUtil {
166
172
  static async bindFlags<T extends CliCommandShape>(cmd: T, args: string[]): Promise<string[]> {
167
173
  const schema = await this.getSchema(cmd);
168
174
 
169
- const restIdx = args.indexOf('--');
170
- const copy = [...args.slice(0, restIdx < 0 ? args.length : restIdx)]
171
- .flatMap(k => (k.startsWith('--') && k.includes('=')) ? k.split('=') : [k]);
172
- const extra = restIdx < 0 ? [] : args.slice(restIdx);
175
+ const [base, extra] = split(args);
176
+ const copy = base.flatMap(k => (k.startsWith('--') && k.includes('=')) ? k.split('=') : [k]);
173
177
 
174
178
  const template: Partial<T> = {};
175
179
 
@@ -223,7 +227,7 @@ export class CliCommandSchemaUtil {
223
227
  const cls = cmd.constructor as Class<CliCommandShape>;
224
228
  BindUtil.bindSchemaToObject(cls, cmd, template);
225
229
 
226
- return [...out, ...extra];
230
+ return [...out, '--', ...extra];
227
231
  }
228
232
 
229
233
  /**
package/src/util.ts CHANGED
@@ -26,7 +26,7 @@ export class CliUtil {
26
26
  * Run a command as restartable, linking into self
27
27
  */
28
28
  static runWithRestart<T extends CliCommandShape & { canRestart?: boolean }>(cmd: T): Promise<unknown> | undefined {
29
- if (cmd.canRestart !== false && Env.isFalse('TRV_CAN_RESTART')) {
29
+ if (cmd.canRestart === false || Env.isFalse('TRV_CAN_RESTART')) {
30
30
  delete process.env.TRV_CAN_RESTART;
31
31
  return;
32
32
  }