diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-06-02 06:50:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-02 06:50:13 +0800 |
commit | bf6900fb2a991f2c252bc7f8594364925a6046e1 (patch) | |
tree | 6030b3125e817d6fac86e4c797721531c24efcb1 /packages/monorepo-scripts/src/utils/changelog_utils.ts | |
parent | c41846805d71983fd4232c5eb796715c3d776d25 (diff) | |
parent | 50552546f392214726e6b969a72c04f320486b16 (diff) | |
download | dexon-0x-contracts-bf6900fb2a991f2c252bc7f8594364925a6046e1.tar dexon-0x-contracts-bf6900fb2a991f2c252bc7f8594364925a6046e1.tar.gz dexon-0x-contracts-bf6900fb2a991f2c252bc7f8594364925a6046e1.tar.bz2 dexon-0x-contracts-bf6900fb2a991f2c252bc7f8594364925a6046e1.tar.lz dexon-0x-contracts-bf6900fb2a991f2c252bc7f8594364925a6046e1.tar.xz dexon-0x-contracts-bf6900fb2a991f2c252bc7f8594364925a6046e1.tar.zst dexon-0x-contracts-bf6900fb2a991f2c252bc7f8594364925a6046e1.zip |
Merge pull request #650 from 0xProject/feature/publishing
Improve publishing flow
Diffstat (limited to 'packages/monorepo-scripts/src/utils/changelog_utils.ts')
-rw-r--r-- | packages/monorepo-scripts/src/utils/changelog_utils.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/monorepo-scripts/src/utils/changelog_utils.ts b/packages/monorepo-scripts/src/utils/changelog_utils.ts new file mode 100644 index 000000000..edfe65a80 --- /dev/null +++ b/packages/monorepo-scripts/src/utils/changelog_utils.ts @@ -0,0 +1,55 @@ +import * as _ from 'lodash'; +import * as moment from 'moment'; + +import { Change, Changelog, VersionChangelog } from '../types'; + +const CHANGELOG_MD_HEADER = ` +<!-- +This file is auto-generated using the monorepo-scripts package. Don't edit directly. +Edit the package's CHANGELOG.json file only. +--> + +CHANGELOG +`; + +export const changelogUtils = { + getChangelogMdTitle(versionChangelog: VersionChangelog): string { + if (_.isUndefined(versionChangelog.timestamp)) { + throw new Error( + 'All CHANGELOG.json entries must be updated to include a timestamp before generating their MD version', + ); + } + const date = moment(`${versionChangelog.timestamp}`, 'X').format('MMMM D, YYYY'); + const title = `\n## v${versionChangelog.version} - _${date}_\n\n`; + return title; + }, + getChangelogMdChange(change: Change): string { + let line = ` * ${change.note}`; + if (!_.isUndefined(change.pr)) { + line += ` (#${change.pr})`; + } + return line; + }, + generateChangelogMd(changelog: Changelog): string { + let changelogMd = CHANGELOG_MD_HEADER; + _.each(changelog, versionChangelog => { + const title = changelogUtils.getChangelogMdTitle(versionChangelog); + changelogMd += title; + const changelogVersionLines = _.map( + versionChangelog.changes, + changelogUtils.getChangelogMdChange.bind(changelogUtils), + ); + changelogMd += `${_.join(changelogVersionLines, '\n')}`; + }); + + return changelogMd; + }, + shouldAddNewChangelogEntry(currentVersion: string, changelog: Changelog): boolean { + if (_.isEmpty(changelog)) { + return true; + } + const lastEntry = changelog[0]; + const isLastEntryCurrentVersion = lastEntry.version === currentVersion; + return isLastEntryCurrentVersion; + }, +}; |