import i18n from './utils/i18n'; import * as program from 'commander'; import { handlerProfileFile } from './utils/handler-set-config'; import logger from './utils/logger'; import { registerCommandChecker, registerExitOverride, recordCommandHistory, registerCustomerCommand, regiserUniversalCommand } from './utils/command'; import {checkAndReturnCurrentDirTemplateFile} from './utils/common'; const description = ` _________ .__ / _____/ ______________ __ ___________| | ____ ______ ______ \\_____ \\_/ __ \\_ __ \\ \\/ // __ \\_ __ \\ | _/ __ \\ / ___// ___/ / \\ ___/| | \\/\\ /\\ ___/| | \\/ |_\\ ___/ \\___ \\ \\___ \\ /_______ /\\___ >__| \\_/ \\___ >__| |____/\\___ >____ >____ > \\/ \\/ \\/ \\/ \\/ \\/ ${i18n.__('Welcome to the Serverless Tool.')} ${i18n.__('You can use the corresponding function through the following instructions.')} `; (async () => { // 初始化打印配置, 默认开启 const setConfigObject = await handlerProfileFile({ read: true }); const outputColorFlag = setConfigObject['output-color'] === false ? false : true; logger.colorSwitch(outputColorFlag); // logger.log(`${(('@s/cli@' + pkg.version) as any).padStart(20, ' ')}`); let system_command = program .version('', '-v, --version', i18n.__('Output the version number')) .description(description) .helpOption('-h, --help', i18n.__('Display help for command')) // .option('--verbose', i18n.__('Verbose output')) .command('config', i18n.__('Configure cloud service account.')) .command('init', i18n.__('Initializing a project.')) .command('search', i18n.__('Search the package.')) .command('platform', i18n.__('Publish a(an) Component/Plugin/Application.')) .command('set', i18n.__('Settings for the tool.')) .addHelpCommand(false); // registerVerbose(program); // 调试模式验证 const templateFile = checkAndReturnCurrentDirTemplateFile(); process['env']['templateFile'] = templateFile; // 判断是否使用了基础指令,没用的话,增加泛指令等 if (!['init', 'config', 'platform', 'search', 'set'].includes(process.argv[2])) { await registerCustomerCommand(program, templateFile); // 增加用户自定义命令 await regiserUniversalCommand(program, templateFile); // 注册泛指令 } // 错误指令 registerCommandChecker(program); // 验证版本 await registerExitOverride(program); try { // 记录命令 recordCommandHistory(process.argv); } catch (ex) {} system_command.parse(process.argv); })();