UNPKG

recastify

Version:

Web Component transfiguration tool. Convert Web Components in a multitude of formats to other formats.

142 lines (141 loc) 5.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* eslint-disable operator-linebreak */ /* eslint-disable indent */ const core_1 = require("@oclif/core"); const inquirer = require("inquirer"); const outline_to_inline_1 = require("../core/outline-to-inline"); class Outline extends core_1.Command { static description = "Converts an Outline component to InlineJS."; static examples = ["<%= config.bin %> <%= command.id %>"]; async run() { /** * Determine if this component is remotely hosted in a package and if so, * we will present prompts to the user to determine which component to * download and convert. */ const isRemote = await inquirer.prompt([ { name: "remote", message: "Is this a remotely hosted component?", type: "confirm", default: true, }, ]); /** * If the component is remotely hosted, we will prompt the user to * let us know if there is a scope (@company) and the name of the scope if so. */ // @todo: Handle error messaging. const hasScope = await inquirer.prompt([ { name: "scope", message: "Does this remote component have an @scope?", type: "confirm", default: true, when: isRemote.remote, }, ]); /** * If the component is remotely hosted, we will prompt the user to * let us know if there is a scope (@company) and the name of the scope if so. */ // @todo: Handle error messaging. const sourceScope = await inquirer.prompt([ { name: "scope", message: "What is the scope of the component?", type: "input", default: "@phase2", when: hasScope.scope === true, validate: function (input) { if (input && typeof input === "string") { return true; } return false; }, }, ]); // @todo: Handle error messaging. const sourceComponent = await inquirer.prompt([ { name: "component", message: "What is the name of the original component?", type: "input", default: "outline-card", when: isRemote.remote === true, validate: function (input) { if (input && typeof input === "string") { return true; } return false; }, }, ]); const remoteComponent = await inquirer.prompt([ { name: "remoteLocation", message: `Is this component located at ${hasScope.scope ? `${sourceScope.scope}/` : ""}${sourceComponent.component}?`, type: "confirm", default: true, when: isRemote.remote, }, ]); const componentName = await inquirer.prompt([ { name: "name", message: "What is the name of the new component?", type: "input", default: "inline-card", validate: function (input) { if (input && typeof input === "string") { return true; } return false; }, }, ]); const destination = await inquirer.prompt([ { name: "path", message: "Where should the copied component live?", type: "input", default: "src/components", validate: function (input) { if (input && typeof input === "string") { return true; } return false; }, }, ]); const impression = await inquirer.prompt([ { name: "impression", message: "How does this tool make you feel.", type: "list", choices: [{ name: "good" }, { name: "great" }, { name: "angry" }], default: "angry", validate: function (input) { if (input && typeof input === "string") { return true; } return false; }, }, ]); // const {args, flags} = await this.parse(Init) const prompts = { remote: isRemote.remote, hasScope: hasScope.scope, scope: sourceScope ? sourceScope.scope : false, src: sourceComponent ? sourceComponent.component : false, package: remoteComponent ? remoteComponent.remoteLocation : false, name: componentName.name, path: destination.path, impression: impression.impression, }; (0, outline_to_inline_1.convertComponent)(prompts); } } exports.default = Outline;