Skip to content

Commit 93c6677

Browse files
authored
Update update-readme.js
1 parent 5b046c1 commit 93c6677

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

update-readme.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ if (!sectionMatch) {
1515
const pluginsListContent = sectionMatch[1].trim();
1616

1717
// Regex to match individual plugin entries
18-
const pluginRegex = /- ### \[(.+?)\]/g;
18+
const pluginRegex = /- ### (.+?)/g;
1919
const pluginNames = [];
2020
let match;
2121

22+
// Extract plugin names from README
2223
while ((match = pluginRegex.exec(pluginsListContent)) !== null) {
2324
pluginNames.push(match[1].trim());
2425
}
@@ -43,26 +44,34 @@ let changesMade = false;
4344
// Iterate over parsed badges to find matching plugins in the README
4445
parsedBadges.forEach(({ name, latestReleaseUrl }) => {
4546
const normalizedPluginName = name.toLowerCase();
46-
console.log(`Checking plugin: ${name}`);
47-
console.log(`Latest release URL: ${latestReleaseUrl}`);
47+
const pluginEntry = readmePlugins.get(normalizedPluginName);
4848

49-
if (readmePlugins.has(normalizedPluginName)) {
50-
console.log(`Matching plugin found in README for ${name}`);
49+
if (pluginEntry) {
50+
console.log(`\nChecking plugin: ${name}`);
51+
console.log(`Latest release URL from badges.json: ${latestReleaseUrl}`);
5152

5253
// Construct the expected badge URL
53-
const expectedBadgeUrl = `https://img.shields.io/github/downloads/${normalizedPluginName}/total`;
54+
const expectedBadgeUrl = `https://img.shields.io/github/downloads/${name}/total`;
5455

55-
// Regex to find and replace badge and download URL
56+
// Regex to find the current entry in README
5657
const badgeRegex = new RegExp(
57-
`\\[!\\[GitHub Downloads \\(all releases\\)\\]\\(https://img\\.shields\\.io/github/downloads/.+?/total\\)\\]\\(.*?\\)`,
58+
`- ### \${pluginEntry}\ \!\GitHub Downloads \all releases\\\https://img\\.shields\\.io/github/downloads/${name}/total\\\.*?\`,
5859
'g'
5960
);
60-
const newBadge = `[![GitHub Downloads (all releases)](${expectedBadgeUrl})](${latestReleaseUrl})`;
61-
const updatedContent = readmeContent.replace(badgeRegex, newBadge);
6261

63-
if (updatedContent !== readmeContent) {
64-
readmeContent = updatedContent;
62+
// Check if the current download URL in README differs from the latest release URL
63+
const currentEntry = readmeContent.match(badgeRegex);
64+
if (currentEntry && !currentEntry[0].includes(latestReleaseUrl)) {
65+
console.log(`Updating download URL for ${name}`);
66+
67+
// Construct the new entry
68+
const newEntry = `- ### [${pluginEntry}] [![GitHub Downloads (all releases)](${expectedBadgeUrl})](${latestReleaseUrl})`;
69+
70+
// Replace the old entry with the new one in the README
71+
readmeContent = readmeContent.replace(badgeRegex, newEntry);
6572
changesMade = true;
73+
} else {
74+
console.log(`No update needed for ${name}`);
6675
}
6776
} else {
6877
console.log(`No matching plugin found in README for ${name}`);
@@ -71,9 +80,9 @@ parsedBadges.forEach(({ name, latestReleaseUrl }) => {
7180

7281
// Write updated README if changes were made
7382
if (changesMade) {
74-
console.log('Changes detected, updating README...');
83+
console.log('\nChanges detected, updating README...');
7584
fs.writeFileSync('README.md', readmeContent, 'utf8');
7685
console.log('README updated successfully.');
7786
} else {
78-
console.log('No changes made to README.');
87+
console.log('\nNo changes made to README.');
7988
}

0 commit comments

Comments
 (0)