1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-16 00:59:07 +02:00
simple-icons/scripts/release/update-svgs-count.js
Álvaro Mondéjar 17ea889273
Refactor tests and scripts (#9237)
Co-authored-by: LitoMore <LitoMore@users.noreply.github.com>
2023-08-08 06:38:52 +02:00

40 lines
1.2 KiB
JavaScript

/**
* @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.
*/
import process from 'node:process';
import fs from 'node:fs/promises';
import path from 'node:path';
import { getDirnameFromImportMeta, getIconsData } from '../../sdk.mjs';
const regexMatcher = /Over\s(\d+)\s/;
const updateRange = 100;
const __dirname = getDirnameFromImportMeta(import.meta.url);
const rootDir = path.resolve(__dirname, '..', '..');
const readmeFile = path.resolve(rootDir, 'README.md');
const readmeContent = await fs.readFile(readmeFile, 'utf-8');
let overNIconsInReadme;
try {
overNIconsInReadme = parseInt(regexMatcher.exec(readmeContent)[1]);
} catch (err) {
console.error(
'Failed to obtain number of SVG icons of current milestone in README:',
err,
);
process.exit(1);
}
const nIcons = (await getIconsData()).length;
const newNIcons = overNIconsInReadme + updateRange;
if (nIcons > newNIcons) {
const newContent = readmeContent.replace(regexMatcher, `Over ${newNIcons} `);
await fs.writeFile(readmeFile, newContent);
}