UNPKG

ai-commit-report-generator-cli

Version:

An AI-powered CLI tool that generates weekly reports from your Git activity

64 lines (63 loc) 2.41 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.JsonStore = void 0; const promises_1 = __importDefault(require("fs/promises")); const utils_1 = require("./utils"); class JsonStore { constructor(config) { this.cache = {}; this.path = "./cache.json"; this.path = config.path; } desirializeCache(fileContent) { this.cache = JSON.parse(fileContent); Object.entries(this.cache).forEach(([key, value]) => { if (typeof value !== "string") { this.cache[key] = value; return; } this.cache[key] = JSON.parse(value); }); } initCache() { return __awaiter(this, void 0, void 0, function* () { const fileContent = yield (0, utils_1.readFileOrCreate)(this.path); if (fileContent) { this.desirializeCache(fileContent); } ; }); } get(key) { return this.cache[key]; } getKeys(key) { return Object.keys(this.cache).filter((key) => { return key.startsWith(key); }); } getAll(keyFilter) { return Object.entries(this.cache).filter(([key, value]) => { return key.startsWith(keyFilter); }); } set(key, value) { this.cache[key] = value; promises_1.default.writeFile(this.path, JSON.stringify(this.cache)).then(() => { console.info(`Cache[id="${this.path}"] updated for key ${key}`); }); } } exports.JsonStore = JsonStore;