oak-cli/lib/index.js

135 lines
5.1 KiB
JavaScript
Executable File

#!/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");
/**
* @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);
};
}
const currentNodeVersion = process.versions.node;
const semver = currentNodeVersion.split('.');
const major = semver[0];
const minNodeVersion = 16;
if (Number(major) < minNodeVersion) {
console.error('You are running Node ' +
currentNodeVersion +
'.\n' +
'Create React App requires Node ' +
minNodeVersion +
' or higher. \n' +
'Please update your version of Node.');
process.exit(-1);
}
commander_1.default.version(config_1.CLI_VERSION, '-v, --version').usage('<command> [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')
.description('make dependency')
.action(makeDependency_1.default);
commander_1.default
.command('start')
.option('--sourcemap', 'sourcemap')
.option('--analyze', 'analyze')
.option('--memoryLimit <memoryLimit>', 'memoryLimit of node')
.option('--stackSize <number>', 'stackSize of node')
.option('--open', 'open in browser')
.option('-t, --target <target>', 'target')
.option('-m, --mode <mode>', 'mode')
.option('-d, --subDir <subDirName>', 'subDirName')
.option('-p, --port <port>', 'port')
.option('-dm, --devMode <devMode>', 'devMode')
.option('--resetCache', '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>', 'memoryLimit of node')
.option('--stackSize <number>', 'stackSize of node')
.option('-t, --target <target>', 'target')
.option('-m, --mode <mode>', 'mode')
.option('-d, --subDir <subDirName>', 'subDirName')
.option('-p, --platform <platform>', 'platform')
.description('build project of build on demand')
.action(build_1.default);
commander_1.default
.command('create <name>')
.usage('<name>')
.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
.rename('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 <name> [subDirName]')
.usage('<name>')
.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>', 'platform')
.option('-d, --subDir <subDirName>', 'subDirName')
.option('-m, --mode <mode>', 'mode')
.option('-suffix, --appIdSuffix <appIdSuffix>', 'appIdSuffix')
.description(`run rn by ${config_1.CLI_NAME}`)
.action(run_1.default);
commander_1.default
.command('clean')
.option('-p, --platform <platform>', 'platform')
.option('-d, --subDir <subDirName>', 'subDirName')
.description(`clean rn build by ${config_1.CLI_NAME}`)
.action(clean_1.default);
// output help information on unknown commands
commander_1.default.arguments('<command>').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);