UNPKG

@imqueue/cli

Version:

Command Line Interface for IMQ

57 lines 2.21 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.handler = exports.promptOverride = exports.builder = exports.describe = exports.command = void 0; const rpc_1 = require("@imqueue/rpc"); const fs = require("fs"); const p = require("path"); const inquirer_1 = 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_1.default.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 (0, exports.promptOverride)(filePath); } await rpc_1.IMQClient.create(name, { compile: false, path: path, }); process.stdout.write(chalk_1.default.green('Successfully created. Path: ') + chalk_1.default.cyan(filePath) + '\n'); } catch (err) { (0, lib_1.printError)(err); } }, }, exports.command = _a.command, exports.describe = _a.describe, exports.builder = _a.builder, exports.promptOverride = _a.promptOverride, exports.handler = _a.handler; //# sourceMappingURL=generate.js.map