@travetto/doc 3.0.0-rc.20 → 3.0.0-rc.22

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
@@ -1,11 +1,15 @@
1
1
  <!-- This file was generated by @travetto/doc and should not be modified directly -->
2
2
  <!-- Please modify https://github.com/travetto/travetto/tree/main/module/doc/DOC.ts and execute "npx trv doc" to rebuild -->
3
3
  # Documentation
4
- ## Documentation support for the travetto framework
4
+ ## Documentation support for the Travetto framework
5
5
 
6
6
  **Install: @travetto/doc**
7
7
  ```bash
8
8
  npm install @travetto/doc
9
+
10
+ # or
11
+
12
+ yarn add @travetto/doc
9
13
  ```
10
14
 
11
15
  This module provides the ability to generate documentation in [HTML](https://en.wikipedia.org/wiki/HTML) and/or [Markdown](https://en.wikipedia.org/wiki/Markdown). The module relies on integrating with the source of the project, and providing a fully referenced code-base. This allows for automatic updates when code is changed and/or refactored.
@@ -62,7 +66,7 @@ As you can see, you need to export a field named `text` as the body of the help
62
66
  * `Header` - Standard header
63
67
  * `Image` - Image reference
64
68
  * `Input` - Input text
65
- * `Install` - NPM Installation
69
+ * `Install` - Installing a package or program
66
70
  * `Item` - List item
67
71
  * `Library` - Library reference
68
72
  * `List` - Standard List
@@ -78,6 +82,7 @@ As you can see, you need to export a field named `text` as the body of the help
78
82
  * `SnippetLink` - Link to a snippet of code, including line number
79
83
  * `Strong` - Strong Content
80
84
  * `SubSection` - Sub-section
85
+ * `SubSubSection` - Sub-sub-section
81
86
  * `Table` - Table
82
87
  * `TableOfContents` - Table Of Contents
83
88
  * `Terminal` - Terminal output
@@ -115,7 +120,7 @@ By default, running the command will output the [Markdown](https://en.wikipedia.
115
120
  $ trv doc -o html
116
121
 
117
122
  <!-- This file was generated by @travetto/doc and should not be modified directly -->
118
- <!-- Please modify @travetto/doc/doc-exec/DOC.ts and execute "npx trv doc" to rebuild -->
123
+ <!-- Please modify ./doc-exec/DOC.ts and execute "npx trv doc" to rebuild -->
119
124
  <h1>@travetto-doc/doc
120
125
 
121
126
  </h1>
@@ -124,7 +129,11 @@ $ trv doc -o html
124
129
  <figcaption class="install">Install @travetto-doc/doc
125
130
 
126
131
  </figcaption>
127
- <pre><code class="language-bash"><span class="token function">npm</span> <span class="token function">install</span> @travetto-doc/doc</code></pre>
132
+ <pre><code class="language-bash"><span class="token function">npm</span> <span class="token function">install</span> @travetto-doc/doc
133
+
134
+ <span class="token comment"># or</span>
135
+
136
+ <span class="token function">yarn</span> <span class="token function">add</span> @travetto-doc/doc</code></pre>
128
137
  </figure>
129
138
 
130
139
  Sample documentation for fictional module. This module fictitiously relies upon <a class="module-link" href="https://github.com/travetto/travetto/tree/main/module/cache" title="Caching functionality with decorators for declarative use.">Caching</a> functionality.
@@ -137,7 +146,7 @@ Sample documentation for fictional module. This module fictitiously relies upon
137
146
 
138
147
  <figure class="code">
139
148
  <figcaption class="code">Document Sample
140
- <cite><a target="_blank" href="@travetto/doc/doc-exec/src/test.ts">Source</a></cite>
149
+ <cite><a target="_blank" href="./doc-exec/src/test.ts">Source</a></cite>
141
150
  </figcaption>
142
151
  <pre><code class="language-typescript"><span class="token keyword">class</span> <span class="token class-name">TestFile</span> <span class="token punctuation">{{'{'}}</span>
143
152
  <span class="token keyword">static</span> <span class="token function">method</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">{{'{'}}</span> <span class="token punctuation">{{'}'}}</span>
@@ -163,5 +172,4 @@ Commands:
163
172
  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>
164
173
  <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>
165
174
  </figure>
166
- Wrote docs for DOC.ts
167
175
  ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/doc",
3
- "version": "3.0.0-rc.20",
4
- "description": "Documentation support for the travetto framework",
3
+ "version": "3.0.0-rc.22",
4
+ "description": "Documentation support for the Travetto framework",
5
5
  "keywords": [
6
6
  "docs",
7
7
  "travetto",
@@ -24,12 +24,12 @@
24
24
  "directory": "module/doc"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/base": "^3.0.0-rc.20",
27
+ "@travetto/base": "^3.0.0-rc.22",
28
28
  "@types/prismjs": "^1.26.0",
29
29
  "prismjs": "^1.29.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@travetto/cli": "^3.0.0-rc.23"
32
+ "@travetto/cli": "^3.0.0-rc.25"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@travetto/cli": {
package/src/lib.ts CHANGED
@@ -6,8 +6,18 @@ const { Library } = node;
6
6
  export const lib = {
7
7
  Travetto: Library('Travetto', 'https://travetto.dev'),
8
8
  Typescript: Library('Typescript', 'https://typescriptlang.org'),
9
+ Javascript: Library('Javascript', 'https://developer.mozilla.org/en-US/docs/Web/JavaScript'),
9
10
  Node: Library('Node', 'https://nodejs.org'),
10
11
  TravettoPlugin: Library('VSCode plugin', 'https://marketplace.visualstudio.com/items?itemName=arcsine.travetto-plugin'),
12
+ Npm: Library('Npm', 'https://docs.npmjs.com/downloading-and-installing-node-js-and-npm'),
13
+ Yarn: Library('Yarn', 'https://yarnpg.com'),
14
+ Eslint: Library('ESLint', 'https://eslint.org/'),
15
+ Rollup: Library('Rollup', 'https://rollupjs.org/'),
16
+
17
+ // Module
18
+ CommonJS: Library('CommonJS', 'https://nodejs.org/api/modules.html'),
19
+ EcmascriptModule: Library('Ecmascript Module', 'https://nodejs.org/api/esm.html'),
20
+ PackageJson: Library('Package JSON', 'https://docs.npmjs.com/cli/v9/configuring-npm/package-json'),
11
21
 
12
22
  // Download
13
23
  NodeDownload: Library('Node', 'https://nodejs.org/en/download/current/'),
@@ -29,11 +39,14 @@ export const lib = {
29
39
  JSDoc: Library('JSDoc', 'http://usejsdoc.org/about-getting-started.html'),
30
40
  CodeLens: Library('CodeLens',
31
41
  'https://code.visualstudio.com/api/language-extensions/programmatic-language-features#codelens-show-actionable-context-information-within-source-code'),
42
+ ORM: Library('Object Relationship Mapping', 'https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping'),
43
+ UUID: Library('UUID', 'https://en.wikipedia.org/wiki/Universally_unique_identifier'),
32
44
 
33
45
  // Node
34
46
  ChildProcess: Library('child_process', 'https://nodejs.org/api/child_process.html'),
35
47
  AsyncHooks: Library('async_hooks', 'https://nodejs.org/api/async_hooks.html'),
36
48
  Http: Library('http', 'https://nodejs.org/api/http.html'),
49
+ Path: Library('http', 'https://nodejs.org/api/path.html'),
37
50
  Https: Library('https', 'https://nodejs.org/api/https.html'),
38
51
  Console: Library('console', 'https://nodejs.org/api/console.html'),
39
52
  Assert: Library('assert', 'https://nodejs.org/api/assert.html'),
@@ -49,11 +62,12 @@ export const lib = {
49
62
  OpenAPIGenerator: Library('OpenAPI client generation tools', 'https://github.com/OpenAPITools/openapi-generator'),
50
63
  Gaze: Library('gaze', 'https://github.com/shama/gaze'),
51
64
  Chokidar: Library('chokidar', 'https://github.com/paulmillr/chokidar'),
52
- Faker: Library('faker', 'https://github.com/marak/Faker.js/'),
65
+ Faker: Library('faker', 'https://github.com/faker-js/faker'),
53
66
  Yeoman: Library('yeoman', 'http://yeoman.io'),
54
67
  Commander: Library('commander', 'https://www.npmjs.com/package/commander'),
55
68
  Curl: Library('curl', 'https://curl.haxx.se/'),
56
69
  Fetch: Library('fetch', 'https://www.npmjs.com/package/node-fetch'),
70
+ ParcelWatcher: Library('fetch', 'https://www.npmjs.com/package/@parcel/watcher'),
57
71
 
58
72
  // JWT
59
73
  JWT: Library('JWT', 'https://jwt.io/'),
@@ -83,7 +97,6 @@ export const lib = {
83
97
  Firestore: Library('Firestore', 'https://firebase.google.com/docs/firestore'),
84
98
  SQLite: Library('SQLite', 'https://www.sqlite.org/'),
85
99
 
86
-
87
100
  // Rest
88
101
  Express: Library('express', 'https://expressjs.com'),
89
102
  Passport: Library('passport', 'http://passportjs.org'),
@@ -13,31 +13,31 @@ export const MOD_MAPPING = {
13
13
  },
14
14
  Auth: {
15
15
  name:'@travetto/auth', folder:'@travetto/auth', displayName: 'Authentication',
16
- description: 'Authentication scaffolding for the travetto framework'
16
+ description: 'Authentication scaffolding for the Travetto framework'
17
17
  },
18
18
  AuthModel: {
19
19
  name:'@travetto/auth-model', folder:'@travetto/auth-model', displayName: 'Authentication Model',
20
- description: 'Authentication model support for the travetto framework'
20
+ description: 'Authentication model support for the Travetto framework'
21
21
  },
22
22
  AuthRest: {
23
23
  name:'@travetto/auth-rest', folder:'@travetto/auth-rest', displayName: 'Rest Auth',
24
- description: 'Rest authentication integration support for the travetto framework'
24
+ description: 'Rest authentication integration support for the Travetto framework'
25
25
  },
26
26
  AuthRestContext: {
27
27
  name:'@travetto/auth-rest-context', folder:'@travetto/auth-rest-context', displayName: 'Rest Auth Context',
28
- description: 'Rest authentication context integration support for the travetto framework'
28
+ description: 'Rest authentication context integration support for the Travetto framework'
29
29
  },
30
30
  AuthRestJwt: {
31
31
  name:'@travetto/auth-rest-jwt', folder:'@travetto/auth-rest-jwt', displayName: 'Rest Auth JWT',
32
- description: 'Rest authentication JWT integration support for the travetto framework'
32
+ description: 'Rest authentication JWT integration support for the Travetto framework'
33
33
  },
34
34
  AuthRestPassport: {
35
35
  name:'@travetto/auth-rest-passport', folder:'@travetto/auth-rest-passport', displayName: 'Rest Auth Passport',
36
- description: 'Rest authentication integration support for the travetto framework'
36
+ description: 'Rest authentication integration support for the Travetto framework'
37
37
  },
38
38
  AuthRestSession: {
39
39
  name:'@travetto/auth-rest-session', folder:'@travetto/auth-rest-session', displayName: 'Rest Auth Session',
40
- description: 'Rest authentication session integration support for the travetto framework'
40
+ description: 'Rest authentication session integration support for the Travetto framework'
41
41
  },
42
42
  Base: {
43
43
  name:'@travetto/base', folder:'@travetto/base', displayName: 'Base',
@@ -49,7 +49,7 @@ export const MOD_MAPPING = {
49
49
  },
50
50
  Cli: {
51
51
  name:'@travetto/cli', folder:'@travetto/cli', displayName: 'Command Line Interface',
52
- description: 'CLI infrastructure for travetto framework'
52
+ description: 'CLI infrastructure for Travetto framework'
53
53
  },
54
54
  Command: {
55
55
  name:'@travetto/command', folder:'@travetto/command', displayName: 'Command',
@@ -57,7 +57,7 @@ export const MOD_MAPPING = {
57
57
  },
58
58
  Compiler: {
59
59
  name:'@travetto/compiler', folder:'@travetto/compiler', displayName: 'Compiler',
60
- description: 'Compiler'
60
+ description: 'The compiler infrastructure for the Travetto framework'
61
61
  },
62
62
  Config: {
63
63
  name:'@travetto/config', folder:'@travetto/config', displayName: 'Configuration',
@@ -73,7 +73,7 @@ export const MOD_MAPPING = {
73
73
  },
74
74
  Doc: {
75
75
  name:'@travetto/doc', folder:'@travetto/doc', displayName: 'Documentation',
76
- description: 'Documentation support for the travetto framework'
76
+ description: 'Documentation support for the Travetto framework'
77
77
  },
78
78
  Email: {
79
79
  name:'@travetto/email', folder:'@travetto/email', displayName: 'Email',
@@ -105,7 +105,7 @@ export const MOD_MAPPING = {
105
105
  },
106
106
  Manifest: {
107
107
  name:'@travetto/manifest', folder:'@travetto/manifest', displayName: 'Manifest',
108
- description: 'Manifest support'
108
+ description: 'Support for project indexing, manifesting, along with file watching'
109
109
  },
110
110
  Model: {
111
111
  name:'@travetto/model', folder:'@travetto/model', displayName: 'Data Modeling Support',
@@ -157,7 +157,7 @@ export const MOD_MAPPING = {
157
157
  },
158
158
  Openapi: {
159
159
  name:'@travetto/openapi', folder:'@travetto/openapi', displayName: 'OpenAPI Specification',
160
- description: 'OpenAPI integration support for the travetto framework'
160
+ description: 'OpenAPI integration support for the Travetto framework'
161
161
  },
162
162
  Overview: {
163
163
  name:'@travetto/overview', folder:'@travetto/overview', displayName: 'Overview Docs',
package/src/mod.ts CHANGED
@@ -1,6 +1,8 @@
1
+ import { TypedObject } from '@travetto/base';
2
+
1
3
  import { node } from './nodes';
2
4
  import { MOD_MAPPING } from './mod-mapping';
3
5
 
4
- export const mod = Object.fromEntries(
5
- Object.entries(MOD_MAPPING).map(([k, v]) => [k, node.Mod(v.name, v)])
6
+ export const mod = TypedObject.fromEntries(
7
+ TypedObject.entries(MOD_MAPPING).map(([k, v]) => [k, node.Mod(v.name, v)])
6
8
  );
package/src/nodes.ts CHANGED
@@ -107,6 +107,11 @@ export const node = {
107
107
  * @param content
108
108
  */
109
109
  SubSection: (title: Content) => $n('subsection', { title: $c(title) }),
110
+ /**
111
+ * Sub-sub-section
112
+ * @param content
113
+ */
114
+ SubSubSection: (title: Content) => $n('subsubsection', { title: $c(title) }),
110
115
  /**
111
116
  * Library reference
112
117
  * @param content
@@ -209,11 +214,14 @@ export const node = {
209
214
  * @param outline
210
215
  * @param language
211
216
  */
212
- Code: (title: Content, content: Content | Function, outline = false, language = 'typescript') => {
217
+ Code: (title: Content, content: Content | Function, outline = false, language = 'typescript', rewrite?: (text: string) => string) => {
213
218
  if (typeof content === 'function') {
214
219
  content = RootIndex.getFunctionMetadata(content)!.source;
215
220
  }
216
221
  const res = ResolveUtil.resolveCode(content, language, outline);
222
+ if (rewrite && typeof res.content === 'string') {
223
+ res.content = rewrite(res.content);
224
+ }
217
225
  return $n('code', { title: $c(title), content: $c(res.content), language: res.language, file: $c(res.file) });
218
226
  },
219
227
 
@@ -268,13 +276,18 @@ export const node = {
268
276
  },
269
277
 
270
278
  /**
271
- * NPM Installation
279
+ * Installing a package or program
272
280
  * @param title
273
281
  * @param pkg
274
282
  */
275
283
  Install: (title: Content, pkg: Content) => {
276
- pkg = typeof pkg === 'string' && !pkg.includes(' ') ? `npm install ${pkg}` : pkg;
277
- return $n('install', { title: $c(title), language: 'bash', content: $c(pkg) });
284
+ if (typeof pkg === 'string' && !pkg.includes(' ')) {
285
+ return $n('install', {
286
+ title: $c(title), language: 'bash', content: $c(`npm install ${pkg}\n\n# or\n\nyarn add ${pkg}`)
287
+ });
288
+ } else {
289
+ return $n('install', { title: $c(title), language: 'bash', content: $c(pkg), subtype: undefined });
290
+ }
278
291
  },
279
292
 
280
293
  /**
@@ -36,8 +36,9 @@ export const Html: Renderer = {
36
36
  case 'mod': return `<a class="module-link" href="${context.link(recurse(c.link), c)}" title="${recurse(c.description)}">${recurse(c.title)}</a>`;
37
37
  case 'image': return `<img src="${context.link(recurse(c.link), c)}" alt="${recurse(c.title)}">`;
38
38
  case 'section':
39
- case 'subsection': {
40
- const tag = c._type === 'section' ? 'h2' : 'h3';
39
+ case 'subsection':
40
+ case 'subsubsection': {
41
+ const tag = c._type === 'section' ? 'h2' : (c._type === 'subsection' ? 'h3' : 'h4');
41
42
  const title = recurse(c.title);
42
43
  return `<${tag} id="${context.getAnchorId(title)}">${title}</${tag}>`;
43
44
  }
@@ -30,6 +30,7 @@ ${context.cleanText(recurse(c.content))}
30
30
  case 'image': return `![${recurse(c.title)}](${context.link(recurse(c.link), c)})`;
31
31
  case 'section': return `## ${recurse(c.title)}`;
32
32
  case 'subsection': return `### ${recurse(c.title)}`;
33
+ case 'subsubsection': return `#### ${recurse(c.title)}`;
33
34
  case 'command':
34
35
  case 'method':
35
36
  case 'path':
@@ -15,10 +15,6 @@ export class RenderUtil {
15
15
 
16
16
  static #imported = new Map<string, { root: AllType, wrap?: Wrapper }>();
17
17
 
18
- static purge(file: string): void {
19
- this.#imported.delete(file);
20
- }
21
-
22
18
  /**
23
19
  * Render content of file and format
24
20
  * @param file
@@ -31,7 +27,11 @@ export class RenderUtil {
31
27
  throw new Error(`Unknown renderer with format: ${fmt}`);
32
28
  }
33
29
 
34
- const mod = RootIndex.getFromSource(file)?.import;
30
+ let mod = RootIndex.getFromSource(file)?.import;
31
+
32
+ if (RootIndex.manifest.moduleType === 'module') {
33
+ mod = `${mod}?ts=${Date.now()}`;
34
+ }
35
35
 
36
36
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
37
37
  const res = await import(mod!) as DocumentShape;
package/src/types.ts CHANGED
@@ -30,7 +30,7 @@ export interface RenderContextShape {
30
30
  baseUrl: string;
31
31
 
32
32
  /**
33
- * Github root for travetto framework
33
+ * Github root for Travetto framework
34
34
  */
35
35
  travettoBaseUrl: string;
36
36
 
package/src/util/file.ts CHANGED
@@ -105,8 +105,12 @@ export class FileUtil {
105
105
  if (info) {
106
106
  const [, space, __name, rest] = info;
107
107
  if (!rest.endsWith(';')) {
108
- methodPrefix = space;
109
- return x.replace(/[{]\s*$/, ';');
108
+ if (/\s*[{]\s*return.*$/.test(x)) {
109
+ return x.replace(/\s*[{]\s*return.*$/, ';');
110
+ } else {
111
+ methodPrefix = space;
112
+ return x.replace(/\s*[{]\s*$/, ';');
113
+ }
110
114
  }
111
115
  }
112
116
  return x;
@@ -48,7 +48,7 @@ export class ResolveUtil {
48
48
  static resolveConfig<T>(content: string | T, language: string): { content: string | T, language: string, file?: string } {
49
49
  let file: string | undefined;
50
50
  if (typeof content === 'string') {
51
- if (/^[@:A-Za-z0-9\/\\\-_.]+[.](ya?ml|properties)$/.test(content)) {
51
+ if (/^[@:A-Za-z0-9\/\\\-_.]+[.](json|ya?ml|properties)$/.test(content)) {
52
52
  const res = FileUtil.read(content);
53
53
  language = res.language;
54
54
  file = res.file;
package/src/util/run.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import { spawnSync } from 'child_process';
2
2
 
3
- import { path } from '@travetto/manifest';
4
- import { Env, ExecUtil, ExecutionOptions, ExecutionState } from '@travetto/base';
3
+ import { path, RootIndex } from '@travetto/manifest';
4
+ import { ExecUtil, ExecutionOptions, ExecutionState } from '@travetto/base';
5
5
  import { stripAnsiCodes } from '@travetto/terminal';
6
6
 
7
+ export const COMMON_DATE = new Date('2029-03-14T00:00:00.000').getTime();
8
+
7
9
  export type RunConfig = {
8
10
  filter?: (line: string) => boolean;
11
+ rewrite?: (text: string) => string;
9
12
  module?: string;
10
13
  env?: Record<string, string>;
11
14
  profiles?: string[];
@@ -19,7 +22,7 @@ type RunState = {
19
22
  };
20
23
 
21
24
  class DocState {
22
- baseline = new Date('2029-03-14T00:00:00.000').getTime();
25
+ baseline = COMMON_DATE;
23
26
  _s = 37;
24
27
  ids: Record<string, string> = {};
25
28
 
@@ -56,7 +59,7 @@ export class DocRunUtil {
56
59
  cwd: path.toPosix(config.cwd ?? path.cwd()),
57
60
  shell: '/bin/bash',
58
61
  env: {
59
- ...Env.export(/^(TRV_.*|NODE_.*|.*COLOR.*|PATH)$/),
62
+ ...process.env,
60
63
  DEBUG: '0',
61
64
  TRV_MANIFEST: '',
62
65
  TRV_BUILD: 'warn',
@@ -73,15 +76,19 @@ export class DocRunUtil {
73
76
  */
74
77
  static cleanRunOutput(text: string, cfg: RunConfig): string {
75
78
  text = stripAnsiCodes(text.trim())
79
+ .replace(new RegExp(path.cwd(), 'g'), '.')
80
+ .replaceAll(RootIndex.manifest.workspacePath, '<workspace-root>')
76
81
  .replace(/^(.{1,4})?Compiling[.]*/, '') // Compiling message, remove
77
82
  .replace(/[A-Za-z0-9_.\-\/\\]+\/travetto\/module\//g, '@travetto/')
78
- .replace(new RegExp(path.cwd(), 'g'), '.')
79
83
  .replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}([.]\d{3})?Z?/g, this.#docState.getDate.bind(this.#docState))
80
84
  .replace(/\b[0-9a-f]{4}[0-9a-f\-]{8,40}\b/ig, this.#docState.getId.bind(this.#docState))
81
85
  .replace(/(\d+[.]\d+[.]\d+)-(alpha|rc)[.]\d+/g, (all, v) => v);
82
86
  if (cfg.filter) {
83
87
  text = text.split(/\n/g).filter(cfg.filter).join('\n');
84
88
  }
89
+ if (cfg.rewrite) {
90
+ text = cfg.rewrite(text);
91
+ }
85
92
  return text;
86
93
  }
87
94
 
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs/promises';
2
2
 
3
3
  import { PackageUtil, path, RootIndex, watchFolders } from '@travetto/manifest';
4
- import { GlobalEnvConfig } from '@travetto/base';
4
+ import { ExecUtil, GlobalEnvConfig } from '@travetto/base';
5
5
  import { CliCommand, OptionConfig, ListOptionConfig } from '@travetto/cli';
6
6
 
7
7
  import { RenderUtil } from '../src/render/util';
@@ -19,8 +19,9 @@ export class DocCommand extends CliCommand<Options> {
19
19
  name = 'doc';
20
20
 
21
21
  getOptions(): Options {
22
+ const input = RootIndex.mainModule.files['doc']?.find(x => x.sourceFile.endsWith('DOC.ts'));
22
23
  return {
23
- input: this.option({ desc: 'Input File', def: 'DOC.ts' }),
24
+ input: this.option({ desc: 'Input File', def: input?.relativeFile ?? 'DOC.ts' }),
24
25
  outputs: this.listOption({ desc: 'Outputs', def: [] }),
25
26
  watch: this.boolOption({ desc: 'Watch' })
26
27
  };
@@ -52,32 +53,32 @@ export class DocCommand extends CliCommand<Options> {
52
53
 
53
54
  const outputs = this.cmd.outputs.map(output => output.includes('.') ? [path.extname(output).substring(1), path.resolve(output)] : [output, null] as const);
54
55
 
55
- // If specifying output
56
- const write = async (): Promise<void> => {
57
- RenderUtil.purge(docFile);
56
+ if (this.cmd.watch) {
57
+ const args = process.argv.slice(2).filter(x => !x.startsWith('-w') && !x.startsWith('--w'));
58
+ await watchFolders([path.dirname(docFile)],
59
+ () => ExecUtil.spawn('npx', ['trv', ...args], {
60
+ cwd: RootIndex.mainModule.sourcePath,
61
+ env: { TRV_QUIET: '1' },
62
+ stdio: 'inherit', catchAsResult: true
63
+ }), {
64
+ filter: ev => ev.action === 'update' && ev.file === docFile
65
+ });
66
+ }
67
+
68
+ try {
58
69
  for (const [fmt, out] of outputs) {
59
70
  const result = await RenderUtil.render(docFile, fmt);
60
71
  if (out) {
61
72
  const finalName = path.resolve(out);
62
73
  await fs.writeFile(finalName, result, 'utf8');
74
+ console.log(`Wrote docs ${this.cmd.input}: ${finalName}`);
63
75
  } else {
64
76
  process.stdout.write(result);
65
77
  }
66
78
  }
67
- };
68
-
69
- if (this.cmd.watch) {
70
- await watchFolders([path.dirname(docFile)], write, {
71
- filter: ev => ev.action === 'update' && ev.file === docFile
72
- });
73
- } else {
74
- try {
75
- await write();
76
- console.log(`Wrote docs for ${this.cmd.input}`);
77
- } catch (err) {
78
- console.error(err);
79
- this.exit(1);
80
- }
79
+ } catch (err) {
80
+ console.error(err);
81
+ this.exit(1);
81
82
  }
82
83
  }
83
84
  }