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 process from 'node:process';
|
|
|
|
import fs from 'node:fs/promises';
|
2021-12-25 16:22:56 +02:00
|
|
|
import path from 'node:path';
|
2023-04-19 15:23:13 +02:00
|
|
|
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);
|
2021-12-10 03:02:58 +02:00
|
|
|
const rootDir = path.resolve(__dirname, '..', '..');
|
|
|
|
const readmeFile = path.resolve(rootDir, 'README.md');
|
2021-12-25 16:22:56 +02:00
|
|
|
|
2023-08-08 06:38:52 +02:00
|
|
|
const readmeContent = await fs.readFile(readmeFile, 'utf-8');
|
2021-12-25 16:22:56 +02:00
|
|
|
|
2023-08-08 06:38:52 +02:00
|
|
|
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);
|
|
|
|
}
|
2021-12-25 16:22:56 +02:00
|
|
|
|
2023-08-08 06:38:52 +02:00
|
|
|
const nIcons = (await getIconsData()).length;
|
|
|
|
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
|
|
|
}
|