Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions scripts/generateClientTypesMap/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { exec } from "node:child_process";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { format } from "prettier";
import { promisify } from "node:util";

import {
CLIENT_NAMES,
Expand All @@ -11,8 +12,7 @@ import {
import { getClientReqRespTypesMap } from "./getClientReqRespTypesMap";
import { getClientTypesMap } from "./getClientTypesMap";

const codegenComment = `// This file is generated by scripts/generateClientTypesMap/index.ts
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.`;
const execAsync = promisify(exec);

(async () => {
for (const [mapName, getTypesMap] of [
Expand All @@ -22,7 +22,9 @@ const codegenComment = `// This file is generated by scripts/generateClientTypes
const filePath = join("src", "transforms", "v2-to-v3", "config", `${mapName}.ts`);
const relativeFilePath = join(__dirname, "..", "..", filePath);

let fileContent = codegenComment;
let fileContent = "// This file is generated by scripts/generateClientTypesMap/index.ts\n";
fileContent +=
"// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.\n";

fileContent += "\n\n\n";
fileContent += `export const ${mapName}: Record<string, Record<string, string>> = `;
Expand All @@ -37,11 +39,8 @@ const codegenComment = `// This file is generated by scripts/generateClientTypes
}

fileContent += JSON.stringify(clientTypesMap);
fileContent += ";\n";

await writeFile(
relativeFilePath,
await format(fileContent, { parser: "typescript", printWidth: 100 })
);
await writeFile(relativeFilePath, fileContent);
await execAsync(`yarn biome format --write ${relativeFilePath}`);
}
})();