@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
80 lines • 2.49 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"));
class InstallFeatureAction extends AbstractAction_1.default {
optionsSchema = optionsSchema;
invocationMessage = 'Installing a feature... 🚀';
commandAliases = ['install.feature'];
async execute(options) {
let { code } = options ?? {};
if (!code) {
const choices = await this.buildFeatureChoices();
if (!choices.length) {
return {
summaryLines: [
'Nothing to install, you have already installed everything!',
],
};
}
code = await this.promptForFeature(choices);
}
this.ui.startLoading('Installing feature...');
const results = await this.features.install({
features: [{ code: code }],
});
return results;
}
async promptForFeature(choices) {
return await this.ui.prompt({
type: 'select',
label: 'Which feature do you want to install?',
isRequired: true,
options: {
choices,
},
});
}
async buildFeatureChoices() {
const choices = [];
for (const key in features) {
const isInstalled = await this.features.isInstalled(key);
if (!isInstalled) {
choices.push({
label: features[key],
value: key,
});
}
}
return choices;
}
}
exports.default = InstallFeatureAction;
const features = {
error: 'Errors',
event: 'Events',
schema: 'Schemas',
store: 'Stores (including database support)',
test: 'Tests',
view: 'Views',
};
const allFeatureChoices = Object.keys(features).map((key) => ({
label: features[key],
value: key,
}));
const optionsSchema = (0, schema_1.buildSchema)({
id: 'installFeature',
fields: {
code: {
type: 'select',
label: 'Feature to install',
options: {
choices: allFeatureChoices,
},
},
},
});
//# sourceMappingURL=InstallFeatureAction.js.map