2024-03-24 19:38:18 +02:00
|
|
|
#!/usr/bin/env node
|
2021-12-10 03:02:58 +02:00
|
|
|
/**
|
|
|
|
* @fileoverview
|
|
|
|
* 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
|
|
|
let overNIconsInReadme;
|
|
|
|
try {
|
2024-03-24 19:38:18 +02:00
|
|
|
overNIconsInReadme = Number.parseInt(regexMatcher.exec(readmeContent)[1], 10);
|
|
|
|
} catch (error) {
|
2023-08-08 06:38:52 +02:00
|
|
|
console.error(
|
|
|
|
'Failed to obtain 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);
|
|
|
|
}
|
2021-12-25 16:22:56 +02:00
|
|
|
|
2024-03-24 19:38:18 +02:00
|
|
|
const iconsData = await getIconsData();
|
|
|
|
const nIcons = iconsData.length;
|
2023-08-08 06:38:52 +02:00
|
|
|
const newNIcons = overNIconsInReadme + updateRange;
|
2021-12-25 16:22:56 +02:00
|
|
|
|
2023-08-08 06:38:52 +02:00
|
|
|
if (nIcons > newNIcons) {
|
2021-12-25 16:22:56 +02:00
|
|
|
const newContent = readmeContent.replace(regexMatcher, `Over ${newNIcons} `);
|
|
|
|
await fs.writeFile(readmeFile, newContent);
|
2023-08-08 06:38:52 +02:00
|
|
|
}
|