|
11 | 11 | import { readFileSync, writeFileSync } from "fs"; |
12 | 12 | import { join, dirname } from "path"; |
13 | 13 | import { fileURLToPath } from "url"; |
14 | | -import { UserConfigSchema } from "../src/common/config.js"; |
| 14 | +import { OPTIONS, UserConfigSchema } from "../src/common/config.js"; |
15 | 15 | import type { ZodObject, ZodRawShape } from "zod"; |
16 | 16 |
|
17 | 17 | const __filename = fileURLToPath(import.meta.url); |
@@ -90,60 +90,6 @@ function extractZodDescriptions(): Record<string, ConfigMetadata> { |
90 | 90 | return result; |
91 | 91 | } |
92 | 92 |
|
93 | | -function parseOptionsFromConfig(): ParsedOptions { |
94 | | - const configPath = join(__dirname, "..", "src", "common", "config.ts"); |
95 | | - const configContent = readFileSync(configPath, "utf-8"); |
96 | | - |
97 | | - // Extract the OPTIONS object using regex |
98 | | - const optionsMatch = configContent.match(/const OPTIONS = \{([\s\S]*?)\} as Readonly<Options>;/); |
99 | | - |
100 | | - if (!optionsMatch) { |
101 | | - throw new Error("Could not find OPTIONS object in config.ts"); |
102 | | - } |
103 | | - |
104 | | - const optionsContent = optionsMatch[1]; |
105 | | - |
106 | | - // Parse each array type |
107 | | - const parseArray = (type: string): string[] => { |
108 | | - const regex = new RegExp(`${type}:\\s*\\[(.*?)\\]`, "s"); |
109 | | - const match = optionsContent?.match(regex); |
110 | | - if (!match) return []; |
111 | | - |
112 | | - // Extract quoted strings from the array |
113 | | - const arrayContent = match[1]; |
114 | | - if (!arrayContent) return []; |
115 | | - const items = arrayContent.match(/"([^"]+)"/g); |
116 | | - return items ? items.map((item) => item.replace(/"/g, "")) : []; |
117 | | - }; |
118 | | - |
119 | | - // Parse alias object |
120 | | - const parseAlias = (): Record<string, string> => { |
121 | | - const aliasMatch = optionsContent?.match(/alias:\s*\{([\s\S]*?)\}/); |
122 | | - if (!aliasMatch) return {}; |
123 | | - |
124 | | - const aliasContent = aliasMatch[1]; |
125 | | - if (!aliasContent) return {}; |
126 | | - const entries = aliasContent.matchAll(/(\w+):\s*"([^"]+)"/g); |
127 | | - const result: Record<string, string> = {}; |
128 | | - |
129 | | - for (const match of entries) { |
130 | | - if (match && match[1] && match[2]) { |
131 | | - result[match[1]] = match[2]; |
132 | | - } |
133 | | - } |
134 | | - |
135 | | - return result; |
136 | | - }; |
137 | | - |
138 | | - return { |
139 | | - string: parseArray("string"), |
140 | | - number: parseArray("number"), |
141 | | - boolean: parseArray("boolean"), |
142 | | - array: parseArray("array"), |
143 | | - alias: parseAlias(), |
144 | | - }; |
145 | | -} |
146 | | - |
147 | 93 | function generateEnvironmentVariables( |
148 | 94 | options: ParsedOptions, |
149 | 95 | zodMetadata: Record<string, ConfigMetadata> |
@@ -237,7 +183,13 @@ function updateServerJsonEnvVars(envVars: EnvironmentVariable[]): void { |
237 | 183 | const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as { version: string }; |
238 | 184 | const serverJson = JSON.parse(content) as { |
239 | 185 | version?: string; |
240 | | - packages: { environmentVariables: EnvironmentVariable[]; packageArguments?: unknown[]; version?: string }[]; |
| 186 | + packages: { |
| 187 | + registryType?: string; |
| 188 | + identifier?: string; |
| 189 | + environmentVariables: EnvironmentVariable[]; |
| 190 | + packageArguments?: unknown[]; |
| 191 | + version?: string; |
| 192 | + }[]; |
241 | 193 | }; |
242 | 194 |
|
243 | 195 | // Get version from package.json |
@@ -280,7 +232,13 @@ function updateServerJsonEnvVars(envVars: EnvironmentVariable[]): void { |
280 | 232 |
|
281 | 233 | function main(): void { |
282 | 234 | const zodMetadata = extractZodDescriptions(); |
283 | | - const options = parseOptionsFromConfig(); |
| 235 | + const options = { |
| 236 | + string: Array.from(OPTIONS.string), |
| 237 | + number: Array.from(OPTIONS.number), |
| 238 | + boolean: Array.from(OPTIONS.boolean), |
| 239 | + array: Array.from(OPTIONS.array), |
| 240 | + alias: { ...OPTIONS.alias }, |
| 241 | + }; |
284 | 242 |
|
285 | 243 | const envVars = generateEnvironmentVariables(options, zodMetadata); |
286 | 244 | updateServerJsonEnvVars(envVars); |
|
0 commit comments