aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/publish.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/monorepo-scripts/src/publish.ts')
-rw-r--r--packages/monorepo-scripts/src/publish.ts24
1 files changed, 8 insertions, 16 deletions
diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts
index 2efbc8bf2..637512a5a 100644
--- a/packages/monorepo-scripts/src/publish.ts
+++ b/packages/monorepo-scripts/src/publish.ts
@@ -119,19 +119,14 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[])
const packageToVersionChange: PackageToVersionChange = {};
for (const lernaPackage of updatedPublicLernaPackages) {
const packageName = lernaPackage.package.name;
- const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json');
- const changelogJSON = utils.getChangelogJSONOrCreateIfMissing(changelogJSONPath);
- let changelog: Changelog;
- try {
- changelog = JSON.parse(changelogJSON);
- } catch (err) {
- throw new Error(
- `${lernaPackage.package.name}'s CHANGELOG.json contains invalid JSON. Please fix and try again.`,
- );
- }
+ let changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location);
const currentVersion = lernaPackage.package.version;
- const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry(currentVersion, changelog);
+ const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry(
+ lernaPackage.package.name,
+ currentVersion,
+ changelog,
+ );
if (shouldAddNewEntry) {
// Create a new entry for a patch version with generic changelog entry.
const nextPatchVersion = utils.getNextPatchVersion(currentVersion);
@@ -160,14 +155,11 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[])
}
// Save updated CHANGELOG.json
- fs.writeFileSync(changelogJSONPath, JSON.stringify(changelog, null, '\t'));
- await utils.prettifyAsync(changelogJSONPath, constants.monorepoRootPath);
+ await changelogUtils.writeChangelogJsonFileAsync(lernaPackage.location, changelog);
utils.log(`${packageName}: Updated CHANGELOG.json`);
// Generate updated CHANGELOG.md
const changelogMd = changelogUtils.generateChangelogMd(changelog);
- const changelogMdPath = path.join(lernaPackage.location, 'CHANGELOG.md');
- fs.writeFileSync(changelogMdPath, changelogMd);
- await utils.prettifyAsync(changelogMdPath, constants.monorepoRootPath);
+ await changelogUtils.writeChangelogMdFileAsync(lernaPackage.location, changelog);
utils.log(`${packageName}: Updated CHANGELOG.md`);
}