-
Notifications
You must be signed in to change notification settings - Fork 5
/
build_number.js
46 lines (40 loc) · 1011 Bytes
/
build_number.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
const admin = require('firebase-admin');
const database = require('firebase/database');
const serviceAccount = require('./fastlane/FirebaseAPIKey.json');
const mobilePath = 'mobileApp';
const valuePath = 'build';
initialize();
incrementBuildNumber();
function initialize() {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://broxus.firebaseio.com',
});
}
function incrementBuildNumber() {
admin
.database()
.ref(mobilePath)
.update({ [valuePath]: database.increment(1) })
.then(() => {
retrieveBuildNumber((build) => {
console.log(build);
process.exit(0);
});
})
.catch(onError);
}
function retrieveBuildNumber(onGetData) {
admin
.database()
.ref(mobilePath)
.once('value', (snapshot) => {
build = snapshot.val()[valuePath];
onGetData(build);
})
.catch(onError);
}
function onError(error) {
console.error(error);
process.exit(1); // something went wrong
}