@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
68 lines • 2.2 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const schema_1 = require("@sprucelabs/schema");
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
const onboarding_schema_1 = __importDefault(require("./../../../.spruce/schemas/spruceCli/v2020_07_22/onboarding.schema"));
const AbstractLocalStore_1 = __importDefault(require("../../../stores/AbstractLocalStore"));
class OnboardingStore extends AbstractLocalStore_1.default {
name = 'onboarding';
static cwdOverride;
static schemasByHome = {};
constructor(options) {
super(options);
this.cwd = this.generateCwd();
this.load();
}
get schema() {
if (!OnboardingStore.schemasByHome[this.homeDir]) {
OnboardingStore.schemasByHome[this.homeDir] =
schema_1.SchemaEntityFactory.Entity(onboarding_schema_1.default);
}
return OnboardingStore.schemasByHome[this.homeDir];
}
save() {
const values = this.schema.getValues();
this.writeValues(values);
return this;
}
load() {
const saved = this.readValues();
this.schema.setValues({
stage: saved.stage ?? null,
mode: saved.mode ?? 'off',
});
return this;
}
getMode() {
return this.schema.get('mode');
}
setMode(mode) {
this.schema.set('mode', mode);
this.schema.validate();
this.save();
}
getStage() {
return this.schema.get('stage');
}
setStage(stage) {
this.schema.set('stage', stage);
this.schema.validate();
this.save();
}
reset() {
this.schema.set('stage', undefined);
this.setMode('off');
}
static overrideCwd(cwd) {
this.cwdOverride = cwd;
}
generateCwd() {
const home = OnboardingStore.cwdOverride ?? spruce_skill_utils_1.diskUtil.createTempDir('spruce-cli');
return home;
}
}
exports.default = OnboardingStore;
//# sourceMappingURL=OnboardingStore.js.map