feat: ai's first take...

This commit is contained in:
2026-02-26 00:17:23 +08:00
parent f005514f56
commit 3c9cf552e5
21 changed files with 4001 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
import type { CommandHandler } from '../types.js';
export const compileCommand: CommandHandler = async (dir, options) => {
console.log(`开始编译...`);
console.log(`目录:${dir}`);
console.log(`输出目录:${options.output}`);
// TODO: 实现编译逻辑
// 1. 扫描目录下的所有 .md 文件
// 2. 解析 markdown 并生成路由
// 3. 打包为带 hash 路由的单个 HTML 入口
console.log('编译完成!');
};
+14
View File
@@ -0,0 +1,14 @@
import type { CommandHandler } from '../types.js';
export const serveCommand: CommandHandler = async (dir, options) => {
console.log(`启动开发服务器...`);
console.log(`目录:${dir}`);
console.log(`端口:${options.port}`);
// TODO: 实现开发服务器逻辑
// 1. 扫描目录下的所有 .md 文件
// 2. 启动 rsbuild 开发服务器
// 3. 监听文件变化
console.log('开发服务器已启动:http://localhost:' + options.port);
};
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env node
import { Command } from 'commander';
import { serveCommand } from './commands/serve.js';
import { compileCommand } from './commands/compile.js';
const program = new Command();
program
.name('ttrpg')
.description('TTRPG 工具箱 - 用于编译和预览 TTRPG 文档')
.version('0.0.1');
program
.command('serve')
.description('运行一个 web 服务器预览目录中的内容,并实时监听更新')
.argument('[dir]', '要预览的目录', '.')
.option('-p, --port <port>', '端口号', '3000')
.action(serveCommand);
program
.command('compile')
.description('将目录中的内容输出为带 hash 路由、单个 html 入口的 web 应用')
.argument('[dir]', '要编译的目录', '.')
.option('-o, --output <dir>', '输出目录', './dist/output')
.action(compileCommand);
program.parse();
+15
View File
@@ -0,0 +1,15 @@
export interface ServeOptions {
port: string;
}
export interface CompileOptions {
output: string;
}
export type CommandHandler = (dir: string, options: ServeOptions | CompileOptions) => Promise<void>;
export interface MarkdownFile {
path: string;
route: string;
content: string;
}