UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

67 lines 2.51 kB
"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 ErrorFeature extends AbstractFeature_1.default { nameReadable = 'error handling'; description = 'Errors: Use schemas to define your errors and get great type checking!'; code = 'error'; dependencies = [ { code: 'schema', isRequired: true }, { code: 'node', isRequired: true }, ]; packageDependencies = [ { name: '@sprucelabs/error@latest', }, ]; actionsDir = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, 'actions'); constructor(options) { super(options); void this.emitter.on('feature.did-execute', this.handleDidExecuteCommand.bind(this)); void this.emitter.on('skill.will-write-directory-template', async () => { const isInstalled = await this.features.isInstalled('error'); if (isInstalled) { return { filesToSkip: ['options.types.ts'], }; } return {}; }); } async afterPackageInstall() { const isSkillInstalled = await this.features.isInstalled('skill'); if (!isSkillInstalled) { return {}; } const files = await this.writePlugin(); return { files, }; } async handleDidExecuteCommand(payload) { const { featureCode, actionCode } = payload; const isInstalled = await this.features.isInstalled('error'); const isSkillInstalled = await this.features.isInstalled('skill'); if (isInstalled && featureCode === 'node' && actionCode === 'upgrade') { const results = await this.Action('error', 'sync').execute({}); if (isSkillInstalled) { if (!results.files) { results.files = []; } const plugin = await this.writePlugin(); results.files.push(...plugin); } return results; } return {}; } async writePlugin() { return this.Writer('error').writePlugin(this.cwd); } } exports.default = ErrorFeature; //# sourceMappingURL=ErrorFeature.js.map