@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
81 lines • 3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSkillSummaryLines = generateSkillSummaryLines;
const schema_1 = require("@sprucelabs/schema");
const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
const AbstractAction_1 = __importDefault(require("../../AbstractAction"));
class RegisterAction extends AbstractAction_1.default {
optionsSchema = optionsSchema;
commandAliases = ['register.skill', 'register'];
invocationMessage = 'Registering your skill... ⚡️';
async execute(options) {
const { nameReadable, nameKebab, description } = this.validateAndNormalizeOptions(options);
const client = await this.connectToApi();
const results = await client.emit('register-skill::v2020_12_25', {
payload: {
name: nameReadable,
slug: nameKebab,
description,
},
});
try {
const { skill } = spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
const summaryLines = generateSkillSummaryLines(skill);
this.Service('auth').updateCurrentSkill(skill);
return {
summaryLines,
hints: [
'Your skill is registered.',
'You can check your .env for more details.',
"If you're ready to deploy, try `spruce deploy`. 🚀",
],
meta: {
skill,
},
};
}
catch (err) {
return {
hints: [
`If you've already registered your skill, try 'spruce login.skill'!`,
],
errors: [err],
};
}
}
}
exports.default = RegisterAction;
function generateSkillSummaryLines(skill) {
return [
`Name: ${skill.name}`,
`Namespace: ${skill.slug}`,
`ID: ${skill.id}`,
`API Key: ${skill.apiKey}`,
];
}
const optionsSchema = (0, schema_1.buildSchema)({
id: 'registerSkillAction',
description: 'Register your skill with Mercury so you can start communicating with other skills.',
fields: {
nameReadable: {
type: 'text',
label: `What is your skill's name?`,
isRequired: true,
hint: 'The name people will see in the Marketplace!',
},
nameKebab: {
type: 'text',
label: 'Namespace',
isRequired: true,
hint: "The namespace of your skill in-kebab-case. It is what you will use in a lot of your code, don't start it with a number!",
},
description: {
type: 'text',
label: 'Describe your skill.',
},
},
});
//# sourceMappingURL=RegisterAction.js.map