| 4 | import type { CliOptions } from './schema'; |
| 5 | |
| 6 | export const cliToConfig = (cli: CliOptions): Partial<UserConfig> => { |
| 7 | const config: Partial<UserConfig> = {}; |
| 8 | |
| 9 | if (cli.input) config.input = cli.input; |
| 10 | if (cli.output) config.output = cli.output; |
| 11 | if (cli.file) config.configFile = cli.file; |
| 12 | if (cli.dryRun !== undefined) config.dryRun = cli.dryRun; |
| 13 | |
| 14 | const plugins: ToArray<UserConfig['plugins']> = []; |
| 15 | if (cli.plugins instanceof Array && cli.plugins.length) { |
| 16 | plugins.push(...cli.plugins); |
| 17 | } |
| 18 | // if (cli.client) plugins.push(cli.client); |
| 19 | if (plugins.length) config.plugins = plugins; |
| 20 | |
| 21 | if (cli.debug || cli.silent || cli.logs || cli.logFile !== undefined) { |
| 22 | config.logs = { |
| 23 | ...(cli.logs && { path: cli.logs }), |
| 24 | ...(cli.debug && { level: 'debug' as const }), |
| 25 | ...(cli.silent && { level: 'silent' as const }), |
| 26 | ...(cli.logFile !== undefined && { file: cli.logFile }), |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | if (cli.watch !== undefined) { |
| 31 | if (typeof cli.watch === 'string') { |
| 32 | config.watch = Number.parseInt(cli.watch, 10); |
| 33 | } else { |
| 34 | config.watch = cli.watch; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return config; |
| 39 | }; |