@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 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, { config: configFile, ...server }) => {
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 [root]')
98
+ .parent.command('build')
94
99
  .description('Build the documentation')
95
- .action(async (root, { config: configFile }) => {
100
+ .argument('[root]', 'Root directory of the documentation')
101
+ .action(async function (root) {
96
102
  setNodeEnv('production');
97
- const { config } = await loadConfig(root, configFile);
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, { config: configFile, ...server }) => {
118
+ .action(async function (root) {
112
119
  setNodeEnv('production');
113
- const { config } = await loadConfig(root, configFile);
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,
@@ -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
  }>;
@@ -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 mergedConfig = mergeRsbuildConfig(await getCommonConfig(config), config);
152
- const base = addLeadingSlash(mergedConfig.base || '/');
153
- mergedConfig.base = 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 = addTrailingSlash(base);
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
- const parts = siteData.base.split('/');
12
- const last = parts.at(-1);
13
- return last === 'master' || /^v\d+\.\d$/.test(last)
14
- ? [parts.slice(0, -1).join('/'), last]
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
- setVersions(parse(text));
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
- return (_jsx(Directive, { title: "Note", children: _jsx(Note, { name: displayName, href: addTrailingSlash(site.base) }) }));
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,6 @@
1
+ import type { JsonValue } from 'type-fest';
2
+ export interface JsonViewerProps {
3
+ value: JsonValue;
4
+ }
5
+ export declare const JsonViewer: ({ value }: JsonViewerProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default JsonViewer;
@@ -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;
@@ -2,6 +2,7 @@ export * from './Badge.js';
2
2
  export * from './Callouts.js';
3
3
  export * from './Card.js';
4
4
  export * from './ExternalSite.js';
5
+ export * from './JsonViewer.js';
5
6
  export * from './K8sCrd.js';
6
7
  export * from './LinkCard.js';
7
8
  export * from './Overview.js';
@@ -2,6 +2,7 @@ export * from './Badge.js';
2
2
  export * from './Callouts.js';
3
3
  export * from './Card.js';
4
4
  export * from './ExternalSite.js';
5
+ export * from './JsonViewer.js';
5
6
  export * from './K8sCrd.js';
6
7
  export * from './LinkCard.js';
7
8
  export * from './Overview.js';
@@ -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 '../utils/types.js';
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,2 @@
1
+ const PLAIN_VERSION_PATTERN = /^(\d+\.)*\d+$/;
2
+ export const normalizeVersion = (version = '') => PLAIN_VERSION_PATTERN.test(version) ? `v${version}` : version;
@@ -0,0 +1,2 @@
1
+ export * from './helpers.js';
2
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ export * from './helpers.js';
2
+ export * from './types.js';
@@ -0,0 +1,7 @@
1
+ export interface DoomSite {
2
+ name: string;
3
+ displayName?: Record<string, string>;
4
+ repo: string;
5
+ base: string;
6
+ defaultVersion?: string;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,5 @@
1
1
  import { UserConfig } from '@rspress/core';
2
- export interface DoomSite {
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.1",
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
  },