From 3f926c74f719c1f567ca00a3bb1d9f66316e9389 Mon Sep 17 00:00:00 2001 From: Batuhan Wilhelm Date: Thu, 12 Dec 2024 17:48:10 +0300 Subject: [PATCH] feat(ci): add script to update publisConfig.registry --- package.json | 2 +- packages/create-refine-app/package.json | 3 +- scripts/update-create-refine-app-registry.js | 63 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 scripts/update-create-refine-app-registry.js diff --git a/package.json b/package.json index 9868f599bfd3..0675d10bc692 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "prepare": "husky install", "publint": "lerna run publint --scope @refinedev/core", "publint:all": "lerna run publint --scope @refinedev/*", - "publish-packages": "pnpm config set registry=https://registry.refine.dev/ --location user && pnpm changeset publish && pnpm config delete registry --location user", + "publish-packages": "node scripts/update-create-refine-app-registry.js add && pnpm changeset publish && node scripts/update-create-refine-app-registry.js remove", "sp": "syncpack", "start": "lerna run start", "test": "lerna run test --stream", diff --git a/packages/create-refine-app/package.json b/packages/create-refine-app/package.json index 0240be11ff73..a2c2336f478b 100644 --- a/packages/create-refine-app/package.json +++ b/packages/create-refine-app/package.json @@ -44,7 +44,6 @@ "typescript": "^5.4.2" }, "publishConfig": { - "access": "public", - "registry": "https://registry.refine.dev" + "access": "public" } } diff --git a/scripts/update-create-refine-app-registry.js b/scripts/update-create-refine-app-registry.js new file mode 100644 index 000000000000..37aa0d6f8c32 --- /dev/null +++ b/scripts/update-create-refine-app-registry.js @@ -0,0 +1,63 @@ +const fs = require("fs"); +const path = require("path"); + +const packageJsonPath = path.join( + process.cwd(), + "packages/create-refine-app/package.json", +); + +function addRegistry() { + try { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); + + packageJson.publishConfig = { + ...packageJson.publishConfig, + registry: "https://registry.refine.dev", + }; + + fs.writeFileSync( + packageJsonPath, + JSON.stringify(packageJson, null, 2) + "\n", + ); + + console.log("Registry configuration added successfully."); + } catch (error) { + console.error("Error adding registry:", error); + process.exit(1); + } +} + +function removeRegistry() { + try { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); + + if (packageJson.publishConfig) { + delete packageJson.publishConfig.registry; + + if (Object.keys(packageJson.publishConfig).length === 0) { + delete packageJson.publishConfig; + } + } + + fs.writeFileSync( + packageJsonPath, + JSON.stringify(packageJson, null, 2) + "\n", + ); + + console.log("Registry configuration removed successfully."); + } catch (error) { + console.error("Error removing registry:", error); + process.exit(1); + } +} + +const action = process.argv[2]; + +if (action === "add") { + addRegistry(); +} else if (action === "remove") { + removeRegistry(); +} else { + console.error("Please specify either 'add' or 'remove' as an argument"); + process.exit(1); +}