vtex
Version:
The platform for e-commerce apps
41 lines (40 loc) • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureFlag = void 0;
const tslib_1 = require("tslib");
const configstore_1 = tslib_1.__importDefault(require("configstore"));
const path_1 = require("path");
const CLIPreTasks_1 = require("../../CLIPreTasks/CLIPreTasks");
class FeatureFlag {
constructor(storeFilePath) {
this.storeFilePath = storeFilePath;
this.store = new configstore_1.default('', null, { configPath: storeFilePath });
}
static getSingleton() {
if (FeatureFlag.singleton) {
return FeatureFlag.singleton;
}
const filePath = path_1.join(CLIPreTasks_1.CLIPreTasks.PRETASKS_LOCAL_DIR, FeatureFlag.FEATURE_FLAG_STORE_FILENAME);
FeatureFlag.singleton = new FeatureFlag(filePath);
return FeatureFlag.singleton;
}
getLastFeatureFlagUpdate() {
var _a;
return (_a = this.store.get('lastFeatureFlagCheck')) !== null && _a !== void 0 ? _a : 0;
}
getAllFeatureFlagInfo() {
var _a;
return (_a = this.store.get('featureFlagInfo')) !== null && _a !== void 0 ? _a : {};
}
getFeatureFlagInfo(flagName) {
return this.store.get(`featureFlagInfo.${flagName}`);
}
setLastFeatureFlagUpdate(date) {
this.store.set('lastFeatureFlagCheck', date);
}
setFeatureFlagInfo(versionFeatureFlagInfo) {
this.store.set('featureFlagInfo', versionFeatureFlagInfo);
}
}
exports.FeatureFlag = FeatureFlag;
FeatureFlag.FEATURE_FLAG_STORE_FILENAME = 'feature-flag.json';