@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
72 lines • 2.56 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 AbstractAction_1 = __importDefault(require("../../AbstractAction"));
const optionsSchema = (0, schema_1.buildSchema)({
id: 'manageDependencies',
description: 'Manage the skills you depend on.',
fields: {},
});
class DeployAction extends AbstractAction_1.default {
optionsSchema = optionsSchema;
commandAliases = [
'manage.dependencies',
'remove.dependency',
'dependencies',
];
invocationMessage = 'Managing dependencies... 🔗';
async execute() {
let skills = await this.Store('skill').fetchMySkills();
skills.sort((a, b) => {
const name1 = a.name.toLowerCase();
const name2 = b.name.toLowerCase();
if (name1 < name2) {
return -1;
}
else if (name1 > name2) {
return 1;
}
return 0;
});
const dep = this.Service('dependency');
const dependencies = dep.get();
const currentSkill = await this.Store('skill').loadCurrentSkill();
if (currentSkill.isRegistered) {
skills = skills.filter((s) => s.id !== currentSkill.id);
}
const selected = await this.ui.prompt({
label: 'Which skills do you depend on?',
type: 'select',
isArray: true,
isRequired: true,
value: dependencies.map((d) => d.id),
options: {
choices: skills.map((skill) => ({
value: skill.id,
label: skill.name + ' (' + skill.slug + ')',
})),
},
});
const summary = [];
const updatedDependencies = selected.map((id) => {
const skill = skills.find((s) => s.id === id);
summary.push(skill?.name + ' (' + skill?.id + ')');
return {
id,
namespace: skill?.slug ?? '**missing**',
};
});
dep.set(updatedDependencies);
return {
summaryLines: [
`${updatedDependencies.length} dependenc${updatedDependencies.length === 1 ? 'y' : 'ies'} added.`,
...summary,
],
};
}
}
exports.default = DeployAction;
//# sourceMappingURL=ManageAction.js.map