@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
67 lines • 2.6 kB
JavaScript
;
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 SpruceError_1 = __importDefault(require("../../../errors/SpruceError"));
const AbstractAction_1 = __importDefault(require("../../AbstractAction"));
const optionsSchema = (0, schema_1.buildSchema)({
id: 'addDepnedency',
description: 'Add a skill as a dependency.',
fields: {
namespace: {
type: 'id',
label: 'Namespace',
hint: 'The namespace of the skill you want to add as a dependency.',
},
},
});
class DeployAction extends AbstractAction_1.default {
optionsSchema = optionsSchema;
commandAliases = ['add.dependency [namespace]'];
invocationMessage = 'Adding a dependency... 🔗';
async execute(options) {
let { namespace } = this.validateAndNormalizeOptions(options);
const skills = await this.Store('skill').fetchAllSkills();
const dependencyService = this.Service('dependency');
if (!namespace) {
const dependencies = dependencyService.get().map((d) => d.namespace);
const choices = skills
.filter((s) => dependencies.indexOf(s.slug) === -1)
.map((s) => ({
value: s.slug,
label: s.name,
}));
namespace = await this.ui.prompt({
type: 'select',
label: 'Which skill would you like to add as a dependency?',
isRequired: true,
options: {
choices,
},
});
}
const skill = skills.find((s) => s.slug === namespace);
if (!skill) {
throw new SpruceError_1.default({
code: 'SKILL_NOT_FOUND',
friendlyMessage: `I could not find a skill with the slug of ${namespace}.`,
});
}
dependencyService.add({
id: skill.id,
namespace: skill.slug,
});
const summaryLines = [`Added "${skill.name}" as a dependency!`];
const isEventInstalled = await this.features.isInstalled('event');
if (isEventInstalled) {
summaryLines.push('You will need to run `spruce sync.events` before accessing any new events.');
}
return {
summaryLines,
};
}
}
exports.default = DeployAction;
//# sourceMappingURL=AddAction.js.map