@alauda/doom 0.0.0-alpha.4 → 0.0.0-alpha.5
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 +3 -3
- package/lib/cli/load-config.d.ts +2 -2
- package/lib/cli/load-config.js +20 -5
- package/package.json +1 -1
package/lib/cli/index.js
CHANGED
|
@@ -35,7 +35,7 @@ program
|
|
|
35
35
|
let devServer;
|
|
36
36
|
let cliWatcher;
|
|
37
37
|
const startDevServer = async () => {
|
|
38
|
-
const { config, filepath } = await loadConfig(configFile);
|
|
38
|
+
const { config, filepath } = await loadConfig(root, configFile);
|
|
39
39
|
config.root = resolveDocRoot(cwd, root, config.root);
|
|
40
40
|
config.i18nSourcePath = path.resolve(config.root, I18N_FILE);
|
|
41
41
|
const docDirectory = config.root;
|
|
@@ -94,7 +94,7 @@ program
|
|
|
94
94
|
.description('Build the documentation')
|
|
95
95
|
.action(async (root, { config: configFile }) => {
|
|
96
96
|
setNodeEnv('production');
|
|
97
|
-
const { config } = await loadConfig(configFile);
|
|
97
|
+
const { config } = await loadConfig(root, configFile);
|
|
98
98
|
config.root = resolveDocRoot(cwd, root, config.root);
|
|
99
99
|
config.i18nSourcePath = path.resolve(config.root, I18N_FILE);
|
|
100
100
|
const docDirectory = config.root;
|
|
@@ -112,7 +112,7 @@ program
|
|
|
112
112
|
.option('--host [host]', 'Host name')
|
|
113
113
|
.action(async (root, { config: configFile, ...server }) => {
|
|
114
114
|
setNodeEnv('production');
|
|
115
|
-
const { config } = await loadConfig(configFile);
|
|
115
|
+
const { config } = await loadConfig(root, configFile);
|
|
116
116
|
config.root = resolveDocRoot(cwd, root, config.root);
|
|
117
117
|
config.i18nSourcePath = path.resolve(config.root, I18N_FILE);
|
|
118
118
|
await serve({
|
package/lib/cli/load-config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function loadConfig(configFile?: string): Promise<{
|
|
1
|
+
import { type UserConfig } from '@rspress/core';
|
|
2
|
+
export declare function loadConfig(root?: string, configFile?: string): Promise<{
|
|
3
3
|
config: UserConfig;
|
|
4
4
|
filepath?: string;
|
|
5
5
|
}>;
|
package/lib/cli/load-config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { nodeTypes } from '@mdx-js/mdx';
|
|
2
|
+
import { addLeadingSlash, addTrailingSlash, } from '@rspress/core';
|
|
2
3
|
import { logger } from '@rspress/shared/logger';
|
|
3
4
|
import fs from 'node:fs';
|
|
4
5
|
import path from 'node:path';
|
|
@@ -7,7 +8,6 @@ import { parse } from 'yaml';
|
|
|
7
8
|
import { autoSidebarPlugin, globalPlugin } from '../plugins/index.js';
|
|
8
9
|
import { DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, YAML_EXTENSIONS, } from './constants.js';
|
|
9
10
|
const COMMON_CONFIG = {
|
|
10
|
-
base: '/docs',
|
|
11
11
|
lang: 'en',
|
|
12
12
|
logo: '/logo.svg',
|
|
13
13
|
icon: '/logo.svg',
|
|
@@ -42,20 +42,29 @@ const COMMON_CONFIG = {
|
|
|
42
42
|
lazyCompilation: true,
|
|
43
43
|
},
|
|
44
44
|
server: {
|
|
45
|
-
open:
|
|
45
|
+
open: true,
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
};
|
|
49
49
|
const findConfig = (basePath) => {
|
|
50
50
|
return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
|
|
51
51
|
};
|
|
52
|
-
export async function loadConfig(configFile) {
|
|
52
|
+
export async function loadConfig(root, configFile) {
|
|
53
53
|
let configFilePath;
|
|
54
54
|
if (configFile) {
|
|
55
55
|
configFilePath = path.resolve(configFile);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
|
|
58
|
+
if (root) {
|
|
59
|
+
configFilePath = findConfig(path.resolve(root, DEFAULT_CONFIG_NAME));
|
|
60
|
+
}
|
|
61
|
+
if (!configFilePath) {
|
|
62
|
+
configFilePath = findConfig(path.resolve(DEFAULT_CONFIG_NAME));
|
|
63
|
+
}
|
|
64
|
+
// when root is not specified, try to find config in docs folder
|
|
65
|
+
if (!root && !configFilePath) {
|
|
66
|
+
configFilePath = findConfig(path.resolve('docs', DEFAULT_CONFIG_NAME));
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
if (!configFilePath) {
|
|
61
70
|
logger.info(`No doom config file found in ${process.cwd()}`);
|
|
@@ -80,8 +89,14 @@ export async function loadConfig(configFile) {
|
|
|
80
89
|
catch {
|
|
81
90
|
logger.error(`Failed to load config from ${configFilePath}`);
|
|
82
91
|
}
|
|
92
|
+
const mergedConfig = mergeRsbuildConfig(COMMON_CONFIG, config ?? {});
|
|
93
|
+
const base = addLeadingSlash(mergedConfig.base || '/');
|
|
94
|
+
mergedConfig.base = base;
|
|
95
|
+
if (mergedConfig.builderConfig?.server?.open) {
|
|
96
|
+
mergedConfig.builderConfig.server.open = addTrailingSlash(base);
|
|
97
|
+
}
|
|
83
98
|
return {
|
|
84
|
-
config:
|
|
99
|
+
config: mergedConfig,
|
|
85
100
|
filepath: configFilePath,
|
|
86
101
|
};
|
|
87
102
|
}
|