2024-03-24 19:38:18 +02:00
|
|
|
#!/usr/bin/env node
|
2021-12-10 03:02:58 +02:00
|
|
|
/**
|
2024-06-06 14:40:35 +02:00
|
|
|
* @file
|
2021-12-10 03:02:58 +02:00
|
|
|
* Replaces the SVG count milestone "Over <NUMBER> Free SVG icons..." located
|
|
|
|
* at README every time the number of current icons is more than `updateRange`
|
|
|
|
* more than the previous milestone.
|
|
|
|
*/
|
2023-08-08 06:38:52 +02:00
|
|
|
|
|
|
|
import fs from 'node:fs/promises';
|
2021-12-25 16:22:56 +02:00
|
|
|
import path from 'node:path';
|
2024-03-24 19:38:18 +02:00
|
|
|
import process from 'node:process';
|
|
|
|
import {getDirnameFromImportMeta, getIconsData} from '../../sdk.mjs';
|
2021-12-10 03:02:58 +02:00
|
|
|
|
|
|
|
const regexMatcher = /Over\s(\d+)\s/;
|
|
|
|
const updateRange = 100;
|
|
|
|
|
2021-12-25 16:22:56 +02:00
|
|
|
const __dirname = getDirnameFromImportMeta(import.meta.url);
|
2024-03-24 19:38:18 +02:00
|
|
|
const rootDirectory = path.resolve(__dirname, '..', '..');
|
|
|
|
const readmeFile = path.resolve(rootDirectory, 'README.md');
|
2021-12-25 16:22:56 +02:00
|
|
|
|
2024-03-24 19:38:18 +02:00
|
|
|
const readmeContent = await fs.readFile(readmeFile, 'utf8');
|
2021-12-25 16:22:56 +02:00
|
|
|
|
2023-08-08 06:38:52 +02:00
|
|
|
try {
|
2024-06-06 14:40:35 +02:00
|
|
|
const match = regexMatcher.exec(readmeContent);
|
|
|
|
if (match === null) {
|
|
|
|
console.error(
|
|
|
|
'Failed to obtain number of SVG icons of current milestone in README:',
|
|
|
|
'No match found',
|
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
} else {
|
|
|
|
const overNIconsInReadme = Number.parseInt(match[1], 10);
|
|
|
|
const iconsData = await getIconsData();
|
|
|
|
const nIcons = iconsData.length;
|
2024-07-26 18:19:45 +02:00
|
|
|
const nIconsRounded = Math.floor(nIcons / updateRange) * updateRange;
|
2024-06-06 14:40:35 +02:00
|
|
|
|
2024-07-26 18:19:45 +02:00
|
|
|
if (overNIconsInReadme !== nIconsRounded) {
|
2024-06-06 14:40:35 +02:00
|
|
|
const newContent = readmeContent.replace(
|
|
|
|
regexMatcher,
|
2024-07-26 18:19:45 +02:00
|
|
|
`Over ${nIconsRounded} `,
|
2024-06-06 14:40:35 +02:00
|
|
|
);
|
|
|
|
await fs.writeFile(readmeFile, newContent);
|
|
|
|
}
|
|
|
|
}
|
2024-03-24 19:38:18 +02:00
|
|
|
} catch (error) {
|
2023-08-08 06:38:52 +02:00
|
|
|
console.error(
|
2024-06-06 14:40:35 +02:00
|
|
|
'Failed to update number of SVG icons of current milestone in README:',
|
2024-03-24 19:38:18 +02:00
|
|
|
error,
|
2023-08-08 06:38:52 +02:00
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
}
|