-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathprepare.js
27 lines (22 loc) · 987 Bytes
/
prepare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const path = require('path');
const {readFile, writeFile, ensureFile} = require('fs-extra');
const resolveConfig = require('./resolve-config.js');
module.exports = async (pluginConfig, {cwd, nextRelease: {notes}, logger}) => {
const {changelogFile, changelogTitle} = resolveConfig(pluginConfig);
const changelogPath = path.resolve(cwd, changelogFile);
if (notes) {
await ensureFile(changelogPath);
const currentFile = (await readFile(changelogPath)).toString().trim();
if (currentFile) {
logger.log('Update %s', changelogPath);
} else {
logger.log('Create %s', changelogPath);
}
const currentContent =
changelogTitle && currentFile.startsWith(changelogTitle)
? currentFile.slice(changelogTitle.length).trim()
: currentFile;
const content = `${notes.trim()}\n${currentContent ? `\n${currentContent}\n` : ''}`;
await writeFile(changelogPath, changelogTitle ? `${changelogTitle}\n\n${content}` : content);
}
};