forked from dhis2/capture-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifyCacheVersion.js
37 lines (32 loc) · 1.16 KB
/
verifyCacheVersion.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
#!/usr/bin/env node
/**
* Validate the version and cacheVersion specified in package.json
* The version and cacheVersion compose the actual storage version.
*/
var packageDesc = require('./package.json');
function verifyMajorCacheVersion(appVersion) {
if (!appVersion) {
console.log('Version not specified');
process.exit(1);
}
var appMajorVersion = Number(appVersion.split('.')[0]);
if (Number.isNaN(appMajorVersion) || !Number.isSafeInteger(appMajorVersion) || appMajorVersion <= 30) {
console.log('Invalid app version');
process.exit(1);
}
}
function verifyMinorCacheVersion(appCacheVersionAsString) {
if (!appCacheVersionAsString) {
console.log('Cache version not specified');
process.exit(1);
}
var appCacheVersion = Number(appCacheVersionAsString);
if (Number.isNaN(appCacheVersion) || !Number.isSafeInteger(appCacheVersion) || appCacheVersion >= 1000) {
console.log('Invalid cache version');
process.exit(1);
}
}
var appVersion = packageDesc.version;
var cacheVersion = packageDesc.cacheVersion;
verifyMajorCacheVersion(appVersion);
verifyMinorCacheVersion(cacheVersion);