1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/development/version-bump.js
Mark Stacey 398a45bfdd
Replace clone dependency with cloneDeep from lodash (#7926)
This was done to reduce the number of direct dependencies we have. It
should be functionally equivalent. The bundle size should not change,
as we use `clone` as a transitive dependency in a number of places.
2020-01-29 13:14:33 -04:00

51 lines
1.2 KiB
JavaScript

const { cloneDeep } = require('lodash')
async function versionBump (bumpType, changelog, oldManifest) {
const manifest = cloneDeep(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++) {
if (logLines[i].includes('Current Develop Branch')) {
logLines.splice(i + 1, 0, logHeader)
break
}
}
return {
version: newVersion,
manifest: manifest,
changelog: logLines.join('\n'),
}
}
function newVersionFrom (manifest, bumpType) {
const string = manifest.version
const segments = string.split('.').map((str) => parseInt(str))
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
default:
throw new Error(`invalid bumpType ${bumpType}`)
}
return segments.map(String).join('.')
}
module.exports = versionBump