import { configHttpsAgent } from '@/https-agent-config' import { add } from '@/lib/add' import { updateCIConfig } from '@/lib/ci' import { init } from '@/lib/init' import { invoke } from '@/lib/invoke' import { login } from '@/lib/login' import { packup } from '@/lib/packup' import { pickteam } from '@/lib/pickteam' import { scan } from '@/lib/scan' import { update } from '@/lib/update' import { upgrade } from '@/lib/upgrade' import { recordCurrentLogLevel } from '@/output' import { getLocalConfigContent } from '@/scripts' import { getCliVersionByMetaPath } from '@ones-open/cli-utils' import { Command } from 'commander' const cliVersion = (await getCliVersionByMetaPath(import.meta.url)) || 'unknown' const PRE_ACTION_EVENT = 'preAction' const commonPreActionHandler = async () => { const localConfig = (await getLocalConfigContent().catch(() => {})) || undefined recordCurrentLogLevel(localConfig) configHttpsAgent(localConfig) } const op = new Command('op') const LOGIN_COMMAND_HELP_MESSAGE = ` Example: npx op login enter the interactive Q&A process and input the login parameters npx op login https://dev.ones.ai login to 'https://dev.ones.ai' environment and then enter the inquiry session flow input rest parameters: hostURL, username, password npx op login https://dev.ones.ai tcp://dev.ones.ai:9006 -u test@ones.ai -p password login to 'https://dev.ones.ai' environment and set hostURL to 'tcp://dev.ones.ai:9006' with two parameters and not enter the interactive Q&A process npx op login https://partnerdev.ones.ai tcp://dev.ones.ai:9006 -s https://dev.ones.ai use 'https://dev.ones.ai' scope parameters to login to 'https://partnerdev.ones.ai' environment Note: Argument [baseURL] and [hostURL] is protocol sensitive, different protocol type will be treated as a different scope After login successfully, CLI will store the scope parameters into '~/.ones/cli-plugin.yaml' for local debugging And at the same time, this command will try to run 'npx op pickteam -t local' automatically if the current project has never had a team picked before ` const CI_COMMAND_HELP_MESSAGE = ` Example: npx op ci enter the interactive Q&A process and input the parameters for CI deployment npx op ci https://dev.ones.ai specify the environment address for the CI deployment as 'https://dev.ones.ai', and then enter the interactive Q&A process input rest parameters: branch, username, password npx op ci https://dev.ones.ai -b next -u test@ones.ai -p password specify the environment address for the CI deployment as 'https://dev.ones.ai', and not enter the interactive Q&A process input rest parameters npx op ci https://partnerdev.ones.ai -b next -s https://dev.ones.ai use 'https://dev.ones.ai' scope parameters and specify the environment address for the CI deployment as 'https://partnerdev.ones.ai' Note: Argument [url] is protocol sensitive, different protocol type will be treated as a different scope Unlike the 'npx op login', current command does not store the scope parameters into '~/.ones/cli-plugin.yaml' But if the current branch has never picked a team after the run is complete, "npx op pickteam -t ci -b $currentSpecifyBranch" will be automatically executed which is consistent ` const PICKTEAM_COMMAND_HELP_MESSAGE = ` Example: npx op pickteam local fetch the team list with the user credentials stored in the 'config/local.config' (if does not store user credentials, you need to execute 'npx op login' first) npx op pickteam ci display the branch list with the user credentials stored in the 'config/ci-deploy.config', and enter the interactive Q&A process for choosing the branch to fetch the team list (if does not store user credentials, you need to execute 'npx op ci' first) npx op pickteam ci -b next fetch the team list with the user credentials stored in 'config/ci-deploy.config' with the branch name 'next' please note that the branch name is case sensitive, and the branch name must be the same as the branch name in the 'config/ci-deploy.config' the CLI will throw an error if no branch name matches npx op pickteam local --team-uuid T7YB134K fetch the team list with the user credentials stored in the 'config/local.config' after fetching the team list, CLI will try to pick the team with the team UUID 'T7YB134K' the CLI will throw an error if no team UUID matches npx op pickteam ci -b next --team-name TestTeamName fetch the team list with the user credentials stored in 'config/ci-deploy.config' with the branch name 'next' after fetching the team list, CLI will try to pick the team with the team name 'TestTeamName' the CLI will throw an error if no team name matches Note: Before performing this operation, the login operation should be completed in the corresponding target When team-uuid and team-name are specified at the same time, only team-uuid will be used ` const INVOKE_COMMAND_HELP_MESSAGE = ` The target can point to the process or the life-cycles, the difference between them is that the process will contain multiple life-cycles Available processes: 1. run: When executed, the 'install' and 'enable' and 'start' life-cycle are called in turn 2. clear: When executed, the 'stop' and 'disable' and 'uninstall' life-cycle are called in turn ` op.version(cliVersion, '-v, --version', 'output the current version') op.command('init') .description('initialize project settings, please run this command in project root directory') .action(init) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('login') .description( `store the parameters used to obtain user credentials in a specific environment into 'config/local.yaml'`, ) .argument('[baseURL]', `specify the environment url for login`) .argument('[hostURL]', `specify the host url for local debugging`) .option('-u, --username ', 'username can be email or phone number') .option('-p, --password ', 'password') .option( '-s, --scope [url]', `use specific scope parameters login, default is current environment url, this option is mutually exclusive with -u, -p options`, ) .addHelpText('after', LOGIN_COMMAND_HELP_MESSAGE) .action(login) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('ci') .description( `store the parameters used to obtain user credentials in a specific branch for (gitlab) CI into 'config/ci-deploy.yaml'`, ) .argument('[url]', `specify the environment url for login`) .option( '-b, --branch-name ', `specify the branch name for CI deployment configuration, default is 'master' or 'main' branch`, ) .option('-u, --username ', 'username can be email or phone number') .option('-p, --password ', 'password') .option( '-s, --scope [url]', `use specific scope parameters login, default is current environment url, this option is mutually exclusive with -u, -p options`, ) .addHelpText('after', CI_COMMAND_HELP_MESSAGE) .action(updateCIConfig) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('pickteam') .description( `fetch the team list with the user credentials stored in the config file and update the config file with the team information from the team list for local debugging or CI deployment`, ) .argument( `[target]`, `specify the target type configuration for which team information needs to be updated, target type only can be 'local' or 'ci'`, ) .option( '-b, --branch-name ', `it only takes effect when the target type is 'ci', specify a branch name for the CI deployment configuration, leave blank or not specify a value to enter the interactive Q&A for branch name selection`, ) .option( '--team-uuid ', `match the specified team uuid in the team list, this option is mutually exclusive with '--team-name'`, ) .option( '--team-name ', `match the specified team name in the team list, this option is mutually exclusive with '--team-uuid'`, ) .addHelpText('after', PICKTEAM_COMMAND_HELP_MESSAGE) .action(pickteam) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('add') .description('add a ability or module for the project') .argument( '', 'specify a content type that you want to add, support: ability, module, sub-module, event', ) .action(add) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('packup') .description('pack up the plugin project and build .opk file in the root directory') .action(packup) .option('--bump ', `select the packup bump mode`) .option('--release', `build the release version of the plugin`) .argument('[filename]', 'specify the name of the .opk file, default is the project name') .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('invoke') .description( 'start the plugin project locally and invoke one or several life-cycles of the plugin', ) .argument( '', 'specify the process (run, clear) or life-cycle (install, start, enable, disable, stop, uninstall) you want to invoke', ) .option('--mode ', `specify the mode, support: 'all', 'backend', 'frontend'`, 'all') .option( '--webpack-stats-preset ', `specify the webpack logging level, support: 'errors-only', 'errors-warnings', 'minimal', 'none','normal','verbose','detailed','summary'`, ) .option( '--reinstall-plugin', `'appid' is conflict between plugin which installed by user and plugin run by developer in the same scope, plugin installed by user will be uninstalled`, ) .option('--skip-verify-user-profile', `skip the verification of user profile`) .addHelpText('after', INVOKE_COMMAND_HELP_MESSAGE) .action(invoke) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('upgrade') .description('upgrade cli-plugin for the project') .action(upgrade) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('update') .description('update package for the project') .argument('', 'specify a content type that you want to update, support: template') .action(update) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.command('scan') .description('scan the project and collect all the APIs the plugin used') .option('-o, --output ', 'specify the output path of the scan result') .argument('[target]', `specify the target to scan, support: 'api' and 'trigger'`) .action(scan) .hook(PRE_ACTION_EVENT, commonPreActionHandler) op.parse()