@travetto/doc 3.0.0-rc.7 → 3.0.0-rc.9
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 +50 -5
- package/package.json +3 -3
- package/src/nodes.ts +8 -4
- package/src/render/util.ts +3 -2
- package/src/util/file.ts +1 -2
- package/src/util/run.ts +5 -2
- package/support/cli.doc.ts +15 -16
package/README.md
CHANGED
|
@@ -105,17 +105,62 @@ Options:
|
|
|
105
105
|
-i, --input <input> Input File (default: "DOC.ts")
|
|
106
106
|
-o, --outputs <outputs> Outputs (default: [])
|
|
107
107
|
-w, --watch Watch
|
|
108
|
-
-s, --stdout Write to stdout (default: false)
|
|
109
108
|
-h, --help display help for command
|
|
110
|
-
|
|
111
|
-
[s[r[u
|
|
112
109
|
```
|
|
113
110
|
|
|
114
111
|
By default, running the command will output the [Markdown](https://en.wikipedia.org/wiki/Markdown) content directly to the terminal.
|
|
115
112
|
|
|
116
113
|
**Terminal: Sample CLI Output**
|
|
117
114
|
```bash
|
|
118
|
-
$ trv doc -
|
|
115
|
+
$ trv doc -o html
|
|
116
|
+
|
|
117
|
+
<!-- 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 -->
|
|
119
|
+
<h1>@travetto-doc/doc
|
|
120
|
+
|
|
121
|
+
</h1>
|
|
122
|
+
|
|
123
|
+
<figure class="install">
|
|
124
|
+
<figcaption class="install">Install @travetto-doc/doc
|
|
125
|
+
|
|
126
|
+
</figcaption>
|
|
127
|
+
<pre><code class="language-bash"><span class="token function">npm</span> <span class="token function">install</span> @travetto-doc/doc</code></pre>
|
|
128
|
+
</figure>
|
|
129
|
+
|
|
130
|
+
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.
|
|
131
|
+
|
|
132
|
+
<ol> <li>First</li>
|
|
133
|
+
<li>Second</li>
|
|
134
|
+
<li><code class="item path">Special</code></li></ol>
|
|
119
135
|
|
|
120
|
-
|
|
136
|
+
<h2 id="content">Content</h2>
|
|
137
|
+
|
|
138
|
+
<figure class="code">
|
|
139
|
+
<figcaption class="code">Document Sample
|
|
140
|
+
<cite><a target="_blank" href="@travetto/doc/doc-exec/src/test.ts">Source</a></cite>
|
|
141
|
+
</figcaption>
|
|
142
|
+
<pre><code class="language-typescript"><span class="token keyword">class</span> <span class="token class-name">TestFile</span> <span class="token punctuation">{{'{'}}</span>
|
|
143
|
+
<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>
|
|
144
|
+
<span class="token punctuation">{{'}'}}</span></code></pre>
|
|
145
|
+
</figure>
|
|
146
|
+
|
|
147
|
+
<h3 id="output">Output</h3>
|
|
148
|
+
|
|
149
|
+
<figure class="terminal">
|
|
150
|
+
<figcaption class="terminal">Run program
|
|
151
|
+
|
|
152
|
+
</figcaption>
|
|
153
|
+
<pre><code class="language-bash">$ trv
|
|
154
|
+
|
|
155
|
+
Usage: <span class="token punctuation">[</span>options<span class="token punctuation">]</span> <span class="token punctuation">[</span>command<span class="token punctuation">]</span>
|
|
156
|
+
|
|
157
|
+
Options:
|
|
158
|
+
-V, <span class="token parameter variable">--version</span> output the version number
|
|
159
|
+
-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>
|
|
160
|
+
|
|
161
|
+
Commands:
|
|
162
|
+
doc <span class="token punctuation">[</span>options<span class="token punctuation">]</span>
|
|
163
|
+
<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>
|
|
164
|
+
</figure>
|
|
165
|
+
Wrote docs for DOC.ts
|
|
121
166
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/doc",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.9",
|
|
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.0-rc.
|
|
27
|
+
"@travetto/base": "^3.0.0-rc.9",
|
|
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.
|
|
32
|
+
"@travetto/cli": "^3.0.0-rc.10"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|
|
35
35
|
"@travetto/cli": {
|
package/src/nodes.ts
CHANGED
|
@@ -19,6 +19,8 @@ const $n = <T extends string, U extends Record<string, unknown>>(t: T, values: U
|
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
20
20
|
({ _type: t, ...values } as { _type: T } & U);
|
|
21
21
|
|
|
22
|
+
type FormattedCommand = { formatCommand?(cmd: string, args: string[]): string };
|
|
23
|
+
|
|
22
24
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -157,7 +159,7 @@ export const node = {
|
|
|
157
159
|
* @param args
|
|
158
160
|
* @param cfg
|
|
159
161
|
*/
|
|
160
|
-
Execute: (title: Content, cmd: string, args: string[] = [], cfg: RunConfig = {}) => {
|
|
162
|
+
Execute: (title: Content, cmd: string, args: string[] = [], cfg: RunConfig & FormattedCommand = {}) => {
|
|
161
163
|
if (cmd !== 'trv') {
|
|
162
164
|
cmd = FileUtil.resolveFile(cmd).replace(path.cwd(), '.');
|
|
163
165
|
}
|
|
@@ -165,7 +167,9 @@ export const node = {
|
|
|
165
167
|
const script = DocRunUtil.run(cmd, args, cfg);
|
|
166
168
|
const prefix = !/.*\/doc\/.*[.]ts$/.test(cmd) ? '$' : '$ node ';
|
|
167
169
|
|
|
168
|
-
|
|
170
|
+
const commandDisplay = cfg.formatCommand?.(cmd, args) ?? `${cmd} ${args.join(' ')}`;
|
|
171
|
+
|
|
172
|
+
return node.Terminal(title, `${prefix} ${commandDisplay}\n\n${script}`);
|
|
169
173
|
},
|
|
170
174
|
|
|
171
175
|
/**
|
|
@@ -174,7 +178,7 @@ export const node = {
|
|
|
174
178
|
*/
|
|
175
179
|
Mod(name: string, cfg?: { folder: string, displayName: string, description: string }) {
|
|
176
180
|
if (!cfg) {
|
|
177
|
-
const folder = RootIndex.getModule(name)!.
|
|
181
|
+
const folder = RootIndex.getModule(name)!.sourcePath;
|
|
178
182
|
const pkg = PackageUtil.readPackage(folder);
|
|
179
183
|
cfg = {
|
|
180
184
|
folder,
|
|
@@ -233,7 +237,7 @@ export const node = {
|
|
|
233
237
|
if (!mod) {
|
|
234
238
|
mod = RootIndex.mainPackage.name;
|
|
235
239
|
}
|
|
236
|
-
const pkg = PackageUtil.readPackage(RootIndex.getModule(mod)!.
|
|
240
|
+
const pkg = PackageUtil.readPackage(RootIndex.getModule(mod)!.sourcePath);
|
|
237
241
|
return $n('header', { title: $c(pkg.travetto?.displayName ?? pkg.name), description: $c(pkg.description), package: pkg.name, install });
|
|
238
242
|
},
|
|
239
243
|
|
package/src/render/util.ts
CHANGED
|
@@ -46,12 +46,13 @@ export class RenderUtil {
|
|
|
46
46
|
|
|
47
47
|
const { wrap, root } = this.#imported.get(file)!;
|
|
48
48
|
|
|
49
|
-
const manifestPkg = PackageUtil.readPackage(RootIndex.getModule('@travetto/manifest')!.
|
|
49
|
+
const manifestPkg = PackageUtil.readPackage(RootIndex.getModule('@travetto/manifest')!.sourcePath);
|
|
50
50
|
|
|
51
51
|
const mf = RootIndex.manifest;
|
|
52
52
|
|
|
53
53
|
const pkg = PackageUtil.readPackage(mf.workspacePath);
|
|
54
|
-
const
|
|
54
|
+
const mainPath = path.resolve(mf.workspacePath, mf.mainFolder);
|
|
55
|
+
const repoBaseUrl = pkg.travetto?.docBaseUrl ?? mainPath;
|
|
55
56
|
|
|
56
57
|
const ctx = new RenderContext(
|
|
57
58
|
file,
|
package/src/util/file.ts
CHANGED
|
@@ -26,8 +26,7 @@ export class FileUtil {
|
|
|
26
26
|
let resolved = path.resolve(file);
|
|
27
27
|
if (!existsSync(resolved)) {
|
|
28
28
|
if (file.endsWith('.ts')) {
|
|
29
|
-
resolved = RootIndex.
|
|
30
|
-
resolved = RootIndex.getSourceFile(resolved);
|
|
29
|
+
resolved = RootIndex.getSourceFile(file);
|
|
31
30
|
}
|
|
32
31
|
if (!existsSync(resolved)) {
|
|
33
32
|
throw new Error(`Unknown file to resolve: ${file}`);
|
package/src/util/run.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type RunConfig = {
|
|
|
8
8
|
filter?: (line: string) => boolean;
|
|
9
9
|
module?: string;
|
|
10
10
|
env?: Record<string, string>;
|
|
11
|
+
profiles?: string[];
|
|
11
12
|
cwd?: string;
|
|
12
13
|
};
|
|
13
14
|
|
|
@@ -57,7 +58,10 @@ export class DocRunUtil {
|
|
|
57
58
|
env: {
|
|
58
59
|
...Env.export(/^(TRV_.*|NODE_.*|.*COLOR.*|PATH)$/),
|
|
59
60
|
DEBUG: '0',
|
|
60
|
-
|
|
61
|
+
TRV_MANIFEST: '',
|
|
62
|
+
TRV_BUILD: 'warn',
|
|
63
|
+
TRV_MODULE: config.module ?? '',
|
|
64
|
+
...(config.profiles ? { TRV_PROFILES: config.profiles.join(' ') } : {}),
|
|
61
65
|
...(config.env ?? {})
|
|
62
66
|
}
|
|
63
67
|
}
|
|
@@ -72,7 +76,6 @@ export class DocRunUtil {
|
|
|
72
76
|
.replace(/^(.{1,4})?Compiling[.]*/, '') // Compiling message, remove
|
|
73
77
|
.replace(/[A-Za-z0-9_.\-\/\\]+\/travetto\/module\//g, '@travetto/')
|
|
74
78
|
.replace(new RegExp(path.cwd(), 'g'), '.')
|
|
75
|
-
.replace(/([.]trv_cache)[_A-Za-z0-9]+/g, (_, b) => b)
|
|
76
79
|
.replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}([.]\d{3})?Z?/g, this.#docState.getDate.bind(this.#docState))
|
|
77
80
|
.replace(/\b[0-9a-f]{4}[0-9a-f\-]{8,40}\b/ig, this.#docState.getId.bind(this.#docState))
|
|
78
81
|
.replace(/(\d+[.]\d+[.]\d+)-(alpha|rc)[.]\d+/g, (all, v) => v);
|
package/support/cli.doc.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
|
|
3
|
-
import { PackageUtil, path, RootIndex } from '@travetto/manifest';
|
|
4
|
-
import {
|
|
3
|
+
import { PackageUtil, path, RootIndex, watchFolders } from '@travetto/manifest';
|
|
4
|
+
import { GlobalEnvConfig } from '@travetto/base';
|
|
5
5
|
import { CliCommand, OptionConfig, ListOptionConfig } from '@travetto/cli';
|
|
6
6
|
|
|
7
7
|
import { RenderUtil } from '../src/render/util';
|
|
@@ -10,7 +10,6 @@ type Options = {
|
|
|
10
10
|
input: OptionConfig<string>;
|
|
11
11
|
outputs: ListOptionConfig<string>;
|
|
12
12
|
watch: OptionConfig<boolean>;
|
|
13
|
-
stdout: OptionConfig<boolean>;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -23,8 +22,7 @@ export class DocCommand extends CliCommand<Options> {
|
|
|
23
22
|
return {
|
|
24
23
|
input: this.option({ desc: 'Input File', def: 'DOC.ts' }),
|
|
25
24
|
outputs: this.listOption({ desc: 'Outputs', def: [] }),
|
|
26
|
-
watch: this.boolOption({ desc: 'Watch' })
|
|
27
|
-
stdout: this.boolOption({ desc: 'Write to stdout', def: false })
|
|
25
|
+
watch: this.boolOption({ desc: 'Watch' })
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
28
|
|
|
@@ -43,7 +41,7 @@ export class DocCommand extends CliCommand<Options> {
|
|
|
43
41
|
async action(): Promise<void> {
|
|
44
42
|
const docFile = path.resolve(this.cmd.input);
|
|
45
43
|
if (!(await fs.stat(docFile).catch(() => false))) {
|
|
46
|
-
|
|
44
|
+
console.error(`The input ${this.cmd.input} does not exist`);
|
|
47
45
|
return this.exit(1);
|
|
48
46
|
}
|
|
49
47
|
|
|
@@ -52,32 +50,33 @@ export class DocCommand extends CliCommand<Options> {
|
|
|
52
50
|
this.cmd.outputs = workspacePkg.travetto?.docOutputs ?? ['README.md'];
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
const outputs = this.cmd.outputs.map(output => [path.extname(output).substring(1), path.resolve(output)]);
|
|
53
|
+
const outputs = this.cmd.outputs.map(output => output.includes('.') ? [path.extname(output).substring(1), path.resolve(output)] : [output, null] as const);
|
|
56
54
|
|
|
57
55
|
// If specifying output
|
|
58
56
|
const write = async (): Promise<void> => {
|
|
59
57
|
RenderUtil.purge(docFile);
|
|
60
58
|
for (const [fmt, out] of outputs) {
|
|
61
|
-
const finalName = path.resolve(out);
|
|
62
59
|
const result = await RenderUtil.render(docFile, fmt);
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
} else {
|
|
60
|
+
if (out) {
|
|
61
|
+
const finalName = path.resolve(out);
|
|
66
62
|
await fs.writeFile(finalName, result, 'utf8');
|
|
63
|
+
} else {
|
|
64
|
+
process.stdout.write(result);
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
67
|
};
|
|
70
68
|
|
|
71
69
|
if (this.cmd.watch) {
|
|
72
|
-
await
|
|
70
|
+
await watchFolders([path.dirname(docFile)], write, {
|
|
71
|
+
filter: ev => ev.action === 'update' && ev.file === docFile
|
|
72
|
+
});
|
|
73
73
|
} else {
|
|
74
74
|
try {
|
|
75
75
|
await write();
|
|
76
|
-
|
|
77
|
-
return this.exit(0);
|
|
76
|
+
console.log(`Wrote docs for ${this.cmd.input}`);
|
|
78
77
|
} catch (err) {
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
console.error(err);
|
|
79
|
+
this.exit(1);
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
}
|