@travetto/cli 3.2.2 → 3.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -24,8 +24,8 @@
24
24
  "directory": "module/cli"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/schema": "^3.2.2",
28
- "@travetto/terminal": "^3.2.0"
27
+ "@travetto/schema": "^3.3.0",
28
+ "@travetto/terminal": "^3.3.0"
29
29
  },
30
30
  "travetto": {
31
31
  "displayName": "Command Line Interface"
package/src/decorators.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Class, ClassInstance, ConcreteClass, ConsoleManager, defineGlobalEnv } from '@travetto/base';
1
+ import { Class, ClassInstance, ConcreteClass, ConsoleManager, GlobalEnv, defineGlobalEnv } from '@travetto/base';
2
2
  import { RootIndex } from '@travetto/manifest';
3
3
  import { SchemaRegistry } from '@travetto/schema';
4
4
 
@@ -37,9 +37,13 @@ export function CliCommand(cfg: { fields?: ExtraFields[], runTarget?: boolean, h
37
37
  hidden: cfg.hidden,
38
38
  runTarget: cfg.runTarget,
39
39
  preMain: (cmd: CliCommandShape & { env?: string, profile?: string[], module?: string }) => {
40
- if (addEnv) { defineGlobalEnv({ envName: cmd.env }); }
41
- if (addProfile) { defineGlobalEnv({ profiles: cmd.profile }); }
42
- if (addEnv || addProfile) { ConsoleManager.setDebugFromEnv(); }
40
+ if (addEnv || addProfile) {
41
+ defineGlobalEnv({
42
+ ...addEnv ? { envName: cmd.env } : {},
43
+ ...addProfile ? { profiles: cmd.profile } : {}
44
+ });
45
+ ConsoleManager.setDebug(GlobalEnv.debug, GlobalEnv.devMode);
46
+ }
43
47
  if (addModule && cmd.module && cmd.module !== RootIndex.mainModuleName) { // Mono-repo support
44
48
  RootIndex.reinitForModule(cmd.module); // Reinit with specified module
45
49
  }
package/src/execute.ts CHANGED
@@ -2,7 +2,7 @@ import { appendFile, mkdir } from 'fs/promises';
2
2
 
3
3
  import { GlobalTerminal } from '@travetto/terminal';
4
4
  import { path } from '@travetto/manifest';
5
- import { ConsoleManager, defineGlobalEnv, ShutdownManager } from '@travetto/base';
5
+ import { ConsoleManager, defineGlobalEnv, ShutdownManager, GlobalEnv } from '@travetto/base';
6
6
 
7
7
  import { HelpUtil } from './help';
8
8
  import { CliCommandShape, CliValidationResultError } from './types';
@@ -16,11 +16,8 @@ export class ExecutionManager {
16
16
 
17
17
  static async #envInit(cmd: CliCommandShape): Promise<void> {
18
18
  if (cmd.envInit) {
19
- defineGlobalEnv({
20
- debug: process.env.DEBUG || false,
21
- ...await cmd.envInit(),
22
- });
23
- ConsoleManager.setDebugFromEnv();
19
+ defineGlobalEnv(await cmd.envInit());
20
+ ConsoleManager.setDebug(GlobalEnv.debug, GlobalEnv.devMode);
24
21
  }
25
22
  }
26
23
 
package/src/module.ts CHANGED
@@ -20,9 +20,7 @@ export class CliModuleUtil {
20
20
  * @returns
21
21
  */
22
22
  static async findChangedModulesRecursive(hash?: string, transitive = true): Promise<IndexedModule[]> {
23
- if (!hash) {
24
- hash = await CliScmUtil.findLastRelease();
25
- }
23
+ hash ??= await CliScmUtil.findLastRelease();
26
24
 
27
25
  if (!hash) {
28
26
  return RootIndex.getLocalModules();
@@ -48,9 +46,9 @@ export class CliModuleUtil {
48
46
  * @param transitive
49
47
  * @returns
50
48
  */
51
- static async findModules(mode: 'all' | 'changed'): Promise<IndexedModule[]> {
49
+ static async findModules(mode: 'all' | 'changed', sinceHash?: string): Promise<IndexedModule[]> {
52
50
  return (mode === 'changed' ?
53
- await this.findChangedModulesRecursive() :
51
+ await this.findChangedModulesRecursive(sinceHash) :
54
52
  [...RootIndex.getModuleList('all')].map(x => RootIndex.getModule(x)!)
55
53
  ).filter(x => x.sourcePath !== RootIndex.manifest.workspacePath);
56
54
  }
package/src/schema.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Class, ConsoleManager } from '@travetto/base';
1
+ import { Class, ConsoleManager, GlobalEnv } from '@travetto/base';
2
2
  import { BindUtil, FieldConfig, SchemaRegistry, SchemaValidator, ValidationResultError } from '@travetto/schema';
3
3
  import { CliCommandRegistry } from './registry';
4
4
 
@@ -57,7 +57,7 @@ export class CliCommandSchemaUtil {
57
57
  }
58
58
  SchemaRegistry.onInstall(cls, { type: 'added', curr: cls });
59
59
  } finally {
60
- ConsoleManager.setDebugFromEnv();
60
+ ConsoleManager.setDebug(GlobalEnv.debug, GlobalEnv.devMode);
61
61
  }
62
62
 
63
63
  const schema = await SchemaRegistry.getViewSchema(cls);
package/src/scm.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs/promises';
2
2
 
3
3
  import { Env, ExecUtil } from '@travetto/base';
4
- import { IndexedModule, RootIndex, path } from '@travetto/manifest';
4
+ import { IndexedFile, IndexedModule, RootIndex, path } from '@travetto/manifest';
5
5
 
6
6
  export class CliScmUtil {
7
7
  /**
@@ -41,21 +41,38 @@ export class CliScmUtil {
41
41
  }
42
42
 
43
43
  /**
44
- * Find all modules that changed since hash
44
+ * Find all source files that changed since hash
45
45
  * @param hash
46
46
  * @returns
47
47
  */
48
- static async findChangedModulesSince(hash: string): Promise<IndexedModule[]> {
48
+ static async findChangedFilesSince(hash: string): Promise<string[]> {
49
49
  const ws = RootIndex.manifest.workspacePath;
50
50
  const res = await ExecUtil.spawn('git', ['diff', '--name-only', `HEAD..${hash}`, ':!**/DOC.*', ':!**/README.*'], { cwd: ws }).result;
51
- const out = new Set<IndexedModule>();
51
+ const out = new Set<string>();
52
52
  for (const line of res.stdout.split(/\n/g)) {
53
- const mod = RootIndex.getFromSource(path.resolve(ws, line));
54
- if (mod) {
55
- out.add(RootIndex.getModule(mod.module)!);
53
+ const entry = RootIndex.getEntry(path.resolve(ws, line));
54
+ if (entry) {
55
+ out.add(entry.sourceFile);
56
56
  }
57
57
  }
58
- return [...out].sort((a, b) => a.name.localeCompare(b.name));
58
+ return [...out].sort((a, b) => a.localeCompare(b));
59
+ }
60
+
61
+ /**
62
+ * Find all modules that changed since hash
63
+ * @param hash
64
+ * @returns
65
+ */
66
+ static async findChangedModulesSince(hash: string): Promise<IndexedModule[]> {
67
+ const files = await this.findChangedFilesSince(hash);
68
+ const mods = files
69
+ .map(x => RootIndex.getFromSource(x))
70
+ .filter((x): x is IndexedFile => !!x)
71
+ .map(x => RootIndex.getModule(x.module))
72
+ .filter((x): x is IndexedModule => !!x);
73
+
74
+ return [...new Set(mods)]
75
+ .sort((a, b) => a.name.localeCompare(b.name));
59
76
  }
60
77
 
61
78
  /**