MCPcopy Create free account
hub / github.com/langgenius/dify / main

Function main

packages/dev-proxy/src/cli.ts:102–151  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100}
101
102async 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
153try {
154 await main()

Callers 1

cli.tsFile · 0.70

Calls 10

parseDevProxyCliArgsFunction · 0.90
loadDevProxyConfigFunction · 0.90
watchDevProxyConfigFunction · 0.90
createDevProxyRuntimeFunction · 0.85
printUsageFunction · 0.70
cleanupFunction · 0.70
sliceMethod · 0.45
onMethod · 0.45
finallyMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected