UNPKG

@unito/integration-cli

Version:

Integration CLI

52 lines (51 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const core_1 = require("@oclif/core"); const chalk_1 = tslib_1.__importDefault(require("chalk")); const inquirer_1 = tslib_1.__importDefault(require("inquirer")); const Configuration = tslib_1.__importStar(require("../resources/configuration")); const integrations_1 = require("../resources/integrations"); const baseCommand_1 = require("../baseCommand"); const errors_1 = require("../errors"); class Init extends baseCommand_1.BaseCommand { static description = 'Initialize a new integration'; static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --name pokemon']; static flags = { name: core_1.Flags.string({ char: 'n', description: 'Name of the integration' }), }; async catch(error) { /* istanbul ignore if */ if ((0, errors_1.handleError)(this, error)) { this.exit(-1); } throw error; } async run() { const { flags: { name: nameFromFlag }, } = await this.parse(Init); const name = nameFromFlag ?? (await inquirer_1.default.prompt([ { type: 'input', name: 'name', message: [ chalk_1.default.gray('Choose a name for your integration.'), chalk_1.default.gray('A folder will be created with the value provided.'), chalk_1.default.gray('Note that "My Integration" will become "my_integration".'), chalk_1.default.yellowBright('What is the name of your integration?'), ].join('\n'), filter: (name) => name .toLowerCase() .replace(/ /g, '_') .replace(/[^a-z0-9_-]*/g, ''), }, ])).name; core_1.ux.action.start('\nInitializing integration', undefined, { stdout: true }); const generatedPath = await (0, integrations_1.copyBoilerplate)(name, process.cwd()); process.chdir(generatedPath); await Configuration.writeConfiguration({ name }); core_1.ux.action.stop(); core_1.ux.log(`Your integration is available at: ${chalk_1.default.greenBright(generatedPath)}`); } } exports.default = Init;