Skip to content

Commit

Permalink
add --prepend option as altenative to prepend-token
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Jun 25, 2020
1 parent 0687370 commit 3ed3651
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async function getOptions (argv) {
.option('--handlebars-setup <file>', 'handlebars setup file')
.option('--append-git-log <string>', 'string to append to git log command')
.option('--stdout', 'output changelog to stdout')
.option('--prepend', 'prepend changelog to the start of the changelog file')
.version(version)
.parse(argv)

Expand Down Expand Up @@ -109,7 +110,14 @@ async function write (changelog, options, log) {
const bytes = Buffer.byteLength(changelog, 'utf8')
const existing = await fileExists(options.output) && await readFile(options.output, 'utf8')
if (existing) {
const index = existing.indexOf(PREPEND_TOKEN)
let index = existing.indexOf(PREPEND_TOKEN)

if (index === -1) {
if(options.prepend) {
index = 0;
}
}

if (index !== -1) {
const prepended = `${changelog}\n${existing.slice(index)}`
await writeFile(options.output, prepended)
Expand Down

0 comments on commit 3ed3651

Please sign in to comment.