UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

90 lines 4.14 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 createTestOptions_schema_1 = __importDefault(require("./../../.spruce/schemas/spruceCli/v2020_07_22/createTestOptions.schema")); const AbstractFeature_1 = __importDefault(require("../AbstractFeature")); const feature_utilities_1 = __importDefault(require("../feature.utilities")); const ScriptLoader_1 = __importDefault(require("./ScriptLoader")); class OnboardFeature extends AbstractFeature_1.default { code = 'onboard'; nameReadable = 'Onboard'; description = 'Get building your first skill already!'; dependencies = []; packageDependencies = []; actionsDir = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, 'actions'); onboardingStore; scriptsDir = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, 'scripts'); constructor(options) { super(options); void this.emitter.on('feature.will-execute', this.handleWillExecuteCommand.bind(this)); void this.emitter.on('test.reporter-did-boot', this.handleTestReporterDidBoot.bind(this)); } OnboardingStore() { if (!this.onboardingStore) { this.onboardingStore = this.Store('onboarding'); } return this.onboardingStore; } async ScriptPlayer() { const store = this.OnboardingStore(); const player = await ScriptLoader_1.default.LoadScripts({ ui: this.ui, dir: this.scriptsDir, onboardingStore: store, commandExecuter: async (_command) => { throw new Error("I can't run commands for you yet, but will be able to soon. For now run `spruce " + _command + '` manually.'); }, }); return player; } async handleWillExecuteCommand(payload) { const onboarding = this.Store('onboarding'); if (onboarding.getMode() !== 'off') { const command = this.generateCommandFromPayload(payload); await this.confirmExpectedCommand(payload, onboarding); if (onboarding.getMode() !== 'off' && this.isExpectedCommand(command, onboarding)) { const player = await this.ScriptPlayer(); await player.playScriptWithKey(`todo.${command}`); } } } handleTestReporterDidBoot() { const onboarding = this.Store('onboarding'); if (onboarding.getMode() !== 'off') { const source = spruce_skill_utils_1.diskUtil.resolvePath(__dirname, 'templates', 'RootViewController.test.ts.hbs'); const contents = spruce_skill_utils_1.diskUtil.readFile(source); const destination = spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, createTestOptions_schema_1.default.fields.testDestinationDir.defaultValue, 'behavioral', 'RootViewController.test.ts'); spruce_skill_utils_1.diskUtil.writeFile(destination, contents); this.Store('onboarding').reset(); } } generateCommandFromPayload(payload) { return feature_utilities_1.default.generateCommand(payload.featureCode, payload.actionCode); } isInstalled = async () => { return true; }; async confirmExpectedCommand(payload, store) { const command = this.generateCommandFromPayload(payload); const isExpectedCommand = this.isExpectedCommand(command, store); if (command !== 'setup.vscode' && payload.featureCode !== 'onboard' && !isExpectedCommand) { const player = await this.ScriptPlayer(); await player.playScriptWithKey('wrongCommand'); } } isExpectedCommand(command, store) { const stage = store.getStage(); const isExpectedCommand = command === stage; return isExpectedCommand; } } exports.default = OnboardFeature; //# sourceMappingURL=OnboardFeature.js.map