Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions changelog-maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const pkg = require('./package.json')
const debug = require('debug')(pkg.name)
const argv = require('minimist')(process.argv.slice(2))

// Skip on formatting on Node.js 10.
const formatMarkdown = process.versions.node.startsWith('10.') ? false : import('./format.mjs')

const quiet = argv.quiet || argv.q
const help = argv.h || argv.help
const commitUrl = argv['commit-url'] || 'https://github.com/{ghUser}/{ghRepo}/commit/{ref}'
Expand Down Expand Up @@ -102,14 +105,13 @@ function organiseCommits (list) {
})
}

function printCommits (list) {
let out = `${list.join('\n')}\n`

if (!process.stdout.isTTY) {
out = stripAnsi(out)
async function printCommits (list) {
for await (let commit of list) {
if (!process.stdout.isTTY) {
commit = stripAnsi(commit)
}
process.stdout.write(commit)
}

process.stdout.write(out)
}

function onCommitList (err, list) {
Expand Down Expand Up @@ -142,10 +144,20 @@ function onCommitList (err, list) {
formatted.push(commitToOutput(commit, formatType.PLAINTEXT, ghId, commitUrl))
}

list = formatted
list = formatted.map((line) => `${line}\n`)
} else {
list = list.map((commit) => {
return commitToOutput(commit, format, ghId, commitUrl)
list = list.map(async (commit) => {
let output = commitToOutput(commit, format, ghId, commitUrl)
if (format === formatType.MARKDOWN) {
if (!process.stdout.isTTY) {
output = stripAnsi(output)
}
if (process.versions.node.startsWith('10.')) {
return `${output}\n`
}
return formatMarkdown.then((module) => module.default(output))
}
return `${output}\n`
})
}

Expand Down
16 changes: 16 additions & 0 deletions format.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { remark } from 'remark'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import presetLintNode from 'remark-preset-lint-node'

const formatter = remark()
.use(remarkParse)
.use(presetLintNode)
.use(remarkStringify)

const format = async (markdown) => {
const result = await formatter.process(markdown)
return result.toString()
}

export default format
Loading