|
| 1 | +const fs = require('fs') |
| 2 | +const path = require('path') |
1 | 3 | const execa = require('execa') |
2 | 4 | const cc = require('conventional-changelog') |
3 | 5 | const config = require('@vue/conventional-changelog') |
4 | 6 |
|
5 | | -const gen = module.exports = version => { |
6 | | - const fileStream = require('fs').createWriteStream(`CHANGELOG.md`) |
7 | | - |
8 | | - cc({ |
9 | | - config, |
10 | | - releaseCount: 0, |
11 | | - pkg: { |
12 | | - transform (pkg) { |
13 | | - pkg.version = `v${version}` |
14 | | - return pkg |
| 7 | +function genNewRelease (version) { |
| 8 | + return new Promise(resolve => { |
| 9 | + const newReleaseStream = cc({ |
| 10 | + config, |
| 11 | + releaseCount: 1, |
| 12 | + pkg: { |
| 13 | + transform (pkg) { |
| 14 | + pkg.version = `v${version}` |
| 15 | + return pkg |
| 16 | + } |
15 | 17 | } |
16 | | - } |
17 | | - }).pipe(fileStream).on('close', async () => { |
18 | | - delete process.env.PREFIX |
19 | | - await execa('git', ['add', '-A'], { stdio: 'inherit' }) |
20 | | - await execa('git', ['commit', '-m', `chore: ${version} changelog [ci skip]`], { stdio: 'inherit' }) |
| 18 | + }) |
| 19 | + |
| 20 | + let output = '' |
| 21 | + newReleaseStream.on('data', buf => { |
| 22 | + output += buf |
| 23 | + }) |
| 24 | + newReleaseStream.on('end', () => resolve(output)) |
21 | 25 | }) |
22 | 26 | } |
23 | 27 |
|
| 28 | +const gen = (module.exports = async version => { |
| 29 | + const newRelease = await genNewRelease(version) |
| 30 | + const changelogPath = path.resolve(__dirname, '../CHANGELOG.md') |
| 31 | + |
| 32 | + const newChangelog = newRelease + fs.readFileSync(changelogPath, { encoding: 'utf8' }) |
| 33 | + fs.writeFileSync(changelogPath, newChangelog) |
| 34 | + |
| 35 | + delete process.env.PREFIX |
| 36 | + await execa('git', ['add', '-A'], { stdio: 'inherit' }) |
| 37 | + await execa('git', ['commit', '-m', `chore: ${version} changelog [ci skip]`], { stdio: 'inherit' }) |
| 38 | +}) |
| 39 | + |
24 | 40 | if (process.argv[2] === 'run') { |
25 | 41 | const version = require('../lerna.json').version |
26 | 42 | gen(version) |
|
0 commit comments