rspress 0.0.0 → 0.0.1
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/LICENSE +21 -0
- package/README.md +1 -0
- package/bin/rspress.js +3 -0
- package/config.ts +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +116 -0
- package/package.json +64 -9
- package/runtime.ts +1 -0
- package/theme.ts +2 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# rspress
|
package/bin/rspress.js
ADDED
package/config.ts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
// src/index.ts
|
2
|
+
import { createRequire as createRequire2 } from "module";
|
3
|
+
import path2 from "path";
|
4
|
+
import { cac } from "cac";
|
5
|
+
import { build, dev, serve } from "@rspress/core";
|
6
|
+
import chokidar from "chokidar";
|
7
|
+
import chalk from "chalk";
|
8
|
+
|
9
|
+
// src/config/loadConfigFile.ts
|
10
|
+
import fs from "fs";
|
11
|
+
import path from "path";
|
12
|
+
import { createRequire } from "module";
|
13
|
+
|
14
|
+
// src/constants.ts
|
15
|
+
var DEFAULT_CONFIG_NAME = "rspress.config";
|
16
|
+
var DEFAULT_EXTENSIONS = [
|
17
|
+
".js",
|
18
|
+
".ts",
|
19
|
+
".mjs",
|
20
|
+
".mts",
|
21
|
+
".cjs",
|
22
|
+
".cts"
|
23
|
+
];
|
24
|
+
|
25
|
+
// src/config/loadConfigFile.ts
|
26
|
+
var findConfig = (basePath) => {
|
27
|
+
return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
|
28
|
+
};
|
29
|
+
async function loadConfigFile(customConfigFile) {
|
30
|
+
const baseDir = process.cwd();
|
31
|
+
let configFilePath = "";
|
32
|
+
if (customConfigFile) {
|
33
|
+
if (path.isAbsolute(customConfigFile)) {
|
34
|
+
configFilePath = customConfigFile;
|
35
|
+
} else {
|
36
|
+
configFilePath = path.join(baseDir, customConfigFile);
|
37
|
+
}
|
38
|
+
} else {
|
39
|
+
configFilePath = findConfig(path.join(baseDir, DEFAULT_CONFIG_NAME));
|
40
|
+
}
|
41
|
+
if (!configFilePath) {
|
42
|
+
console.log("no config file found");
|
43
|
+
return {};
|
44
|
+
}
|
45
|
+
const require3 = createRequire(import.meta.url);
|
46
|
+
const nodeBundleRequire = require3("@modern-js/node-bundle-require");
|
47
|
+
let result = await nodeBundleRequire.bundleRequire(configFilePath, {
|
48
|
+
require: require3
|
49
|
+
});
|
50
|
+
if (result && typeof result === "object" && "default" in result) {
|
51
|
+
result = result.default || {};
|
52
|
+
}
|
53
|
+
return result;
|
54
|
+
}
|
55
|
+
|
56
|
+
// src/index.ts
|
57
|
+
var require2 = createRequire2(import.meta.url);
|
58
|
+
var CONFIG_FILES = [
|
59
|
+
"rspress.config.ts",
|
60
|
+
"rspress.config.js",
|
61
|
+
"_meta.json"
|
62
|
+
];
|
63
|
+
var packageJson = require2("../package.json");
|
64
|
+
var cli = cac("rspress").version(packageJson.version).help();
|
65
|
+
cli.option("--config [config]", "Specify the path to the config file");
|
66
|
+
cli.command("[root]", "start dev server").alias("dev").action(async (root, options) => {
|
67
|
+
const cwd = process.cwd();
|
68
|
+
const startDevServer = async () => {
|
69
|
+
const config = await loadConfigFile(options.config);
|
70
|
+
return dev({
|
71
|
+
appDirectory: cwd,
|
72
|
+
docDirectory: config.root || path2.join(cwd, root ?? "docs"),
|
73
|
+
config
|
74
|
+
});
|
75
|
+
};
|
76
|
+
let devServer = await startDevServer();
|
77
|
+
const cliWatcher = chokidar.watch(`${cwd}/**/{${CONFIG_FILES.join(",")}}`, {
|
78
|
+
ignoreInitial: true,
|
79
|
+
ignored: [
|
80
|
+
"**/node_modules/**",
|
81
|
+
"**/.git/**",
|
82
|
+
"**/.DS_Store/**"
|
83
|
+
]
|
84
|
+
});
|
85
|
+
cliWatcher.on("all", async (_eventName, filepath) => {
|
86
|
+
await devServer.close();
|
87
|
+
console.log(`${chalk.green(path2.relative(cwd, filepath))} has changed, dev server will restart...
|
88
|
+
`);
|
89
|
+
devServer = await startDevServer();
|
90
|
+
});
|
91
|
+
const exitProcess = async () => {
|
92
|
+
await cliWatcher.close();
|
93
|
+
await devServer.close();
|
94
|
+
};
|
95
|
+
process.on("SIGINT", exitProcess);
|
96
|
+
process.on("SIGTERM", exitProcess);
|
97
|
+
});
|
98
|
+
cli.command("build [root]").option("-c --config <config>", "specify config file").action(async (root, options) => {
|
99
|
+
const cwd = process.cwd();
|
100
|
+
const config = await loadConfigFile(options.config);
|
101
|
+
await build({
|
102
|
+
appDirectory: cwd,
|
103
|
+
docDirectory: config.root || path2.join(cwd, root ?? "docs"),
|
104
|
+
config
|
105
|
+
});
|
106
|
+
});
|
107
|
+
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) => {
|
108
|
+
const { port, host } = options || {};
|
109
|
+
const config = await loadConfigFile(options?.config);
|
110
|
+
await serve({
|
111
|
+
config,
|
112
|
+
host,
|
113
|
+
port
|
114
|
+
});
|
115
|
+
});
|
116
|
+
cli.parse();
|
package/package.json
CHANGED
@@ -1,12 +1,67 @@
|
|
1
1
|
{
|
2
2
|
"name": "rspress",
|
3
|
-
"version": "0.0.
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
7
|
-
|
3
|
+
"version": "0.0.1",
|
4
|
+
"type": "module",
|
5
|
+
"types": "./dist/index.d.ts",
|
6
|
+
"main": "./dist/index.js",
|
7
|
+
"module": "./dist/index.js",
|
8
|
+
"bin": {
|
9
|
+
"rspress": "./bin/rspress.js"
|
10
|
+
},
|
11
|
+
"repository": {
|
12
|
+
"type": "git",
|
13
|
+
"url": "https://github.com/web-infra-dev/rspress",
|
14
|
+
"directory": "packages/cli"
|
15
|
+
},
|
16
|
+
"exports": {
|
17
|
+
".": {
|
18
|
+
"default": "./dist/index.js"
|
19
|
+
},
|
20
|
+
"./runtime": {
|
21
|
+
"default": "./runtime.ts"
|
22
|
+
},
|
23
|
+
"./theme": {
|
24
|
+
"default": "./theme.ts"
|
25
|
+
},
|
26
|
+
"./config": {
|
27
|
+
"default": "./config.ts"
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"dependencies": {
|
31
|
+
"@modern-js/node-bundle-require": "2.30.0",
|
32
|
+
"cac": "^6.7.14",
|
33
|
+
"chokidar": "^3.5.3",
|
34
|
+
"chalk": "5.3.0",
|
35
|
+
"@rspress/core": "0.0.1"
|
8
36
|
},
|
9
|
-
"
|
10
|
-
|
11
|
-
|
12
|
-
|
37
|
+
"devDependencies": {
|
38
|
+
"@types/jest": "~29.2.4",
|
39
|
+
"@types/node": "~16.11.7",
|
40
|
+
"@types/react": "~18.0.26",
|
41
|
+
"rimraf": "~3.0.2",
|
42
|
+
"ts-node": "^10.9.1",
|
43
|
+
"typescript": "~5.0.4"
|
44
|
+
},
|
45
|
+
"sideEffects": [],
|
46
|
+
"publishConfig": {
|
47
|
+
"access": "public",
|
48
|
+
"provenance": true,
|
49
|
+
"registry": "https://registry.npmjs.org/"
|
50
|
+
},
|
51
|
+
"files": [
|
52
|
+
"bin",
|
53
|
+
"dist",
|
54
|
+
"runtime.ts",
|
55
|
+
"theme.ts",
|
56
|
+
"config.ts"
|
57
|
+
],
|
58
|
+
"scripts": {
|
59
|
+
"dev": "modern build -w",
|
60
|
+
"build": "modern build",
|
61
|
+
"build:watch": "modern build -w",
|
62
|
+
"test": "vitest run",
|
63
|
+
"reset": "rimraf ./**/node_modules",
|
64
|
+
"new": "modern new",
|
65
|
+
"upgrade": "modern upgrade"
|
66
|
+
}
|
67
|
+
}
|
package/runtime.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from '@rspress/core/runtime';
|
package/theme.ts
ADDED