UNPKG

imq-cli

Version:

Command Line Interface for IMQ

56 lines 2.07 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); const imq_rpc_1 = require("imq-rpc"); const fs = require("fs"); const p = require("path"); const inquirer = require("inquirer"); const chalk_1 = require("chalk"); const lib_1 = require("../../lib"); // noinspection JSUnusedGlobalSymbols _a = { command: 'generate <name> [path]', describe: 'Generates IMQ-RPC client for a specified service', builder(yargs) { return yargs .option('o', { alias: 'overwrite', describe: 'Overwrite existing client without prompt', boolean: true }) .describe('path', 'Directory where client file should be placed') .default('path', '.'); }, async promptOverride(filePath) { const write = (await inquirer.prompt([{ type: 'confirm', name: 'overwrite', default: false, message: `File "${filePath}" already exists. Overwrite it?` }])).overwrite; if (!write) { process.stdout.write(chalk_1.default.yellow('File exists, overwrite disabled, exit...')); process.exit(0); } }, async handler(argv) { try { const { path, name } = argv; const filePath = p.resolve(path, `${name}.ts`); const exists = fs.existsSync(filePath); if (!argv.o && exists) { await this.promptOverride(filePath); } await imq_rpc_1.IMQClient.create(name, { compile: false, path }); process.stdout.write(chalk_1.default.green('Successfully created. Path: ') + chalk_1.default.cyan(filePath) + '\n'); } catch (err) { lib_1.printError(err); } } }, exports.command = _a.command, exports.describe = _a.describe, exports.builder = _a.builder, exports.handler = _a.handler, exports.promptOverride = _a.promptOverride; //# sourceMappingURL=generate.js.map