@erda-ui/cli
Version:
Command line interface for rapid Erda UI development
132 lines (131 loc) • 6.8 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const commander_1 = require("commander");
const inquirer_1 = __importDefault(require("inquirer"));
const build_1 = __importDefault(require("../lib/build"));
const build_enterprise_1 = __importDefault(require("../lib/build-enterprise"));
const build_online_1 = __importDefault(require("../lib/build-online"));
const build_enterprise_online_1 = __importDefault(require("../lib/build-enterprise-online"));
const add_license_1 = __importDefault(require("../lib/add-license"));
const check_license_1 = __importDefault(require("../lib/check-license"));
const init_1 = __importDefault(require("../lib/init"));
const init_online_1 = __importDefault(require("../lib/init-online"));
const i18n_1 = __importDefault(require("../lib/i18n"));
const local_icon_1 = __importDefault(require("../lib/local-icon"));
const service_generator_1 = __importDefault(require("../lib/service-generator"));
const check_build_status_1 = __importDefault(require("../lib/check-build-status"));
const fetch_image_content_1 = __importDefault(require("../lib/fetch-image-content"));
const program = new commander_1.Command();
inquirer_1.default.registerPrompt('directory', require('inquirer-select-directory'));
program.version(`erda-ui/cli ${require('../../package').version}`).usage('<command> [options]');
program
.command('init')
.description('install dependency & initialize .env config')
.option('-p, --port <port>', 'set scheduler port')
.option('-o, --override', 'ignore current .env file and override')
.option('--online', 'is online execution')
.option('--skipInstall', 'whether to skip the installation step')
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
const { online } = options, restOptions = __rest(options, ["online"]);
if (online) {
(0, init_online_1.default)();
}
else {
(0, init_1.default)(restOptions);
}
}));
program
.command('build')
.description('bundle files to public directory, pass true to launch a local full compilation build, pass image sha to launch a local partial compilation build based on image')
.option('--enableSourceMap', 'generate source map, default is false')
.option('--online', 'whether is online build, default is false')
.option('--enterprise', 'whether is enterprise build, default is false')
.option('--release', 'whether need build docker image & push, default is false')
.option('--registry', 'docker registry address which to push')
.option('--skipBuild', 'skip build and only run docker build & push command. Only take effect when --release is set')
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
const { online, enterprise } = options, restOptions = __rest(options, ["online", "enterprise"]);
if (online) {
enterprise ? (0, build_enterprise_online_1.default)() : (0, build_online_1.default)();
}
else {
enterprise ? (0, build_enterprise_1.default)(restOptions) : (0, build_1.default)(restOptions);
}
}));
program
.command('fetch-image')
.description('pull image by image tag version, run this image locally and copy the content to local folder')
.requiredOption('-i, --image <image>', 'image full tag name. e.g. registry.cn-hangzhou.aliyuncs.com/terminus/erda-ui:1.3-20210918-release')
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
(0, fetch_image_content_1.default)(options);
}));
program
.command('i18n')
.description('translate words in work dir')
.option('--switch', 'batch switch namespace')
.option('--external', 'handle external module i18n')
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
const { switch: switchNs, external } = options;
(0, i18n_1.default)({ isSwitchNs: switchNs, isExternal: external });
}));
program
.command('generate-service [workDir]')
.description('generate service by API swagger')
.action((_workDir) => __awaiter(void 0, void 0, void 0, function* () {
const workDir = _workDir ? path_1.default.resolve(process.cwd(), _workDir) : process.cwd();
(0, service_generator_1.default)({ workDir });
}));
program
.command('add-license')
.option('-t, --fileType <file_type>', 'File type', 'js,ts,jsx,tsx')
.description('add license header in files if not exist')
.action(({ fileType }) => {
(0, add_license_1.default)({ fileType });
});
program
.command('check-license')
.option('-t, --fileType <file_type>', 'File type', 'js,ts,jsx,tsx')
.option('-d, --directory <directory>', 'work directory')
.option('-f, --filter <filter>', 'filter log', 'warn')
.description('check license header in files')
.action(({ fileType, directory, filter }) => {
(0, check_license_1.default)({ fileType, directory, filter });
});
program
.command('check-build-status')
.description('compare git commit sha with previous build, if match it will skip build and reuse last built files. Only used in pipeline build')
.action(() => __awaiter(void 0, void 0, void 0, function* () {
(0, check_build_status_1.default)();
}));
program
.command('icon-localize')
.description('download icon resource and store at local image')
.action(() => __awaiter(void 0, void 0, void 0, function* () {
(0, local_icon_1.default)();
}));
program.parse(process.argv);