()
| 100 | } |
| 101 | |
| 102 | async function main() { |
| 103 | const cliOptions = parseDevProxyCliArgs(process.argv.slice(2)) |
| 104 | |
| 105 | if (cliOptions.help) { |
| 106 | printUsage() |
| 107 | return |
| 108 | } |
| 109 | |
| 110 | const config = await loadDevProxyConfig(cliOptions.config, process.cwd(), { |
| 111 | envFile: cliOptions.envFile, |
| 112 | }) |
| 113 | const runtime = createDevProxyRuntime(config, cliOptions) |
| 114 | |
| 115 | if (cliOptions.watch === false) |
| 116 | return |
| 117 | |
| 118 | const configWatcher = await watchDevProxyConfig(cliOptions.config, process.cwd(), { |
| 119 | envFile: cliOptions.envFile, |
| 120 | onUpdate: ({ newConfig }) => runtime.enqueueReload(() => newConfig.config, 'config changes'), |
| 121 | }) |
| 122 | |
| 123 | const envWatcher = cliOptions.envFile |
| 124 | ? watch(cliOptions.envFile, { |
| 125 | cwd: process.cwd(), |
| 126 | ignoreInitial: true, |
| 127 | }) |
| 128 | : undefined |
| 129 | |
| 130 | envWatcher?.on('all', () => { |
| 131 | void runtime.enqueueReload( |
| 132 | () => loadDevProxyConfig(cliOptions.config, process.cwd(), { |
| 133 | envFile: cliOptions.envFile, |
| 134 | }), |
| 135 | 'env file changes', |
| 136 | ) |
| 137 | }) |
| 138 | |
| 139 | const cleanup = async () => { |
| 140 | await envWatcher?.close() |
| 141 | await configWatcher.unwatch() |
| 142 | await runtime.close() |
| 143 | } |
| 144 | |
| 145 | process.once('SIGINT', () => { |
| 146 | void cleanup().finally(() => process.exit(0)) |
| 147 | }) |
| 148 | process.once('SIGTERM', () => { |
| 149 | void cleanup().finally(() => process.exit(0)) |
| 150 | }) |
| 151 | } |
| 152 | |
| 153 | try { |
| 154 | await main() |
no test coverage detected