Skip to content

Commit

Permalink
workflow: only generate changelog for the latest release and concat w…
Browse files Browse the repository at this point in the history
…ith the old

so that the old manually edited parts won't be overwritten.
  • Loading branch information
haoqunjiang committed Jan 3, 2019
1 parent a7fa191 commit 016d474
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
Binary file removed docs/.vuepress/public/favicon.png
Binary file not shown.
46 changes: 31 additions & 15 deletions scripts/genChangelog.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
const fs = require('fs')
const path = require('path')
const execa = require('execa')
const cc = require('conventional-changelog')
const config = require('@vue/conventional-changelog')

const gen = module.exports = version => {
const fileStream = require('fs').createWriteStream(`CHANGELOG.md`)

cc({
config,
releaseCount: 0,
pkg: {
transform (pkg) {
pkg.version = `v${version}`
return pkg
function genNewRelease (version) {
return new Promise(resolve => {
const newReleaseStream = cc({
config,
releaseCount: 1,
pkg: {
transform (pkg) {
pkg.version = `v${version}`
return pkg
}
}
}
}).pipe(fileStream).on('close', async () => {
delete process.env.PREFIX
await execa('git', ['add', '-A'], { stdio: 'inherit' })
await execa('git', ['commit', '-m', `chore: ${version} changelog [ci skip]`], { stdio: 'inherit' })
})

let output = ''
newReleaseStream.on('data', buf => {
output += buf
})
newReleaseStream.on('end', () => resolve(output))
})
}

const gen = (module.exports = async version => {
const newRelease = await genNewRelease(version)
const changelogPath = path.resolve(__dirname, '../CHANGELOG.md')

const newChangelog = newRelease + fs.readFileSync(changelogPath, { encoding: 'utf8' })
fs.writeFileSync(changelogPath, newChangelog)

delete process.env.PREFIX
await execa('git', ['add', '-A'], { stdio: 'inherit' })
await execa('git', ['commit', '-m', `chore: ${version} changelog [ci skip]`], { stdio: 'inherit' })
})

if (process.argv[2] === 'run') {
const version = require('../lerna.json').version
gen(version)
Expand Down
2 changes: 1 addition & 1 deletion scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const release = async () => {
}
await execa(require.resolve('lerna/cli'), lernaArgs, { stdio: 'inherit' })

require('./genChangelog')(version)
await require('./genChangelog')(version)

const packages = JSON.parse(
(await execa(require.resolve('lerna/cli'), ['list', '--json'])).stdout
Expand Down

0 comments on commit 016d474

Please sign in to comment.