material-icons-browser-exte.../scripts/update-upstream-version.ts
Michael Goodman 0d067d0394
[Bug fix] Fix custom domains not working after conversion to typescript. (#6)
* added dotenv dev dependency, to prevent being dependent on IDE to set env variables

* added biomejs to dev dependencies, was missing

* fixed custom domains not working after ts conversion

* fixed a bug where you could not add multiple custom domains, because the script was trying to register multiple content scripts with same id
2024-07-04 09:51:54 +02:00

52 lines
1.5 KiB
TypeScript

import 'dotenv/config';
import * as path from 'path';
import * as fs from 'fs/promises';
/**
* Gets latest VSCode Extension release version by parsing its most recent 100 commit msgs
*
* @returns {Promise<string>} The current version of the upstream repository.
*/
const getUpstreamVersion = async (): Promise<string> => {
const packagePath: string = path.resolve(
__dirname,
'..',
'node_modules',
'material-icon-theme',
'package.json'
);
const packageData: string = await fs.readFile(packagePath, {
encoding: 'utf8',
});
const packageJson = JSON.parse(packageData);
return packageJson.version;
};
/**
* Updates the version badge in the README file.
*
* @param {string} version - The new version to update the badge to.
* @returns {Promise<void>}
*/
const updateReadmeBadge = async (version: string): Promise<void> => {
const readmeFilePath: string = path.resolve(__dirname, '..', 'README.md');
const readme: string = await fs.readFile(readmeFilePath, {
encoding: 'utf8',
});
const versionRgx: RegExp = /(badge\/[\w_]+-v)\d+\.\d+\.\d+/;
const replacement: string = `$1${version}`;
const updatedReadme: string = readme.replace(versionRgx, replacement);
await fs.writeFile(readmeFilePath, updatedReadme);
};
/**
* Main function to run the update process.
*/
const run = async (): Promise<void> => {
const latestVersion: string = await getUpstreamVersion();
await updateReadmeBadge(latestVersion);
};
run().catch(console.error);