aboutsummaryrefslogtreecommitdiffstats
path: root/development/run-version-bump.js
blob: 3b26b00dbad43aaf9578fe6ed5d54af58fafc5de (plain) (blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
}