#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const commander_1 = tslib_1.__importDefault(require("commander")); const create_1 = require("./create"); const build_1 = tslib_1.__importDefault(require("./build")); const makeDomain_1 = tslib_1.__importDefault(require("./makeDomain")); const makeLocale_1 = tslib_1.__importDefault(require("./makeLocale")); const makeDependency_1 = tslib_1.__importDefault(require("./makeDependency")); const run_1 = tslib_1.__importDefault(require("./run")); const clean_1 = tslib_1.__importDefault(require("./clean")); const config_1 = require("./config"); const tip_style_1 = require("./tip-style"); const rename_1 = require("./rename"); const utils_1 = require("./utils"); /** * @name 未知参数错误提示 * @param {string} methodName * @param {Function} log */ function enhanceErrorMessages(methodName, log) { commander_1.default.Command.prototype[methodName] = function (...args) { if (methodName === 'unknownOption' && this._allowUnknownOption) { return; } this.outputHelp(); console.log(` ` + (0, tip_style_1.error)(log(...args))); console.log(); process.exit(-1); }; } (0, utils_1.checkNodeVersion)(); commander_1.default.version(config_1.CLI_VERSION, '-v, --version').usage(' [options]'); commander_1.default .command('make:domain') .description('make oak app domain') .action(makeDomain_1.default); commander_1.default .command('make:locale') .description('make locales') .option('-a --asLib', 'asLib') .option('-w --watch', 'watch') .action(makeLocale_1.default); commander_1.default .command('make:dependency') .option('-r --rebuild', 'rebuild') .description('make dependency') .action(makeDependency_1.default); commander_1.default .command('start') .option('--sourcemap', 'sourcemap') .option('--analyze', 'analyze') .option('--memoryLimit ', 'memoryLimit of node') .option('--stackSize ', 'stackSize of node') .option('--open', 'open in browser') .option('-t, --target ', 'target') .option('-m, --mode ', 'mode') .option('-d, --subDir ', 'subDirName') .option('-p, --port ', 'port') .option('-dm, --devMode ', 'devMode') .option('--reset', 'react native start --reset-cache') .description('build project of start on demand') .action(build_1.default); commander_1.default .command('build') .option('--sourcemap', 'sourcemap') .option('--analyze', 'analyze') .option('--memoryLimit ', 'memoryLimit of node') .option('--stackSize ', 'stackSize of node') .option('-t, --target ', 'target') .option('-m, --mode ', 'mode') .option('-d, --subDir ', 'subDirName') .option('-p, --platform ', 'platform') .description('build project of build on demand') .action(build_1.default); commander_1.default .command('create ') .usage('') .option('-d, --dev', 'dev') .option('-m, --module', 'module') .description(`create a new project powered by ${config_1.CLI_NAME}`) .action(create_1.create); commander_1.default .command('rename') .option('-on --old-name', 'oldName') .option('-nn --new-name', 'newName') .option('-ot --old-title', 'oldTitle') .option('-nt --new-title', 'newTitle') .description('rename an existed project') .action(rename_1.rename); commander_1.default .command('update [subDirName]') .usage('') .option('-d, --dev', 'dev') .description(`update project's template powered by ${config_1.CLI_NAME}`) .action(create_1.update); commander_1.default .command('run') .option('-p, --platform ', 'platform') .option('-d, --subDir ', 'subDirName') .option('-m, --mode ', 'mode') .option('-suffix, --appIdSuffix ', 'appIdSuffix') .description(`run rn by ${config_1.CLI_NAME}`) .action(run_1.default); commander_1.default .command('clean') .option('-p, --platform ', 'platform') .option('-d, --subDir ', 'subDirName') .description(`clean rn build by ${config_1.CLI_NAME}`) .action(clean_1.default); // output help information on unknown commands commander_1.default.arguments('').action((cmd) => { commander_1.default.outputHelp(); console.log(); console.log(` ` + `${(0, tip_style_1.error)(`Unknown command ${(0, tip_style_1.warn)(cmd)}`)}`); console.log(); }); enhanceErrorMessages('missingArgument', (argName) => { console.log(); return `${(0, tip_style_1.error)(`Missing required argument ${(0, tip_style_1.warn)(argName)}.`)}`; }); commander_1.default.parse(process.argv);