@travetto/cli 4.1.0 → 4.1.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ArcSine Technologies
3
+ Copyright (c) 2020 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -29,8 +29,8 @@
29
29
  "directory": "module/cli"
30
30
  },
31
31
  "dependencies": {
32
- "@travetto/schema": "^4.1.0",
33
- "@travetto/terminal": "^4.1.0"
32
+ "@travetto/schema": "^4.1.1",
33
+ "@travetto/terminal": "^4.1.1"
34
34
  },
35
35
  "travetto": {
36
36
  "displayName": "Command Line Interface",
package/src/help.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import util from 'node:util';
2
+
1
3
  import { Primitive } from '@travetto/base';
2
- import { StyleUtil } from '@travetto/terminal';
3
4
 
4
5
  import { cliTpl } from './color';
5
6
  import { CliCommandShape } from './types';
@@ -70,8 +71,8 @@ export class HelpUtil {
70
71
  descs.push(desc.join(' '));
71
72
  }
72
73
 
73
- const paramWidths = params.map(x => StyleUtil.cleanText(x).length);
74
- const descWidths = descs.map(x => StyleUtil.cleanText(x).length);
74
+ const paramWidths = params.map(x => util.stripVTControlCharacters(x).length);
75
+ const descWidths = descs.map(x => util.stripVTControlCharacters(x).length);
75
76
 
76
77
  const paramWidth = Math.max(...paramWidths);
77
78
  const descWidth = Math.max(...descWidths);
@@ -99,7 +100,7 @@ export class HelpUtil {
99
100
  static async renderAllHelp(title?: string): Promise<string> {
100
101
  const rows: string[] = [];
101
102
  const keys = [...CliCommandRegistry.getCommandMapping().keys()].sort((a, b) => a.localeCompare(b));
102
- const maxWidth = keys.reduce((a, b) => Math.max(a, StyleUtil.cleanText(b).length), 0);
103
+ const maxWidth = keys.reduce((a, b) => Math.max(a, util.stripVTControlCharacters(b).length), 0);
103
104
 
104
105
  for (const cmd of keys) {
105
106
  try {
package/src/module.ts CHANGED
@@ -43,9 +43,9 @@ export class CliModuleUtil {
43
43
  * @param transitive
44
44
  * @returns
45
45
  */
46
- static async findModules(mode: 'all' | 'changed', fromHash?: string, toHash?: string): Promise<IndexedModule[]> {
46
+ static async findModules(mode: 'all' | 'changed', fromHash?: string, toHash?: string, emptyOnFail = false): Promise<IndexedModule[]> {
47
47
  return (mode === 'changed' ?
48
- await this.findChangedModulesRecursive(fromHash, toHash) :
48
+ await this.findChangedModulesRecursive(fromHash, toHash, emptyOnFail) :
49
49
  [...RuntimeIndex.getModuleList('all')].map(x => RuntimeIndex.getModule(x)!)
50
50
  ).filter(x => x.sourcePath !== RuntimeContext.workspace.path);
51
51
  }
package/src/parse.ts CHANGED
@@ -210,7 +210,7 @@ export class CliParseUtil {
210
210
  inputs,
211
211
  all: out,
212
212
  unknown: out.filter(x => x.type === 'unknown').map(x => x.input),
213
- flags: out.filter((x): x is ParsedInput & { type: 'flag' } => x.type === 'flag')
213
+ flags: out.filter(x => x.type === 'flag')
214
214
  };
215
215
  }
216
216
  }
package/src/scm.ts CHANGED
@@ -2,7 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import fs from 'node:fs/promises';
3
3
 
4
4
  import { ExecUtil } from '@travetto/base';
5
- import { IndexedFile, IndexedModule, RuntimeIndex, RuntimeContext, path } from '@travetto/manifest';
5
+ import { IndexedModule, RuntimeIndex, RuntimeContext, path } from '@travetto/manifest';
6
6
 
7
7
  export class CliScmUtil {
8
8
  /**
@@ -45,9 +45,13 @@ export class CliScmUtil {
45
45
  * @param fromHash
46
46
  * @returns
47
47
  */
48
- static async findChangedFiles(fromHash: string, toHash: string = 'HEAD'): Promise<string[]> {
48
+ static async findChangedFiles(fromHash: string, toHash: string = 'HEAD', emptyOnFail = false): Promise<string[]> {
49
49
  const ws = RuntimeContext.workspace.path;
50
- const res = await ExecUtil.getResult(spawn('git', ['diff', '--name-only', `${fromHash}..${toHash}`, ':!**/DOC.*', ':!**/README.*'], { cwd: ws }));
50
+ const res = await ExecUtil.getResult(spawn('git', ['diff', '--name-only', `${fromHash}..${toHash}`, ':!**/DOC.*', ':!**/README.*'], { cwd: ws }), { catch: true });
51
+ if (!res.valid && emptyOnFail) {
52
+ console.warn('Unable to detect changes between', fromHash, toHash, 'with', (res.stderr || res.stdout));
53
+ return [];
54
+ }
51
55
  const out = new Set<string>();
52
56
  for (const line of res.stdout.split(/\n/g)) {
53
57
  const entry = RuntimeIndex.getEntry(path.resolve(ws, line));
@@ -68,9 +72,9 @@ export class CliScmUtil {
68
72
  const files = await this.findChangedFiles(fromHash, toHash);
69
73
  const mods = files
70
74
  .map(x => RuntimeIndex.getFromSource(x))
71
- .filter((x): x is IndexedFile => !!x)
75
+ .filter(x => !!x)
72
76
  .map(x => RuntimeIndex.getModule(x.module))
73
- .filter((x): x is IndexedModule => !!x);
77
+ .filter(x => !!x);
74
78
 
75
79
  return [...new Set(mods)]
76
80
  .sort((a, b) => a.name.localeCompare(b.name));
@@ -17,12 +17,14 @@ export class CliSchemaCommand implements CliCommandShape {
17
17
  return CliCommandSchemaUtil.getSchema(inst!);
18
18
  }
19
19
 
20
- async validate(name?: string): Promise<CliValidationError | undefined> {
21
- if (name && !CliCommandRegistry.getCommandMapping().has(name)) {
22
- return {
23
- source: 'arg',
24
- message: `name: ${name} is not a valid cli command`
25
- };
20
+ async validate(names: string[]): Promise<CliValidationError | undefined> {
21
+ for (const name of names ?? []) {
22
+ if (name && !CliCommandRegistry.getCommandMapping().has(name)) {
23
+ return {
24
+ source: 'arg',
25
+ message: `name: ${name} is not a valid cli command`
26
+ };
27
+ }
26
28
  }
27
29
  }
28
30
 
@@ -30,15 +32,11 @@ export class CliSchemaCommand implements CliCommandShape {
30
32
  Env.DEBUG.set(false);
31
33
  }
32
34
 
33
- async main(name?: string): Promise<void> {
34
- let output: unknown = undefined;
35
- if (name) {
36
- output = await this.#getSchema(name);
37
- } else {
38
- const names = [...CliCommandRegistry.getCommandMapping().keys()];
39
- const schemas = await Promise.all(names.map(x => this.#getSchema(x)));
40
- output = schemas;
35
+ async main(names?: string[]): Promise<void> {
36
+ if (!names?.length) {
37
+ names = [...CliCommandRegistry.getCommandMapping().keys()];
41
38
  }
42
- await CliUtil.writeAndEnsureComplete(output);
39
+ const resolved = await Promise.all(names.map(x => this.#getSchema(x)));
40
+ await CliUtil.writeAndEnsureComplete(resolved);
43
41
  }
44
42
  }