diff options
author | Dan Finlay <dan@danfinlay.com> | 2018-03-03 05:55:56 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2018-03-03 05:55:56 +0800 |
commit | bf17d7e1153180fe68cc568a6f4ffa8db66010dc (patch) | |
tree | d82dbcb2c5588f5f18ca779f42037a60c25b1e4a /development | |
parent | 452c5d0513a14419b71ffd92d253fef661b74300 (diff) | |
download | tangerine-wallet-browser-bf17d7e1153180fe68cc568a6f4ffa8db66010dc.tar tangerine-wallet-browser-bf17d7e1153180fe68cc568a6f4ffa8db66010dc.tar.gz tangerine-wallet-browser-bf17d7e1153180fe68cc568a6f4ffa8db66010dc.tar.bz2 tangerine-wallet-browser-bf17d7e1153180fe68cc568a6f4ffa8db66010dc.tar.lz tangerine-wallet-browser-bf17d7e1153180fe68cc568a6f4ffa8db66010dc.tar.xz tangerine-wallet-browser-bf17d7e1153180fe68cc568a6f4ffa8db66010dc.tar.zst tangerine-wallet-browser-bf17d7e1153180fe68cc568a6f4ffa8db66010dc.zip |
Add version bumping script
One step towards automating our deploy process is automating our version
bumping scheme. This PR does that.
Diffstat (limited to 'development')
-rw-r--r-- | development/run-version-bump.js | 51 | ||||
-rw-r--r-- | development/version-bump.js | 53 |
2 files changed, 104 insertions, 0 deletions
diff --git a/development/run-version-bump.js b/development/run-version-bump.js new file mode 100644 index 000000000..3b26b00db --- /dev/null +++ b/development/run-version-bump.js @@ -0,0 +1,51 @@ +const { promisify } = require('util') +const fs = require('fs') +const readFile = promisify(fs.readFile) +const writeFile = promisify(fs.writeFile) +const path = require('path') +const changelogPath = path.join(__dirname, '..', 'CHANGELOG.md') +const manifestPath = path.join(__dirname, '..', 'app', 'manifest.json') +const manifest = require('../app/manifest.json') +const versionBump = require('./version-bump') + +console.dir(process.argv) +const bumpType = normalizeType(process.argv[2]) + + +readFile(changelogPath) +.then(async (changeBuffer) => { + const changelog = changeBuffer.toString() + + const newData = await versionBump(bumpType, changelog, manifest) + console.dir(newData) + + const manifestString = JSON.stringify(newData.manifest, null, 2) + + console.log('now writing files to ', changelogPath, manifestPath) + console.log(typeof newData.manifest) + await writeFile(changelogPath, newData.changelog) + await writeFile(manifestPath, manifestString) + + return newData.version +}) +.then((version) => console.log(`Bumped ${bumpType} to version ${version}`)) +.catch(console.error) + + +function normalizeType (userInput) { + console.log(`user inputted ${userInput}`) + const err = new Error('First option must be a type (major, minor, or patch)') + if (!userInput || typeof userInput !== 'string') { + console.log('first no') + throw err + } + + const lower = userInput.toLowerCase() + + if (lower !== 'major' && lower !== 'minor' && lower !== 'patch') { + console.log('second no') + throw err + } + + return lower +} diff --git a/development/version-bump.js b/development/version-bump.js new file mode 100644 index 000000000..63dd802d1 --- /dev/null +++ b/development/version-bump.js @@ -0,0 +1,53 @@ +const clone = require('clone') + +async function versionBump(bumpType, changelog, oldManifest) { + 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++) { + if (logLines[i].includes('Current Master')) { + logLines.splice(i + 1, 0, logHeader) + break + } + } + + return { + version: newVersion, + manifest: manifest, + changelog: logLines.join('\n') + } +} + +function newVersionFrom (manifest, bumpType) { + const string = manifest.version + let segments = string.split('.').map((str) => parseInt(str)) + + console.log('bump type is ' + bumpType) + 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('.') +} + +function bumpManifest (manifest, bumpType) { + +} + +module.exports = versionBump |