aboutsummaryrefslogblamecommitdiffstats
path: root/development/run-version-bump.js
blob: 98757f58e9b1637b6d45f2b6bf2f99488a502bdd (plain) (tree)
1
2
3
4
5
6
7
8
9
                                 







                                                                       

                                               


                            
 
                                                    


                                                                  


                                                                  


                                                   

                                                                 


                                    

                                                                               





                                                                    




              
const promisify = require('pify')
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')
const bumpType = normalizeType(process.argv[2])

start().catch(console.error)

async function start() {

  const changeBuffer = await readFile(changelogPath)
  const changelog = changeBuffer.toString()

  const newData = await versionBump(bumpType, changelog, manifest)

  const manifestString = JSON.stringify(newData.manifest, null, 2)

  await writeFile(changelogPath, newData.changelog)
  await writeFile(manifestPath, manifestString)

  console.log(`Bumped ${bumpType} to version ${newData.version}`)
}


function normalizeType (userInput) {
  const err = new Error('First option must be a type (major, minor, or patch)')
  if (!userInput || typeof userInput !== 'string') {
    throw err
  }

  const lower = userInput.toLowerCase()

  if (lower !== 'major' && lower !== 'minor' && lower !== 'patch') {
    throw err
  }

  return lower
}