mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
312f2afc41
The `auto-changelog.js` script has been refactoring into various different modules. This was done in preparation for migrating this to a separate repository, where it can be used in our libraries as well. Functionally this should act _mostly_ the same way, but there have been some changes. It was difficult to make this a pure refactor because of the strategy used to validate the changelog and ensure each addition remained valid. Instead of being updated in-place, the changelog is now parsed upfront and stored as a "Changelog" instance, which is a new class that was written to allow only valid changes. The new changelog is then stringified and completely overwrites the old one. The parsing had to be much more strict, as any unanticipated content would otherwise be erased unintentionally. This script now also normalizes the formatting of the changelog (though the individual change descriptions are still unformatted). The changelog stringification now accommodates non-linear releases as well. For example, you can now release v1.0.1 *after* v2.0.0, and it will be listed in chronological order while also correctly constructing the `compare` URLs for each release.
68 lines
2.0 KiB
JavaScript
Executable File
68 lines
2.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
const fs = require('fs').promises;
|
|
|
|
const path = require('path');
|
|
const { version } = require('../app/manifest/_base.json');
|
|
const { updateChangelog } = require('./lib/changelog/updateChangelog');
|
|
const { unreleased } = require('./lib/changelog/constants');
|
|
|
|
const REPO_URL = 'https://github.com/MetaMask/metamask-extension';
|
|
|
|
const command = 'yarn update-changelog';
|
|
|
|
const helpText = `Usage: ${command} [--rc] [-h|--help]
|
|
Update CHANGELOG.md with any changes made since the most recent release.
|
|
|
|
Options:
|
|
--rc Add new changes to the current release header, rather than to the
|
|
'${unreleased}' section.
|
|
-h, --help Display this help and exit.
|
|
|
|
New commits will be added to the "${unreleased}" section (or to the section for the
|
|
current release if the '--rc' flag is used) in reverse chronological order. Any
|
|
commits for PRs that are represented already in the changelog will be ignored.
|
|
|
|
If the '--rc' flag is used and the section for the current release does not yet
|
|
exist, it will be created.
|
|
`;
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
let isReleaseCandidate = false;
|
|
|
|
for (const arg of args) {
|
|
if (arg === '--rc') {
|
|
isReleaseCandidate = true;
|
|
} else if (['--help', '-h'].includes(arg)) {
|
|
console.log(helpText);
|
|
process.exit(0);
|
|
} else {
|
|
console.error(
|
|
`Unrecognized argument: ${arg}\nTry '${command} --help' for more information.\n`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
const changelogFilename = path.resolve(__dirname, '..', 'CHANGELOG.md');
|
|
const changelogContent = await fs.readFile(changelogFilename, {
|
|
encoding: 'utf8',
|
|
});
|
|
|
|
const newChangelogContent = await updateChangelog({
|
|
changelogContent,
|
|
currentVersion: version,
|
|
repoUrl: REPO_URL,
|
|
isReleaseCandidate,
|
|
});
|
|
|
|
await fs.writeFile(changelogFilename, newChangelogContent);
|
|
|
|
console.log('CHANGELOG updated');
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|