UNPKG

jenkins-cli-node

Version:
44 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fse = require("fs-extra"); const config_1 = require("./config"); class Cache { constructor(fileName) { this.readFile = () => { return fse.readFileSync(this.fileName, "utf8"); }; this.writeToFile = () => { return fse.writeFile(this.fileName, JSON.stringify(this.cacheInfo, null, 2), "utf8"); }; this.fileName = fileName; fse.ensureFileSync(this.fileName); } } exports.Cache = Cache; class JobCache extends Cache { constructor(dir) { const fileName = `${dir}/${config_1.JENKINS_DIR}/build-job-cache.json`; super(fileName); try { this.cacheInfo = JSON.parse(this.readFile()); } catch (_a) { this.cacheInfo = []; } } getJob() { return this.cacheInfo; } refreshJob(job) { const index = this.cacheInfo.findIndex(k => k.name === job.name); let count = 0; if (this.cacheInfo.length && index !== -1) { count = this.cacheInfo[index].count; this.cacheInfo.splice(index, 1); } this.cacheInfo.splice(0, 0, Object.assign(Object.assign({}, job), { date: Date.now(), count: count + 1 })); this.writeToFile(); } } exports.JobCache = JobCache; //# sourceMappingURL=cache.js.map