@travetto/compiler 8.0.0-alpha.7 → 8.0.0-alpha.8

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
@@ -25,7 +25,7 @@ Beyond the [Typescript](https://typescriptlang.org) compiler functionality, the
25
25
  The compiler cli, [trvc](https://github.com/travetto/travetto/tree/main/module/compiler/bin/trvc.js) is the entry point for compilation-related operations. It has the ability to check for active builds, and ongoing watch operations to ensure only one process is building at a time. Within the framework, regardless of mono-repo or not, the compilation always targets the entire project. With the efficient caching behavior, this leads to generally a minimal overhead but allows for centralization of all operations.
26
26
 
27
27
  The compiler cli supports the following operations:
28
- * `start|watch` - Run the compiler in watch mode
28
+ * `start` - Run the compiler in watch mode
29
29
  * `stop` - Stop the compiler if running
30
30
  * `restart` - Restart the compiler in watch mode
31
31
  * `build` - Ensure the project is built and upto date
package/bin/trvc.js CHANGED
@@ -3,4 +3,4 @@
3
3
  import '@travetto/runtime/support/patch.js';
4
4
  import './hook.js';
5
5
  const { invoke } = await import('@travetto/compiler/support/invoke.ts');
6
- await invoke();
6
+ await invoke(...process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/compiler",
3
- "version": "8.0.0-alpha.7",
3
+ "version": "8.0.0-alpha.8",
4
4
  "type": "module",
5
5
  "description": "The compiler infrastructure for the Travetto framework",
6
6
  "keywords": [
@@ -35,7 +35,7 @@
35
35
  "@travetto/transformer": "^8.0.0-alpha.4"
36
36
  },
37
37
  "peerDependencies": {
38
- "@travetto/cli": "^8.0.0-alpha.9"
38
+ "@travetto/cli": "^8.0.0-alpha.11"
39
39
  },
40
40
  "peerDependenciesMeta": {
41
41
  "@travetto/cli": {
package/support/invoke.ts CHANGED
@@ -7,40 +7,62 @@ import { CompilerClient } from '../src/server/client.ts';
7
7
  import { CommonUtil } from '../src/common.ts';
8
8
  import { EventUtil } from '../src/event.ts';
9
9
 
10
- const HELP = `
11
- trvc [command]
10
+ const hasColor = (process.stdout.isTTY && /^(0)*$/.test(process.env.NO_COLOR ?? '')) || /1\d*/.test(process.env.FORCE_COLOR ?? '');
11
+ const color = (code: number) => (value: string): string => hasColor ? `\x1b[${code}m${value}\x1b[0m` : `${value}`;
12
+ const STYLE = { error: color(91), title: color(36), main: color(92), command: color(35), arg: color(37), description: color(33), };
12
13
 
13
- Available Commands:
14
- * start|watch - Run the compiler in watch mode
15
- * stop - Stop the compiler if running
16
- * restart - Restart the compiler in watch mode
17
- * build - Ensure the project is built and upto date
18
- * clean - Clean out the output and compiler caches
19
- * info - Retrieve the compiler information, if running
20
- * event <log|progress|state> - Watch events in realtime as newline delimited JSON
21
- * exec <file> [...args] - Allow for compiling and executing an entrypoint file
22
- * manifest [output] - Generate the project manifest
23
- * manifest:production [output] - Generate the production project manifest
24
- `;
14
+ const COMMANDS = {
15
+ start: { description: 'Run the compiler in watch mode' },
16
+ stop: { description: 'Stop the compiler if running' },
17
+ restart: { description: 'Restart the compiler in watch mode' },
18
+ build: { description: 'Ensure the project is built and upto date' },
19
+ clean: { description: 'Clean out the output and compiler caches' },
20
+ info: { description: 'Retrieve the compiler information, if running' },
21
+ event: { args: ['<log|progress|state>'], description: 'Watch events in realtime as newline delimited JSON' },
22
+ exec: { args: ['<file>', '[...args]'], description: 'Allow for compiling and executing an entrypoint file' },
23
+ manifest: { args: ['[output]'], description: 'Generate the project manifest' },
24
+ 'manifest:production': { args: ['[output]'], description: 'Generate the production project manifest' }
25
+ } as const;
26
+
27
+ function showHelp(errorMessage?: string): void {
28
+ const PREPARED = Object.entries(COMMANDS)
29
+ .map(([name, config]) => ({ args: [], ...config, name }))
30
+ .map(config => ({ ...config, commandLength: [config.name, ...config.args].join(' ').length }));
31
+
32
+ const commandWidth = Math.max(...PREPARED.map(config => config.commandLength));
33
+
34
+ console.log([
35
+ ...(errorMessage ? ['', STYLE.error(errorMessage)] : []),
36
+ '', `${STYLE.main('trvc')} ${STYLE.command('[command]')}`,
37
+ '', STYLE.title('Available Commands'),
38
+ ...PREPARED.map(({ name, args, description, commandLength }) => [
39
+ '*', STYLE.command(name), ...args.map(arg => STYLE.arg(arg)),
40
+ ' '.repeat(commandWidth - commandLength), '-', STYLE.description(description)
41
+
42
+ ].join(' ')),
43
+ ''
44
+ ].join('\n'));
45
+ }
46
+
47
+ const validateInputs = (value: string[]): value is [keyof typeof COMMANDS, ...string[]] => !!value.length && value[0] in COMMANDS;
25
48
 
26
49
  /**
27
50
  * Invoke the compiler
28
51
  */
29
- export async function invoke(operation?: string, args: string[] = []): Promise<unknown> {
30
- if (operation === undefined) {
31
- [operation, ...args] = process.argv.slice(2);
52
+ export async function invoke(...input: string[]): Promise<unknown> {
53
+ if (!validateInputs(input)) {
54
+ return showHelp(input[0] ? `Unknown trvc command: ${input[0]}` : undefined);;
32
55
  }
56
+
57
+ const [command, ...args] = input;
33
58
  const ctx = getManifestContext();
34
59
  const client = new CompilerClient(ctx, Log.scoped('client'));
35
60
 
36
61
  Log.initLevel('error');
37
62
  Log.root = ctx.workspace.path;
38
63
 
39
- switch (operation) {
40
- case undefined:
41
- case 'help': console.log(HELP); break;
42
- case 'start':
43
- case 'watch': return CompilerManager.compile(ctx, client, { watch: true });
64
+ switch (command) {
65
+ case 'start': return CompilerManager.compile(ctx, client, { watch: true });
44
66
  case 'build': return CompilerManager.compile(ctx, client, { watch: false });
45
67
  case 'restart': return CompilerManager.compile(ctx, client, { watch: true, forceRestart: true });
46
68
  case 'info': {
@@ -59,7 +81,7 @@ export async function invoke(operation?: string, args: string[] = []): Promise<u
59
81
  case 'manifest:production':
60
82
  case 'manifest': {
61
83
  let manifest = await ManifestUtil.buildManifest(ctx);
62
- if (operation === 'manifest:production') {
84
+ if (command === 'manifest:production') {
63
85
  manifest = ManifestUtil.createProductionManifest(manifest);
64
86
  }
65
87
  if (args[0]) {
@@ -92,6 +114,5 @@ export async function invoke(operation?: string, args: string[] = []): Promise<u
92
114
  // Return function to run import on a module
93
115
  return import(importTarget);
94
116
  }
95
- default: console.error(`\nUnknown trvc operation: ${operation}\n${HELP}`);
96
117
  }
97
118
  }