Skip to content

Commit 9724f95

Browse files
committed
chore: import options
1 parent df96544 commit 9724f95

File tree

1 file changed

+15
-57
lines changed

1 file changed

+15
-57
lines changed

scripts/generateArguments.ts

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import { readFileSync, writeFileSync } from "fs";
1212
import { join, dirname } from "path";
1313
import { fileURLToPath } from "url";
14-
import { UserConfigSchema } from "../src/common/config.js";
14+
import { OPTIONS, UserConfigSchema } from "../src/common/config.js";
1515
import type { ZodObject, ZodRawShape } from "zod";
1616

1717
const __filename = fileURLToPath(import.meta.url);
@@ -90,60 +90,6 @@ function extractZodDescriptions(): Record<string, ConfigMetadata> {
9090
return result;
9191
}
9292

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-
14793
function generateEnvironmentVariables(
14894
options: ParsedOptions,
14995
zodMetadata: Record<string, ConfigMetadata>
@@ -237,7 +183,13 @@ function updateServerJsonEnvVars(envVars: EnvironmentVariable[]): void {
237183
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as { version: string };
238184
const serverJson = JSON.parse(content) as {
239185
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+
}[];
241193
};
242194

243195
// Get version from package.json
@@ -280,7 +232,13 @@ function updateServerJsonEnvVars(envVars: EnvironmentVariable[]): void {
280232

281233
function main(): void {
282234
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+
};
284242

285243
const envVars = generateEnvironmentVariables(options, zodMetadata);
286244
updateServerJsonEnvVars(envVars);

0 commit comments

Comments
 (0)