2021-05-05 23:29:49 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
/**
|
|
|
|
* @fileoverview
|
|
|
|
* Updates the CDN URLs in the README.md to match the major version in the
|
|
|
|
* NPM package manifest. Does nothing if the README.md is already up-to-date.
|
|
|
|
*/
|
|
|
|
|
2021-12-25 16:22:56 +02:00
|
|
|
import fs from 'node:fs';
|
|
|
|
import path from 'node:path';
|
|
|
|
import { getDirnameFromImportMeta } from '../utils.js';
|
|
|
|
|
|
|
|
const __dirname = getDirnameFromImportMeta(import.meta.url);
|
2021-05-05 23:29:49 +02:00
|
|
|
|
2021-10-25 21:13:10 +02:00
|
|
|
const rootDir = path.resolve(__dirname, '..', '..');
|
|
|
|
const packageJsonFile = path.resolve(rootDir, 'package.json');
|
|
|
|
const readmeFile = path.resolve(rootDir, 'README.md');
|
2021-05-05 23:29:49 +02:00
|
|
|
|
2021-10-25 21:13:10 +02:00
|
|
|
const getMajorVersion = (semVerVersion) => {
|
2021-05-05 23:29:49 +02:00
|
|
|
const majorVersionAsString = semVerVersion.split('.')[0];
|
|
|
|
return parseInt(majorVersionAsString);
|
2021-10-25 21:13:10 +02:00
|
|
|
};
|
2021-05-05 23:29:49 +02:00
|
|
|
|
2021-10-25 21:13:10 +02:00
|
|
|
const getManifest = () => {
|
2021-12-10 03:02:58 +02:00
|
|
|
const manifestRaw = fs.readFileSync(packageJsonFile, 'utf-8');
|
2021-05-05 23:29:49 +02:00
|
|
|
return JSON.parse(manifestRaw);
|
2021-10-25 21:13:10 +02:00
|
|
|
};
|
2021-05-05 23:29:49 +02:00
|
|
|
|
2021-10-25 21:13:10 +02:00
|
|
|
const updateVersionInReadmeIfNecessary = (majorVersion) => {
|
2021-05-05 23:29:49 +02:00
|
|
|
let content = fs.readFileSync(readmeFile).toString();
|
|
|
|
|
|
|
|
content = content.replace(
|
|
|
|
/simple-icons@v[0-9]+/g,
|
|
|
|
`simple-icons@v${majorVersion}`,
|
|
|
|
);
|
|
|
|
|
|
|
|
fs.writeFileSync(readmeFile, content);
|
2021-10-25 21:13:10 +02:00
|
|
|
};
|
2021-05-05 23:29:49 +02:00
|
|
|
|
2021-10-25 21:13:10 +02:00
|
|
|
const main = () => {
|
2021-05-05 23:29:49 +02:00
|
|
|
try {
|
|
|
|
const manifest = getManifest();
|
|
|
|
const majorVersion = getMajorVersion(manifest.version);
|
|
|
|
updateVersionInReadmeIfNecessary(majorVersion);
|
|
|
|
} catch (error) {
|
2021-10-25 21:13:10 +02:00
|
|
|
console.error('Failed to update CDN version number:', error);
|
2021-05-05 23:29:49 +02:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2021-10-25 21:13:10 +02:00
|
|
|
};
|
2021-05-05 23:29:49 +02:00
|
|
|
|
|
|
|
main();
|