From 6eae77a84a2849224d770fa7d5f203a2b8ce7cf7 Mon Sep 17 00:00:00 2001 From: DerZersaeger <45258253+DerZersaeger@users.noreply.github.com> Date: Thu, 22 Nov 2018 11:22:27 +0100 Subject: [PATCH] Minor fixes (#1) * Fix issue with filePath * Write changelog to md-file * Fix wrong spelling: precendence -> precedence --- README.md | 4 ++-- src/cli/index.js | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index fd099da..9c7b993 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ file header. * `text` - An introductory text or a complete description of all changes * `pin`: Pins this change to the specified version tag -* `precedence`: The change with the highest precendence number will be +* `precedence`: The change with the highest precedence number will be shown first in its type category ### Example file @@ -56,7 +56,7 @@ file header. --- type: enhancement pin: v4.3.7 -precendence: 10 +precedence: 10 --- Description of the enhancement diff --git a/src/cli/index.js b/src/cli/index.js index e2da8b2..57523f1 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -135,12 +135,23 @@ const getNormalizedType = (changeType) => { } }; -const getChangelogData = (filesToVersionTags, includeDrafts, includeUpcoming) => { +const getChangelogData = (filesToVersionTags, includeDrafts, includeUpcoming, dir) => { const changelogData = {}; Object.keys(filesToVersionTags).forEach(file => { - const parsedData = fm(fs.readFileSync(file).toString()); + + file = dir + '/' + file; + + let parsedData = undefined; + try { + parsedData = fm(fs.readFileSync(file).toString()); + } catch (e) { + // failed reading file + return; + } const type = getNormalizedType(parsedData.attributes.type); + if(!type) return; + let version = parsedData.attributes.pin || filesToVersionTags[file]; if (file.endsWith('.draft.md')) { if (includeDrafts) { @@ -168,16 +179,16 @@ const getChangelogData = (filesToVersionTags, includeDrafts, includeUpcoming) => }; const compareChangePrecedence = (a, b) => { - const aPrecendence = a.precedence; - const bPrecendence = b.precedence; + const aPrecedence = a.precedence; + const bPrecedence = b.precedence; - if (aPrecendence === bPrecendence) { + if (aPrecedence === bPrecedence) { return 0; } - if (!!aPrecendence && !!bPrecendence) { - return aPrecendence > bPrecendence ? -1 : 1; - } else if (!!aPrecendence && !bPrecendence) { + if (!!aPrecedence && !!bPrecedence) { + return aPrecedence > bPrecedence ? -1 : 1; + } else if (!!aPrecedence && !bPrecedence) { return -1; } else { return 1; @@ -231,8 +242,8 @@ const run = () => { // create changelog const versionTagsToCommitHashes = getVersionTagsToCommitHashes(); const commitHashesToVersionTags = getCommitHashesToVersionTags(versionTagsToCommitHashes); - const filesToVersionTags = getFilesToVersionTags(changelogDir, commitHashesToVersionTags); - const changelogData = getChangelogData(filesToVersionTags, program.includeDrafts, program.includeUpcoming); + const filesToVersionTags = getFilesToVersionTags(process.cwd(), commitHashesToVersionTags); + const changelogData = getChangelogData(filesToVersionTags, program.includeDrafts, program.includeUpcoming, process.cwd()); let changelog = ''; Object.keys(changelogData).filter(version => version !== 'undefined').sort((a, b) => { @@ -263,6 +274,13 @@ const run = () => { // echo changelog console.log(changelog.trim()); + + const filePath = path.resolve(changelogDir, 'changelog.md') + fs.writeFile(filePath, changelog.trim(), (err) => { + if (err) throw err + + console.log('\n\nsuccessfully written to', filePath) + }) } catch (err) { log(err.message, 'err'); process.exitCode = 1;