UNPKG

@cto.ai/ops

Version:

💻 CTO.ai Ops - The CLI built for Teams 🚀

93 lines (92 loc) • 3.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); /** * Author: Brett Campbell (brett@hackcapital.com) * Date: Saturday, 6th April 2019 10:39:58 pm * Last Modified By: Brett Campbell (brett@hackcapital.com) * Last Modified Time: Saturday, 6th April 2019 10:40:00 pm * * DESCRIPTION * */ const sdk_1 = require("@cto.ai/sdk"); const fs = tslib_1.__importStar(require("fs-extra")); const path = tslib_1.__importStar(require("path")); const base_1 = tslib_1.__importStar(require("../base")); const opConfig_1 = require("../constants/opConfig"); const CustomErrors_1 = require("../errors/CustomErrors"); const utils_1 = require("../utils"); class Build extends base_1.default { constructor() { super(...arguments); this.resolvePath = (inputs) => { let { opPath } = inputs; if (!opPath) throw new CustomErrors_1.MissingRequiredArgument('ops [command]'); opPath = path.resolve(process.cwd(), opPath); return Object.assign(Object.assign({}, inputs), { opPath }); }; this.getOpsFromFileSystem = async (inputs) => { const { opPath } = inputs; const manifest = await fs .readFile(path.join(opPath, opConfig_1.OP_FILE), 'utf8') .catch(err => { this.debug('%O', err); throw new CustomErrors_1.FileNotFoundError(err, opPath, opConfig_1.OP_FILE); }); if (!manifest) { throw new CustomErrors_1.NoLocalOpsFound(); } const { ops } = utils_1.parseYaml(manifest); if (!ops) { throw new CustomErrors_1.NoLocalOpsFound(); } return Object.assign(Object.assign({}, inputs), { ops }); }; this.selectOpToBuild = async (inputs) => { const { ops } = inputs; if (ops.length === 1) { return Object.assign(Object.assign({}, inputs), { opsToBuild: ops }); } const { opsToBuild } = await sdk_1.ux.prompt({ type: 'checkbox', name: 'opsToBuild', message: `\n Which ops would you like to build ${sdk_1.ux.colors.reset.green('→')}`, choices: ops.map(op => { return { value: op, name: `${op.name} - ${op.description}`, }; }), validate: input => input.length > 0, }); return Object.assign(Object.assign({}, inputs), { opsToBuild }); }; this.executeOpService = async (inputs) => { const { opsToBuild, opPath, config } = inputs; await this.services.opService.opsBuildLoop(opsToBuild, opPath, config); return inputs; }; } async run() { const { args: { path }, } = this.parse(Build); try { await this.isLoggedIn(); const buildPipeline = utils_1.asyncPipe(this.resolvePath, this.getOpsFromFileSystem, this.selectOpToBuild, this.executeOpService); await buildPipeline({ opPath: path, config: this.state.config }); } catch (err) { this.debug('%O', err); this.config.runHook('error', { err, accessToken: this.accessToken }); } } } exports.default = Build; Build.description = 'Build your op for sharing.'; Build.flags = { help: base_1.flags.help({ char: 'h' }), }; Build.args = [ { name: 'path', description: 'Path to the op you want to build.' }, ];