@veecode-platform/safira-cli
Version:
Generate a microservice project from your spec.
55 lines (54 loc) • 2.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheName = exports.CacheManager = void 0;
const file_system_utils_1 = require("../utils/file-system-utils");
const json_utils_1 = require("../utils/json-utils");
const array_utils_1 = require("../utils/array-utils");
const string_utils_1 = require("../utils/string-utils");
class CacheManager {
constructor() { }
getCache(cacheName) {
const cacheFile = this._buildCachePath(cacheName);
if (file_system_utils_1.FileSystemUtils.exists(cacheFile)) {
try {
return json_utils_1.JsonUtils.loadJsonFile(cacheFile);
}
catch { }
}
return [];
}
addItem(cacheName, ...items) {
if (array_utils_1.ArrayUtils.isNullOrEmpty(items) || !items.some(item => !string_utils_1.StringUtils.isNullOrEmpty(item)))
return;
const newCache = array_utils_1.ArrayUtils.clone(items);
newCache.push(...this.getCache(cacheName));
file_system_utils_1.FileSystemUtils.writeFile(this._buildCachePath(cacheName), json_utils_1.JsonUtils.stringify(array_utils_1.ArrayUtils.removeDuplicates(newCache)
.filter(item => !string_utils_1.StringUtils.isNullOrEmpty(item))));
}
clear(cacheName) {
file_system_utils_1.FileSystemUtils.deleteFile(this._buildCachePath(cacheName));
}
_buildCachePath(cacheName) {
return file_system_utils_1.FileSystemUtils.buildPath(CacheManager._cacheFolder, `${cacheName}.json`);
}
static get instance() {
if (!this._instance)
this._instance = new this();
return this._instance;
}
}
exports.CacheManager = CacheManager;
CacheManager._cacheFolder = file_system_utils_1.FileSystemUtils.buildPath(file_system_utils_1.FileSystemUtils.getOsUserHome(), ".cache", "safira-cli", "cache");
var CacheName;
(function (CacheName) {
CacheName["mockserver"] = "mockserver";
CacheName["specHouseBranch"] = "spec-house-branch";
CacheName["specHouseRepository"] = "spec-house-repository";
CacheName["iac"] = "iac";
CacheName["domain"] = "domain";
CacheName["kongLicense"] = "kong-license";
CacheName["oktaId"] = "okta-id";
CacheName["argoCDBRanch"] = "argocd-branch";
CacheName["kubernetesServer"] = "kubernetes-server";
CacheName["kubernetesNamespace"] = "kubernetes-namespace";
})(CacheName = exports.CacheName || (exports.CacheName = {}));