-
Notifications
You must be signed in to change notification settings - Fork 4
/
versioning.cjs
53 lines (45 loc) · 1.66 KB
/
versioning.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require("fs");
function findPackageVersion(packageName) {
try {
// Read the package.json file
const packageJson = JSON.parse(fs.readFileSync("./packages/database/package.json", "utf-8"));
// Check if the package is in the dependencies
if (
packageJson.peerDependencies &&
packageJson.peerDependencies[packageName]
) {
return packageJson.peerDependencies[packageName];
} else {
return undefined; // Package not found
}
} catch (error) {
console.error("Error reading or parsing package.json:", error);
return undefined;
}
}
function updateReadme(version) {
const readmeFilePath = "README.md";
try {
// Read the content of the README.md file
let readmeContent = fs.readFileSync(readmeFilePath, "utf-8").split("\n");
// Check if there are at least 4 lines in the file
if (readmeContent.length >= 4) {
// Replace the 4th line with "123"
readmeContent[3] = `This package is compatible with Atala Prism Wallet SDK v${version.slice(
1
)}`;
// Join the lines back together
readmeContent = readmeContent.join("\n");
// Write the modified content back to the README.md file
fs.writeFileSync(readmeFilePath, readmeContent, "utf-8");
console.log("README.md updated successfully.");
} else {
console.log("README.md does not have at least 4 lines.");
}
} catch (error) {
console.error("Error reading or updating README.md:", error);
}
}
const packageNameToFind = "@atala/prism-wallet-sdk"; // Replace with the package name you want to find
const packageVersion = findPackageVersion(packageNameToFind);
updateReadme(packageVersion);