@travetto/doc 3.0.3 → 3.1.0-rc.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/README.md CHANGED
@@ -93,13 +93,13 @@ The run command allows for generating documentation output.
93
93
  ```bash
94
94
  $ trv doc --help
95
95
 
96
- Usage: doc [options]
96
+ Usage: doc [options]
97
97
 
98
98
  Options:
99
- -i, --input <input> Input File (default: "DOC.tsx")
100
- -o, --outputs <outputs> Outputs (default: [])
101
- -w, --watch Watch
102
- -h, --help display help for command
99
+ -i, --input <string> Input File (default: "DOC.tsx")
100
+ -o, --outputs <string> Outputs (default: [])
101
+ -w, --watch Watch? (default: false)
102
+ -h, --help display help for command
103
103
  ```
104
104
 
105
105
  By default, running the command will output the [Markdown](https://en.wikipedia.org/wiki/Markdown) content directly to the terminal.
@@ -151,13 +151,7 @@ Sample documentation for fictional module. This module fictitiously relies upon
151
151
 
152
152
  Usage: <span class="token punctuation">[</span>options<span class="token punctuation">]</span> <span class="token punctuation">[</span>command<span class="token punctuation">]</span>
153
153
 
154
- Options:
155
- -V, <span class="token parameter variable">--version</span> output the version number
156
- -h, <span class="token parameter variable">--help</span> display <span class="token builtin class-name">help</span> <span class="token keyword">for</span> <span class="token builtin class-name">command</span>
157
-
158
154
  Commands:
159
- doc <span class="token punctuation">[</span>options<span class="token punctuation">]</span>
160
- main <span class="token operator">&lt;</span>fileOrImport<span class="token operator">></span> <span class="token punctuation">[</span>args<span class="token punctuation">..</span>.<span class="token punctuation">]</span>
161
- <span class="token builtin class-name">help</span> <span class="token punctuation">[</span>command<span class="token punctuation">]</span> display <span class="token builtin class-name">help</span> <span class="token keyword">for</span> <span class="token builtin class-name">command</span></code></pre>
155
+ doc Command line support <span class="token keyword">for</span> generating module docs.</code></pre>
162
156
  </figure>
163
157
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/doc",
3
- "version": "3.0.3",
3
+ "version": "3.1.0-rc.0",
4
4
  "description": "Documentation support for the Travetto framework",
5
5
  "keywords": [
6
6
  "docs",
@@ -24,12 +24,12 @@
24
24
  "directory": "module/doc"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/base": "^3.0.3",
27
+ "@travetto/base": "^3.1.0-rc.0",
28
28
  "@types/prismjs": "^1.26.0",
29
29
  "prismjs": "^1.29.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@travetto/cli": "^3.0.3"
32
+ "@travetto/cli": "^3.1.0-rc.0"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@travetto/cli": {
@@ -1,8 +1,4 @@
1
1
  export const MOD_MAPPING = {
2
- App: {
3
- name: '@travetto/app', folder: '@travetto/app', displayName: 'Application',
4
- description: 'Application registration/management and run support.'
5
- },
6
2
  Asset: {
7
3
  name: '@travetto/asset', folder: '@travetto/asset', displayName: 'Asset',
8
4
  description: 'Modular library for storing and retrieving binary assets'
package/src/util/run.ts CHANGED
@@ -49,12 +49,13 @@ export class DocRunUtil {
49
49
  static #docState = new DocState();
50
50
 
51
51
  static runState(cmd: string, args: string[], config: RunConfig = {}): RunState {
52
+ const cwd = config.cwd ?? (config.module ? RootIndex.getModule(config.module)! : RootIndex.mainModule).sourcePath;
52
53
  args = [...args];
53
54
  return {
54
55
  cmd,
55
56
  args,
56
57
  opts: {
57
- cwd: path.toPosix(config.cwd ?? path.cwd()),
58
+ cwd: path.toPosix(cwd),
58
59
  shell: '/bin/bash',
59
60
  env: {
60
61
  ...process.env,
@@ -73,9 +74,11 @@ export class DocRunUtil {
73
74
  * Clean run output
74
75
  */
75
76
  static cleanRunOutput(text: string, cfg: RunConfig): string {
77
+ const cwd = path.toPosix((cfg.module ? RootIndex.getModule(cfg.module)! : RootIndex.mainModule).sourcePath);
76
78
  text = stripAnsiCodes(text.trim())
77
- .replace(new RegExp(path.cwd(), 'g'), '.')
79
+ .replaceAll(cwd, '.')
78
80
  .replaceAll(RootIndex.manifest.workspacePath, '<workspace-root>')
81
+ .replace(/[/]tmp[/][a-z_A-Z0-9\/\-]+/g, '/tmp/<temp-folder>')
79
82
  .replace(/^(\s*framework:\s*')(\d+[.]\d+)[^']*('[,]?\s*)$/gm, (_, pre, ver, post) => `${pre}${ver}.x${post}`)
80
83
  .replace(/^(\s*nodeVersion:\s*'v)(\d+)[^']*('[,]?\s*)$/gm, (_, pre, ver, post) => `${pre}${ver}.x.x${post}`)
81
84
  .replace(/^(.{1,4})?Compiling[.]*/, '') // Compiling message, remove
@@ -1,30 +1,25 @@
1
1
  import fs from 'fs/promises';
2
2
 
3
- import { PackageUtil, path, RootIndex, watchFolderImmediate } from '@travetto/manifest';
3
+ import { PackageUtil, path, RootIndex, watchFolders } from '@travetto/manifest';
4
4
  import { ExecUtil, GlobalEnvConfig } from '@travetto/base';
5
- import { CliCommand, OptionConfig, ListOptionConfig } from '@travetto/cli';
6
-
7
- import { DocRenderer } from '../src/render/renderer';
8
-
9
- type Options = {
10
- input: OptionConfig<string>;
11
- outputs: ListOptionConfig<string>;
12
- watch: OptionConfig<boolean>;
13
- };
5
+ import { CliCommandShape, CliCommand, CliValidationError } from '@travetto/cli';
6
+ import { MinLength } from '@travetto/schema';
14
7
 
15
8
  /**
16
9
  * Command line support for generating module docs.
17
10
  */
18
- export class DocCommand extends CliCommand<Options> {
19
- name = 'doc';
11
+ @CliCommand()
12
+ export class DocCommand implements CliCommandShape {
20
13
 
21
- getOptions(): Options {
22
- return {
23
- input: this.option({ desc: 'Input File', def: 'DOC.tsx' }),
24
- outputs: this.listOption({ desc: 'Outputs', def: [] }),
25
- watch: this.boolOption({ desc: 'Watch' })
26
- };
27
- }
14
+ /** Input File */
15
+ input = 'DOC.tsx';
16
+
17
+ /** Outputs */
18
+ @MinLength(1)
19
+ outputs: string[] = [];
20
+
21
+ /** Watch? */
22
+ watch = false;
28
23
 
29
24
  envInit(): GlobalEnvConfig {
30
25
  return {
@@ -38,52 +33,60 @@ export class DocCommand extends CliCommand<Options> {
38
33
  };
39
34
  }
40
35
 
41
- async action(): Promise<void> {
42
- const docFile = path.resolve(this.cmd.input);
43
- if (!(await fs.stat(docFile).catch(() => false))) {
44
- console.error(`The input ${this.cmd.input} does not exist`);
45
- return this.exit(1);
46
- }
47
-
48
- if (this.cmd.outputs.length === 0) {
36
+ finalize(): void {
37
+ if (this.outputs.length === 0) {
49
38
  const workspacePkg = PackageUtil.readPackage(RootIndex.manifest.workspacePath);
50
- this.cmd.outputs = workspacePkg.travetto?.docOutputs ?? ['README.md'];
39
+ this.outputs = workspacePkg.travetto?.docOutputs ?? ['README.md'];
51
40
  }
41
+ this.input = path.resolve(this.input);
42
+ }
52
43
 
53
- const outputs = this.cmd.outputs.map(output =>
54
- output.includes('.') ? [path.extname(output).substring(1), path.resolve(output)] :
55
- [output, null] as const
56
- );
44
+ async validate(...args: unknown[]): Promise<CliValidationError | undefined> {
45
+ const docFile = path.resolve(this.input);
46
+ if (!(await fs.stat(docFile).catch(() => false))) {
47
+ return {
48
+ kind: 'required',
49
+ path: 'input',
50
+ message: `The input ${this.input} does not exist`
51
+ };
52
+ }
53
+ }
57
54
 
58
- if (this.cmd.watch) {
59
- const args = process.argv.slice(2).filter(x => !x.startsWith('-w') && !x.startsWith('--w'));
60
- await watchFolderImmediate(path.dirname(docFile),
61
- () => ExecUtil.spawn('npx', ['trv', ...args], {
55
+ async runWatch(): Promise<void> {
56
+ const args = process.argv.slice(2).filter(x => !/(-w|--watch)/.test(x));
57
+ const stream = watchFolders([{ src: path.dirname(this.input), immediate: true }]);
58
+ for await (const { action, file } of stream) {
59
+ if (action === 'update' && file === this.input) {
60
+ await ExecUtil.spawn('npx', ['trv', ...args], {
62
61
  cwd: RootIndex.mainModule.sourcePath,
63
62
  env: { TRV_QUIET: '1' },
64
63
  stdio: 'inherit', catchAsResult: true
65
- }), {
66
- filter: ev => ev.action === 'update' && ev.file === docFile,
67
- persistent: true
68
- });
64
+ });
65
+ }
69
66
  }
67
+ }
70
68
 
71
- try {
72
- const ctx = await DocRenderer.get(docFile, RootIndex.manifest);
69
+ async render(): Promise<void> {
70
+ const { DocRenderer } = await import('../src/render/renderer.js');
71
+ const ctx = await DocRenderer.get(this.input, RootIndex.manifest);
72
+ const outputs = this.outputs.map(output =>
73
+ output.includes('.') ? [path.extname(output).substring(1), path.resolve(output)] :
74
+ [output, null] as const
75
+ );
73
76
 
74
- for (const [fmt, out] of outputs) {
75
- const result = await ctx.render(fmt);
76
- if (out) {
77
- const finalName = path.resolve(out);
78
- await fs.writeFile(finalName, result, 'utf8');
79
- console.log(`Wrote docs ${this.cmd.input}: ${finalName}`);
80
- } else {
81
- process.stdout.write(result);
82
- }
77
+ for (const [fmt, out] of outputs) {
78
+ const result = await ctx.render(fmt);
79
+ if (out) {
80
+ const finalName = path.resolve(out);
81
+ await fs.writeFile(finalName, result, 'utf8');
82
+ console.log(`Wrote docs ${this.input}: ${finalName}`);
83
+ } else {
84
+ process.stdout.write(result);
83
85
  }
84
- } catch (err) {
85
- console.error(err);
86
- this.exit(1);
87
86
  }
88
87
  }
88
+
89
+ main(): Promise<void> {
90
+ return this.watch ? this.runWatch() : this.render();
91
+ }
89
92
  }