refactor: 重构为单向生成架构,CLI 零参数可用

- 迁移 examples/rules/ 到 src/rules/,resources/devices.json 到 src/devices.json
- 迁移 resources/fetch-devlist.js 到 src/tools/fetch-devlist.ts 并改造为 ESM
- CLI 简化为零参数:bun run pack 自动编译并输出 dist/miot_{timestamp}.bak
- 移除备份合并能力:删除 mergeCompiledRules、RuleReplaceStrategy、dry-run、replace 参数
- 编译器简化为从零生成,不再支持 baseBackup 合并
- 新增 fetch-devices 命令用于从中枢网关更新设备清单
- 新增 bn.js、elliptic 依赖
- 更新测试路径引用,移除依赖合并逻辑的测试用例
- 更新 README.md 反映新项目结构和命令
This commit is contained in:
2026-05-08 00:03:27 +08:00
parent 690ef8ce83
commit 63dc55fa5a
15 changed files with 2133 additions and 243 deletions

View File

@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { compileRule, readDeviceInventoryFile, validateBackup } from "../src/index.ts";
import { eventTurnOn } from "../examples/rules/index.ts";
import { compileRule, validateBackup } from "../src/index.ts";
import { eventTurnOn } from "../src/rules/index.ts";
const now = 1_760_000_000_000;
@@ -25,9 +25,10 @@ describe("备份校验", () => {
expect(diagnostics.filter((diagnostic) => diagnostic.code === "device-not-found")).toHaveLength(2);
});
test("真实设备清单可通过设备校验", () => {
test("真实设备清单可通过设备校验", async () => {
const backup = backupFromRule();
const diagnostics = validateBackup(backup, { devices: readDeviceInventoryFile("resources/devices.json") });
const devices = (await import("../src/devices.json")).default;
const diagnostics = validateBackup(backup, { devices });
expect(diagnostics.filter((diagnostic) => diagnostic.severity === "error")).toEqual([]);
});
});