rspress 0.0.8 → 0.0.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.
Files changed (2) hide show
  1. package/dist/index.js +37 -47
  2. 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 chalk2 from "chalk";
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(chalk2.bold(rainbowMessage));
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
- return dev({
82
+ docDirectory = config.root || path2.join(cwd, root ?? "docs");
83
+ devServer = await dev({
102
84
  appDirectory: cwd,
103
- docDirectory: config.root || path2.join(cwd, root ?? "docs"),
104
- config,
105
- logger
85
+ docDirectory,
86
+ config
106
87
  });
107
- };
108
- let devServer = await startDevServer();
109
- const cliWatcher = chokidar.watch(`${cwd}/**/{${CONFIG_FILES.join(",")}}`, {
110
- ignoreInitial: true,
111
- ignored: [
112
- "**/node_modules/**",
113
- "**/.git/**",
114
- "**/.DS_Store/**"
115
- ]
116
- });
117
- cliWatcher.on("all", async (_eventName, filepath) => {
118
- await devServer.close();
119
- console.log(`${chalk2.green(path2.relative(cwd, filepath))} has changed, dev server will restart...
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
- devServer = await startDevServer();
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({
@@ -137,6 +126,7 @@ cli.command("build [root]").option("-c --config <config>", "specify config file"
137
126
  });
138
127
  });
139
128
  cli.command("preview [root]").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.8",
3
+ "version": "0.0.10",
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.33.0",
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.8"
36
+ "@rspress/core": "0.0.10"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/jest": "~29.2.4",