Skip to content

Commit

Permalink
chore(scripts): attempt to programatically format
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Jul 28, 2024
1 parent d1044a6 commit 79584d2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions scripts/generateClientTypesMap/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { Biome, Distribution } from "@biomejs/js-api";

import {
CLIENT_NAMES,
Expand All @@ -10,9 +11,6 @@ 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.`;

(async () => {
for (const [mapName, getTypesMap] of [
["CLIENT_TYPES_MAP", getClientTypesMap],
Expand All @@ -21,7 +19,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 @@ -36,8 +36,11 @@ const codegenComment = `// This file is generated by scripts/generateClientTypes
}

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

await writeFile(relativeFilePath, fileContent);
const biome = await Biome.create({ distribution: Distribution.NODE });
const formatted = biome.formatContent(fileContent, {
filePath: relativeFilePath,
});
await writeFile(relativeFilePath, formatted.content);
}
})();

0 comments on commit 79584d2

Please sign in to comment.