@travetto/doc 7.1.2 → 7.1.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/package.json +3 -3
- package/src/jsx.ts +5 -1
- package/src/render/context.ts +2 -2
- package/src/render/html.ts +1 -5
- package/src/render/markdown.ts +1 -5
- package/src/util/run.ts +22 -26
- package/src/util/types.ts +4 -1
- package/support/cli.doc.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/doc",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.3",
|
|
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/runtime": "^7.1.
|
|
27
|
+
"@travetto/runtime": "^7.1.3",
|
|
28
28
|
"@types/prismjs": "^1.26.5",
|
|
29
29
|
"prismjs": "^1.30.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@travetto/cli": "^7.1.
|
|
32
|
+
"@travetto/cli": "^7.1.3"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|
|
35
35
|
"@travetto/cli": {
|
package/src/jsx.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { castTo, TypedObject } from '@travetto/runtime';
|
|
1
|
+
import { castTo, Runtime, TypedObject } from '@travetto/runtime';
|
|
2
|
+
import { PackageUtil } from '@travetto/manifest';
|
|
2
3
|
|
|
3
4
|
import type { LIBRARIES } from './mapping/library.ts';
|
|
4
5
|
import type { MODULES } from './mapping/module.ts';
|
|
@@ -105,4 +106,7 @@ export const d = {
|
|
|
105
106
|
field: (name: string) => createElement(c.Field, { name }),
|
|
106
107
|
library: (name: keyof typeof LIBRARIES) => createElement(c.Library, { name }),
|
|
107
108
|
module: (name: keyof typeof MODULES) => createElement(c.Module, { name }),
|
|
109
|
+
installCommand: (pkg: string, production?: boolean) => PackageUtil.getInstallCommand(Runtime, pkg, production),
|
|
110
|
+
workspaceInitCommand: () => PackageUtil.getWorkspaceInitCommand(Runtime),
|
|
111
|
+
get trv() { return PackageUtil.getPackageCommand(Runtime, 'trv'); },
|
|
108
112
|
};
|
package/src/render/context.ts
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { PackageUtil } from '@travetto/manifest';
|
|
4
4
|
import { castTo, RuntimeIndex } from '@travetto/runtime';
|
|
5
5
|
|
|
6
|
-
import { type JSXElementByFn, c } from '../jsx.ts';
|
|
6
|
+
import { type JSXElementByFn, c, d } from '../jsx.ts';
|
|
7
7
|
import { DocResolveUtil, type ResolvedCode, type ResolvedRef, type ResolvedSnippetLink } from '../util/resolve.ts';
|
|
8
8
|
import { DocRunUtil } from '../util/run.ts';
|
|
9
9
|
import { createElement, JSXRuntimeTag } from '../../support/jsx-runtime.ts';
|
|
@@ -56,7 +56,7 @@ export class RenderContext {
|
|
|
56
56
|
* Get rebuilt comment
|
|
57
57
|
*/
|
|
58
58
|
get rebuildStamp(): string {
|
|
59
|
-
return `Please modify ${this.file.replace(this.repoRoot, this.baseUrl)} and execute "
|
|
59
|
+
return `Please modify ${this.file.replace(this.repoRoot, this.baseUrl)} and execute "${d.trv} doc" to rebuild`;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
package/src/render/html.ts
CHANGED
|
@@ -52,11 +52,7 @@ export const Html: RenderProvider<RenderContext> = {
|
|
|
52
52
|
},
|
|
53
53
|
Install: async ({ context, node }) => {
|
|
54
54
|
const highlighted = highlight(`
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# or
|
|
58
|
-
|
|
59
|
-
yarn add ${node.props.pkg}
|
|
55
|
+
${PackageUtil.getInstallInstructions(node.props.pkg, true)}
|
|
60
56
|
`, 'bash');
|
|
61
57
|
|
|
62
58
|
return `\n
|
package/src/render/markdown.ts
CHANGED
|
@@ -55,11 +55,7 @@ export const Markdown: RenderProvider<RenderContext> = {
|
|
|
55
55
|
Install: async ({ context, node }) =>
|
|
56
56
|
`\n\n**Install: ${node.props.title}**
|
|
57
57
|
\`\`\`bash
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
# or
|
|
61
|
-
|
|
62
|
-
yarn add ${node.props.pkg}
|
|
58
|
+
${PackageUtil.getInstallInstructions(node.props.pkg, true)}
|
|
63
59
|
\`\`\`
|
|
64
60
|
`,
|
|
65
61
|
Code: async ({ context, node, props }) => {
|
package/src/util/run.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import util from 'node:util';
|
|
3
|
-
import { spawn
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
import { Env, ExecUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
@@ -62,41 +62,37 @@ export class DocRunUtil {
|
|
|
62
62
|
.replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}([.]\d{3})?Z?/g, this.#docState.getDate.bind(this.#docState))
|
|
63
63
|
.replace(/\b[0-9a-f]{4}[0-9a-f\-]{8,40}\b/ig, this.#docState.getId.bind(this.#docState))
|
|
64
64
|
.replace(/(\d+[.]\d+[.]\d+)-(alpha|rc)[.]\d+/g, (all, value) => value);
|
|
65
|
-
if (config.filter) {
|
|
66
|
-
text = text.split(/\n/g)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
if (config.filter || config.rewrite) {
|
|
66
|
+
text = text.split(/\n/g)
|
|
67
|
+
.filter(line => config.filter?.(line) ?? true)
|
|
68
|
+
.map(line => config.rewrite?.(line) ?? line)
|
|
69
|
+
.join('\n');
|
|
70
70
|
}
|
|
71
71
|
return text;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
* Spawn command with appropriate environment, and cwd
|
|
76
|
-
*/
|
|
77
|
-
static spawn(cmd: string, args: string[], config: RunConfig = {}): ChildProcess {
|
|
78
|
-
return spawn(cmd, args, {
|
|
79
|
-
cwd: config.workingDirectory ?? this.workingDirectory(config),
|
|
80
|
-
env: {
|
|
81
|
-
...process.env,
|
|
82
|
-
...Env.DEBUG.export(false),
|
|
83
|
-
...Env.TRV_CLI_IPC.export(undefined),
|
|
84
|
-
...Env.TRV_MANIFEST.export(''),
|
|
85
|
-
...Env.TRV_BUILD.export('none'),
|
|
86
|
-
...Env.TRV_ROLE.export(undefined),
|
|
87
|
-
...Env.TRV_MODULE.export(config.module ?? ''),
|
|
88
|
-
...config.env
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
74
|
/**
|
|
94
75
|
* Run command synchronously and return output
|
|
95
76
|
*/
|
|
96
77
|
static async run(cmd: string, args: string[], config: RunConfig = {}): Promise<string> {
|
|
97
78
|
let final: string;
|
|
98
79
|
try {
|
|
99
|
-
const
|
|
80
|
+
const spawnCmd = config.spawn ?? spawn;
|
|
81
|
+
const subProcess = spawnCmd(cmd, args, {
|
|
82
|
+
...config,
|
|
83
|
+
cwd: config.workingDirectory ?? this.workingDirectory(config),
|
|
84
|
+
env: {
|
|
85
|
+
...process.env,
|
|
86
|
+
...Env.DEBUG.export(false),
|
|
87
|
+
...Env.TRV_CLI_IPC.export(undefined),
|
|
88
|
+
...Env.TRV_MANIFEST.export(''),
|
|
89
|
+
...Env.TRV_BUILD.export('none'),
|
|
90
|
+
...Env.TRV_ROLE.export(undefined),
|
|
91
|
+
...Env.TRV_MODULE.export(config.module ?? ''),
|
|
92
|
+
...config.env
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
100
96
|
const result = await ExecUtil.getResult(subProcess, { catch: true });
|
|
101
97
|
if (!result.valid) {
|
|
102
98
|
throw new Error(result.stderr);
|
package/src/util/types.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { ChildProcess, SpawnOptions } from 'node:child_process';
|
|
2
|
+
|
|
1
3
|
export type RunConfig = {
|
|
2
4
|
filter?: (line: string) => boolean;
|
|
3
|
-
rewrite?: (
|
|
5
|
+
rewrite?: (line: string) => string;
|
|
4
6
|
module?: string;
|
|
5
7
|
env?: Record<string, string>;
|
|
6
8
|
workingDirectory?: string;
|
|
9
|
+
spawn?: (cmd: string, args: string[], options: SpawnOptions) => ChildProcess;
|
|
7
10
|
};
|
|
8
11
|
|
|
9
12
|
export type CodeProps = { title?: string, src: string | Function, language?: string, outline?: boolean, startRe?: RegExp, endRe?: RegExp };
|
package/support/cli.doc.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { spawn } from 'node:child_process';
|
|
4
3
|
|
|
5
4
|
import { PackageUtil } from '@travetto/manifest';
|
|
6
5
|
import { ExecUtil, Env, Runtime, WatchUtil } from '@travetto/runtime';
|
|
@@ -51,7 +50,7 @@ export class DocCommand implements CliCommandShape {
|
|
|
51
50
|
const [first, ...args] = process.argv.slice(2).filter(arg => !/(-w|--watch)/.test(arg));
|
|
52
51
|
await WatchUtil.watchCompilerEvents('change', async ({ file }) => {
|
|
53
52
|
if (file === this.input) {
|
|
54
|
-
const subProcess =
|
|
53
|
+
const subProcess = ExecUtil.spawnPackageCommand('trv', [first, ...args], {
|
|
55
54
|
cwd: Runtime.mainSourcePath,
|
|
56
55
|
env: { ...process.env, ...Env.TRV_QUIET.export(true) },
|
|
57
56
|
stdio: 'inherit'
|