@travetto/cli 3.1.0-rc.2 → 3.1.0-rc.3

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
@@ -22,32 +22,35 @@ $ trv --help
22
22
  Usage: [options] [command]
23
23
 
24
24
  Commands:
25
- doc Command line support for generating module docs.
26
- doc:angular Generate documentation into the angular webapp under related/travetto.github.io
27
- doc:mapping Generate module mapping for @travetto/doc
28
- email:compile CLI Entry point for running the email server
29
- email:editor The email editor compilation service and output serving
30
- exec Repo execution
31
- lint Command line support for linting
32
- lint:register Writes the lint configuration file
33
- list Allows for listing of modules
34
- model:export Exports model schemas
35
- model:install Installing models
36
- openapi:client CLI for generating the cli client
37
- openapi:spec CLI for outputting the open api spec to a local file
38
- pack Standard pack support
39
- pack:docker Standard docker support for pack
40
- pack:lambda Standard lambda support for pack
41
- pack:zip Standard zip support for pack
42
- repo:publish Publish all pending modules
43
- repo:version Version all changed dependencies
44
- run:double Doubles a number
45
- run:rest Run a rest server as an application
46
- scaffold Command to run scaffolding
47
- service Allows for running services
48
- test Launch test framework and execute tests
49
- test:watch Invoke the test watcher
50
- version-sync Enforces all packages to write out their versions and dependencies
25
+ doc Command line support for generating module docs.
26
+ doc:angular Generate documentation into the angular webapp under related/travetto.github.io
27
+ doc:mapping Generate module mapping for @travetto/doc
28
+ email:compile CLI Entry point for running the email server
29
+ email:editor The email editor compilation service and output serving
30
+ exec Repo execution
31
+ lint Command line support for linting
32
+ lint:register Writes the lint configuration file
33
+ list Allows for listing of modules
34
+ model:export Exports model schemas
35
+ model:install Installing models
36
+ openapi:client CLI for generating the cli client
37
+ openapi:spec CLI for outputting the open api spec to a local file
38
+ pack Standard pack support
39
+ pack:docker Standard docker support for pack
40
+ pack:lambda Standard lambda support for pack
41
+ pack:zip Standard zip support for pack
42
+ repo:exec Repo execution
43
+ repo:list Allows for listing of modules
44
+ repo:publish Publish all pending modules
45
+ repo:version Version all changed dependencies
46
+ repo:version-sync Enforces all packages to write out their versions and dependencies
47
+ run:double Doubles a number
48
+ run:rest Run a rest server as an application
49
+ scaffold Command to run scaffolding
50
+ service Allows for running services
51
+ test Launch test framework and execute tests
52
+ test:watch Invoke the test watcher
53
+ version-sync Enforces all packages to write out their versions and dependencies
51
54
  ```
52
55
 
53
56
  This listing is from the [Travetto](https://travetto.dev) monorepo, and represents the majority of tools that can be invoked from the command line.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "3.1.0-rc.2",
3
+ "version": "3.1.0-rc.3",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -24,9 +24,8 @@
24
24
  "directory": "module/cli"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/schema": "^3.1.0-rc.2",
28
- "@travetto/terminal": "^3.1.0-rc.0",
29
- "@travetto/worker": "^3.1.0-rc.0"
27
+ "@travetto/schema": "^3.1.0-rc.3",
28
+ "@travetto/terminal": "^3.1.0-rc.0"
30
29
  },
31
30
  "travetto": {
32
31
  "displayName": "Command Line Interface"
package/src/decorators.ts CHANGED
@@ -39,7 +39,7 @@ export function CliCommand(cfg: { fields?: ExtraFields[], runTarget?: boolean, h
39
39
  if (addEnv) { defineGlobalEnv({ envName: cmd.env }); }
40
40
  if (addProfile) { defineGlobalEnv({ profiles: cmd.profile }); }
41
41
  if (addEnv || addProfile) { ConsoleManager.setDebugFromEnv(); }
42
- if (addModule && cmd.module && cmd.module !== RootIndex.mainModule.name) { // Mono-repo support
42
+ if (addModule && cmd.module && cmd.module !== RootIndex.mainModuleName) { // Mono-repo support
43
43
  RootIndex.reinitForModule(cmd.module); // Reinit with specified module
44
44
  }
45
45
  }
package/src/module.ts CHANGED
@@ -1,32 +1,11 @@
1
- import { ColorDefineUtil, NAMED_COLORS, Terminal, GlobalTerminal, TermLinePosition } from '@travetto/terminal';
2
- import { Env, ExecutionOptions, ExecutionResult, ExecutionState, TypedObject } from '@travetto/base';
3
- import { IndexedModule, PackageUtil, RootIndex } from '@travetto/manifest';
4
- import { IterableWorkSet, WorkPool, type Worker } from '@travetto/worker';
1
+ import { IndexedModule, RootIndex } from '@travetto/manifest';
5
2
 
6
3
  import { CliScmUtil } from './scm';
7
4
  import { CliValidationError } from './types';
8
5
  import { CliUtil } from './util';
9
6
 
10
- type ModuleRunConfig<T = ExecutionResult> = {
11
- progressMessage?: (mod: IndexedModule | undefined) => string;
12
- filter?: (mod: IndexedModule) => boolean | Promise<boolean>;
13
- transformResult?: (mod: IndexedModule, result: ExecutionResult) => T;
14
- workerCount?: number;
15
- progressPosition?: TermLinePosition;
16
- prefixOutput?: boolean;
17
- showStdout?: boolean;
18
- showStderr?: boolean;
19
- };
20
-
21
7
  type ModuleGraphEntry = { children: Set<string>, name: string, active: Set<string>, parents?: string[] };
22
8
 
23
- const COLORS = TypedObject.keys(NAMED_COLORS)
24
- .map(k => [k, ColorDefineUtil.defineColor(k).hsl] as const)
25
- .filter(([, [, s, l]]) => l > .5 && l < .8 && s > .8)
26
- .map(([k]) => GlobalTerminal.colorer(k));
27
-
28
- const colorize = (val: string, idx: number): string => COLORS[idx % COLORS.length](val);
29
-
30
9
  const modError = (message: string): CliValidationError => ({ source: 'flag', message: `module: ${message}` });
31
10
 
32
11
  /**
@@ -34,45 +13,6 @@ const modError = (message: string): CliValidationError => ({ source: 'flag', mes
34
13
  */
35
14
  export class CliModuleUtil {
36
15
 
37
- /**
38
- * Generate execution options for running on modules
39
- */
40
- static #buildExecutionOptions<T = ExecutionState>(
41
- mod: IndexedModule,
42
- config: ModuleRunConfig<T>,
43
- prefixes: Record<string, string>,
44
- stdoutTerm: Terminal,
45
- stderrTerm: Terminal
46
- ): ExecutionOptions {
47
- const folder = mod.sourceFolder;
48
- const opts: ExecutionOptions = {
49
- stdio: ['ignore', 'pipe', 'pipe', 'ignore'],
50
- outputMode: 'text',
51
- catchAsResult: true,
52
- cwd: folder,
53
- env: { TRV_MANIFEST: '', TRV_MODULE: mod.name },
54
- };
55
-
56
- if (config.showStdout) {
57
- opts.onStdOutLine = (line: string): unknown => stdoutTerm.writeLines(`${prefixes[folder] ?? ''}${line}`);
58
- }
59
- if (config.showStderr) {
60
- opts.onStdErrorLine = (line: string): unknown => stderrTerm.writeLines(`${prefixes[folder] ?? ''}${line}`);
61
- }
62
- return opts;
63
- }
64
-
65
- /**
66
- * Build equal sized prefix labels for outputting
67
- * @param mods
68
- * @returns
69
- */
70
- static #buildPrefixes(mods: IndexedModule[]): Record<string, string> {
71
- const folders = mods.map(x => x.sourceFolder);
72
- const maxWidth = Math.max(...folders.map(x => x.length));
73
- return Object.fromEntries(folders.map((x, i) => [x, colorize(x.padStart(maxWidth, ' ').padEnd(maxWidth + 1), i)]));
74
- }
75
-
76
16
  /**
77
17
  * Find modules that changed, and the dependent modules
78
18
  * @param hash
@@ -115,86 +55,6 @@ export class CliModuleUtil {
115
55
  ).filter(x => x.sourcePath !== RootIndex.manifest.workspacePath);
116
56
  }
117
57
 
118
- /**
119
- * Synchronize all workspace modules to have the correct versions from the current packages
120
- */
121
- static async synchronizeModuleVersions(): Promise<Record<string, string>> {
122
- const versions = {};
123
- await PackageUtil.syncVersions((await this.findModules('all')).map(x => x.sourcePath), versions);
124
- return versions;
125
- }
126
-
127
- /**
128
- * Run on all modules
129
- */
130
- static async execOnModules<T = ExecutionResult>(
131
- mode: 'all' | 'changed',
132
- operation: (mod: IndexedModule, options: ExecutionOptions) => ExecutionState,
133
- config: ModuleRunConfig<T> = {}
134
- ): Promise<Map<IndexedModule, T>> {
135
-
136
- config.showStdout = config.showStdout ?? (Env.isSet('DEBUG') && !Env.isFalse('DEBUG'));
137
- config.showStderr = config.showStderr ?? true;
138
-
139
- const workerCount = config.workerCount ?? WorkPool.DEFAULT_SIZE;
140
-
141
- const mods = await CliModuleUtil.findModules(mode);
142
- const results = new Map<IndexedModule, T>();
143
- const processes = new Map<IndexedModule, ExecutionState>();
144
-
145
- const prefixes = config.prefixOutput !== false ? this.#buildPrefixes(mods) : {};
146
- const stdoutTerm = await Terminal.for({ output: process.stdout });
147
- const stderrTerm = await Terminal.for({ output: process.stderr });
148
-
149
- let id = 1;
150
- const pool = new WorkPool(async () => {
151
- const worker: Worker<IndexedModule> & { mod?: IndexedModule } = {
152
- id: id += 1,
153
- mod: undefined,
154
- active: false,
155
- async destroy() {
156
- this.active = false;
157
- processes.get(this.mod!)?.process.kill('SIGKILL');
158
- },
159
- async execute(mod: IndexedModule) {
160
- try {
161
- this.mod = mod;
162
- this.active = true;
163
-
164
- if (await config.filter?.(mod) === false) {
165
- this.active = false;
166
- } else {
167
- const opts = CliModuleUtil.#buildExecutionOptions(mod, config, prefixes, stdoutTerm, stderrTerm);
168
-
169
- const result = await operation(mod, opts).result;
170
-
171
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
172
- const output = (config.transformResult ? config.transformResult(mod, result) : result) as T;
173
- results.set(mod, output);
174
- }
175
- } finally {
176
- this.active = false;
177
- delete this.mod;
178
- }
179
- },
180
- };
181
- return worker;
182
- }, { max: workerCount, min: workerCount });
183
-
184
- const work = pool.iterateProcess(new IterableWorkSet(mods));
185
-
186
- if (config.progressMessage) {
187
- const cfg = { position: config.progressPosition ?? 'bottom' } as const;
188
- await stdoutTerm.trackProgress(work, ev => ({ ...ev, text: config.progressMessage!(ev.value) }), cfg);
189
- } else {
190
- for await (const _ of work) {
191
- // Ensure its all consumed
192
- }
193
- }
194
-
195
- return results;
196
- }
197
-
198
58
  /**
199
59
  * Get module dependency graph, fully collapsed
200
60
  */
package/src/util.ts CHANGED
@@ -12,7 +12,7 @@ export class CliUtil {
12
12
  * Get a simplified version of a module name
13
13
  * @returns
14
14
  */
15
- static getSimpleModuleName(name = RootIndex.mainPackage.name): string {
15
+ static getSimpleModuleName(name = RootIndex.mainModuleName): string {
16
16
  return name.replace(/[\/]/, '_').replace(/@/, '');
17
17
  }
18
18
  }
@@ -1,55 +0,0 @@
1
- import { CliCommand, CliCommandShape, CliModuleUtil } from '@travetto/cli';
2
- import { WorkPool } from '@travetto/worker';
3
- import { RootIndex } from '@travetto/manifest';
4
- import { ExecUtil, GlobalEnvConfig } from '@travetto/base';
5
- import { Max, Min } from '@travetto/schema';
6
-
7
- /**
8
- * Repo execution
9
- */
10
- @CliCommand()
11
- export class RepoExecCommand implements CliCommandShape {
12
-
13
- #unknownArgs?: string[];
14
-
15
- /** Only changed modules */
16
- changed = true;
17
-
18
- /** Number of concurrent workers */
19
- @Min(1) @Max(WorkPool.MAX_SIZE)
20
- workers = WorkPool.DEFAULT_SIZE;
21
-
22
- /** Prefix output by folder */
23
- prefixOutput = true;
24
-
25
- /** Show stdout */
26
- showStdout = true;
27
-
28
- isActive(): boolean {
29
- return !!RootIndex.manifest.monoRepo;
30
- }
31
-
32
- envInit(): GlobalEnvConfig {
33
- return { debug: false };
34
- }
35
-
36
- finalize(unknownArgs?: string[] | undefined): void | Promise<void> {
37
- this.#unknownArgs = unknownArgs;
38
- }
39
-
40
- async main(cmd: string, args: string[]): Promise<void> {
41
- const finalArgs = [...args, ...this.#unknownArgs ?? []];
42
-
43
- await CliModuleUtil.execOnModules(
44
- this.changed ? 'changed' : 'all',
45
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
46
- (mod, opts) => ExecUtil.spawn(cmd, finalArgs, opts),
47
- {
48
- progressMessage: mod => `Running '${cmd} ${finalArgs.join(' ')}' [%idx/%total] ${mod?.sourceFolder ?? ''}`,
49
- showStdout: this.showStdout,
50
- prefixOutput: this.prefixOutput,
51
- workerCount: this.workers,
52
- }
53
- );
54
- }
55
- }
@@ -1,51 +0,0 @@
1
- import { CliCommandShape, CliCommand, CliModuleUtil } from '@travetto/cli';
2
- import { RootIndex } from '@travetto/manifest';
3
-
4
- const write = (line: string): Promise<void> => new Promise(r => process.stdout.write(`${line}\n`, () => r()));
5
-
6
- /**
7
- * Allows for listing of modules
8
- */
9
- @CliCommand()
10
- export class ListModuleCommand implements CliCommandShape {
11
-
12
- /** Only show changed modules */
13
- changed = false;
14
-
15
- /** Output format */
16
- format: 'graph' | 'json' | 'list' = 'list';
17
-
18
- isActive(): boolean {
19
- return !!RootIndex.manifest.monoRepo;
20
- }
21
-
22
- async main(): Promise<void> {
23
-
24
- const mods = await CliModuleUtil.findModules(this.changed ? 'changed' : 'all');
25
- switch (this.format) {
26
- case 'list': {
27
- for (const mod of mods.map(x => x.sourceFolder).sort()) {
28
- await write(mod);
29
- }
30
- break;
31
- }
32
- case 'json': {
33
- const outputMap = CliModuleUtil.getDependencyGraph(mods);
34
- await write(JSON.stringify(Object.entries(outputMap).map(([name, children]) => ({ name, children, local: RootIndex.getModule(name)?.local })), null, 2));
35
- break;
36
- }
37
- case 'graph': {
38
- await write('digraph g {');
39
- for (const el of mods) {
40
- for (const dep of el.parents) {
41
- if (dep !== RootIndex.mainPackage.name) {
42
- await write(` "${dep}" -> "${el.name}";`);
43
- }
44
- }
45
- }
46
- await write('}');
47
- break;
48
- }
49
- }
50
- }
51
- }
@@ -1,16 +0,0 @@
1
- import { CliCommandShape, CliCommand, CliModuleUtil } from '@travetto/cli';
2
- import { RootIndex } from '@travetto/manifest';
3
-
4
- /**
5
- * Enforces all packages to write out their versions and dependencies
6
- */
7
- @CliCommand()
8
- export class VersionSyncCommand implements CliCommandShape {
9
- isActive(): boolean {
10
- return !!RootIndex.manifest.monoRepo;
11
- }
12
-
13
- async main(): Promise<void> {
14
- await CliModuleUtil.synchronizeModuleVersions();
15
- }
16
- }