Skip to content
This repository has been archived by the owner on Mar 2, 2024. It is now read-only.

Commit

Permalink
Minor fixes (#1)
Browse files Browse the repository at this point in the history
* Fix issue with filePath
* Write changelog to md-file
* Fix wrong spelling: precendence -> precedence
  • Loading branch information
deroke authored and bitionaire committed Nov 22, 2018
1 parent 1282f25 commit 6eae77a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,7 +56,7 @@ file header.
---
type: enhancement
pin: v4.3.7
precendence: 10
precedence: 10
---

Description of the enhancement
Expand Down
38 changes: 28 additions & 10 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6eae77a

Please sign in to comment.