@alauda/doom 0.17.6 → 0.18.10

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/export.js CHANGED
@@ -8,24 +8,29 @@ import { pathExists, setNodeEnv } from '../utils/index.js';
8
8
  import { generatePdf, } from './export-pdf-core/index.js';
9
9
  import { loadConfig } from './load-config.js';
10
10
  export const exportCommand = new Command('export')
11
- .description('Export the documentation as PDF')
11
+ .description('Export the documentation as PDF, `apis/**` and `*/apis/**` routes will be ignored automatically')
12
12
  .argument('[root]', 'Root directory of the documentation')
13
13
  .option('-H, --host [host]', 'Serve host name')
14
14
  .option('-P, --port [port]', 'Serve port number', '4173')
15
15
  .action(async function (root) {
16
16
  setNodeEnv('production');
17
17
  const { port, host, ...globalOptions } = this.optsWithGlobals();
18
- let { config } = await loadConfig(root, globalOptions);
18
+ let { config } = await loadConfig(root, {
19
+ ...globalOptions,
20
+ export: true,
21
+ });
19
22
  const outDir = config.outDir;
20
23
  if (!(await pathExists(path.resolve(outDir, 'index.html'), 'file'))) {
21
24
  logger.error('Please build the documentation first');
22
25
  process.exit(1);
23
26
  }
24
27
  config = await autoSidebar(config, {
25
- excludeRoutes: (globalOptions.ignore && config.internalRoutes) || [],
28
+ ignore: globalOptions.ignore,
29
+ export: true,
26
30
  });
27
31
  config.builderConfig.server.open = false;
28
- const themeConfig = config.themeConfig;
32
+ // make sure it won't be overridden by `serve`
33
+ const themeConfig = { ...config.themeConfig };
29
34
  logger.start('Serving...');
30
35
  await serve({ config, host, port });
31
36
  const collectPages = (sidebarItems) => {
@@ -80,6 +85,7 @@ export const exportCommand = new Command('export')
80
85
  },
81
86
  };
82
87
  const exportPdf = async (sidebarItems, lang = config.lang) => {
88
+ // console.log(sidebarItems, collectPages(sidebarItems))
83
89
  await generatePdf({
84
90
  pages: collectPages(sidebarItems),
85
91
  outFile: getPdfName(lang, config.userBase, config.title),
package/lib/cli/index.js CHANGED
@@ -36,6 +36,7 @@ program
36
36
  2. translate ignore hash equality check and original text`, parseBoolean, false)
37
37
  .option('-i, --ignore [boolean]', 'Ignore internal routes', parseBoolean, false)
38
38
  .option('-d, --download [boolean]', 'Display download pdf link on nav bar', parseBoolean, false)
39
+ .option('-e, --export [boolean]', 'Run or build in exporting PDF mode, `apis/**` and `*/apis/**` routes will be ignored automatically', parseBoolean, false)
39
40
  .option('--no-open [boolean]', 'Do not open the browser after starting the server')
40
41
  .command('dev', { isDefault: true })
41
42
  .description('Start the development server')
@@ -1,6 +1,6 @@
1
1
  import { type UserConfig } from '@rspress/core';
2
2
  import type { GlobalCliOptions } from '../types.js';
3
- export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, ignore, force, open, lazy, }?: GlobalCliOptions): Promise<{
3
+ export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, }?: GlobalCliOptions): Promise<{
4
4
  config: UserConfig;
5
5
  filepath?: string;
6
6
  }>;
@@ -19,11 +19,10 @@ const zhLocaleConfig = {
19
19
  prevPageText: '上一页',
20
20
  nextPageText: '下一页',
21
21
  };
22
- const getCommonConfig = ({ config, root, configFilePath, base, version, download, ignore, force, open, lazy, }) => {
22
+ const getCommonConfig = ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, }) => {
23
23
  const fallbackToZh = 'lang' in config && !config.lang;
24
24
  root = resolveDocRoot(CWD, root, config.root);
25
25
  const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
26
- const excludeRoutes = (ignore && config.internalRoutes) || [];
27
26
  const userBase = (base = addLeadingSlash(addTrailingSlash(base || config.base || '/')));
28
27
  if (version && version !== 'unversioned') {
29
28
  base = userBase + `${version}/`;
@@ -42,7 +41,6 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
42
41
  'doom.config.*',
43
42
  '**/assets/**/*',
44
43
  '**/*.d.ts',
45
- ...excludeRoutes,
46
44
  ],
47
45
  },
48
46
  markdown: {
@@ -71,9 +69,7 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
71
69
  apiPlugin({
72
70
  localBasePath,
73
71
  }),
74
- autoSidebarPlugin({
75
- excludeRoutes,
76
- }),
72
+ autoSidebarPlugin({ export: export_, ignore }),
77
73
  directivesPlugin(),
78
74
  globalPlugin({ version, download }),
79
75
  mermaidPlugin(),
@@ -138,7 +134,7 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
138
134
  const findConfig = (basePath) => {
139
135
  return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
140
136
  };
141
- export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, ignore, force, open, lazy, } = {}) {
137
+ export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, } = {}) {
142
138
  let configFilePath;
143
139
  if (configFile) {
144
140
  configFilePath = path.resolve(configFile);
@@ -195,6 +191,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
195
191
  base,
196
192
  version,
197
193
  download,
194
+ export: export_,
198
195
  ignore,
199
196
  force,
200
197
  open,
package/lib/cli/new.js CHANGED
@@ -6,6 +6,7 @@ import { Command } from 'commander';
6
6
  import { render } from 'ejs';
7
7
  import { glob } from 'tinyglobby';
8
8
  import { cyan, magenta } from 'yoctocolors';
9
+ import { JS_STR_FALSY_VALUES } from '../shared/index.js';
9
10
  import { resolveRepo, resolveStaticConfig } from '../utils/index.js';
10
11
  export const DEFAULT_PATH = 'templates/scaffolding.yaml';
11
12
  const scaffoldingTemplates = {
@@ -97,14 +98,16 @@ export const newCommand = new Command('new')
97
98
  }
98
99
  const parameters = {};
99
100
  for (const param of scaffolding.parameters || []) {
100
- parameters[param.name] = await prompts[param.type](param.options);
101
+ parameters[param.name] =
102
+ await // @ts-expect-error -- no idea how to fix this
103
+ prompts[param.type](param.options);
101
104
  }
102
105
  logger.start('Generating scaffolding...');
103
106
  for (const layout of scaffolding.layout || []) {
104
107
  const source = path.resolve(base, render(layout.source, { parameters }));
105
108
  const target = path.resolve(render(layout.target, { parameters }));
106
109
  const when = layout.when && render(layout.when, { parameters });
107
- if (['', '0', 'false', 'null', 'undefined'].includes(when)) {
110
+ if (JS_STR_FALSY_VALUES.has(when)) {
108
111
  continue;
109
112
  }
110
113
  switch (layout.type) {
@@ -2,8 +2,9 @@ import { type RspressPlugin, type UserConfig } from '@rspress/core';
2
2
  export type * from './walk.js';
3
3
  export type * from './type.js';
4
4
  export interface AutoSidebarPluginOptions {
5
- excludeRoutes?: string[];
5
+ ignore?: boolean;
6
+ export?: boolean;
6
7
  collapsed?: boolean;
7
8
  }
8
- export declare const autoSidebar: (config: UserConfig, { excludeRoutes }: AutoSidebarPluginOptions) => Promise<UserConfig<import("@rspress/shared").DefaultThemeConfig>>;
9
+ export declare const autoSidebar: (config: UserConfig, { ignore, export: export_ }: AutoSidebarPluginOptions) => Promise<UserConfig<import("@rspress/shared").DefaultThemeConfig>>;
9
10
  export declare const autoSidebarPlugin: (options?: AutoSidebarPluginOptions) => RspressPlugin;
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { addTrailingSlash, } from '@rspress/core';
3
+ import { APIS_ROUTES } from '../../shared/index.js';
3
4
  import { combineWalkResult } from './utils.js';
4
5
  import { walk } from './walk.js';
5
6
  // Scan all the directories and files in the work directory(such as `docs`), and then generate the nav and sidebar configuration according to the directory structure.
@@ -154,17 +155,26 @@ function processLocales(langs, versions, root, defaultLang, defaultVersion, exte
154
155
  }));
155
156
  }
156
157
  const defaultExtensions = ['.mdx', '.md', '.tsx', '.jsx', '.ts', '.js'];
157
- export const autoSidebar = async (config, { excludeRoutes }) => {
158
- config.themeConfig = config.themeConfig || {};
159
- config.themeConfig.locales =
160
- config.themeConfig.locales || config.locales || [];
158
+ export const autoSidebar = async (config, { ignore, export: export_ }) => {
159
+ const excludeRoutes = (ignore && config.internalRoutes) || [];
160
+ const route = (config.route ??= {});
161
+ if (export_ || excludeRoutes.length) {
162
+ const exclude = (route.exclude ??= []);
163
+ exclude.push(...excludeRoutes);
164
+ // only exclude apis routes for sidebar but not site data to avoid dead links
165
+ if (export_) {
166
+ excludeRoutes.push(...APIS_ROUTES);
167
+ }
168
+ }
169
+ config.themeConfig ??= {};
170
+ config.themeConfig.locales ??= config.locales || [];
161
171
  const root = config.root;
162
172
  const langs = config.themeConfig.locales.map((locale) => locale.lang);
163
173
  const hasLocales = langs.length > 0;
164
174
  const versions = config.multiVersion?.versions || [];
165
175
  const defaultLang = config.lang || '';
166
176
  const { default: defaultVersion = '' } = config.multiVersion || {};
167
- const { extensions = defaultExtensions } = config.route || {};
177
+ const { extensions = defaultExtensions } = route;
168
178
  const collapsed = config.sidebar?.collapsed;
169
179
  if (hasLocales) {
170
180
  const metaInfo = await processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, excludeRoutes, collapsed);
@@ -1,2 +1,4 @@
1
1
  export declare const ACP_BASE = "/container_platform/";
2
2
  export declare const FALSY_VALUES: Set<string>;
3
+ export declare const JS_STR_FALSY_VALUES: Set<string>;
4
+ export declare const APIS_ROUTES: Set<string>;
@@ -1,2 +1,10 @@
1
1
  export const ACP_BASE = '/container_platform/';
2
- export const FALSY_VALUES = new Set(['0', 'false', 'no', 'off', 'n', 'f']);
2
+ export const FALSY_VALUES = new Set(['', '0', 'false', 'no', 'off', 'n', 'f']);
3
+ export const JS_STR_FALSY_VALUES = new Set([
4
+ '',
5
+ '0',
6
+ 'false',
7
+ 'null',
8
+ 'undefined',
9
+ ]);
10
+ export const APIS_ROUTES = new Set(['apis/**', '*/apis/**']);
package/lib/types.d.ts CHANGED
@@ -9,6 +9,7 @@ export interface GlobalCliOptions {
9
9
  prefix?: string;
10
10
  v?: string;
11
11
  download?: boolean;
12
+ export?: boolean;
12
13
  ignore?: boolean;
13
14
  force?: boolean;
14
15
  open?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.17.6",
3
+ "version": "0.18.10",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "https://gitlab-ce.alauda.cn/idp/Doom.git",
@@ -30,6 +30,7 @@
30
30
  "doom": "yarn swc-node src/cli/index.ts",
31
31
  "export": "yarn doom export",
32
32
  "fixture": "yarn dev fixture-docs",
33
+ "format": "prettier --write .",
33
34
  "lint": "run-p 'lint:*'",
34
35
  "lint:es": "eslint . --cache",
35
36
  "lint:tsc": "tsc -b",
@@ -40,7 +41,7 @@
40
41
  "translate": "yarn doom translate fixture-docs"
41
42
  },
42
43
  "dependencies": {
43
- "@inquirer/prompts": "^7.4.0",
44
+ "@inquirer/prompts": "^7.4.1",
44
45
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
45
46
  "@playwright/browser-chromium": "^1.51.1",
46
47
  "@rsbuild/plugin-yaml": "^1.0.2",
@@ -70,14 +71,14 @@
70
71
  "simple-git": "^3.27.0",
71
72
  "swagger2openapi": "^7.0.8",
72
73
  "tinyglobby": "^0.2.12",
73
- "type-fest": "^4.39.0",
74
+ "type-fest": "^4.39.1",
74
75
  "yaml": "^2.7.1",
75
76
  "yoctocolors": "^2.1.1"
76
77
  },
77
78
  "devDependencies": {
78
- "@eslint/js": "^9.23.0",
79
+ "@eslint/js": "^9.24.0",
79
80
  "@swc-node/register": "^1.10.10",
80
- "@swc/core": "1.11.16",
81
+ "@swc/core": "1.11.18",
81
82
  "@types/cli-progress": "^3.11.6",
82
83
  "@types/ejs": "^3.1.5",
83
84
  "@types/node": "^18.19.86",
@@ -86,16 +87,16 @@
86
87
  "@types/react-dom": "^18.3.6",
87
88
  "@types/swagger2openapi": "^7.0.4",
88
89
  "@unts/patch-package": "^8.1.1",
89
- "eslint": "^9.23.0",
90
- "eslint-import-resolver-typescript": "^4.3.1",
91
- "eslint-plugin-import-x": "^4.10.0",
90
+ "eslint": "^9.24.0",
91
+ "eslint-import-resolver-typescript": "^4.3.2",
92
+ "eslint-plugin-import-x": "^4.10.2",
92
93
  "lint-staged": "^15.5.0",
93
94
  "npm-run-all2": "^7.0.2",
94
95
  "prettier": "^3.5.3",
95
- "prettier-plugin-pkg": "^0.18.1",
96
+ "prettier-plugin-pkg": "^0.19.0",
96
97
  "simple-git-hooks": "^2.12.1",
97
- "typescript": "^5.8.2",
98
- "typescript-eslint": "^8.29.0",
98
+ "typescript": "^5.8.3",
99
+ "typescript-eslint": "^8.29.1",
99
100
  "yarn-berry-deduplicate": "^6.1.1"
100
101
  },
101
102
  "publishConfig": {