feat: rename project to TTTK
- Update package name and CLI binary to 'tttk' - Revise documentation to reflect new name - Add default serve behavior when no subcommand is given - Add directory existence check in serve command - Refactor inline comments to Chinese
This commit is contained in:
+23
-6
@@ -8,25 +8,42 @@ import type { ServeOptions, CompileOptions } from "./types.js";
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.name("ttrpg")
|
||||
.description("TTRPG 工具箱 - 用于编译和预览 TTRPG 文档")
|
||||
.name("tttk")
|
||||
.description(
|
||||
"TTRPG 内容预览服务器。不带参数运行时默认启动当前目录的预览服务。",
|
||||
)
|
||||
.version("0.0.1");
|
||||
|
||||
program
|
||||
.command("serve")
|
||||
.description("运行一个 web 服务器预览目录中的内容,并实时监听更新")
|
||||
.description("启动 web 服务器预览目录中的内容,并实时监听文件更新")
|
||||
.argument("[dir]", "要预览的目录", ".")
|
||||
.option("-p, --port <port>", "HTTP 端口号", "3000")
|
||||
.option("-h, --host <host>", "主机地址", "0.0.0.0")
|
||||
.option("--host <host>", "主机地址", "0.0.0.0")
|
||||
.action(serveCommand);
|
||||
|
||||
program
|
||||
.command("compile")
|
||||
.description("将目录中的内容输出为带 hash 路由、单个 html 入口的 web 应用")
|
||||
.description("[实验性] 将目录内容编译为带 hash 路由的单页 Web 应用 (开发中)")
|
||||
.argument("[dir]", "要编译的目录", ".")
|
||||
.option("-o, --output <dir>", "输出目录", "./dist/output")
|
||||
.action(compileCommand);
|
||||
|
||||
program.addCommand(mcpCommand);
|
||||
|
||||
program.parse();
|
||||
// 无子命令时默认执行 serve(即 `npx tttk` 等同于 `npx tttk serve .`)
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length > 0) {
|
||||
const first = args[0];
|
||||
const isKnownCommand =
|
||||
!first.startsWith("-") &&
|
||||
program.commands.some(
|
||||
(c) => c.name() === first || c.aliases().includes(first),
|
||||
);
|
||||
if (!isKnownCommand) {
|
||||
args.unshift("serve");
|
||||
}
|
||||
} else {
|
||||
args.unshift("serve");
|
||||
}
|
||||
program.parse([process.argv[0], process.argv[1], ...args]);
|
||||
|
||||
Reference in New Issue
Block a user