2018-03-02 22:55:56 +01:00
|
|
|
const clone = require('clone')
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
async function versionBump (bumpType, changelog, oldManifest) {
|
2018-03-02 22:55:56 +01:00
|
|
|
const manifest = clone(oldManifest)
|
|
|
|
const newVersion = newVersionFrom(manifest, bumpType)
|
|
|
|
|
|
|
|
manifest.version = newVersion
|
|
|
|
const date = (new Date()).toDateString()
|
|
|
|
|
|
|
|
const logHeader = `\n## ${newVersion} ${date}`
|
|
|
|
const logLines = changelog.split('\n')
|
|
|
|
for (let i = 0; i < logLines.length; i++) {
|
2018-11-20 19:34:14 +01:00
|
|
|
if (logLines[i].includes('Current Develop Branch')) {
|
2018-03-02 22:55:56 +01:00
|
|
|
logLines.splice(i + 1, 0, logHeader)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
version: newVersion,
|
|
|
|
manifest: manifest,
|
2018-07-03 00:49:33 +02:00
|
|
|
changelog: logLines.join('\n'),
|
2018-03-02 22:55:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function newVersionFrom (manifest, bumpType) {
|
|
|
|
const string = manifest.version
|
2018-07-03 00:49:33 +02:00
|
|
|
const segments = string.split('.').map((str) => parseInt(str))
|
2018-03-02 22:55:56 +01:00
|
|
|
|
|
|
|
switch (bumpType) {
|
|
|
|
case 'major':
|
|
|
|
segments[0] += 1
|
|
|
|
segments[1] = 0
|
|
|
|
segments[2] = 0
|
|
|
|
break
|
|
|
|
case 'minor':
|
|
|
|
segments[1] += 1
|
|
|
|
segments[2] = 0
|
|
|
|
break
|
|
|
|
case 'patch':
|
|
|
|
segments[2] += 1
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
return segments.map(String).join('.')
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = versionBump
|