@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
74 lines • 2.71 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 spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
const AbstractFeature_1 = __importDefault(require("../AbstractFeature"));
class SchemaFeature extends AbstractFeature_1.default {
nameReadable = 'Schema';
description = 'Define, validate, and normalize everything.';
dependencies = [
{ code: 'skill', isRequired: false },
{ code: 'node', isRequired: true },
];
packageDependencies = [
{
name: '@sprucelabs/schema@latest',
},
{
name: '@sprucelabs/spruce-core-schemas@latest',
},
{ name: '@sprucelabs/resolve-path-aliases@latest', isDev: true },
{
name: '@sprucelabs/spruce-skill-utils',
},
];
code = 'schema';
actionsDir = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, 'actions');
constructor(options) {
super(options);
void this.emitter.on('feature.will-execute', this.handleWillExecute.bind(this));
void this.emitter.on('feature.did-execute', this.handleDidExecute.bind(this));
}
async handleWillExecute(payload) {
const isInstalled = await this.features.isInstalled('schema');
const isSkillInstalled = await this.features.isInstalled('skill');
if (payload.featureCode === 'node' &&
payload.actionCode === 'upgrade' &&
isInstalled &&
isSkillInstalled) {
const files = await this.writePlugin();
return { files };
}
return {};
}
async handleDidExecute(payload) {
const isInstalled = await this.features.isInstalled('schema');
if (payload.featureCode === 'node' &&
payload.actionCode === 'upgrade' &&
isInstalled) {
const hasLocalSchemas = await this.Store('schema').hasLocalSchemas();
if (hasLocalSchemas) {
const results = await this.Action('schema', 'sync').execute({});
return results;
}
}
return {};
}
async afterPackageInstall() {
const isSkillInstalled = await this.features.isInstalled('skill');
if (!isSkillInstalled) {
return {};
}
const files = await this.writePlugin();
return {
files,
};
}
async writePlugin() {
return this.Writer('schema').writePlugin(this.cwd);
}
}
exports.default = SchemaFeature;
//# sourceMappingURL=SchemaFeature.js.map