From 29aa09e448c7b379eeea680e2e7c89a4998b04b8 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 29 Mar 2018 17:41:39 +0200 Subject: Generate CHANGELOG.mds --- packages/monorepo-scripts/src/custom_prepublish.ts | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/custom_prepublish.ts b/packages/monorepo-scripts/src/custom_prepublish.ts index 90db51465..b18389fcd 100644 --- a/packages/monorepo-scripts/src/custom_prepublish.ts +++ b/packages/monorepo-scripts/src/custom_prepublish.ts @@ -65,6 +65,8 @@ const TODAYS_TIMESTAMP = moment().unix(); fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, '\t')); // Generate updated CHANGELOG.md const changelogMd = generateChangelogMd(changelogs); + const changelogMdPath = path.join(lernaPackage.location, 'CHANGELOG.md'); + fs.writeFileSync(changelogMdPath, changelogMd); }); })().catch(err => { utils.log(err); @@ -111,5 +113,30 @@ function shouldAddNewChangelogEntry(changelogs: Changelog[]): boolean { } function generateChangelogMd(changelogs: Changelog[]): string { - return ''; + let changelogMd = ` + +CHANGELOG + `; + + _.each(changelogs, changelog => { + const date = moment(changelog.timestamp, 'X').format('MMMM D, YYYY'); + const title = `\n## v${changelog.version} - _${date}_\n\n`; + changelogMd += title; + + let changes = ''; + _.each(changelog.changes, change => { + let line = ` * ${change.note}`; + if (!_.isUndefined(change.pr)) { + line += ` (#${change.pr})`; + } + line += '\n'; + changes += line; + }); + changelogMd += `${changes}`; + }); + + return changelogMd; } -- cgit v1.2.3