bookr-cli
Version:
A terminal-based CLI tool to book time in Jira using the Tempo plugin by parsing your current Git branch name
57 lines • 1.49 kB
JavaScript
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import envPaths from 'env-paths';
/**
* Get cache file path for storing update check results
*/
export function getCachePath() {
const paths = envPaths('bookr-cli', { suffix: '' });
return join(paths.cache, 'update-cache.json');
}
/**
* Read cached update information
*/
export function readCache() {
try {
const cachePath = getCachePath();
if (!existsSync(cachePath)) {
return null;
}
const cacheContent = readFileSync(cachePath, 'utf-8');
return JSON.parse(cacheContent);
}
catch {
return null;
}
}
/**
* Write update information to cache
*/
export function writeCache(data) {
try {
const cachePath = getCachePath();
const cacheDir = dirname(cachePath);
// Ensure cache directory exists
if (!existsSync(cacheDir)) {
mkdirSync(cacheDir, { recursive: true });
}
writeFileSync(cachePath, JSON.stringify(data, null, 2));
}
catch {
// Silently fail cache writes
}
}
export const getCache = readCache;
export const setCache = writeCache;
export function clearCache() {
try {
const cachePath = getCachePath();
if (existsSync(cachePath)) {
unlinkSync(cachePath);
}
}
catch {
// Silently fail
}
}
//# sourceMappingURL=cache.js.map