UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

69 lines (68 loc) 2.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateSummary = exports.saveResult = exports.loadSnapshot = exports.saveSnapshot = exports.getSummaryPath = exports.getResultPath = exports.getSnapshotPath = void 0; const path_1 = __importDefault(require("path")); const fs_extra_1 = require("fs-extra"); const get_project_directory_1 = require("../get-project-directory"); const EVAL_DIR = '.point-eval'; function getSnapshotPath(caseId) { return path_1.default.join((0, get_project_directory_1.getProjectDirectory)(), EVAL_DIR, 'snapshots', `${caseId}.json`); } exports.getSnapshotPath = getSnapshotPath; function getResultPath(caseId) { return path_1.default.join((0, get_project_directory_1.getProjectDirectory)(), EVAL_DIR, 'results', `${caseId}.json`); } exports.getResultPath = getResultPath; function getSummaryPath() { return path_1.default.join((0, get_project_directory_1.getProjectDirectory)(), EVAL_DIR, 'results', 'summary.json'); } exports.getSummaryPath = getSummaryPath; function saveSnapshot(caseId, data) { const snapshotPath = getSnapshotPath(caseId); (0, fs_extra_1.ensureDirSync)(path_1.default.dirname(snapshotPath)); (0, fs_extra_1.writeJSONSync)(snapshotPath, data, { spaces: 2 }); } exports.saveSnapshot = saveSnapshot; function loadSnapshot(caseId) { const snapshotPath = getSnapshotPath(caseId); if (!(0, fs_extra_1.existsSync)(snapshotPath)) { return null; } return (0, fs_extra_1.readJSONSync)(snapshotPath); } exports.loadSnapshot = loadSnapshot; function saveResult(caseId, result) { const resultPath = getResultPath(caseId); (0, fs_extra_1.ensureDirSync)(path_1.default.dirname(resultPath)); (0, fs_extra_1.writeJSONSync)(resultPath, result, { spaces: 2 }); } exports.saveResult = saveResult; function updateSummary(caseId, result) { const summaryPath = getSummaryPath(); (0, fs_extra_1.ensureDirSync)(path_1.default.dirname(summaryPath)); let summary = []; if ((0, fs_extra_1.existsSync)(summaryPath)) { summary = (0, fs_extra_1.readJSONSync)(summaryPath); } const entry = { caseId, status: result.status, matchedCount: result.matched.length, diffCount: result.diffs.length, missingInRemote: result.missingInRemote.length, extraInRemote: result.extraInRemote.length, evaluatedAt: new Date().toISOString(), }; const existingIdx = summary.findIndex(e => e.caseId === caseId); if (existingIdx >= 0) { summary[existingIdx] = entry; } else { summary.push(entry); } (0, fs_extra_1.writeJSONSync)(summaryPath, summary, { spaces: 2 }); } exports.updateSummary = updateSummary;