From 388f72b7a029a14bf5c20861d5f54bdaa98b3ac7 Mon Sep 17 00:00:00 2001 From: Ursula Date: Tue, 7 Jan 2025 11:04:50 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Improved=20error=20handling=20and=20inpu?= =?UTF-8?q?t=20validation=20for=20project=20name=20in=E2=80=A6=20(#362)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: Improved error handling and input validation for project name in script --- scripts/remove-stable-version-field.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/remove-stable-version-field.ts b/scripts/remove-stable-version-field.ts index 861ede2db..bdb5225ff 100644 --- a/scripts/remove-stable-version-field.ts +++ b/scripts/remove-stable-version-field.ts @@ -1,17 +1,28 @@ import { readFileSync, writeFileSync } from "node:fs" async function main() { - const projectDirectory = `packages/${process.argv[2]}` + const projectName = process.argv[2] + if (!projectName) { + console.error("Please specify the project name as the second argument.") + process.exit(1) + } + const projectDirectory = `packages/${projectName}` const filePath = `${projectDirectory}/package.json` - const content = JSON.parse(readFileSync(filePath, "utf8")) + try { + const content = JSON.parse(readFileSync(filePath, "utf8")) - if (content.stableVersion) { - delete content.stableVersion - } + if (content.stableVersion) { + delete content.stableVersion + } - writeFileSync(filePath, JSON.stringify(content, null, 4), "utf8") + writeFileSync(filePath, JSON.stringify(content, null, 4), "utf8") + console.log(`Successfully updated ${filePath}`) + } catch (error) { + console.error("Error reading or writing the file:", error) + process.exit(1) + } } main()