seed.js 1.4 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.seedTemplates = seedTemplates;
  7. const fs_1 = __importDefault(require("fs"));
  8. const path_1 = __importDefault(require("path"));
  9. const COLORING_MANIFEST_PATH = path_1.default.resolve(__dirname, "../../../../templates/coloring/manifest.json");
  10. function seedTemplates(db) {
  11. // 检查 coloring 模板是否已注册
  12. const existing = db
  13. .prepare("SELECT id FROM templates WHERE id = ?")
  14. .get("coloring");
  15. if (existing) {
  16. // 更新 manifest(开发阶段可能频繁变更)
  17. const manifest = fs_1.default.readFileSync(COLORING_MANIFEST_PATH, "utf-8");
  18. const manifestJson = JSON.parse(manifest);
  19. db.prepare("UPDATE templates SET manifest = ?, name = ?, updated_at = datetime('now') WHERE id = ?").run(manifest, manifestJson.name, "coloring");
  20. console.log("[db] Template 'coloring' updated");
  21. return;
  22. }
  23. // 首次注册
  24. const manifest = fs_1.default.readFileSync(COLORING_MANIFEST_PATH, "utf-8");
  25. const manifestJson = JSON.parse(manifest);
  26. db.prepare("INSERT INTO templates (id, name, manifest) VALUES (?, ?, ?)").run("coloring", manifestJson.name, manifest);
  27. console.log("[db] Template 'coloring' seeded");
  28. }
  29. //# sourceMappingURL=seed.js.map