@alauda/doom 0.4.1 → 0.4.2
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/lib/cli/index.js +15 -7
- package/lib/cli/load-config.d.ts +1 -1
- package/lib/cli/load-config.js +15 -10
- package/lib/global/VersionsNav/index.js +13 -10
- package/lib/plugins/global/index.d.ts +1 -1
- package/lib/plugins/global/index.js +2 -1
- package/lib/runtime/components/ExternalSite.js +5 -1
- package/lib/runtime/components/JsonViewer.d.ts +6 -0
- package/lib/runtime/components/JsonViewer.js +8 -0
- package/lib/runtime/components/index.d.ts +1 -0
- package/lib/runtime/components/index.js +1 -0
- package/lib/runtime/types.d.ts +2 -1
- package/lib/shared/helpers.d.ts +1 -0
- package/lib/shared/helpers.js +2 -0
- package/lib/shared/index.d.ts +2 -0
- package/lib/shared/index.js +2 -0
- package/lib/shared/types.d.ts +7 -0
- package/lib/shared/types.js +1 -0
- package/lib/utils/types.d.ts +1 -7
- package/package.json +2 -1
package/lib/cli/index.js
CHANGED
|
@@ -22,18 +22,23 @@ program
|
|
|
22
22
|
.name('doom')
|
|
23
23
|
.description(pkg.description)
|
|
24
24
|
.version(pkg.version)
|
|
25
|
+
.configureHelp({
|
|
26
|
+
showGlobalOptions: true,
|
|
27
|
+
})
|
|
25
28
|
.option('-c, --config [config]', 'Specify the path to the config file')
|
|
29
|
+
.option('-v <version>', 'Specify the version of the documentation')
|
|
26
30
|
.command('dev', { isDefault: true })
|
|
27
31
|
.description('Start the development server')
|
|
28
32
|
.argument('[root]', 'Root directory of the documentation')
|
|
29
33
|
.option('--port [port]', 'Port number')
|
|
30
34
|
.option('--host [host]', 'Host name')
|
|
31
|
-
.action(async (root
|
|
35
|
+
.action(async function (root) {
|
|
32
36
|
setNodeEnv('development');
|
|
33
37
|
let devServer;
|
|
34
38
|
let cliWatcher;
|
|
39
|
+
const { config: configFile, v: version, ...server } = this.optsWithGlobals();
|
|
35
40
|
const startDevServer = async () => {
|
|
36
|
-
const { config, filepath } = await loadConfig(root, configFile);
|
|
41
|
+
const { config, filepath } = await loadConfig(root, configFile, version);
|
|
37
42
|
const docDirectory = config.root;
|
|
38
43
|
try {
|
|
39
44
|
devServer = await dev({
|
|
@@ -90,11 +95,13 @@ program
|
|
|
90
95
|
process.on('SIGINT', exitProcess);
|
|
91
96
|
process.on('SIGTERM', exitProcess);
|
|
92
97
|
})
|
|
93
|
-
.parent.command('build
|
|
98
|
+
.parent.command('build')
|
|
94
99
|
.description('Build the documentation')
|
|
95
|
-
.
|
|
100
|
+
.argument('[root]', 'Root directory of the documentation')
|
|
101
|
+
.action(async function (root) {
|
|
96
102
|
setNodeEnv('production');
|
|
97
|
-
const { config } =
|
|
103
|
+
const { config: configFile, v: version } = this.optsWithGlobals();
|
|
104
|
+
const { config } = await loadConfig(root, configFile, version);
|
|
98
105
|
const docDirectory = config.root;
|
|
99
106
|
await build({
|
|
100
107
|
config,
|
|
@@ -108,9 +115,10 @@ program
|
|
|
108
115
|
.argument('[root]', 'Root directory of the documentation')
|
|
109
116
|
.option('--port [port]', 'Port number', '4173')
|
|
110
117
|
.option('--host [host]', 'Host name')
|
|
111
|
-
.action(async (root
|
|
118
|
+
.action(async function (root) {
|
|
112
119
|
setNodeEnv('production');
|
|
113
|
-
const { config } =
|
|
120
|
+
const { config: configFile, v: version, ...server } = this.optsWithGlobals();
|
|
121
|
+
const { config } = await loadConfig(root, configFile, version);
|
|
114
122
|
await serve({
|
|
115
123
|
config,
|
|
116
124
|
...server,
|
package/lib/cli/load-config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DoomConfig } from '../utils/index.js';
|
|
2
|
-
export declare function loadConfig(root?: string, configFile?: string): Promise<{
|
|
2
|
+
export declare function loadConfig(root?: string, configFile?: string, version?: string): Promise<{
|
|
3
3
|
config: DoomConfig;
|
|
4
4
|
filepath?: string;
|
|
5
5
|
}>;
|
package/lib/cli/load-config.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { nodeTypes } from '@mdx-js/mdx';
|
|
4
|
-
import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, } from '@rspress/core';
|
|
4
|
+
import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, removeTrailingSlash, } from '@rspress/core';
|
|
5
5
|
import { pluginPreview } from '@rspress/plugin-preview';
|
|
6
6
|
import { logger } from '@rspress/shared/logger';
|
|
7
7
|
import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
|
|
8
8
|
import getPort from 'get-port';
|
|
9
9
|
import rehypeRaw from 'rehype-raw';
|
|
10
10
|
import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, globalPlugin, shikiPlugin, } from '../plugins/index.js';
|
|
11
|
+
import { normalizeVersion } from '../shared/index.js';
|
|
11
12
|
import { pkgResolve, resolveStaticConfig, } from '../utils/index.js';
|
|
12
13
|
import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
|
|
13
14
|
const DEFAULT_LOGO = '/logo.svg';
|
|
@@ -19,7 +20,7 @@ const zhLocaleConfig = {
|
|
|
19
20
|
prevPageText: '上一页',
|
|
20
21
|
nextPageText: '下一页',
|
|
21
22
|
};
|
|
22
|
-
const getCommonConfig = async (config) => {
|
|
23
|
+
const getCommonConfig = async (config, version) => {
|
|
23
24
|
const fallbackToZh = 'lang' in config && config.lang == null;
|
|
24
25
|
return {
|
|
25
26
|
lang: fallbackToZh ? 'zh' : config.lang,
|
|
@@ -62,9 +63,9 @@ const getCommonConfig = async (config) => {
|
|
|
62
63
|
}),
|
|
63
64
|
apiPlugin(),
|
|
64
65
|
autoSidebarPlugin(),
|
|
65
|
-
globalPlugin(),
|
|
66
|
+
globalPlugin(version),
|
|
66
67
|
shikiPlugin({
|
|
67
|
-
langs: ['dockerfile', 'go', 'jsonc'],
|
|
68
|
+
langs: ['dockerfile', 'html', 'go', 'jsonc'],
|
|
68
69
|
transformers: [
|
|
69
70
|
// builtin transformers
|
|
70
71
|
transformerMetaHighlight(),
|
|
@@ -99,7 +100,7 @@ const getCommonConfig = async (config) => {
|
|
|
99
100
|
const findConfig = (basePath) => {
|
|
100
101
|
return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
|
|
101
102
|
};
|
|
102
|
-
export async function loadConfig(root, configFile) {
|
|
103
|
+
export async function loadConfig(root, configFile, version) {
|
|
103
104
|
let configFilePath;
|
|
104
105
|
if (configFile) {
|
|
105
106
|
configFilePath = path.resolve(configFile);
|
|
@@ -148,9 +149,13 @@ export async function loadConfig(root, configFile) {
|
|
|
148
149
|
config.sites = await resolveStaticConfig(sitesConfigFilePath);
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
mergedConfig.base
|
|
152
|
+
const normalizedVersion = normalizeVersion(version);
|
|
153
|
+
const mergedConfig = mergeRsbuildConfig(await getCommonConfig(config, normalizedVersion), config);
|
|
154
|
+
let base = addLeadingSlash(mergedConfig.base || '/');
|
|
155
|
+
if (normalizedVersion && normalizedVersion !== 'unversioned') {
|
|
156
|
+
base = removeTrailingSlash(base) + `/${normalizedVersion}`;
|
|
157
|
+
}
|
|
158
|
+
mergedConfig.base = base = addTrailingSlash(base);
|
|
154
159
|
mergedConfig.root = resolveDocRoot(CWD, root, mergedConfig.root);
|
|
155
160
|
let ensureDefaultLogo = false;
|
|
156
161
|
if (!mergedConfig.logo) {
|
|
@@ -178,10 +183,10 @@ export async function loadConfig(root, configFile) {
|
|
|
178
183
|
mergedConfig.i18nSourcePath = path.resolve(mergedConfig.root, I18N_FILE);
|
|
179
184
|
}
|
|
180
185
|
if (!mergedConfig.outDir) {
|
|
181
|
-
mergedConfig.outDir = `dist${base}`;
|
|
186
|
+
mergedConfig.outDir = `dist${version === 'unversioned' ? `/unversioned${base}` : base}`;
|
|
182
187
|
}
|
|
183
188
|
if (mergedConfig.builderConfig?.server?.open === true) {
|
|
184
|
-
mergedConfig.builderConfig.server.open =
|
|
189
|
+
mergedConfig.builderConfig.server.open = base;
|
|
185
190
|
}
|
|
186
191
|
return {
|
|
187
192
|
config: mergedConfig,
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { usePageData } from '@rspress/core/runtime';
|
|
2
|
+
import { isProduction, usePageData } from '@rspress/core/runtime';
|
|
3
3
|
import { noop } from 'es-toolkit';
|
|
4
4
|
import { useEffect, useMemo, useState } from 'react';
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
6
6
|
import { parse } from 'yaml';
|
|
7
7
|
import { NavMenuGroup } from './NavMenuGroup.js';
|
|
8
8
|
export const VersionsNav = () => {
|
|
9
|
-
const { siteData } = usePageData();
|
|
9
|
+
const { siteData, page } = usePageData();
|
|
10
10
|
const [versionsBase, version] = useMemo(() => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}, [siteData.base]);
|
|
11
|
+
if (!page.v) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return [siteData.base.slice(0, -page.v.length - 1), page.v];
|
|
15
|
+
}, [siteData.base, page.v]);
|
|
17
16
|
const [navMenu, setNavMenu] = useState();
|
|
18
17
|
const [versions, setVersions] = useState();
|
|
19
18
|
useEffect(() => {
|
|
@@ -21,10 +20,14 @@ export const VersionsNav = () => {
|
|
|
21
20
|
if (versionsBase == null) {
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
24
|
-
const res = await fetch(`${versionsBase}/versions.yaml`);
|
|
23
|
+
const res = await fetch(`${isProduction() ? versionsBase : ''}/versions.yaml`);
|
|
25
24
|
const text = await res.text();
|
|
26
25
|
setNavMenu(document.querySelector('.rspress-nav-menu'));
|
|
27
|
-
|
|
26
|
+
const versions = parse(text);
|
|
27
|
+
if (version && !versions.includes(version)) {
|
|
28
|
+
versions.unshift(version);
|
|
29
|
+
}
|
|
30
|
+
setVersions(versions);
|
|
28
31
|
};
|
|
29
32
|
fetchVersions().catch(noop);
|
|
30
33
|
}, []);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RspressPlugin } from '@rspress/core';
|
|
2
|
-
export declare const globalPlugin: () => RspressPlugin;
|
|
2
|
+
export declare const globalPlugin: (version?: string) => RspressPlugin;
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { baseResolve, pkgResolve } from '../../utils/index.js';
|
|
4
4
|
const componentsDir = baseResolve('runtime/components');
|
|
5
|
-
export const globalPlugin = () => {
|
|
5
|
+
export const globalPlugin = (version) => {
|
|
6
6
|
let config;
|
|
7
7
|
return {
|
|
8
8
|
name: 'doom-global',
|
|
@@ -24,6 +24,7 @@ export const globalPlugin = () => {
|
|
|
24
24
|
},
|
|
25
25
|
extendPageData(pageData) {
|
|
26
26
|
pageData.sites = config.sites;
|
|
27
|
+
pageData.v = version === 'unversioned' ? undefined : version;
|
|
27
28
|
},
|
|
28
29
|
};
|
|
29
30
|
};
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { useLang, usePageData } from '@rspress/core/runtime';
|
|
3
3
|
import { addTrailingSlash } from '@rspress/shared';
|
|
4
4
|
import { useMemo } from 'react';
|
|
5
|
+
import { normalizeVersion } from '../../shared/index.js';
|
|
5
6
|
import { handleCJKWhitespaces } from '../utils.js';
|
|
6
7
|
import { Directive } from './_Directive.js';
|
|
7
8
|
const Notes = {
|
|
@@ -23,6 +24,9 @@ export const ExternalSite = ({ name }) => {
|
|
|
23
24
|
return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
|
|
24
25
|
}
|
|
25
26
|
const Note = Notes[lang] || Notes[fallbackLang] || Notes.en;
|
|
26
|
-
|
|
27
|
+
const siteBase = addTrailingSlash(site.base);
|
|
28
|
+
return (_jsx(Directive, { title: "Note", children: _jsx(Note, { name: displayName, href: page.v
|
|
29
|
+
? addTrailingSlash(siteBase + normalizeVersion(site.defaultVersion))
|
|
30
|
+
: siteBase }) }));
|
|
27
31
|
};
|
|
28
32
|
export default ExternalSite;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getCustomMDXComponent, Tab, Tabs } from '@rspress/core/theme';
|
|
3
|
+
import { stringify } from 'yaml';
|
|
4
|
+
const X = getCustomMDXComponent();
|
|
5
|
+
export const JsonViewer = ({ value }) => {
|
|
6
|
+
return (_jsxs(Tabs, { children: [_jsx(Tab, { label: "yaml", children: _jsx(X.pre, { children: _jsx(X.code, { className: "language-yaml", codeHighlighter: "prism", children: stringify(value) }) }) }), _jsx(Tab, { label: "json", children: _jsx(X.pre, { children: _jsx(X.code, { className: "language-json", codeHighlighter: "prism", children: JSON.stringify(value, null, 2) }) }) })] }));
|
|
7
|
+
};
|
|
8
|
+
export default JsonViewer;
|
package/lib/runtime/types.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { PageData } from '@rspress/core';
|
|
2
2
|
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
import type { CustomResourceDefinition } from '../plugins/api/types.js';
|
|
4
|
-
import { DoomSite } from '../
|
|
4
|
+
import type { DoomSite } from '../shared/types.js';
|
|
5
5
|
export interface ExtendedPage {
|
|
6
6
|
crdsMap?: Record<string, CustomResourceDefinition>;
|
|
7
7
|
openapisMap?: Record<string, OpenAPIV3_1.Document>;
|
|
8
8
|
references?: Record<string, string>;
|
|
9
9
|
pathPrefix?: string;
|
|
10
10
|
sites?: DoomSite[];
|
|
11
|
+
v?: string;
|
|
11
12
|
}
|
|
12
13
|
export interface ExtendedPageData extends PageData {
|
|
13
14
|
page: PageData['page'] & ExtendedPage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const normalizeVersion: (version?: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/utils/types.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { UserConfig } from '@rspress/core';
|
|
2
|
-
|
|
3
|
-
name: string;
|
|
4
|
-
displayName?: Record<string, string>;
|
|
5
|
-
repo: string;
|
|
6
|
-
base: string;
|
|
7
|
-
defaultVersion?: string;
|
|
8
|
-
}
|
|
2
|
+
import { DoomSite } from '../shared/index.js';
|
|
9
3
|
export interface DoomConfig extends UserConfig {
|
|
10
4
|
api?: {
|
|
11
5
|
crds?: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"shiki": "^1.24.3",
|
|
55
55
|
"swagger2openapi": "^7.0.8",
|
|
56
56
|
"tinyglobby": "^0.2.10",
|
|
57
|
+
"type-fest": "^4.30.2",
|
|
57
58
|
"yaml": "^2.6.1",
|
|
58
59
|
"yoctocolors": "^2.1.1"
|
|
59
60
|
},
|