UNPKG

1.73 kBPlain TextView Raw
1// this script is called from travis and is used to determine if a native app binary has
2// been built for a specific version
3// exit codes:
4// 0 = a binary build for the version number in package.json does not exist on hockey
5// 1 = config or environment error
6// 2 = build already exists on hockey
7
8import request from 'request';
9import path from 'path';
10
11const appConfig = require(path.join(process.cwd(), 'env' , 'env'));
12const appPackage = require(path.join(process.cwd(), 'package.json'));
13let hockeyAppToken;
14
15if (!process.env.HOCKEYAPP_API_TOKEN) {
16 console.error('No HOCKEYAPP_API_TOKEN provided');
17 process.exit(1);
18}
19
20if (!appConfig.hockey) {
21 console.error('No hockey app configuration exists for this env');
22 process.exit(1);
23}
24
25if (!process.argv[2]) {
26 console.error('No platform was specified');
27 process.exit(1);
28} else {
29 hockeyAppToken = appConfig.hockey[process.argv[2]];
30}
31
32if (!hockeyAppToken) {
33 console.error('No hockey app configuration exists for this platform: ' + process.argv[2]);
34 process.exit(1);
35}
36
37interface CodepushVersions {
38 app_versions?: {
39 shortversion: string;
40 }[];
41}
42
43// check package.json version with the latest version on hockeyapp
44request({
45 url: `https://rink.hockeyapp.net/api/2/apps/${hockeyAppToken}/app_versions`,
46 json: true,
47 headers: {
48 'X-HockeyAppToken': process.env.HOCKEYAPP_API_TOKEN
49 }
50}, (err: any, response: any, body: CodepushVersions) => {
51 const version = !err && body && body.app_versions && body.app_versions.length &&
52 body.app_versions[0].shortversion;
53
54 console.log('latest app version on hockey', version);
55 console.log('package.json app version', appPackage.version);
56
57 process.exit(version === appPackage.version ? 2 : 0);
58});