建立完整的 CLI 产品基础骨架,支持多种演进方向 - 添加项目基础配置(package.json、tsconfig、pnpm-lock.yaml、.gitignore、.npmignore) - 实现运行时基础设施(RuntimeServices 统一注入、日志、输出模式、配置存储、插件加载、任务注册表) - 采用 command/use-case/presenter 三层架构组织业务模块(demo、config、task) - 添加 UI 渲染层(banner、panel、table、主题样式) - 实现插件机制,支持运行时扫描加载外部模块和任务 - 支持 text/json 双输出模式,便于集成与调试 - 添加统一错误模型 AppError 和 CLI 错误边界处理 - 基于 node:test 建立测试基座,包含示例测试用例 - 配置 npm 发布脚本和包元数据 - 编写完整 README 文档,包含快速开始、开发约定和演进方向
28 lines
1.2 KiB
TypeScript
28 lines
1.2 KiB
TypeScript
import type { Command } from "commander";
|
|
import type { CommandModule, RuntimeServices } from "../../runtime/types.js";
|
|
import { presentDemoIntro, presentDemoSelection } from "./presenter.js";
|
|
import { createDemoViewModel, selectDemoProfile } from "./use-case.js";
|
|
|
|
export function createDemoModule(): CommandModule {
|
|
return {
|
|
register(program: Command, services: RuntimeServices) {
|
|
program
|
|
.command("demo")
|
|
.description("Preview the reusable terminal UI patterns in this template.")
|
|
.action(async () => {
|
|
const viewModel = createDemoViewModel(services);
|
|
presentDemoIntro(services, viewModel);
|
|
|
|
const profile = await services.ui.promptSelect("What kind of CLI do you want to extend this into?", [
|
|
{ value: "desktop", label: "Desktop software control" },
|
|
{ value: "config", label: "Configuration workflow" },
|
|
{ value: "assistant", label: "AI or workflow assistant" }
|
|
]);
|
|
const verbose = await services.ui.promptConfirm("Enable verbose logging in the starter config?", true);
|
|
|
|
presentDemoSelection(services, selectDemoProfile(profile, verbose));
|
|
});
|
|
}
|
|
};
|
|
}
|