Skip to content

Commit f22fd7f

Browse files
authored
Update update-readme.js
1 parent 8fc6f46 commit f22fd7f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

update-readme.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ if (pluginNames.length === 0) {
3232
}
3333

3434
// Load parsed badges
35-
const parsedBadges = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
35+
const parsedBadges = JSON.parse(fs.readFileSync(process.argv[2], 'utf8')).plugins;
3636

3737
// Map plugin names from the README for easier matching
38-
const readmePlugins = new Map(pluginNames.map((name) => [name.toLowerCase(), name]));
38+
const readmePlugins = new Map(pluginNames.map(name => [name.toLowerCase(), name]));
3939

4040
// Flag to track changes
4141
let changesMade = false;
4242

43-
parsedBadges.forEach(({ name, repo, latestReleaseUrl }) => {
43+
// Iterate over parsed badges to find matching plugins in the README
44+
parsedBadges.forEach(({ name, latestReleaseUrl }) => {
4445
const normalizedPluginName = name.toLowerCase();
4546
console.log(`Checking plugin: ${name}`);
4647
console.log(`Latest release URL: ${latestReleaseUrl}`);
@@ -49,21 +50,19 @@ parsedBadges.forEach(({ name, repo, latestReleaseUrl }) => {
4950
console.log(`Matching plugin found in README for ${name}`);
5051

5152
// Construct the expected badge URL
52-
const expectedBadgeUrl = `https://img.shields.io/github/downloads/${repo}/total`;
53+
const expectedBadgeUrl = `https://img.shields.io/github/downloads/${normalizedPluginName}/total`;
5354

5455
// Regex to find and replace badge and download URL
5556
const badgeRegex = new RegExp(
56-
`\\[!\\[GitHub Downloads \\(all releases\\)\\]\\(https://img\\.shields\\.io/github/downloads/${repo}/total\\)\\]\\(.*?\\)`,
57+
`\\[!\\[GitHub Downloads \\(all releases\\)\\]\\(https://img\\.shields\\.io/github/downloads/.+?/total\\)\\]\\(.*?\\)`,
5758
'g'
5859
);
5960
const newBadge = `[![GitHub Downloads (all releases)](${expectedBadgeUrl})](${latestReleaseUrl})`;
60-
6161
const updatedContent = readmeContent.replace(badgeRegex, newBadge);
6262

6363
if (updatedContent !== readmeContent) {
6464
readmeContent = updatedContent;
6565
changesMade = true;
66-
console.log(`Updated badge and download URL for ${name}`);
6766
}
6867
} else {
6968
console.log(`No matching plugin found in README for ${name}`);

0 commit comments

Comments
 (0)