From e4905f438a59b93f53b2564cb385ecf2f2a6430f Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Thu, 1 Aug 2024 09:43:16 -0700 Subject: [PATCH] Fix create entrypoints script --- libs/sdk-js/.gitignore | 2 ++ libs/sdk-js/scripts/create-entrypoints.js | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/sdk-js/.gitignore b/libs/sdk-js/.gitignore index a43bf2e13..4b85d8c2a 100644 --- a/libs/sdk-js/.gitignore +++ b/libs/sdk-js/.gitignore @@ -1,4 +1,5 @@ /docs +## GENERATED create-entrypoints.js /client.cjs /client.js /client.d.ts @@ -7,3 +8,4 @@ /index.js /index.d.ts /index.d.cts +## END GENERATED create-entrypoints.js diff --git a/libs/sdk-js/scripts/create-entrypoints.js b/libs/sdk-js/scripts/create-entrypoints.js index 69af43c6d..63ddd2ce9 100644 --- a/libs/sdk-js/scripts/create-entrypoints.js +++ b/libs/sdk-js/scripts/create-entrypoints.js @@ -97,11 +97,15 @@ const updateConfig = () => { const endMarker = "## END GENERATED create-entrypoints.js"; const startIdx = lines.findIndex((line) => line.includes(startMarker)); const endIdx = lines.findIndex((line) => line.includes(endMarker)); - const newLines = [ - ...lines.slice(0, startIdx + 1), - ...filenames.map((fname) => `/${fname}`), - ...lines.slice(endIdx), - ]; + const newLines = lines.slice(0, startIdx + 1); + if (startIdx === -1) { + newLines.push(startMarker); + } + newLines.push(...filenames.map((fname) => `/${fname}`)); + if (endIdx === -1) { + newLines.push(endMarker); + } + newLines.push(...lines.slice(endIdx)); fs.writeFileSync("./.gitignore", newLines.join("\n")); };