@alauda/doom 0.0.0-alpha.9 → 0.1.0

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 CHANGED
@@ -1,3 +1,5 @@
1
1
  # Doom
2
2
 
3
3
  Doctor Doom making docs.
4
+
5
+ Please view <https://doom.alauda.cn/> for its documents.
@@ -1,5 +1,6 @@
1
1
  import { nodeTypes } from '@mdx-js/mdx';
2
- import { addLeadingSlash, addTrailingSlash, } from '@rspress/core';
2
+ import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, } from '@rspress/core';
3
+ import { pluginPreview } from '@rspress/plugin-preview';
3
4
  import { logger } from '@rspress/shared/logger';
4
5
  import fs from 'node:fs';
5
6
  import path from 'node:path';
@@ -8,41 +9,68 @@ import { parse } from 'yaml';
8
9
  import { autoSidebarPlugin, globalPlugin } from '../plugins/index.js';
9
10
  import { pkgResolve } from '../utils/helpers.js';
10
11
  import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, YAML_EXTENSIONS, } from './constants.js';
11
- const DEFAULT_LOGO = path.relative(CWD, pkgResolve('assets/logo.svg'));
12
- const COMMON_CONFIG = {
13
- lang: 'en',
14
- logo: DEFAULT_LOGO,
15
- icon: DEFAULT_LOGO,
16
- markdown: {
17
- checkDeadLinks: true,
18
- mdxRs: false,
19
- rehypePlugins: [[rehypeRaw, { passThrough: nodeTypes }]],
20
- },
21
- ssg: {
22
- strict: true,
23
- },
24
- themeConfig: {
25
- locales: [
26
- {
27
- lang: 'zh',
28
- label: '简体中文',
29
- searchPlaceholderText: '搜索文档',
30
- searchNoResultsText: '未搜索到相关结果',
31
- searchSuggestedQueryText: '可更换不同的关键字后重试',
32
- outlineTitle: '本页概览',
12
+ const DEFAULT_LOGO = '/logo.svg';
13
+ const getCommonConfig = (config) => {
14
+ return {
15
+ lang: 'en',
16
+ route: {
17
+ exclude: ['shared/**/*', 'doom.config.*'],
18
+ },
19
+ markdown: {
20
+ checkDeadLinks: true,
21
+ highlightLanguages: [['jsonc', 'json']],
22
+ mdxRs: false,
23
+ rehypePlugins: [[rehypeRaw, { passThrough: nodeTypes }]],
24
+ },
25
+ ssg: {
26
+ strict: true,
27
+ },
28
+ themeConfig: {
29
+ enableScrollToTop: true,
30
+ locales: 'lang' in config && config.lang == null
31
+ ? undefined
32
+ : [
33
+ {
34
+ lang: 'zh',
35
+ label: '简体中文',
36
+ searchPlaceholderText: '搜索文档',
37
+ searchNoResultsText: '未搜索到相关结果',
38
+ searchSuggestedQueryText: '可更换不同的关键字后重试',
39
+ outlineTitle: '本页概览',
40
+ prevPageText: '上一页',
41
+ nextPageText: '下一页',
42
+ },
43
+ {
44
+ lang: 'en',
45
+ label: 'English',
46
+ },
47
+ ],
48
+ },
49
+ plugins: [
50
+ pluginPreview({
51
+ iframeOptions: {
52
+ devPort: 7891,
53
+ },
54
+ defaultRenderMode: 'pure',
55
+ }),
56
+ autoSidebarPlugin(),
57
+ globalPlugin(),
58
+ ],
59
+ builderConfig: {
60
+ server: {
61
+ open: true,
33
62
  },
34
- {
35
- lang: 'en',
36
- label: 'English',
63
+ tools: {
64
+ rspack: {
65
+ resolve: {
66
+ extensionAlias: {
67
+ '.js': ['.ts', '.tsx', '.js'],
68
+ },
69
+ },
70
+ },
37
71
  },
38
- ],
39
- },
40
- plugins: [autoSidebarPlugin(), globalPlugin()],
41
- builderConfig: {
42
- server: {
43
- open: true,
44
72
  },
45
- },
73
+ };
46
74
  };
47
75
  const findConfig = (basePath) => {
48
76
  return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
@@ -64,36 +92,53 @@ export async function loadConfig(root, configFile) {
64
92
  configFilePath = findConfig(path.resolve('docs', DEFAULT_CONFIG_NAME));
65
93
  }
66
94
  }
95
+ let config;
96
+ const { loadConfig, mergeRsbuildConfig } = await import('@rsbuild/core');
67
97
  if (!configFilePath) {
68
98
  logger.info(`No doom config file found in ${process.cwd()}`);
69
- return {
70
- config: {},
71
- };
72
99
  }
73
- const { loadConfig, mergeRsbuildConfig } = await import('@rsbuild/core');
74
- let config;
75
- try {
76
- if (YAML_EXTENSIONS.includes(path.extname(configFilePath))) {
77
- config = parse(fs.readFileSync(configFilePath, 'utf-8'));
100
+ else {
101
+ try {
102
+ if (YAML_EXTENSIONS.includes(path.extname(configFilePath))) {
103
+ config = parse(fs.readFileSync(configFilePath, 'utf-8'));
104
+ }
105
+ else {
106
+ const { content } = await loadConfig({
107
+ cwd: path.dirname(configFilePath),
108
+ path: configFilePath,
109
+ });
110
+ config = content;
111
+ }
78
112
  }
79
- else {
80
- const { content } = await loadConfig({
81
- cwd: path.dirname(configFilePath),
82
- path: configFilePath,
83
- });
84
- config = content;
113
+ catch {
114
+ logger.error(`Failed to load config from ${configFilePath}`);
85
115
  }
86
116
  }
87
- catch {
88
- logger.error(`Failed to load config from ${configFilePath}`);
89
- }
90
- const mergedConfig = mergeRsbuildConfig(COMMON_CONFIG, config ?? {});
117
+ config ??= {};
118
+ const mergedConfig = mergeRsbuildConfig(getCommonConfig(config), config);
91
119
  const base = addLeadingSlash(mergedConfig.base || '/');
92
120
  mergedConfig.base = base;
93
121
  mergedConfig.root = resolveDocRoot(CWD, root, mergedConfig.root);
122
+ let ensureDefaultLogo = false;
123
+ if (!mergedConfig.logo) {
124
+ mergedConfig.logo = DEFAULT_LOGO;
125
+ ensureDefaultLogo = true;
126
+ }
127
+ if (!mergedConfig.icon) {
128
+ mergedConfig.icon = DEFAULT_LOGO;
129
+ ensureDefaultLogo = true;
130
+ }
131
+ if (ensureDefaultLogo) {
132
+ const publicPath = path.resolve(mergedConfig.root, `public`);
133
+ fs.mkdirSync(publicPath, { recursive: true });
134
+ const logoPath = path.resolve(publicPath, removeLeadingSlash(DEFAULT_LOGO));
135
+ if (!fs.existsSync(logoPath)) {
136
+ fs.copyFileSync(pkgResolve(`assets${DEFAULT_LOGO}`), logoPath);
137
+ }
138
+ }
94
139
  if (mergedConfig.i18nSourcePath) {
95
140
  if (!path.isAbsolute(mergedConfig.i18nSourcePath)) {
96
- mergedConfig.i18nSourcePath = path.resolve(configFilePath, mergedConfig.i18nSourcePath);
141
+ mergedConfig.i18nSourcePath = path.resolve(configFilePath ?? mergedConfig.root, mergedConfig.i18nSourcePath);
97
142
  }
98
143
  }
99
144
  else {
@@ -102,7 +147,7 @@ export async function loadConfig(root, configFile) {
102
147
  if (!mergedConfig.outDir) {
103
148
  mergedConfig.outDir = `dist${base}`;
104
149
  }
105
- if (mergedConfig.builderConfig?.server?.open) {
150
+ if (mergedConfig.builderConfig?.server?.open === true) {
106
151
  mergedConfig.builderConfig.server.open = addTrailingSlash(base);
107
152
  }
108
153
  return {
@@ -181,7 +181,9 @@ export async function walk(workDir, routePrefix = '/', docsDir, extensions) {
181
181
  }
182
182
  });
183
183
  // find the `_meta.json` file in the subdirectory
184
- const subDirs = (await fs.readdir(workDir)).filter((v) => fs.statSync(path.join(workDir, v)).isDirectory() && v !== 'node_modules');
184
+ const subDirs = (await fs.readdir(workDir)).filter((v) => fs.statSync(path.join(workDir, v)).isDirectory() &&
185
+ v !== 'node_modules' &&
186
+ (workDir !== docsDir || !['public', 'shared'].includes(v)));
185
187
  const sidebars = [];
186
188
  // Every sub dir will represent a group of sidebar
187
189
  const sidebarConfig = {
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.0.0-alpha.9",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
- "repository": "https://gitlab-ce.alauda.cn/idp/Doom",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://gitlab-ce.alauda.cn/idp/Doom.git"
9
+ },
7
10
  "packageManager": "yarn@4.5.0",
8
11
  "engines": {
9
12
  "node": ">=18.12.0"
10
13
  },
11
- "bin": "./lib/cli/index.js",
14
+ "bin": {
15
+ "doom": "lib/cli/index.js"
16
+ },
12
17
  "exports": {
13
18
  "./package.json": "./package.json",
14
19
  "./runtime": "./lib/runtime/index.js"
@@ -33,7 +38,8 @@
33
38
  "swc-node": "node --enable-source-maps --import @swc-node/register/esm-register"
34
39
  },
35
40
  "dependencies": {
36
- "@rspress/core": "^1.35.2",
41
+ "@rspress/core": "^1.36.0",
42
+ "@rspress/plugin-preview": "^1.36.0",
37
43
  "chokidar": "^4.0.1",
38
44
  "commander": "^12.1.0",
39
45
  "rehype-raw": "^6.1.1",
@@ -41,20 +47,20 @@
41
47
  "yoctocolors": "^2.1.1"
42
48
  },
43
49
  "devDependencies": {
44
- "@eslint/js": "^9.13.0",
50
+ "@eslint/js": "^9.14.0",
45
51
  "@swc-node/register": "^1.10.9",
46
- "@swc/core": "1.7.40",
52
+ "@swc/core": "1.9.2",
47
53
  "@types/eslint__js": "^8.42.3",
48
54
  "@types/fs-extra": "^11.0.4",
49
55
  "@types/node": "~18.13.0",
50
- "eslint": "^9.13.0",
56
+ "eslint": "^9.14.0",
51
57
  "lint-staged": "^15.2.10",
52
58
  "npm-run-all2": "^7.0.1",
53
59
  "prettier": "^3.3.3",
54
60
  "prettier-plugin-pkg": "^0.18.1",
55
61
  "simple-git-hooks": "^2.11.1",
56
62
  "typescript": "^5.6.3",
57
- "typescript-eslint": "^8.12.2"
63
+ "typescript-eslint": "^8.14.0"
58
64
  },
59
65
  "publishConfig": {
60
66
  "access": "public"