Skip to content

Commit

Permalink
Use biome CLI for formatting client types map (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Jul 28, 2024
1 parent 8ae9bf1 commit a777b79
Showing 1 changed file with 8 additions and 9 deletions.
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}`);
}
})();

0 comments on commit a777b79

Please sign in to comment.