From 79584d235fff403c9ccf3bddcaf5fc628b98c020 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:24:21 -0700 Subject: [PATCH] chore(scripts): attempt to programatically format --- scripts/generateClientTypesMap/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/generateClientTypesMap/index.ts b/scripts/generateClientTypesMap/index.ts index 6874fe5c0..4842888d8 100644 --- a/scripts/generateClientTypesMap/index.ts +++ b/scripts/generateClientTypesMap/index.ts @@ -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, @@ -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], @@ -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> = `; @@ -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); } })();