UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

63 lines 2.18 kB
"use strict"; 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: 'watchViewsOptions', description: 'Watch for view changes and preview them in real time.', fields: {}, }); class WatchAction extends AbstractAction_1.default { commandAliases = ['watch.views']; optionsSchema = optionsSchema; invocationMessage = 'Watching views... 🤩'; skillName; skillNamespace; async execute() { const skill = this.Service('auth').getCurrentSkill(); this.skillName = skill?.name ?? 'Unknown'; this.skillNamespace = skill?.slug ?? 'heartwood'; this.resetUi(); const commands = this.Service('command'); await commands.execute('SHOULD_WATCH_VIEWS=true MAXIMUM_LOG_PREFIXES_LENGTH=0 yarn boot', { onData: (data) => { const line = this.popLastLine(data); this.ui.startLoading(line); }, }); return { summaryLines: [`Done watching...`], }; } popLastLine(data) { const line = data .trim() .split('\n') .filter((s) => !!s) .pop(); return line && line.length > 0 ? line.trim() : 'Waiting for changes'; } getPreviewUrl() { const host = this.Service('remote').getHost(); return host + `/#views/${this.skillNamespace}.root`; } resetUi() { this.ui.clear(); this.ui.renderHero('Heartwood'); this.ui.renderDivider(); this.ui.renderLines([ '', `Skill: ${this.skillName}`, `Preview: ${this.getPreviewUrl()}`, '', ]); this.ui.renderDivider(); this.ui.renderLine(''); this.ui.startLoading('Watching for changes'); } } exports.default = WatchAction; //# sourceMappingURL=WatchAction.js.map