import cac from 'cac'; import { blue, lightGreen } from 'kolorist'; import { version } from '../package.json'; import { cleanup, gitCommit, gitCommitVerify, updatePkg } from './commands'; import { loadCliOptions } from './config'; type Command = 'cleanup' | 'update-pkg' | 'git-commit' | 'git-commit-verify'; type CommandAction = (args?: A) => Promise | void; type CommandWithAction = Record }>; interface CommandArg { total?: boolean; } export async function setupCli() { const cliOptions = await loadCliOptions(); const cli = cac(blue('soybean')); cli.version(lightGreen(version)).help(); const commands: CommandWithAction = { cleanup: { desc: 'delete dirs: node_modules, dist, etc.', action: async () => { await cleanup(cliOptions.cleanupDirs); } }, 'update-pkg': { desc: 'update package.json dependencies versions', action: async () => { await updatePkg(cliOptions.ncuCommandArgs); } }, 'git-commit': { desc: 'git commit, generate commit message which match Conventional Commits standard', action: async () => { await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes); } }, 'git-commit-verify': { desc: 'verify git commit message, make sure it match Conventional Commits standard', action: async () => { await gitCommitVerify(); } } }; for (const [command, { desc, action }] of Object.entries(commands)) { cli.command(command, lightGreen(desc)).action(action); } cli.parse(); } setupCli();