Newer
Older
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
#!/usr/bin/env node
// from https://gitlab.com/staltz/manyverse/blob/master/tools/update-version.js
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const ReactNativeVersion = require('react-native-version')
const readline = require('readline')
const leftPad = require('left-pad')
const path = require('path')
const fs = require('fs')
const currentVersion = JSON.parse(fs.readFileSync('./package.json')).version
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
function createTodaysVersion(attempt) {
const today = new Date()
const yy = today.getFullYear() - 2000 // So it's two digits
const mm = leftPad(today.getMonth() + 1, 2, '0')
const d = today.getDate()
if (attempt === 0) {
return `0.${yy}${mm}.${d}-beta`
} else {
const letter = String.fromCharCode(97 + attempt) // 0=a, 1=b, 2=c, ...
return `0.${yy}${mm}.${d}-beta.${letter}`
}
}
let nextVersion
for (let i = 0 /* letter a */; i <= 25 /* letter z */; i++) {
nextVersion = createTodaysVersion(i)
if (nextVersion !== currentVersion) break
}
if (nextVersion === currentVersion) {
console.error('I dont know what else to generate beyong ' + nextVersion)
process.exit(1)
}
rl.question('Next version will be `' + nextVersion + '`, okay? y/n ', yn => {
if (yn !== 'y' && yn !== 'Y') {
console.log('Release cancelled.\n')
process.exit(1)
return
}
const pkgJSON = JSON.parse(fs.readFileSync('./package.json'))
const pkgLockJSON = JSON.parse(fs.readFileSync('./package-lock.json'))
pkgJSON.version = nextVersion
pkgLockJSON.version = nextVersion
fs.writeFileSync('./package.json', JSON.stringify(pkgJSON, null, 2))
fs.writeFileSync('./package-lock.json', JSON.stringify(pkgLockJSON, null, 2))
ReactNativeVersion.version(
{
neverAmend: true,
target: 'android',
},
path.resolve(__dirname, '../'),
).catch(err => {
console.error(err)
process.exit(1)
})
rl.close()
})