forked from irony/mydata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.js
115 lines (96 loc) · 2.54 KB
/
version.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const fs = require('fs')
const { exec } = require('child_process')
const plist = require('plist')
const PACKAGE_JSON_LOCATIONS = [
'.',
'./app',
'./client',
'./examples/cv',
'./operator'
]
/*
* Program
*/
const action = process.argv[2]
if (!action) {
console.log('Usage: node version.js <major|minor|patch>')
process.exit(1)
}
getTags()
.then(versions => {
const latestVersion = Math.max.apply(null, Object.keys(versions))
const version = versions[latestVersion]
switch (action) {
case 'major':
version.major++
version.minor = 0
version.patch = 0
break
case 'minor':
version.minor++
version.patch = 0
break
case 'patch':
version.patch++
}
const versionString = `${version.major}.${version.minor}.${version.patch}`
PACKAGE_JSON_LOCATIONS.forEach(location => {
let path = `${location}/package.json`
let package = require(path)
package.version = versionString
fs.writeFileSync(path, JSON.stringify(package, null, 2))
console.log(`Set ${path} to v${package.version}`)
})
updatePlist(versionString)
console.log(`
# To finish, run the following commands:
git add **/package.json
git add .version.json
git commit -m "chore: preparing tag v${versionString}"
git tag v${versionString}
git push origin v${versionString}
`)
})
.catch(error => {
console.log(`\nSomethig went wrong`)
console.log(error)
})
/*
* Helpers
*/
function getVersionFromTag (tag) {
const v = {}
v.major = parseInt(tag.split('v')[1].split('.')[0])
v.minor = parseInt(tag.split('v')[1].split('.')[1])
v.patch = parseInt(tag.split('v')[1].split('.')[2])
return v
}
function getTags () {
return new Promise((resolve, reject) => {
exec('git fetch --tags -p && git tag', (err, stdout, stderr) => {
if (err) {
console.log('Unable to get git tags, exiting.')
return reject(err)
}
if (stderr) {
return reject(stderr)
}
// the *entire* stdout and stderr (buffered)
const tags = stdout.split('\n')
const versions = {}
tags.forEach(tag => {
if (/^v[0-9]+\.[0-9]+\.[0-9]+/.test(tag)) {
let v = getVersionFromTag(tag)
versions[v.major * 10000 + v.minor * 1000 + v.patch] = v
}
})
return resolve(versions)
})
})
}
function updatePlist(versionString) {
const appPlistFile = './app/ios/MyData/Info.plist'
const plistObject = plist.parseFileSync(appPlistFile);
plistObject.CFBundleShortVersionString = versionString
fs.writeFileSync(appPlistFile, plist.build(plistObject).toString())
}