diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-02 08:13:02 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-02 08:13:02 +0800 |
commit | d3c64bd5b493dc1779a24c7c051c255106a4292a (patch) | |
tree | d1c818e64b75c1f4fed1c7d797892fb0d35dd779 /packages/monorepo-scripts/src/utils/changelog_utils.ts | |
parent | 7024a7468a549a96cf120e6b7e287e79d7ad2d61 (diff) | |
parent | 62e60e2ba6d07b9b892b4f2e92a5421c54f5fa20 (diff) | |
download | dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.gz dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.zst dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.zip |
Merge branch 'v2-prototype' into refactor/order-utils/for-v2
* v2-prototype:
Set contract expiration time to a constant 10 minutes
Remove unused promises array
Make erc20_wrapper and erc721_wrapper serial
Rename changelogs to changelog
Add CHANGELOG entry
Check that git branch is up to date before publishing
Move prepublish checks before building packages for publishing
Refactor changelog utils to a separate module
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; + }, +}; |