rspress 0.0.9 → 0.0.11
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/index.js +38 -48
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -4,7 +4,7 @@ import path2 from "path";
|
|
4
4
|
import { cac } from "cac";
|
5
5
|
import { build, dev, serve } from "@rspress/core";
|
6
6
|
import chokidar from "chokidar";
|
7
|
-
import
|
7
|
+
import chalk from "chalk";
|
8
8
|
|
9
9
|
// src/config/loadConfigFile.ts
|
10
10
|
import fs from "fs";
|
@@ -53,32 +53,6 @@ async function loadConfigFile(customConfigFile) {
|
|
53
53
|
return result;
|
54
54
|
}
|
55
55
|
|
56
|
-
// src/logger.ts
|
57
|
-
import chalk from "chalk";
|
58
|
-
var rspressMark = chalk.cyan("[Rspress]");
|
59
|
-
var logger = {
|
60
|
-
info(msg) {
|
61
|
-
console.log(`${chalk.cyan.bold("[info]")} ${msg}`);
|
62
|
-
},
|
63
|
-
error(msg) {
|
64
|
-
console.log(`${chalk.red("[error]")} ${msg}`);
|
65
|
-
},
|
66
|
-
warn(msg) {
|
67
|
-
console.log(`${chalk.yellow("[warn]")} ${msg}`);
|
68
|
-
},
|
69
|
-
success(msg) {
|
70
|
-
console.log(`${chalk.green("[success]")} ${msg}`);
|
71
|
-
},
|
72
|
-
debug(msg) {
|
73
|
-
if (process.env.DEBUG) {
|
74
|
-
console.log(`${chalk.gray("[rspress:debug]")} ${msg}`);
|
75
|
-
}
|
76
|
-
},
|
77
|
-
log(msg) {
|
78
|
-
console.log(`${chalk.cyan("[rspress]")} ${msg}`);
|
79
|
-
}
|
80
|
-
};
|
81
|
-
|
82
56
|
// src/index.ts
|
83
57
|
var CONFIG_FILES = [
|
84
58
|
"rspress.config.ts",
|
@@ -92,34 +66,48 @@ var cli = cac("rspress").version(packageJson.version).help();
|
|
92
66
|
var landingMessage = `🔥 Rspress v${packageJson.version}
|
93
67
|
`;
|
94
68
|
var rainbowMessage = gradient.cristal(landingMessage);
|
95
|
-
console.log(
|
69
|
+
console.log(chalk.bold(rainbowMessage));
|
70
|
+
var setNodeEnv = (env) => {
|
71
|
+
process.env.NODE_ENV = env;
|
72
|
+
};
|
96
73
|
cli.option("--config [config]", "Specify the path to the config file");
|
97
74
|
cli.command("[root]", "start dev server").alias("dev").action(async (root, options) => {
|
75
|
+
setNodeEnv("development");
|
98
76
|
const cwd = process.cwd();
|
77
|
+
let docDirectory;
|
78
|
+
let cliWatcher;
|
79
|
+
let devServer;
|
99
80
|
const startDevServer = async () => {
|
100
81
|
const config = await loadConfigFile(options.config);
|
101
|
-
|
82
|
+
docDirectory = config.root || path2.join(cwd, root ?? "docs");
|
83
|
+
devServer = await dev({
|
102
84
|
appDirectory: cwd,
|
103
|
-
docDirectory
|
104
|
-
config
|
105
|
-
logger
|
85
|
+
docDirectory,
|
86
|
+
config
|
106
87
|
});
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
88
|
+
cliWatcher = chokidar.watch([
|
89
|
+
`${cwd}/**/{${CONFIG_FILES.join(",")}}`,
|
90
|
+
docDirectory
|
91
|
+
], {
|
92
|
+
ignoreInitial: true,
|
93
|
+
ignored: [
|
94
|
+
"**/node_modules/**",
|
95
|
+
"**/.git/**",
|
96
|
+
"**/.DS_Store/**"
|
97
|
+
]
|
98
|
+
});
|
99
|
+
cliWatcher.on("all", async (eventName, filepath) => {
|
100
|
+
if (eventName === "add" || eventName === "unlink" || eventName === "change" && CONFIG_FILES.includes(path2.basename(filepath))) {
|
101
|
+
console.log(`
|
102
|
+
✨ ${eventName} ${chalk.green(path2.relative(cwd, filepath))}, dev server will restart...
|
120
103
|
`);
|
121
|
-
|
122
|
-
|
104
|
+
await devServer.close();
|
105
|
+
await cliWatcher.close();
|
106
|
+
await startDevServer();
|
107
|
+
}
|
108
|
+
});
|
109
|
+
};
|
110
|
+
await startDevServer();
|
123
111
|
const exitProcess = async () => {
|
124
112
|
await cliWatcher.close();
|
125
113
|
await devServer.close();
|
@@ -128,6 +116,7 @@ cli.command("[root]", "start dev server").alias("dev").action(async (root, optio
|
|
128
116
|
process.on("SIGTERM", exitProcess);
|
129
117
|
});
|
130
118
|
cli.command("build [root]").option("-c --config <config>", "specify config file").action(async (root, options) => {
|
119
|
+
setNodeEnv("production");
|
131
120
|
const cwd = process.cwd();
|
132
121
|
const config = await loadConfigFile(options.config);
|
133
122
|
await build({
|
@@ -136,7 +125,8 @@ cli.command("build [root]").option("-c --config <config>", "specify config file"
|
|
136
125
|
config
|
137
126
|
});
|
138
127
|
});
|
139
|
-
cli.command("preview
|
128
|
+
cli.command("preview").alias("serve").option("-c --config <config>", "specify config file").option("--port [port]", "port number").option("--host [host]", "hostname").action(async (options) => {
|
129
|
+
setNodeEnv("production");
|
140
130
|
const { port, host } = options || {};
|
141
131
|
const config = await loadConfigFile(options?.config);
|
142
132
|
await serve({
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "rspress",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.11",
|
4
4
|
"type": "module",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"main": "./dist/index.js",
|
@@ -28,12 +28,12 @@
|
|
28
28
|
}
|
29
29
|
},
|
30
30
|
"dependencies": {
|
31
|
-
"@modern-js/node-bundle-require": "2.
|
31
|
+
"@modern-js/node-bundle-require": "2.34.0",
|
32
32
|
"cac": "^6.7.14",
|
33
33
|
"chokidar": "^3.5.3",
|
34
34
|
"chalk": "5.3.0",
|
35
35
|
"gradient-string": "2.0.2",
|
36
|
-
"@rspress/core": "0.0.
|
36
|
+
"@rspress/core": "0.0.11"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
39
|
"@types/jest": "~29.2.4",
|