@revopush/code-push-cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +17 -0
- package/.idea/cli.iml +9 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +774 -0
- package/bin/script/acquisition-sdk.js +178 -0
- package/bin/script/cli.js +23 -0
- package/bin/script/command-executor.js +1290 -0
- package/bin/script/command-parser.js +1097 -0
- package/bin/script/commands/debug.js +125 -0
- package/bin/script/hash-utils.js +203 -0
- package/bin/script/index.js +5 -0
- package/bin/script/management-sdk.js +419 -0
- package/bin/script/react-native-utils.js +249 -0
- package/bin/script/sign.js +69 -0
- package/bin/script/types/cli.js +40 -0
- package/bin/script/types/rest-definitions.js +19 -0
- package/bin/script/types.js +4 -0
- package/bin/script/utils/file-utils.js +50 -0
- package/bin/test/acquisition-rest-mock.js +108 -0
- package/bin/test/acquisition-sdk.js +188 -0
- package/bin/test/cli.js +1342 -0
- package/bin/test/hash-utils.js +149 -0
- package/bin/test/management-sdk.js +338 -0
- package/package.json +68 -0
- package/prettier.config.js +7 -0
- package/script/acquisition-sdk.ts +273 -0
- package/script/cli.ts +27 -0
- package/script/command-executor.ts +1610 -0
- package/script/command-parser.ts +1310 -0
- package/script/commands/debug.ts +148 -0
- package/script/hash-utils.ts +241 -0
- package/script/index.ts +5 -0
- package/script/management-sdk.ts +575 -0
- package/script/react-native-utils.ts +283 -0
- package/script/sign.ts +80 -0
- package/script/types/cli.ts +232 -0
- package/script/types/rest-definitions.ts +152 -0
- package/script/types.ts +35 -0
- package/script/utils/file-utils.ts +46 -0
- package/test/acquisition-rest-mock.ts +125 -0
- package/test/acquisition-sdk.ts +272 -0
- package/test/cli.ts +1692 -0
- package/test/hash-utils.ts +170 -0
- package/test/management-sdk.ts +438 -0
- package/test/resources/TestApp/android/app/build.gradle +56 -0
- package/test/resources/TestApp/iOS/TestApp/Info.plist +49 -0
- package/test/resources/TestApp/index.android.js +2 -0
- package/test/resources/TestApp/index.ios.js +2 -0
- package/test/resources/TestApp/index.windows.js +2 -0
- package/test/resources/TestApp/package.json +6 -0
- package/test/resources/TestApp/windows/TestApp/Package.appxmanifest +46 -0
- package/test/resources/ignoredMetadata.zip +0 -0
- package/test/resources/test.zip +0 -0
- package/test/superagent-mock-config.js +58 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { UpdateCheckResponse, UpdateCheckRequest, DeploymentStatusReport, DownloadReport } from "../script/types/rest-definitions";
|
|
5
|
+
|
|
6
|
+
export module Http {
|
|
7
|
+
export const enum Verb {
|
|
8
|
+
GET,
|
|
9
|
+
HEAD,
|
|
10
|
+
POST,
|
|
11
|
+
PUT,
|
|
12
|
+
DELETE,
|
|
13
|
+
TRACE,
|
|
14
|
+
OPTIONS,
|
|
15
|
+
CONNECT,
|
|
16
|
+
PATCH,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Response {
|
|
20
|
+
statusCode: number;
|
|
21
|
+
body?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface Requester {
|
|
25
|
+
request(verb: Verb, url: string, callback: Callback<Response>): void;
|
|
26
|
+
request(verb: Verb, url: string, requestBody: string, callback: Callback<Response>): void;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// All fields are non-nullable, except when retrieving the currently running package on the first run of the app,
|
|
31
|
+
// in which case only the appVersion is compulsory
|
|
32
|
+
export interface Package {
|
|
33
|
+
deploymentKey: string;
|
|
34
|
+
description: string;
|
|
35
|
+
label: string;
|
|
36
|
+
appVersion: string;
|
|
37
|
+
isMandatory: boolean;
|
|
38
|
+
packageHash: string;
|
|
39
|
+
packageSize: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface RemotePackage extends Package {
|
|
43
|
+
downloadUrl: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface NativeUpdateNotification {
|
|
47
|
+
updateAppVersion: boolean; // Always true
|
|
48
|
+
appVersion: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface LocalPackage extends Package {
|
|
52
|
+
localPath: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface Callback<T> {
|
|
56
|
+
(error: Error, parameter: T): void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface Configuration {
|
|
60
|
+
appVersion: string;
|
|
61
|
+
clientUniqueId: string;
|
|
62
|
+
deploymentKey: string;
|
|
63
|
+
serverUrl: string;
|
|
64
|
+
ignoreAppVersion?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class AcquisitionStatus {
|
|
68
|
+
public static DeploymentSucceeded = "DeploymentSucceeded";
|
|
69
|
+
public static DeploymentFailed = "DeploymentFailed";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class AcquisitionManager {
|
|
73
|
+
private _appVersion: string;
|
|
74
|
+
private _clientUniqueId: string;
|
|
75
|
+
private _deploymentKey: string;
|
|
76
|
+
private _httpRequester: Http.Requester;
|
|
77
|
+
private _ignoreAppVersion: boolean;
|
|
78
|
+
private _serverUrl: string;
|
|
79
|
+
|
|
80
|
+
constructor(httpRequester: Http.Requester, configuration: Configuration) {
|
|
81
|
+
this._httpRequester = httpRequester;
|
|
82
|
+
|
|
83
|
+
this._serverUrl = configuration.serverUrl;
|
|
84
|
+
if (this._serverUrl.slice(-1) !== "/") {
|
|
85
|
+
this._serverUrl += "/";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this._appVersion = configuration.appVersion;
|
|
89
|
+
this._clientUniqueId = configuration.clientUniqueId;
|
|
90
|
+
this._deploymentKey = configuration.deploymentKey;
|
|
91
|
+
this._ignoreAppVersion = configuration.ignoreAppVersion;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public queryUpdateWithCurrentPackage(currentPackage: Package, callback?: Callback<RemotePackage | NativeUpdateNotification>): void {
|
|
95
|
+
if (!currentPackage || !currentPackage.appVersion) {
|
|
96
|
+
throw new Error("Calling common acquisition SDK with incorrect package"); // Unexpected; indicates error in our implementation
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const updateRequest: UpdateCheckRequest = {
|
|
100
|
+
deploymentKey: this._deploymentKey,
|
|
101
|
+
appVersion: currentPackage.appVersion,
|
|
102
|
+
packageHash: currentPackage.packageHash,
|
|
103
|
+
isCompanion: this._ignoreAppVersion,
|
|
104
|
+
label: currentPackage.label,
|
|
105
|
+
clientUniqueId: this._clientUniqueId,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const requestUrl: string = this._serverUrl + "updateCheck?" + queryStringify(updateRequest);
|
|
109
|
+
|
|
110
|
+
this._httpRequester.request(Http.Verb.GET, requestUrl, (error: Error, response: Http.Response) => {
|
|
111
|
+
if (error) {
|
|
112
|
+
callback(error, /*remotePackage=*/ null);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (response.statusCode !== 200) {
|
|
117
|
+
callback(new Error(response.statusCode + ": " + response.body), /*remotePackage=*/ null);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let updateInfo: UpdateCheckResponse;
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const responseObject = JSON.parse(response.body);
|
|
125
|
+
updateInfo = responseObject.updateInfo;
|
|
126
|
+
} catch (error) {
|
|
127
|
+
callback(error, /*remotePackage=*/ null);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!updateInfo) {
|
|
132
|
+
callback(error, /*remotePackage=*/ null);
|
|
133
|
+
return;
|
|
134
|
+
} else if (updateInfo.updateAppVersion) {
|
|
135
|
+
callback(/*error=*/ null, {
|
|
136
|
+
updateAppVersion: true,
|
|
137
|
+
appVersion: updateInfo.appVersion,
|
|
138
|
+
});
|
|
139
|
+
return;
|
|
140
|
+
} else if (!updateInfo.isAvailable) {
|
|
141
|
+
callback(/*error=*/ null, /*remotePackage=*/ null);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const remotePackage: RemotePackage = {
|
|
146
|
+
deploymentKey: this._deploymentKey,
|
|
147
|
+
description: updateInfo.description,
|
|
148
|
+
label: updateInfo.label,
|
|
149
|
+
appVersion: updateInfo.appVersion,
|
|
150
|
+
isMandatory: updateInfo.isMandatory,
|
|
151
|
+
packageHash: updateInfo.packageHash,
|
|
152
|
+
packageSize: updateInfo.packageSize,
|
|
153
|
+
downloadUrl: updateInfo.downloadURL,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
callback(/*error=*/ null, remotePackage);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public reportStatusDeploy(
|
|
161
|
+
deployedPackage?: Package,
|
|
162
|
+
status?: string,
|
|
163
|
+
previousLabelOrAppVersion?: string,
|
|
164
|
+
previousDeploymentKey?: string,
|
|
165
|
+
callback?: Callback<void>
|
|
166
|
+
): void {
|
|
167
|
+
const url: string = this._serverUrl + "reportStatus/deploy";
|
|
168
|
+
const body: DeploymentStatusReport = {
|
|
169
|
+
appVersion: this._appVersion,
|
|
170
|
+
deploymentKey: this._deploymentKey,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
if (this._clientUniqueId) {
|
|
174
|
+
body.clientUniqueId = this._clientUniqueId;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (deployedPackage) {
|
|
178
|
+
body.label = deployedPackage.label;
|
|
179
|
+
body.appVersion = deployedPackage.appVersion;
|
|
180
|
+
|
|
181
|
+
switch (status) {
|
|
182
|
+
case AcquisitionStatus.DeploymentSucceeded:
|
|
183
|
+
case AcquisitionStatus.DeploymentFailed:
|
|
184
|
+
body.status = status;
|
|
185
|
+
break;
|
|
186
|
+
|
|
187
|
+
default:
|
|
188
|
+
if (callback) {
|
|
189
|
+
if (!status) {
|
|
190
|
+
callback(new Error("Missing status argument."), /*not used*/ null);
|
|
191
|
+
} else {
|
|
192
|
+
callback(new Error('Unrecognized status "' + status + '".'), /*not used*/ null);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (previousLabelOrAppVersion) {
|
|
200
|
+
body.previousLabelOrAppVersion = previousLabelOrAppVersion;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (previousDeploymentKey) {
|
|
204
|
+
body.previousDeploymentKey = previousDeploymentKey;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
callback = typeof arguments[arguments.length - 1] === "function" && arguments[arguments.length - 1];
|
|
208
|
+
|
|
209
|
+
this._httpRequester.request(Http.Verb.POST, url, JSON.stringify(body), (error: Error, response: Http.Response): void => {
|
|
210
|
+
if (callback) {
|
|
211
|
+
if (error) {
|
|
212
|
+
callback(error, /*not used*/ null);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (response.statusCode !== 200) {
|
|
217
|
+
callback(new Error(response.statusCode + ": " + response.body), /*not used*/ null);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
callback(/*error*/ null, /*not used*/ null);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public reportStatusDownload(downloadedPackage: Package, callback?: Callback<void>): void {
|
|
227
|
+
const url: string = this._serverUrl + "reportStatus/download";
|
|
228
|
+
const body: DownloadReport = {
|
|
229
|
+
clientUniqueId: this._clientUniqueId,
|
|
230
|
+
deploymentKey: this._deploymentKey,
|
|
231
|
+
label: downloadedPackage.label,
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
this._httpRequester.request(Http.Verb.POST, url, JSON.stringify(body), (error: Error, response: Http.Response): void => {
|
|
235
|
+
if (callback) {
|
|
236
|
+
if (error) {
|
|
237
|
+
callback(error, /*not used*/ null);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (response.statusCode !== 200) {
|
|
242
|
+
callback(new Error(response.statusCode + ": " + response.body), /*not used*/ null);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
callback(/*error*/ null, /*not used*/ null);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function queryStringify(object: Object): string {
|
|
253
|
+
let queryString = "";
|
|
254
|
+
let isFirst: boolean = true;
|
|
255
|
+
|
|
256
|
+
for (const property in object) {
|
|
257
|
+
if (object.hasOwnProperty(property)) {
|
|
258
|
+
const value: string = (<any>object)[property];
|
|
259
|
+
if (!isFirst) {
|
|
260
|
+
queryString += "&";
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
queryString += encodeURIComponent(property) + "=";
|
|
264
|
+
if (value !== null && typeof value !== "undefined") {
|
|
265
|
+
queryString += encodeURIComponent(value);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
isFirst = false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return queryString;
|
|
273
|
+
}
|
package/script/cli.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Microsoft Corporation.
|
|
4
|
+
// Licensed under the MIT License.
|
|
5
|
+
|
|
6
|
+
import * as parser from "./command-parser";
|
|
7
|
+
import * as execute from "./command-executor";
|
|
8
|
+
import * as chalk from "chalk";
|
|
9
|
+
|
|
10
|
+
function run() {
|
|
11
|
+
const command = parser.createCommand();
|
|
12
|
+
|
|
13
|
+
if (!command) {
|
|
14
|
+
parser.showHelp(/*showRootDescription*/ false);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
execute
|
|
19
|
+
.execute(command)
|
|
20
|
+
.catch((error: any): void => {
|
|
21
|
+
console.error(chalk.red(`[Error] ${error.message}`));
|
|
22
|
+
process.exit(1);
|
|
23
|
+
})
|
|
24
|
+
.done();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
run();
|