Skip to content

Commit dc7ddfe

Browse files
authored
Merge pull request #5 from TheoBrigitte/show
add missing show.js
2 parents 69e13dc + 4639f0c commit dc7ddfe

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/show.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { parser } = require("keep-a-changelog");
2+
const fs = require("fs");
3+
4+
// Show and release and its changes
5+
function show(version, options) {
6+
// Read changelog file
7+
const changelog = parser(fs.readFileSync(options.file, options.encoding));
8+
changelog.format = options.format;
9+
changelog.sortReleases();
10+
11+
// Find release
12+
let release;
13+
switch (version) {
14+
case "latest":
15+
release = changelog.releases.find((release) =>
16+
release.date && release.version
17+
);
18+
break;
19+
case "unreleased":
20+
version = undefined;
21+
default:
22+
release = changelog.findRelease(version);
23+
}
24+
if (!release) {
25+
throw new Error(`release ${version} not found`);
26+
}
27+
28+
// Print changes
29+
console.log(release.toString(changelog));
30+
}
31+
32+
module.exports = { show };

0 commit comments

Comments
 (0)