Now that every version of a package published has a corresponding entry in it's CHANGELOG we no longer need the isPublished flag. Remove it.

This commit is contained in:
Fabio Berger
2018-04-03 09:45:30 +09:00
parent 29042e1939
commit dd87588dfe
3 changed files with 19 additions and 33 deletions

View File

@@ -91,7 +91,7 @@ export const postpublishUtils = {
); );
}, },
async publishReleaseNotesAsync(cwd: string, packageName: string, version: string, assets: string[]): Promise<void> { async publishReleaseNotesAsync(cwd: string, packageName: string, version: string, assets: string[]): Promise<void> {
const notes = this.getReleaseNotes(packageName); const notes = this.getReleaseNotes(packageName, version);
const releaseName = this.getReleaseName(packageName, version); const releaseName = this.getReleaseName(packageName, version);
const tag = this.getTag(packageName, version); const tag = this.getTag(packageName, version);
const finalAssets = this.adjustAssetPaths(cwd, assets); const finalAssets = this.adjustAssetPaths(cwd, assets);
@@ -109,9 +109,8 @@ export const postpublishUtils = {
reuseDraftOnly: false, reuseDraftOnly: false,
assets, assets,
}); });
this.updateChangelogIsPublished(packageName);
}, },
getReleaseNotes(packageName: string) { getReleaseNotes(packageName: string, version: string) {
const packageNameWithNamespace = packageName.replace('@0xproject/', ''); const packageNameWithNamespace = packageName.replace('@0xproject/', '');
const changelogJSONPath = path.join( const changelogJSONPath = path.join(
constants.monorepoRootPath, constants.monorepoRootPath,
@@ -122,7 +121,11 @@ export const postpublishUtils = {
const changelogJSON = fs.readFileSync(changelogJSONPath, 'utf-8'); const changelogJSON = fs.readFileSync(changelogJSONPath, 'utf-8');
const changelogs = JSON.parse(changelogJSON); const changelogs = JSON.parse(changelogJSON);
const latestLog = changelogs[0]; const latestLog = changelogs[0];
if (_.isUndefined(latestLog.isPublished)) { // We sanity check that the version for the changelog notes we are about to publish to Github
// correspond to the new version of the package.
if (version !== latestLog.version) {
throw new Error('Expected CHANGELOG.json latest entry version to coincide with published version.');
}
let notes = ''; let notes = '';
_.each(latestLog.changes, change => { _.each(latestLog.changes, change => {
notes += `* ${change.note}`; notes += `* ${change.note}`;
@@ -132,23 +135,6 @@ export const postpublishUtils = {
notes += `\n`; notes += `\n`;
}); });
return notes; return notes;
}
return 'N/A';
},
updateChangelogIsPublished(packageName: string) {
const packageNameWithNamespace = packageName.replace('@0xproject/', '');
const changelogJSONPath = path.join(
constants.monorepoRootPath,
'packages',
packageNameWithNamespace,
'CHANGELOG.json',
);
const changelogJSON = fs.readFileSync(changelogJSONPath, 'utf-8');
const changelogs = JSON.parse(changelogJSON);
const latestLog = changelogs[0];
latestLog.isPublished = true;
changelogs[0] = latestLog;
fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, '\t'));
}, },
getTag(packageName: string, version: string) { getTag(packageName: string, version: string) {
return `${packageName}@${version}`; return `${packageName}@${version}`;

View File

@@ -48,7 +48,7 @@ const semverNameToIndex: { [semver: string]: number } = {
} }
const currentVersion = lernaPackage.package.version; const currentVersion = lernaPackage.package.version;
const shouldAddNewEntry = shouldAddNewChangelogEntry(changelogs); const shouldAddNewEntry = shouldAddNewChangelogEntry(currentVersion, changelogs);
if (shouldAddNewEntry) { if (shouldAddNewEntry) {
// Create a new entry for a patch version with generic changelog entry. // Create a new entry for a patch version with generic changelog entry.
const nextPatchVersion = utils.getNextPatchVersion(currentVersion); const nextPatchVersion = utils.getNextPatchVersion(currentVersion);
@@ -174,12 +174,13 @@ function getChangelogJSONOrCreateIfMissing(packageName: string, changelogPath: s
} }
} }
function shouldAddNewChangelogEntry(changelogs: Changelog[]): boolean { function shouldAddNewChangelogEntry(currentVersion: string, changelogs: Changelog[]): boolean {
if (_.isEmpty(changelogs)) { if (_.isEmpty(changelogs)) {
return true; return true;
} }
const lastEntry = changelogs[0]; const lastEntry = changelogs[0];
return !!lastEntry.isPublished; const lastEntryCurrentVersion = lastEntry.version === currentVersion;
return lastEntryCurrentVersion;
} }
function generateChangelogMd(changelogs: Changelog[]): string { function generateChangelogMd(changelogs: Changelog[]): string {

View File

@@ -13,7 +13,6 @@ export interface Changelog {
timestamp?: number; timestamp?: number;
version: string; version: string;
changes: Changes[]; changes: Changes[];
isPublished?: boolean;
} }
export enum SemVerIndex { export enum SemVerIndex {