@rspress/core 2.0.0-beta.20 → 2.0.0-beta.22

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/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { }
package/dist/cli.js ADDED
@@ -0,0 +1,144 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import node_path from "node:path";
4
+ import { logger } from "@rspress/shared/logger";
5
+ import { cac } from "cac";
6
+ import chokidar from "chokidar";
7
+ import picocolors from "picocolors";
8
+ import { build, dev, serve } from "./index.js";
9
+ import node_fs from "node:fs";
10
+ import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "@rspress/shared/constants";
11
+ var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.22"}');
12
+ const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
13
+ async function loadConfigFile(customConfigFile) {
14
+ const baseDir = process.cwd();
15
+ let configFilePath = '';
16
+ configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
17
+ if (!configFilePath) {
18
+ logger.info(`No config file found in ${baseDir}`);
19
+ return {
20
+ config: {},
21
+ configFilePath: ''
22
+ };
23
+ }
24
+ const { loadConfig } = await import("@rsbuild/core");
25
+ const { content } = await loadConfig({
26
+ cwd: node_path.dirname(configFilePath),
27
+ path: configFilePath
28
+ });
29
+ return {
30
+ config: content,
31
+ configFilePath
32
+ };
33
+ }
34
+ function resolveDocRoot(cwd, cliRoot, configRoot) {
35
+ if (cliRoot) return node_path.join(cwd, cliRoot);
36
+ if (configRoot) return node_path.isAbsolute(configRoot) ? configRoot : node_path.join(cwd, configRoot);
37
+ return node_path.join(cwd, 'docs');
38
+ }
39
+ const CONFIG_FILES = [
40
+ 'rspress.config.ts',
41
+ 'rspress.config.js'
42
+ ];
43
+ const META_FILES = [
44
+ '_meta.json',
45
+ '_nav.json'
46
+ ];
47
+ const cli = cac('rspress').version(package_namespaceObject.i8).help();
48
+ const landingMessage = `\u{1F525} Rspress v${package_namespaceObject.i8}\n`;
49
+ logger.greet(landingMessage);
50
+ const setNodeEnv = (env)=>{
51
+ process.env.NODE_ENV = env;
52
+ };
53
+ cli.option('-c,--config [config]', 'Specify the path to the config file');
54
+ cli.command('[root]', 'start dev server').alias('dev').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
55
+ setNodeEnv('development');
56
+ let isRestarting = false;
57
+ const cwd = process.cwd();
58
+ let cliWatcher;
59
+ let devServer;
60
+ const startDevServer = async ()=>{
61
+ const { port, host } = options || {};
62
+ const { config, configFilePath } = await loadConfigFile(options?.config);
63
+ config.root = resolveDocRoot(cwd, root, config.root);
64
+ const docDirectory = config.root;
65
+ devServer = await dev({
66
+ appDirectory: cwd,
67
+ docDirectory,
68
+ config,
69
+ configFilePath,
70
+ extraBuilderConfig: {
71
+ server: {
72
+ port,
73
+ host
74
+ }
75
+ }
76
+ });
77
+ cliWatcher = chokidar.watch([
78
+ `${cwd}/**/{${CONFIG_FILES.join(',')}}`,
79
+ docDirectory
80
+ ], {
81
+ ignoreInitial: true,
82
+ ignored: [
83
+ '**/node_modules/**',
84
+ '**/.git/**',
85
+ '**/.DS_Store/**'
86
+ ]
87
+ });
88
+ cliWatcher.on('all', async (eventName, filepath)=>{
89
+ const basename = node_path.basename(filepath);
90
+ if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && (CONFIG_FILES.includes(basename) || META_FILES.includes(basename))) {
91
+ if (isRestarting) return;
92
+ isRestarting = true;
93
+ console.log(`
94
+ \u{2728} ${eventName} ${picocolors.green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
95
+ await devServer.close();
96
+ await cliWatcher.close();
97
+ await startDevServer();
98
+ isRestarting = false;
99
+ }
100
+ });
101
+ };
102
+ await startDevServer();
103
+ const exitProcess = async ()=>{
104
+ try {
105
+ await devServer.close();
106
+ await cliWatcher.close();
107
+ } finally{
108
+ process.exit(0);
109
+ }
110
+ };
111
+ process.on('SIGINT', exitProcess);
112
+ process.on('SIGTERM', exitProcess);
113
+ });
114
+ cli.command('build [root]').action(async (root, options)=>{
115
+ setNodeEnv('production');
116
+ const cwd = process.cwd();
117
+ const { config, configFilePath } = await loadConfigFile(options.config);
118
+ config.root = resolveDocRoot(cwd, root, config.root);
119
+ const docDirectory = config.root;
120
+ try {
121
+ await build({
122
+ docDirectory,
123
+ config,
124
+ configFilePath
125
+ });
126
+ } catch (err) {
127
+ logger.error(err);
128
+ process.exit(1);
129
+ }
130
+ });
131
+ cli.command('preview [root]').alias('serve').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
132
+ setNodeEnv('production');
133
+ const cwd = process.cwd();
134
+ const { port, host } = options || {};
135
+ const { config, configFilePath } = await loadConfigFile(options?.config);
136
+ config.root = resolveDocRoot(cwd, root, config.root);
137
+ await serve({
138
+ config,
139
+ host,
140
+ port,
141
+ configFilePath
142
+ });
143
+ });
144
+ cli.parse();
package/dist/index.d.ts CHANGED
@@ -1,15 +1,32 @@
1
1
  import { AdditionalPage } from '@rspress/shared';
2
2
  import type { Data as Data_2 } from 'unist';
3
3
  import { DefaultThemeConfig } from '@rspress/shared';
4
+ import { getIconUrlPath } from '@rspress/shared/node-utils';
5
+ import { getNodeAttribute } from '@rspress/shared/node-utils';
6
+ import { getSidebarDataGroup } from '@rspress/shared';
7
+ import { logger } from '@rspress/shared/logger';
8
+ import { matchPath } from '@rspress/runtime/server';
4
9
  import { mergeDocConfig } from '@rspress/shared/node-utils';
10
+ import { Nav } from '@rspress/shared';
11
+ import { NavItemWithLink } from '@rspress/shared';
5
12
  import type { Node as Node_3 } from 'unist';
6
- import type { PageIndexInfo } from '@rspress/shared';
13
+ import { normalizeHref } from '@rspress/shared';
14
+ import { normalizePosixPath } from '@rspress/shared';
15
+ import { PageIndexInfo } from '@rspress/shared';
7
16
  import type { Plugin as Plugin_2 } from 'unified';
8
- import type { RouteMeta } from '@rspress/shared';
17
+ import { removeTrailingSlash } from '@rspress/shared';
18
+ import { RouteMeta } from '@rspress/shared';
9
19
  import type { RsbuildConfig } from '@rsbuild/core';
10
20
  import { RsbuildInstance } from '@rsbuild/core';
11
- import type { RspressPlugin } from '@rspress/shared';
12
- import type { UserConfig } from '@rspress/shared';
21
+ import { RSPRESS_TEMP_DIR } from '@rspress/shared';
22
+ import { RspressPlugin } from '@rspress/shared';
23
+ import { Sidebar } from '@rspress/shared';
24
+ import { SidebarDivider } from '@rspress/shared';
25
+ import { SidebarGroup } from '@rspress/shared';
26
+ import { SidebarItem } from '@rspress/shared';
27
+ import { SidebarSectionHeader } from '@rspress/shared';
28
+ import { UserConfig } from '@rspress/shared';
29
+ import { withBase } from '@rspress/shared';
13
30
 
14
31
  export declare function build(options: BuildOptions): Promise<void>;
15
32
 
@@ -39,6 +56,8 @@ declare interface BuildOptions {
39
56
  */
40
57
  declare interface Data extends Data_2 {}
41
58
 
59
+ export declare function defineConfig(config: UserConfig): UserConfig;
60
+
42
61
  export declare function dev(options: DevOptions): Promise<ServerInstance>;
43
62
 
44
63
  declare interface DevOptions {
@@ -49,6 +68,12 @@ declare interface DevOptions {
49
68
  extraBuilderConfig?: RsbuildConfig;
50
69
  }
51
70
 
71
+ export { getIconUrlPath }
72
+
73
+ export { getNodeAttribute }
74
+
75
+ export { getSidebarDataGroup }
76
+
52
77
  declare interface InitOptions {
53
78
  scanDir: string;
54
79
  config: UserConfig;
@@ -56,8 +81,16 @@ declare interface InitOptions {
56
81
  pluginDriver: PluginDriver;
57
82
  }
58
83
 
84
+ export { logger }
85
+
86
+ export { matchPath }
87
+
59
88
  export { mergeDocConfig }
60
89
 
90
+ export { Nav }
91
+
92
+ export { NavItemWithLink }
93
+
61
94
  /**
62
95
  * Abstract mdast node.
63
96
  *
@@ -78,6 +111,12 @@ declare interface Node_2 extends Node_3 {
78
111
  data?: Data | undefined;
79
112
  }
80
113
 
114
+ export { normalizeHref }
115
+
116
+ export { normalizePosixPath }
117
+
118
+ export { PageIndexInfo }
119
+
81
120
  /**
82
121
  * Abstract mdast node that contains other mdast nodes (*children*).
83
122
  *
@@ -110,17 +149,16 @@ declare class PluginDriver {
110
149
  routeGenerated(routes: RouteMeta[]): Promise<void[]>;
111
150
  routeServiceGenerated(routeService: RouteService): Promise<void[]>;
112
151
  addRuntimeModules(): Promise<Record<string, string>>;
113
- addSSGRoutes(): Promise<({
114
- path: string;
115
- } | {
116
- path: string;
117
- })[]>;
118
152
  globalUIComponents(): (string | [string, object])[];
119
153
  globalStyles(): string[];
120
154
  _runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
121
155
  _runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
122
156
  }
123
157
 
158
+ export declare const remarkFileCodeBlock: Plugin_2<[{
159
+ filepath: string;
160
+ }], Root>;
161
+
124
162
  /**
125
163
  * Remark plugin to normalize a link href
126
164
  */
@@ -133,6 +171,8 @@ export declare const remarkPluginNormalizeLink: Plugin_2<[
133
171
  }
134
172
  ], Root>;
135
173
 
174
+ export { removeTrailingSlash }
175
+
136
176
  /**
137
177
  * Document fragment or a whole document.
138
178
  *
@@ -162,6 +202,8 @@ declare type RootContent = RootContentMap[keyof RootContentMap];
162
202
  */
163
203
  declare interface RootData extends Data {}
164
204
 
205
+ export { RouteMeta }
206
+
165
207
  declare class RoutePage {
166
208
  #private;
167
209
  routeMeta: RouteMeta;
@@ -184,7 +226,7 @@ export declare class RouteService {
184
226
  getRoutePages(): RoutePage[];
185
227
  isExistRoute(routePath: string): boolean;
186
228
  generateRoutesCode(): string;
187
- generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
229
+ private generateRoutesCodeByRouteMeta;
188
230
  getRoutePathParts(relativePath: string): readonly [string, string, string];
189
231
  normalizeRoutePath(relativePath: string): {
190
232
  pureRoutePath: string;
@@ -197,7 +239,11 @@ export declare class RouteService {
197
239
  getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
198
240
  }
199
241
 
200
- declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
242
+ export { RSPRESS_TEMP_DIR }
243
+
244
+ export { RspressPlugin }
245
+
246
+ declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'extendPageData' | 'modifySearchIndexData';
201
247
 
202
248
  export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
203
249
 
@@ -212,7 +258,18 @@ declare interface ServerInstance {
212
258
  close: () => Promise<void>;
213
259
  }
214
260
 
261
+ export { Sidebar }
262
+
263
+ export { SidebarDivider }
264
+
265
+ export { SidebarGroup }
266
+
267
+ export { SidebarItem }
268
+
269
+ export { SidebarSectionHeader }
270
+
271
+ export { UserConfig }
215
272
 
216
- export * from "@rspress/shared";
273
+ export { withBase }
217
274
 
218
275
  export { }