1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import request from 'request';
|
9 | import path from 'path';
|
10 |
|
11 | const appConfig = require(path.join(process.cwd(), 'env' , 'env'));
|
12 | const appPackage = require(path.join(process.cwd(), 'package.json'));
|
13 | let hockeyAppToken;
|
14 |
|
15 | if (!process.env.HOCKEYAPP_API_TOKEN) {
|
16 | console.error('No HOCKEYAPP_API_TOKEN provided');
|
17 | process.exit(1);
|
18 | }
|
19 |
|
20 | if (!appConfig.hockey) {
|
21 | console.error('No hockey app configuration exists for this env');
|
22 | process.exit(1);
|
23 | }
|
24 |
|
25 | if (!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 |
|
32 | if (!hockeyAppToken) {
|
33 | console.error('No hockey app configuration exists for this platform: ' + process.argv[2]);
|
34 | process.exit(1);
|
35 | }
|
36 |
|
37 | interface CodepushVersions {
|
38 | app_versions?: {
|
39 | shortversion: string;
|
40 | }[];
|
41 | }
|
42 |
|
43 |
|
44 | request({
|
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 | });
|