Skip to content

Commit

Permalink
feat(ci): add script to update publisConfig.registry
Browse files Browse the repository at this point in the history
  • Loading branch information
BatuhanW committed Dec 12, 2024
1 parent 223506b commit 3f926c7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions packages/create-refine-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"typescript": "^5.4.2"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.refine.dev"
"access": "public"
}
}
63 changes: 63 additions & 0 deletions scripts/update-create-refine-app-registry.js
Original file line number Diff line number Diff line change
@@ -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",

Check failure on line 20 in scripts/update-create-refine-app-registry.js

View workflow job for this annotation

GitHub Actions / Lint

Template literals are preferred over string concatenation.
);

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",

Check failure on line 44 in scripts/update-create-refine-app-registry.js

View workflow job for this annotation

GitHub Actions / Lint

Template literals are preferred over string concatenation.
);

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);
}

0 comments on commit 3f926c7

Please sign in to comment.