@hulog/cli 0.0.0-stage → 0.1.6
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 +110 -2
- package/dist/commands/build.d.ts +4 -0
- package/dist/commands/build.js +9 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/clean.d.ts +5 -0
- package/dist/commands/clean.js +15 -0
- package/dist/commands/clean.js.map +1 -0
- package/dist/commands/dev.d.ts +5 -0
- package/dist/commands/dev.js +119 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +72 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/new.d.ts +8 -0
- package/dist/commands/new.js +62 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/publish.d.ts +7 -0
- package/dist/commands/publish.js +76 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/render.d.ts +16 -0
- package/dist/commands/render.js +17 -0
- package/dist/commands/render.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/run.d.ts +4 -0
- package/dist/run.js +15 -0
- package/dist/run.js.map +1 -0
- package/package.json +60 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Huzerovo
|
|
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
CHANGED
|
@@ -1,3 +1,111 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hulog/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
hulog 静态博客生成器的命令行工具:构建站点、启动开发服务器、管理文章,以及把单个 Markdown 渲染为自包含 HTML。
|
|
4
|
+
|
|
5
|
+
> 构建逻辑由 [`@hulog/core`](https://www.npmjs.com/package/@hulog/core) 提供,CLI 仅做薄封装。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
要求 Node.js >= 22.12.0。
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -D @hulog/cli
|
|
13
|
+
# 或全局安装
|
|
14
|
+
npm install -g @hulog/cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 快速开始
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
mkdir my-blog && cd my-blog
|
|
21
|
+
npm init -y
|
|
22
|
+
npm install -D @hulog/cli
|
|
23
|
+
|
|
24
|
+
# 生成 blog.config.ts、theme.config.ts 与内容目录
|
|
25
|
+
npx hulog init
|
|
26
|
+
|
|
27
|
+
# 将主题放入 themes/<name>/,或在 blog.config.ts 中指定已安装的主题包
|
|
28
|
+
npx hulog dev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
开发服务器默认监听 `http://localhost:3000`,生产构建输出到 `dist/`。
|
|
32
|
+
|
|
33
|
+
## 命令
|
|
34
|
+
|
|
35
|
+
| 命令 | 说明 |
|
|
36
|
+
|------|------|
|
|
37
|
+
| `hulog init [dir]` | 创建站点目录、默认配置与示例页面 |
|
|
38
|
+
| `hulog dev` | 启动开发服务器(构建 + 静态服务 + WebSocket 热重载) |
|
|
39
|
+
| `hulog build` | 生产构建到 `dist/` |
|
|
40
|
+
| `hulog clean` | 删除 `dist/` |
|
|
41
|
+
| `hulog new <title>` | 新建草稿(默认写入 `content/drafts/`) |
|
|
42
|
+
| `hulog publish [slug]` | 发布草稿到集合(补 `date`、移除 `draft`) |
|
|
43
|
+
| `hulog render <file.md>` | 将单个 Markdown 渲染为自包含 HTML |
|
|
44
|
+
|
|
45
|
+
常用参数:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
hulog dev -p 4000 -b ./my-blog # 端口 / 站点根目录
|
|
49
|
+
hulog build -b ./my-blog
|
|
50
|
+
hulog new "Hello World" -c posts # 指定集合
|
|
51
|
+
hulog new "Hello World" --no-draft # 直接创建到集合
|
|
52
|
+
hulog publish hello-world # 发布指定草稿
|
|
53
|
+
hulog publish --all --collection posts
|
|
54
|
+
hulog render notes.md -o notes.html -b . --layout post
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
全局 `-v/--verbose`、`-q/--quiet` 分别输出 debug / warn 级别日志。
|
|
58
|
+
|
|
59
|
+
## 配置
|
|
60
|
+
|
|
61
|
+
站点根目录的 `blog.config.ts` 定义站点信息与内容集合:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
export default {
|
|
65
|
+
siteTitle: "My Blog",
|
|
66
|
+
theme: "default",
|
|
67
|
+
contentDir: "content",
|
|
68
|
+
assetsDir: "assets",
|
|
69
|
+
collections: [
|
|
70
|
+
{
|
|
71
|
+
name: "posts",
|
|
72
|
+
sourceDir: "posts",
|
|
73
|
+
routePattern: "/post/:slug/",
|
|
74
|
+
defaultLayout: "post",
|
|
75
|
+
sortBy: "date",
|
|
76
|
+
sortOrder: "desc",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "pages",
|
|
80
|
+
sourceDir: "pages",
|
|
81
|
+
routePattern: "/:slug/",
|
|
82
|
+
defaultLayout: "page",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
常见目录:
|
|
89
|
+
|
|
90
|
+
```text
|
|
91
|
+
content/posts/ 文章
|
|
92
|
+
content/pages/ 独立页面
|
|
93
|
+
content/drafts/ 草稿
|
|
94
|
+
assets/ 全局资源
|
|
95
|
+
public/ 原样复制到 dist/
|
|
96
|
+
themes/ 本地主题
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 单文件渲染
|
|
100
|
+
|
|
101
|
+
`render` 会复用站点配置与主题,把纯 Markdown 输出为自包含 HTML(CSS、本地 JS 与图片内联):
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
hulog render ./notes.md -b . -o ./notes.html
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 链接
|
|
108
|
+
|
|
109
|
+
- 仓库:https://github.com/Huzerovo/hulog
|
|
110
|
+
- 问题反馈:https://github.com/Huzerovo/hulog/issues
|
|
111
|
+
- 许可证:MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { build, Logger } from "@hulog/core";
|
|
2
|
+
export async function buildCmd(opts) {
|
|
3
|
+
const logger = Logger.getLogger("cli:build");
|
|
4
|
+
const start = Date.now();
|
|
5
|
+
const result = await build({ cwd: opts.base || process.cwd() });
|
|
6
|
+
const ms = Date.now() - start;
|
|
7
|
+
logger.info(`构建完成: ${result.pages.length} 个页面, ${result.site.assets.length} 个资源 (${ms}ms)`);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAK5C,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAkB;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAChE,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAC9B,MAAM,CAAC,IAAI,CACT,SAAS,MAAM,CAAC,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,SAAS,EAAE,KAAK,CAC/E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Logger } from "@hulog/core";
|
|
4
|
+
export function cleanCmd(opts = {}) {
|
|
5
|
+
const logger = Logger.getLogger("cli:clean");
|
|
6
|
+
const dist = path.join(opts.base ?? process.cwd(), "dist");
|
|
7
|
+
if (fs.existsSync(dist)) {
|
|
8
|
+
fs.rmSync(dist, { recursive: true, force: true });
|
|
9
|
+
logger.info("已清理 dist/");
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
logger.info("dist/ 不存在,无需清理");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=clean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,MAAM,UAAU,QAAQ,CAAC,OAAqB,EAAE;IAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;IAC3D,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC3B,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import { WebSocketServer, WebSocket } from "ws";
|
|
5
|
+
import chokidar from "chokidar";
|
|
6
|
+
import { build, Logger } from "@hulog/core";
|
|
7
|
+
const MIME = {
|
|
8
|
+
".html": "text/html; charset=utf-8",
|
|
9
|
+
".css": "text/css; charset=utf-8",
|
|
10
|
+
".js": "text/javascript; charset=utf-8",
|
|
11
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
12
|
+
".json": "application/json",
|
|
13
|
+
".png": "image/png",
|
|
14
|
+
".jpg": "image/jpeg",
|
|
15
|
+
".jpeg": "image/jpeg",
|
|
16
|
+
".gif": "image/gif",
|
|
17
|
+
".webp": "image/webp",
|
|
18
|
+
".svg": "image/svg+xml",
|
|
19
|
+
".ico": "image/x-icon",
|
|
20
|
+
".woff": "font/woff",
|
|
21
|
+
".woff2": "font/woff2",
|
|
22
|
+
".ttf": "font/ttf",
|
|
23
|
+
};
|
|
24
|
+
/** 注入热重载客户端脚本(WebSocket 收到 reload 消息才刷新;断线重连也刷新一次) */
|
|
25
|
+
const RELOAD_SCRIPT = (port) => `<script>
|
|
26
|
+
(function(){
|
|
27
|
+
var ws = new WebSocket("ws://" + location.host + "/__reload");
|
|
28
|
+
ws.onmessage = function(e){ if (e.data === "reload") location.reload(); };
|
|
29
|
+
ws.onclose = function(){ setTimeout(function(){ location.reload(); }, 1000); };
|
|
30
|
+
})();
|
|
31
|
+
</script>`;
|
|
32
|
+
export async function devCmd(opts) {
|
|
33
|
+
const logger = Logger.getLogger("cli:dev");
|
|
34
|
+
const cwd = opts.base;
|
|
35
|
+
const port = opts.port;
|
|
36
|
+
const distDir = path.join(cwd, "dist");
|
|
37
|
+
// 静态服务器
|
|
38
|
+
const server = http.createServer((req, res) => {
|
|
39
|
+
const rawPath = (req.url ?? "/").split("?")[0];
|
|
40
|
+
const urlPath = decodeURIComponent(rawPath);
|
|
41
|
+
let rel = urlPath === "/" ? "index.html" : urlPath.replace(/^\/+/, "");
|
|
42
|
+
let abs = path.join(distDir, rel);
|
|
43
|
+
// 目录名可能是编码形式(如 /categories/%E9%9A%8F%E7%AC%94/),原样路径也尝试
|
|
44
|
+
if (!abs.startsWith(distDir)) {
|
|
45
|
+
res.writeHead(403);
|
|
46
|
+
res.end("forbidden");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!fs.existsSync(abs)) {
|
|
50
|
+
const rawRel = rawPath === "/" ? "index.html" : rawPath.replace(/^\/+/, "");
|
|
51
|
+
const rawAbs = path.join(distDir, rawRel);
|
|
52
|
+
if (rawAbs.startsWith(distDir) && fs.existsSync(rawAbs))
|
|
53
|
+
abs = rawAbs;
|
|
54
|
+
}
|
|
55
|
+
if (!fs.existsSync(abs) || fs.statSync(abs).isDirectory()) {
|
|
56
|
+
abs = path.join(abs, "index.html");
|
|
57
|
+
}
|
|
58
|
+
if (!fs.existsSync(abs)) {
|
|
59
|
+
res.writeHead(404);
|
|
60
|
+
res.end("404 Not Found");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const ext = path.extname(abs).toLowerCase();
|
|
64
|
+
res.writeHead(200, {
|
|
65
|
+
"Content-Type": MIME[ext] ?? "application/octet-stream",
|
|
66
|
+
// 开发服务器禁用缓存:避免浏览器继续使用旧版 JS/CSS(改动后必须拿到最新内容)
|
|
67
|
+
"Cache-Control": "no-store, must-revalidate",
|
|
68
|
+
});
|
|
69
|
+
let body = fs.readFileSync(abs);
|
|
70
|
+
if (ext === ".html") {
|
|
71
|
+
// 注入热重载脚本
|
|
72
|
+
body = Buffer.from(String(body).replace("</body>", RELOAD_SCRIPT(port) + "</body>"));
|
|
73
|
+
}
|
|
74
|
+
res.end(body);
|
|
75
|
+
});
|
|
76
|
+
// WebSocket 热重载:仅广播 "reload",连接建立时不发消息(否则浏览器无条件刷新导致循环)
|
|
77
|
+
const wss = new WebSocketServer({ server, path: "/__reload" });
|
|
78
|
+
const notifyReload = () => {
|
|
79
|
+
for (const client of wss.clients) {
|
|
80
|
+
if (client.readyState === WebSocket.OPEN)
|
|
81
|
+
client.send("reload");
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// 首次构建(dev 模式:渲染草稿)
|
|
85
|
+
await rebuild("initial");
|
|
86
|
+
await new Promise((resolve) => server.listen(port, "0.0.0.0", resolve));
|
|
87
|
+
logger.info(`dev server: http://localhost:${port}(草稿已启用渲染)`);
|
|
88
|
+
// 监听变化 → 防抖重建
|
|
89
|
+
let timer = null;
|
|
90
|
+
const watcher = chokidar.watch([
|
|
91
|
+
path.join(cwd, "content"),
|
|
92
|
+
path.join(cwd, "themes"),
|
|
93
|
+
path.join(cwd, "blog.config.ts"),
|
|
94
|
+
path.join(cwd, "theme.config.ts"),
|
|
95
|
+
path.join(cwd, "assets"),
|
|
96
|
+
path.join(cwd, "public"),
|
|
97
|
+
], { ignoreInitial: true });
|
|
98
|
+
watcher.on("all", (_event, file) => {
|
|
99
|
+
if (timer)
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
timer = setTimeout(() => {
|
|
102
|
+
rebuild("change").catch((e) => logger.error(`重建失败: ${e.message}`));
|
|
103
|
+
}, 200);
|
|
104
|
+
});
|
|
105
|
+
async function rebuild(reason) {
|
|
106
|
+
const start = Date.now();
|
|
107
|
+
try {
|
|
108
|
+
const result = await build({ cwd, dev: true });
|
|
109
|
+
notifyReload();
|
|
110
|
+
logger.info(`[${reason}] 重建完成: ${result.pages.length} 页 (${Date.now() - start}ms)`);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
logger.error(`[${reason}] 构建失败: ${e.message}`);
|
|
114
|
+
// 构建失败也通知刷新,让浏览器显示错误页
|
|
115
|
+
notifyReload();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAO5C,MAAM,IAAI,GAA2B;IACnC,OAAO,EAAE,0BAA0B;IACnC,MAAM,EAAE,yBAAyB;IACjC,KAAK,EAAE,gCAAgC;IACvC,MAAM,EAAE,gCAAgC;IACxC,OAAO,EAAE,kBAAkB;IAC3B,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE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AC;KACzB,EACD,EAAE,aAAa,EAAE,IAAI,EAAE,CACxB,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACjC,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,SAAU,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAChF,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;IAEH,KAAK,UAAU,OAAO,CAAC,MAAc;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;YAC/C,YAAY,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CACT,IAAI,MAAM,WAAW,MAAM,CAAC,KAAK,CAAC,MAAM,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,KAAK,CACvE,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,WAAY,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1D,sBAAsB;YACtB,YAAY,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initCmd(dir: string): void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Logger } from "@hulog/core";
|
|
4
|
+
const CONFIG_TEMPLATE = `
|
|
5
|
+
export default {
|
|
6
|
+
siteTitle: "My Blog",
|
|
7
|
+
description: "A static blog",
|
|
8
|
+
url: "https://example.com",
|
|
9
|
+
theme: "default",
|
|
10
|
+
contentDir: "content",
|
|
11
|
+
assetsDir: "assets",
|
|
12
|
+
collections: [
|
|
13
|
+
{
|
|
14
|
+
name: "posts",
|
|
15
|
+
sourceDir: "posts",
|
|
16
|
+
routePattern: "/post/:slug/",
|
|
17
|
+
defaultLayout: "post",
|
|
18
|
+
sortBy: "date",
|
|
19
|
+
sortOrder: "desc",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "pages",
|
|
23
|
+
sourceDir: "pages",
|
|
24
|
+
routePattern: "/:slug/",
|
|
25
|
+
defaultLayout: "page",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
markdown: {
|
|
29
|
+
highlight: true,
|
|
30
|
+
katex: true,
|
|
31
|
+
},
|
|
32
|
+
server: {
|
|
33
|
+
port: 3000,
|
|
34
|
+
hot: true,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
`;
|
|
38
|
+
const THEME_CONFIG_TEMPLATE = `/**
|
|
39
|
+
* 主题配置(可选):独立于 blog.config.ts,覆盖主题自带默认配置。
|
|
40
|
+
* 不创建此文件时使用主题默认配置;这里只写需要覆盖的键即可。
|
|
41
|
+
*/
|
|
42
|
+
export default {
|
|
43
|
+
// 示例:
|
|
44
|
+
// menu: { home: { title: "首页", link: "/" } },
|
|
45
|
+
};
|
|
46
|
+
`;
|
|
47
|
+
export function initCmd(dir) {
|
|
48
|
+
const logger = Logger.getLogger("cli:init");
|
|
49
|
+
const target = path.resolve(process.cwd(), dir);
|
|
50
|
+
if (fs.existsSync(path.join(target, "blog.config.ts"))) {
|
|
51
|
+
logger.error("目标目录已存在 blog.config.ts,已中止");
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
const dirs = [
|
|
55
|
+
"content/posts",
|
|
56
|
+
"content/drafts",
|
|
57
|
+
"content/pages",
|
|
58
|
+
"themes",
|
|
59
|
+
"assets",
|
|
60
|
+
"public",
|
|
61
|
+
];
|
|
62
|
+
for (const d of dirs) {
|
|
63
|
+
fs.mkdirSync(path.join(target, d), { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
fs.writeFileSync(path.join(target, "blog.config.ts"), CONFIG_TEMPLATE);
|
|
66
|
+
fs.writeFileSync(path.join(target, "theme.config.ts"), THEME_CONFIG_TEMPLATE);
|
|
67
|
+
fs.writeFileSync(path.join(target, "content/pages/about.md"), `---\ntitle: 关于我\nlayout: page\n---\n\n这里写关于你的介绍。\n`);
|
|
68
|
+
fs.writeFileSync(path.join(target, ".gitignore"), "node_modules/\ndist/\n");
|
|
69
|
+
logger.info(`站点已创建: ${target}`);
|
|
70
|
+
logger.info("下一步:将主题放入 themes/ 目录后运行 " + process.title + " dev");
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCvB,CAAC;AAEF,MAAM,qBAAqB,GAAG;;;;;;;;CAQ7B,CAAC;AAEF,MAAM,UAAU,OAAO,CAAC,GAAW;IACjC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;IAChD,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,GAAG;QACX,eAAe;QACf,gBAAgB;QAChB,eAAe;QACf,QAAQ;QACR,QAAQ;QACR,QAAQ;KACT,CAAC;IACF,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,eAAe,CAAC,CAAC;IACvE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAC9E,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,wBAAwB,CAAC,EAC3C,oDAAoD,CACrD,CAAC;IACF,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,wBAAwB,CACzB,CAAC;IACF,MAAM,CAAC,IAAI,CAAC,UAAU,MAAM,EAAE,CAAC,CAAC;IAChC,MAAM,CAAC,IAAI,CAAC,0BAA0B,GAAG,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Logger, loadSiteConfig } from "@hulog/core";
|
|
4
|
+
/** 标题 → slug(小写、空格转连字符、保留中文字符) */
|
|
5
|
+
export function slugify(title) {
|
|
6
|
+
const s = title
|
|
7
|
+
.trim()
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.replace(/\s+/g, "-")
|
|
10
|
+
.replace(/[^\w\u4e00-\u9fa5-]/g, "")
|
|
11
|
+
.replace(/-+/g, "-");
|
|
12
|
+
return s || "untitled";
|
|
13
|
+
}
|
|
14
|
+
export async function newCmd(opts) {
|
|
15
|
+
const logger = Logger.getLogger("cli:new");
|
|
16
|
+
const cwd = process.cwd();
|
|
17
|
+
const config = await loadSiteConfig(cwd);
|
|
18
|
+
const draftByDefault = opts.draft !== false;
|
|
19
|
+
const contentRoot = path.join(cwd, config.contentDir ?? "content");
|
|
20
|
+
// 目标集合与目录
|
|
21
|
+
let collectionName = opts.collection;
|
|
22
|
+
if (!collectionName) {
|
|
23
|
+
if (draftByDefault) {
|
|
24
|
+
// 草稿区不属于集合,目标目录为 drafts/
|
|
25
|
+
const draftsDir = path.join(contentRoot, "drafts");
|
|
26
|
+
fs.mkdirSync(draftsDir, { recursive: true });
|
|
27
|
+
const file = path.join(draftsDir, slugify(opts.title) + ".md");
|
|
28
|
+
writeDraft(file, opts.title);
|
|
29
|
+
logger.info(`草稿已创建: ${path.relative(cwd, file)}`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// 直接发布:默认第一个集合
|
|
33
|
+
collectionName = config.collections[0]?.name;
|
|
34
|
+
if (!collectionName) {
|
|
35
|
+
logger.error("未配置集合,无法创建文章");
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const col = config.collections.find((c) => c.name === collectionName);
|
|
40
|
+
if (!col) {
|
|
41
|
+
logger.error(`集合不存在: ${collectionName}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
const dir = path.join(contentRoot, col.sourceDir);
|
|
45
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
46
|
+
const slug = slugify(opts.title);
|
|
47
|
+
const file = path.join(dir, slug + ".md");
|
|
48
|
+
if (fs.existsSync(file)) {
|
|
49
|
+
logger.error(`文件已存在: ${path.relative(cwd, file)}`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
const fm = [`title: ${JSON.stringify(opts.title)}`];
|
|
53
|
+
if (col.sortBy === "date") {
|
|
54
|
+
fm.push(`date: ${new Date().toISOString().slice(0, 10)}`);
|
|
55
|
+
}
|
|
56
|
+
fs.writeFileSync(file, `---\n${fm.join("\n")}\n---\n\n`);
|
|
57
|
+
logger.info(`文章已创建: ${path.relative(cwd, file)}`);
|
|
58
|
+
}
|
|
59
|
+
function writeDraft(file, title) {
|
|
60
|
+
fs.writeFileSync(file, `---\ntitle: ${JSON.stringify(title)}\n---\n\n`);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=new.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../src/commands/new.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAQrD,kCAAkC;AAClC,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,MAAM,CAAC,GAAG,KAAK;SACZ,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC;SACnC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACvB,OAAO,CAAC,IAAI,UAAU,CAAC;AACzB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAgB;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,KAAK,KAAK,CA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AACJ,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import matter from "gray-matter";
|
|
4
|
+
import { Logger, loadSiteConfig } from "@hulog/core";
|
|
5
|
+
import { slugify } from "./new.js";
|
|
6
|
+
export async function publishCmd(opts) {
|
|
7
|
+
const logger = Logger.getLogger("cli:publish");
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
const config = await loadSiteConfig(cwd);
|
|
10
|
+
const contentRoot = path.join(cwd, config.contentDir ?? "content");
|
|
11
|
+
const draftsDir = path.join(contentRoot, "drafts");
|
|
12
|
+
if (!fs.existsSync(draftsDir)) {
|
|
13
|
+
logger.error("草稿区不存在: content/drafts/");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
// 目标集合
|
|
17
|
+
const targetName = opts.collection ?? "posts";
|
|
18
|
+
const col = config.collections.find((c) => c.name === targetName);
|
|
19
|
+
if (!col) {
|
|
20
|
+
logger.error(`目标集合 "${targetName}" 不存在(可用 --collection 指定,当前集合: ${config.collections.map((c) => c.name).join(", ")})`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
const targetDir = path.join(contentRoot, col.sourceDir);
|
|
24
|
+
// 收集草稿文件
|
|
25
|
+
const drafts = fs
|
|
26
|
+
.readdirSync(draftsDir, { withFileTypes: true })
|
|
27
|
+
.filter((e) => e.isFile() && /\.md$/i.test(e.name))
|
|
28
|
+
.map((e) => e.name);
|
|
29
|
+
let targets;
|
|
30
|
+
if (opts.all) {
|
|
31
|
+
targets = drafts;
|
|
32
|
+
}
|
|
33
|
+
else if (opts.slug) {
|
|
34
|
+
const slug = slugify(opts.slug);
|
|
35
|
+
const match = drafts.find((f) => f.replace(/\.md$/i, "") === slug);
|
|
36
|
+
if (!match) {
|
|
37
|
+
logger.error(`草稿不存在: ${slug}(可用 --all 发布全部)`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
targets = [match];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
logger.error("请指定草稿 slug 或使用 --all");
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
if (targets.length === 0) {
|
|
47
|
+
logger.info("草稿区为空,无内容可发布");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const file of targets) {
|
|
51
|
+
const src = path.join(draftsDir, file);
|
|
52
|
+
const slug = file.replace(/\.md$/i, "");
|
|
53
|
+
const dest = path.join(targetDir, file);
|
|
54
|
+
if (fs.existsSync(dest)) {
|
|
55
|
+
logger.error(`冲突:目标已存在同名文件,已跳过: ${path.relative(cwd, dest)}`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// 处理 front-matter:补 date、去 draft
|
|
59
|
+
const raw = fs.readFileSync(src, "utf8");
|
|
60
|
+
const { data, content } = matter(raw);
|
|
61
|
+
if (opts.autoDate !== false && !data.date) {
|
|
62
|
+
data.date = new Date().toISOString().slice(0, 10);
|
|
63
|
+
}
|
|
64
|
+
delete data.draft;
|
|
65
|
+
const out = matter.stringify(content, data);
|
|
66
|
+
fs.writeFileSync(dest, out);
|
|
67
|
+
fs.rmSync(src);
|
|
68
|
+
// 移动同名专属资源目录
|
|
69
|
+
const assetDir = path.join(draftsDir, slug);
|
|
70
|
+
if (fs.existsSync(assetDir)) {
|
|
71
|
+
fs.renameSync(assetDir, path.join(targetDir, slug));
|
|
72
|
+
}
|
|
73
|
+
logger.info(`已发布: ${path.relative(cwd, dest)}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/commands/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,a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AC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;QACtD,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface RenderCommandOptions {
|
|
2
|
+
/** 输入 markdown 文件 */
|
|
3
|
+
file: string;
|
|
4
|
+
/** 输出 html 路径 */
|
|
5
|
+
out?: string;
|
|
6
|
+
/** 主题名或路径(缺省取站点配置) */
|
|
7
|
+
theme?: string;
|
|
8
|
+
/** 站点根目录 */
|
|
9
|
+
base?: string;
|
|
10
|
+
/** 布局名 */
|
|
11
|
+
layout?: string;
|
|
12
|
+
/** 覆盖标题 */
|
|
13
|
+
title?: string;
|
|
14
|
+
}
|
|
15
|
+
/** hulog render:将单个 Markdown 渲染为自包含 HTML(复用站点主题) */
|
|
16
|
+
export declare function renderCmd(opts: RenderCommandOptions): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { Logger, renderMarkdownFile } from "@hulog/core";
|
|
3
|
+
/** hulog render:将单个 Markdown 渲染为自包含 HTML(复用站点主题) */
|
|
4
|
+
export async function renderCmd(opts) {
|
|
5
|
+
const logger = Logger.getLogger("cli:render");
|
|
6
|
+
const result = await renderMarkdownFile({
|
|
7
|
+
file: opts.file,
|
|
8
|
+
outFile: opts.out,
|
|
9
|
+
theme: opts.theme,
|
|
10
|
+
root: opts.base,
|
|
11
|
+
layout: opts.layout,
|
|
12
|
+
title: opts.title,
|
|
13
|
+
});
|
|
14
|
+
const rel = path.relative(process.cwd(), result.outFile);
|
|
15
|
+
logger.info(`输出: ${rel.startsWith("..") ? result.outFile : rel}`);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/commands/render.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAiBzD,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAA0B;IACxD,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC;QACtC,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,GAAG;QACjB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzD,MAAM,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;AACpE,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { initCmd } from "./commands/init.js";
|
|
5
|
+
import { buildCmd } from "./commands/build.js";
|
|
6
|
+
import { cleanCmd } from "./commands/clean.js";
|
|
7
|
+
import { newCmd } from "./commands/new.js";
|
|
8
|
+
import { publishCmd } from "./commands/publish.js";
|
|
9
|
+
import { devCmd } from "./commands/dev.js";
|
|
10
|
+
import { renderCmd } from "./commands/render.js";
|
|
11
|
+
import { run } from "./run.js";
|
|
12
|
+
const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
13
|
+
const program = new Command();
|
|
14
|
+
program
|
|
15
|
+
.name(process.title)
|
|
16
|
+
.description("静态博客生成器(Hexo 内容模型 + TSX 主题)")
|
|
17
|
+
.version(packageJson.version)
|
|
18
|
+
.option("-v, --verbose", "输出 debug 级日志")
|
|
19
|
+
.option("-q, --quiet", "仅输出 warn/error 日志");
|
|
20
|
+
// 全局日志级别(作用于 core/cli 的 Logger,需在命令创建 Logger 前生效)
|
|
21
|
+
program.hook("preAction", () => {
|
|
22
|
+
const { verbose, quiet } = program.opts();
|
|
23
|
+
if (verbose)
|
|
24
|
+
process.env.HULOG_LOG_LEVEL = "debug";
|
|
25
|
+
else if (quiet)
|
|
26
|
+
process.env.HULOG_LOG_LEVEL = "warn";
|
|
27
|
+
});
|
|
28
|
+
program
|
|
29
|
+
.command("init")
|
|
30
|
+
.description("创建新站点")
|
|
31
|
+
.argument("[dir]", "目标目录,默认当前目录", ".")
|
|
32
|
+
.action((dir) => run("init", () => initCmd(dir)));
|
|
33
|
+
program
|
|
34
|
+
.command("dev")
|
|
35
|
+
.description("启动开发服务器(热重载)")
|
|
36
|
+
.option("-p, --port <port>", "端口", "3000")
|
|
37
|
+
.option("-b, --base <path>", "网站根目录", process.cwd())
|
|
38
|
+
.action((opts) => run("dev", () => devCmd({ port: Number(opts.port), base: opts.base })));
|
|
39
|
+
program
|
|
40
|
+
.command("build")
|
|
41
|
+
.description("生产构建")
|
|
42
|
+
.option("-b, --base <path>", "网站根目录", process.cwd())
|
|
43
|
+
.action((opts) => run("build", () => buildCmd({ base: opts.base })));
|
|
44
|
+
program
|
|
45
|
+
.command("render")
|
|
46
|
+
.description("将单个 Markdown 文件渲染为自包含 HTML(复用站点主题)")
|
|
47
|
+
.argument("<file>", "输入 markdown 文件")
|
|
48
|
+
.option("-o, --out <file>", "输出 HTML 路径(默认与输入同名 .html)")
|
|
49
|
+
.option("-t, --theme <name>", "主题名或路径(缺省读取站点配置)")
|
|
50
|
+
.option("-b, --base <path>", "站点根目录(定位 themes/ 与配置)", process.cwd())
|
|
51
|
+
.option("--layout <name>", "布局名", "post")
|
|
52
|
+
.option("--title <title>", "覆盖标题(缺省取正文首个 H1)")
|
|
53
|
+
.action((file, opts) => run("render", () => renderCmd({
|
|
54
|
+
file,
|
|
55
|
+
out: opts.out,
|
|
56
|
+
theme: opts.theme,
|
|
57
|
+
base: opts.base,
|
|
58
|
+
layout: opts.layout,
|
|
59
|
+
title: opts.title,
|
|
60
|
+
})));
|
|
61
|
+
program
|
|
62
|
+
.command("clean")
|
|
63
|
+
.description("清理输出目录")
|
|
64
|
+
.option("-b, --base <path>", "网站根目录", process.cwd())
|
|
65
|
+
.action((opts) => run("clean", () => cleanCmd({ base: opts.base })));
|
|
66
|
+
program
|
|
67
|
+
.command("new")
|
|
68
|
+
.description("创建新文章(默认写入草稿区)")
|
|
69
|
+
.argument("<title>", "文章标题")
|
|
70
|
+
.option("-c, --collection <name>", "目标集合")
|
|
71
|
+
.option("--no-draft", "直接创建到集合(不写入草稿区)")
|
|
72
|
+
.action((title, opts) => run("new", () => newCmd({ title, draft: opts.draft, collection: opts.collection })));
|
|
73
|
+
program
|
|
74
|
+
.command("publish")
|
|
75
|
+
.description("发布草稿:移动到目标集合,自动补 date,移除 draft 标记")
|
|
76
|
+
.argument("[slug]", "草稿 slug;省略时配合 --all")
|
|
77
|
+
.option("--all", "发布全部草稿")
|
|
78
|
+
.option("--no-date", "不自动补 date")
|
|
79
|
+
.option("--collection <name>", "目标集合,默认 posts")
|
|
80
|
+
.action((slug, opts) => run("publish", () => publishCmd({ slug, all: opts.all, autoDate: opts.date, collection: opts.collection })));
|
|
81
|
+
program.parse();
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"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AE,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CACpF,CAAC;AAEJ,OAAO;KACJ,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,mCAAmC,CAAC;KAChD,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;KACzC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC;KACzB,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC;KAChC,MAAM,CAAC,qBAAqB,EAAE,eAAe,CAAC;KAC9C,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CACrB,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,CAClB,UAAU,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CACtF,CACF,CAAC;AAEJ,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/run.d.ts
ADDED
package/dist/run.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger } from "@hulog/core";
|
|
2
|
+
/**
|
|
3
|
+
* 统一命令执行包装:捕获异常 → logger.error(无堆栈)+ exit 1。
|
|
4
|
+
*/
|
|
5
|
+
export async function run(name, fn) {
|
|
6
|
+
try {
|
|
7
|
+
await fn();
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
11
|
+
Logger.getLogger(`cli:${name}`).error(msg);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CACvB,IAAY,EACZ,EAA8B;IAE9B,IAAI,CAAC;QACH,MAAM,EAAE,EAAE,CAAC;IACb,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,MAAM,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hulog/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "生成器 CLI:init/dev/build/clean/new/publish/render(开发服务器与热重载)",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"hulog",
|
|
8
|
+
"static-site-generator",
|
|
9
|
+
"blog",
|
|
10
|
+
"markdown",
|
|
11
|
+
"cli"
|
|
12
|
+
],
|
|
13
|
+
"author": "Huzerovo",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/Huzerovo/hulog.git",
|
|
18
|
+
"directory": "packages/cli"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/Huzerovo/hulog#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/Huzerovo/hulog/issues"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"bin": {
|
|
27
|
+
"hulog": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22.12.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -p tsconfig.json",
|
|
43
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
44
|
+
"clean": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\"",
|
|
45
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
46
|
+
"prepack": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@hulog/core": "^0.1.5",
|
|
50
|
+
"chokidar": "^5.0.0",
|
|
51
|
+
"commander": "^15.0.0",
|
|
52
|
+
"gray-matter": "^4.0.3",
|
|
53
|
+
"ws": "^8.21.2"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^26.1.2",
|
|
57
|
+
"@types/ws": "^8.18.1"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
}
|
|
62
|
+
}
|