code-push-itspar 1.0.0

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.
@@ -0,0 +1,1225 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.createCommand = exports.showHelp = void 0;
6
+ const yargs = require("yargs");
7
+ const cli = require("../script/types/cli");
8
+ const chalk = require("chalk");
9
+ const backslash = require("backslash");
10
+ const parseDuration = require("parse-duration");
11
+ const packageJson = require("../../package.json");
12
+ const ROLLOUT_PERCENTAGE_REGEX = /^(100|[1-9][0-9]|[1-9])%?$/;
13
+ const USAGE_PREFIX = "Usage: code-push-itspar";
14
+ // Command categories are: access-key, app, release, deployment, deployment-key, login, logout, register
15
+ // eslint-disable-next-line no-var, @typescript-eslint/no-unused-vars
16
+ var isValidCommandCategory = false;
17
+ // Commands are the verb following the command category (e.g.: "add" in "app add").
18
+ let isValidCommand = false;
19
+ let wasHelpShown = false;
20
+ function showHelp(showRootDescription) {
21
+ if (!wasHelpShown) {
22
+ if (showRootDescription) {
23
+ console.log(chalk.cyan(" _____ __ " + chalk.green(" ___ __ ")));
24
+ console.log(chalk.cyan(" / ___/__ ___/ /__" + chalk.green(" / _ \\__ _____ / / ")));
25
+ console.log(chalk.cyan("/ /__/ _ \\/ _ / -_)" + chalk.green(" ___/ // (_-</ _ \\")));
26
+ console.log(chalk.cyan("\\___/\\___/\\_,_/\\__/" + chalk.green("_/ \\_,_/___/_//_/")) + " CLI v" + packageJson.version);
27
+ console.log(chalk.cyan("======================================"));
28
+ console.log("");
29
+ console.log("CodePush is a service that enables you to deploy mobile app updates directly to your users' devices.\n");
30
+ }
31
+ yargs.showHelp();
32
+ wasHelpShown = true;
33
+ }
34
+ }
35
+ exports.showHelp = showHelp;
36
+ function accessKeyAdd(commandName, yargs) {
37
+ isValidCommand = true;
38
+ yargs
39
+ .usage(USAGE_PREFIX + " access-key " + commandName + " <accessKeyName>")
40
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
41
+ .example("access-key " + commandName + ' "VSTS Integration"', 'Creates a new access key with the name "VSTS Integration", which expires in 60 days')
42
+ .example("access-key " + commandName + ' "One time key" --ttl 5m', 'Creates a new access key with the name "One time key", which expires in 5 minutes')
43
+ .option("ttl", {
44
+ default: "60d",
45
+ demand: false,
46
+ description: "Duration string which specifies the amount of time that the access key should remain valid for (e.g 5m, 60d, 1y)",
47
+ type: "string",
48
+ });
49
+ addCommonConfiguration(yargs);
50
+ }
51
+ function accessKeyPatch(commandName, yargs) {
52
+ isValidCommand = true;
53
+ yargs
54
+ .usage(USAGE_PREFIX + " access-key " + commandName + " <accessKeyName>")
55
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
56
+ .example("access-key " + commandName + ' "Key for build server" --name "Key for CI machine"', 'Renames the access key named "Key for build server" to "Key for CI machine"')
57
+ .example("access-key " + commandName + ' "Key for build server" --ttl 7d', 'Updates the access key named "Key for build server" to expire in 7 days')
58
+ .option("name", {
59
+ default: null,
60
+ demand: false,
61
+ description: "Display name for the access key",
62
+ type: "string",
63
+ })
64
+ .option("ttl", {
65
+ default: null,
66
+ demand: false,
67
+ description: "Duration string which specifies the amount of time that the access key should remain valid for (e.g 5m, 60d, 1y)",
68
+ type: "string",
69
+ });
70
+ addCommonConfiguration(yargs);
71
+ }
72
+ function accessKeyList(commandName, yargs) {
73
+ isValidCommand = true;
74
+ yargs
75
+ .usage(USAGE_PREFIX + " access-key " + commandName + " [options]")
76
+ .demand(/*count*/ 0, /*max*/ 0)
77
+ .example("access-key " + commandName, "Lists your access keys in tabular format")
78
+ .example("access-key " + commandName + " --format json", "Lists your access keys in JSON format")
79
+ .option("format", {
80
+ default: "table",
81
+ demand: false,
82
+ description: 'Output format to display your access keys with ("json" or "table")',
83
+ type: "string",
84
+ });
85
+ addCommonConfiguration(yargs);
86
+ }
87
+ function accessKeyRemove(commandName, yargs) {
88
+ isValidCommand = true;
89
+ yargs
90
+ .usage(USAGE_PREFIX + " access-key " + commandName + " <accessKeyName>")
91
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
92
+ .example("access-key " + commandName + ' "VSTS Integration"', 'Removes the "VSTS Integration" access key');
93
+ addCommonConfiguration(yargs);
94
+ }
95
+ function addCommonConfiguration(yargs) {
96
+ yargs
97
+ .wrap(/*columnLimit*/ null)
98
+ .string("_") // Interpret non-hyphenated arguments as strings (e.g. an app version of '1.10').
99
+ .fail((_msg) => showHelp()); // Suppress the default error message.
100
+ }
101
+ function orgList(commandName, yargs) {
102
+ isValidCommand = true;
103
+ yargs
104
+ .usage(USAGE_PREFIX + " org " + commandName + " [options]")
105
+ .demand(/*count*/ 0, /*max*/ 0)
106
+ .example("org " + commandName, "Lists your organisations in tabular format")
107
+ .example("org " + commandName + " --format json", "Lists your organisations in JSON format")
108
+ .option("format", {
109
+ default: "table",
110
+ demand: false,
111
+ description: 'Output format to display your organisations with ("json" or "table")',
112
+ type: "string",
113
+ });
114
+ addCommonConfiguration(yargs);
115
+ }
116
+ function appList(commandName, yargs) {
117
+ isValidCommand = true;
118
+ yargs
119
+ .usage(USAGE_PREFIX + " app " + commandName + " [options]")
120
+ .demand(/*count*/ 0, /*max*/ 0)
121
+ .example("app " + commandName, "List your apps in tabular format")
122
+ .example("app <orgName> " + commandName, "List your apps in tabular format")
123
+ .example("app " + commandName + " --format json", "List your apps in JSON format")
124
+ .example("app <orgName> " + commandName + " --format json", "List org apps in JSON format")
125
+ .option("org", {
126
+ default: null,
127
+ demand: false,
128
+ description: "Organisation name",
129
+ type: "string",
130
+ })
131
+ .option("format", {
132
+ default: "table",
133
+ demand: false,
134
+ description: 'Output format to display your apps with ("json" or "table")',
135
+ type: "string",
136
+ });
137
+ addCommonConfiguration(yargs);
138
+ }
139
+ function appRemove(commandName, yargs) {
140
+ isValidCommand = true;
141
+ yargs
142
+ .usage(USAGE_PREFIX + " app " + commandName + " <ownerName>/<appName>")
143
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
144
+ .example("app " + commandName + " OrgName/MyApp", 'Removes app "MyApp"');
145
+ addCommonConfiguration(yargs);
146
+ }
147
+ function listCollaborators(commandName, yargs) {
148
+ isValidCommand = true;
149
+ yargs
150
+ .usage(USAGE_PREFIX + " collaborator " + commandName + " <ownerName>/<appName> [options]")
151
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
152
+ .example("collaborator " + commandName + " OrgName/MyApp", 'Lists the collaborators for app "MyApp" in tabular format')
153
+ .example("collaborator " + commandName + " OrgName/MyApp --format json", 'Lists the collaborators for app "MyApp" in JSON format')
154
+ .option("format", {
155
+ default: "table",
156
+ demand: false,
157
+ description: 'Output format to display collaborators with ("json" or "table")',
158
+ type: "string",
159
+ });
160
+ addCommonConfiguration(yargs);
161
+ }
162
+ function removeCollaborator(commandName, yargs) {
163
+ isValidCommand = true;
164
+ yargs
165
+ .usage(USAGE_PREFIX + " collaborator " + commandName + " <ownerName>/<appName> <email>")
166
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
167
+ .example("collaborator " + commandName + " OrgName/MyApp foo@bar.com", 'Removes foo@bar.com as a collaborator from app "MyApp"');
168
+ addCommonConfiguration(yargs);
169
+ }
170
+ function sessionList(commandName, yargs) {
171
+ isValidCommand = true;
172
+ yargs
173
+ .usage(USAGE_PREFIX + " session " + commandName + " [options]")
174
+ .demand(/*count*/ 0, /*max*/ 0)
175
+ .example("session " + commandName, "Lists your sessions in tabular format")
176
+ .example("session " + commandName + " --format json", "Lists your login sessions in JSON format")
177
+ .option("format", {
178
+ default: "table",
179
+ demand: false,
180
+ description: 'Output format to display your login sessions with ("json" or "table")',
181
+ type: "string",
182
+ });
183
+ addCommonConfiguration(yargs);
184
+ }
185
+ function sessionRemove(commandName, yargs) {
186
+ isValidCommand = true;
187
+ yargs
188
+ .usage(USAGE_PREFIX + " session " + commandName + " <machineName>")
189
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
190
+ .example("session " + commandName + ' "John\'s PC"', 'Removes the existing login session from "John\'s PC"');
191
+ addCommonConfiguration(yargs);
192
+ }
193
+ function deploymentHistoryClear(commandName, yargs) {
194
+ isValidCommand = true;
195
+ yargs
196
+ .usage(USAGE_PREFIX + " deployment " + commandName + " <ownerName>/<appName> <deploymentName>")
197
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
198
+ .example("deployment " + commandName + " OrgName/MyApp MyDeployment", 'Clears the release history associated with deployment "MyDeployment" from app "MyApp"');
199
+ addCommonConfiguration(yargs);
200
+ }
201
+ function deploymentList(commandName, yargs) {
202
+ isValidCommand = true;
203
+ yargs
204
+ .usage(USAGE_PREFIX + " deployment " + commandName + " <ownerName>/<appName> [options]")
205
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
206
+ .example("deployment " + commandName + " OrgName/MyApp", 'Lists the deployments for app "MyApp" in tabular format')
207
+ .example("deployment " + commandName + " OrgName/MyApp --format json", 'Lists the deployments for app "MyApp" in JSON format')
208
+ .option("format", {
209
+ default: "table",
210
+ demand: false,
211
+ description: 'Output format to display your deployments with ("json" or "table")',
212
+ type: "string",
213
+ })
214
+ .option("displayKeys", {
215
+ alias: "k",
216
+ default: false,
217
+ demand: false,
218
+ description: "Specifies whether to display the deployment keys",
219
+ type: "boolean",
220
+ });
221
+ addCommonConfiguration(yargs);
222
+ }
223
+ function deploymentRemove(commandName, yargs) {
224
+ isValidCommand = true;
225
+ yargs
226
+ .usage(USAGE_PREFIX + " deployment " + commandName + " <ownerName>/<appName> <deploymentName>")
227
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
228
+ .example("deployment " + commandName + " OrgName/MyApp MyDeployment", 'Removes deployment "MyDeployment" from app "MyApp"');
229
+ addCommonConfiguration(yargs);
230
+ }
231
+ function deploymentHistory(commandName, yargs) {
232
+ isValidCommand = true;
233
+ yargs
234
+ .usage(USAGE_PREFIX + " deployment " + commandName + " <ownerName>/<appName> <deploymentName> [options]")
235
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
236
+ .example("deployment " + commandName + " OrgName/MyApp MyDeployment", 'Displays the release history for deployment "MyDeployment" from app "MyApp" in tabular format')
237
+ .example("deployment " + commandName + " OrgName/MyApp MyDeployment --format json", 'Displays the release history for deployment "MyDeployment" from app "MyApp" in JSON format')
238
+ .option("format", {
239
+ default: "table",
240
+ demand: false,
241
+ description: 'Output format to display the release history with ("json" or "table")',
242
+ type: "string",
243
+ })
244
+ .option("displayAuthor", {
245
+ alias: "a",
246
+ default: false,
247
+ demand: false,
248
+ description: "Specifies whether to display the release author",
249
+ type: "boolean",
250
+ });
251
+ addCommonConfiguration(yargs);
252
+ }
253
+ yargs
254
+ .usage(USAGE_PREFIX + " <command>")
255
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option argument.
256
+ .command("access-key", "View and manage the access keys associated with your account", (yargs) => {
257
+ isValidCommandCategory = true;
258
+ yargs
259
+ .usage(USAGE_PREFIX + " access-key <command>")
260
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
261
+ .command("add", "Create a new access key associated with your account", (yargs) => accessKeyAdd("add", yargs))
262
+ .command("patch", "Update the name and/or TTL of an existing access key", (yargs) => accessKeyPatch("patch", yargs))
263
+ .command("remove", "Remove an existing access key", (yargs) => accessKeyRemove("remove", yargs))
264
+ .command("rm", "Remove an existing access key", (yargs) => accessKeyRemove("rm", yargs))
265
+ .command("list", "List the access keys associated with your account", (yargs) => accessKeyList("list", yargs))
266
+ .command("ls", "List the access keys associated with your account", (yargs) => accessKeyList("ls", yargs))
267
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
268
+ addCommonConfiguration(yargs);
269
+ })
270
+ .command("org", "View and manage the organisations associated with your account", (yargs) => {
271
+ isValidCommandCategory = true;
272
+ yargs
273
+ .usage(USAGE_PREFIX + " org <command>")
274
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
275
+ .command("remove", "Remove an existing organisation", (yargs) => accessKeyRemove("remove", yargs))
276
+ .command("rm", "Remove an existing organisation", (yargs) => accessKeyRemove("rm", yargs))
277
+ .command("list", "List the organisations associated with your account", (yargs) => orgList("list", yargs))
278
+ .command("ls", "List the organisations associated with your account", (yargs) => orgList("ls", yargs))
279
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
280
+ addCommonConfiguration(yargs);
281
+ })
282
+ .command("app", "View and manage your CodePush apps", (yargs) => {
283
+ isValidCommandCategory = true;
284
+ yargs
285
+ .usage(USAGE_PREFIX + " app <command>")
286
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
287
+ .command("add", "Add a new app to your account", (yargs) => {
288
+ isValidCommand = true;
289
+ yargs
290
+ .usage(USAGE_PREFIX + " app add <ownerName>/<appName>")
291
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
292
+ .example("app add OrgName/MyApp", 'Adds app "MyApp"');
293
+ addCommonConfiguration(yargs);
294
+ })
295
+ .command("remove", "Remove an app from your account", (yargs) => appRemove("remove", yargs))
296
+ .command("rm", "Remove an app from your account", (yargs) => appRemove("rm", yargs))
297
+ .command("rename", "Rename an existing app", (yargs) => {
298
+ isValidCommand = true;
299
+ yargs
300
+ .usage(USAGE_PREFIX + " app rename <currentAppName> <newAppName>")
301
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
302
+ .example("app rename CurrentName NewName", 'Renames app "CurrentName" to "NewName"');
303
+ addCommonConfiguration(yargs);
304
+ })
305
+ .command("list", "Lists the apps associated with your/passed org account", (yargs) => appList("list", yargs))
306
+ .command("ls", "Lists the apps associated with your/passed org account", (yargs) => appList("ls", yargs))
307
+ .command("transfer", "Transfer the ownership of an app to another account", (yargs) => {
308
+ isValidCommand = true;
309
+ yargs
310
+ .usage(USAGE_PREFIX + " app transfer <ownerName>/<appName> <email>")
311
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
312
+ .example("app transfer MyApp foo@bar.com", 'Transfers the ownership of app "MyApp" to an account with email "foo@bar.com"');
313
+ addCommonConfiguration(yargs);
314
+ })
315
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
316
+ addCommonConfiguration(yargs);
317
+ })
318
+ .command("collaborator", "View and manage app collaborators", (yargs) => {
319
+ isValidCommandCategory = true;
320
+ yargs
321
+ .usage(USAGE_PREFIX + " collaborator <command>")
322
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
323
+ .command("add", "Add a new collaborator to an app", (yargs) => {
324
+ isValidCommand = true;
325
+ yargs
326
+ .usage(USAGE_PREFIX + " collaborator add <ownerName>/<appName> <email>")
327
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
328
+ .example("collaborator add MyApp foo@bar.com", 'Adds foo@bar.com as a collaborator to app "MyApp"');
329
+ addCommonConfiguration(yargs);
330
+ })
331
+ .command("remove", "Remove a collaborator from an app", (yargs) => removeCollaborator("remove", yargs))
332
+ .command("rm", "Remove a collaborator from an app", (yargs) => removeCollaborator("rm", yargs))
333
+ .command("list", "List the collaborators for an app", (yargs) => listCollaborators("list", yargs))
334
+ .command("ls", "List the collaborators for an app", (yargs) => listCollaborators("ls", yargs))
335
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
336
+ addCommonConfiguration(yargs);
337
+ })
338
+ .command("debug", "View the CodePush debug logs for a running app", (yargs) => {
339
+ isValidCommandCategory = true;
340
+ isValidCommand = true;
341
+ yargs
342
+ .usage(USAGE_PREFIX + " debug <platform>")
343
+ .demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option arguments
344
+ .example("debug android", "View the CodePush debug logs for an Android emulator or device")
345
+ .example("debug ios", "View the CodePush debug logs for the iOS simulator");
346
+ addCommonConfiguration(yargs);
347
+ })
348
+ .command("deployment", "View and manage your app deployments", (yargs) => {
349
+ isValidCommandCategory = true;
350
+ yargs
351
+ .usage(USAGE_PREFIX + " deployment <command>")
352
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
353
+ .command("add", "Add a new deployment to an app", (yargs) => {
354
+ isValidCommand = true;
355
+ yargs
356
+ .usage(USAGE_PREFIX + " deployment add <ownerName>/<appName> <deploymentName>")
357
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
358
+ .example("deployment add OrgName/MyApp MyDeployment", 'Adds deployment "MyDeployment" to app "MyApp"')
359
+ .example("deployment add MyApp MyDeployment", 'Adds deployment "MyDeployment" to app "MyApp"')
360
+ .example("deployment add MyApp MyDeployment -k abc123", 'Adds deployment key "abc123"')
361
+ .option("key", {
362
+ alias: "k",
363
+ demand: false,
364
+ description: "Specify deployment key",
365
+ type: "string",
366
+ });
367
+ addCommonConfiguration(yargs);
368
+ })
369
+ .command("clear", "Clear the release history associated with a deployment", (yargs) => deploymentHistoryClear("clear", yargs))
370
+ .command("remove", "Remove a deployment from an app", (yargs) => deploymentRemove("remove", yargs))
371
+ .command("rm", "Remove a deployment from an app", (yargs) => deploymentRemove("rm", yargs))
372
+ .command("rename", "Rename an existing deployment", (yargs) => {
373
+ isValidCommand = true;
374
+ yargs
375
+ .usage(USAGE_PREFIX + " deployment rename <ownerName>/<appName> <currentDeploymentName> <newDeploymentName>")
376
+ .demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments
377
+ .example("deployment rename OrgName/MyApp CurrentDeploymentName NewDeploymentName", 'Renames deployment "CurrentDeploymentName" to "NewDeploymentName"');
378
+ addCommonConfiguration(yargs);
379
+ })
380
+ .command("list", "List the deployments associated with an app", (yargs) => deploymentList("list", yargs))
381
+ .command("ls", "List the deployments associated with an app", (yargs) => deploymentList("ls", yargs))
382
+ .command("history", "Display the release history for a deployment", (yargs) => deploymentHistory("history", yargs))
383
+ .command("h", "Display the release history for a deployment", (yargs) => deploymentHistory("h", yargs))
384
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
385
+ addCommonConfiguration(yargs);
386
+ })
387
+ .command("link", "Link an additional authentication provider (e.g. GitHub) to an existing CodePush account", (yargs) => {
388
+ isValidCommandCategory = true;
389
+ isValidCommand = true;
390
+ yargs
391
+ .usage(USAGE_PREFIX + " link")
392
+ .demand(/*count*/ 0, /*max*/ 1) //set 'max' to one to allow usage of serverUrl undocument parameter for testing
393
+ .example("link", "Links an account on the CodePush server")
394
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
395
+ addCommonConfiguration(yargs);
396
+ })
397
+ .command("login", "Authenticate with the CodePush server in order to begin managing your apps", (yargs) => {
398
+ isValidCommandCategory = true;
399
+ isValidCommand = true;
400
+ yargs
401
+ .usage(USAGE_PREFIX + " login [options]")
402
+ .demand(/*count*/ 0, /*max*/ 1) //set 'max' to one to allow usage of serverUrl undocument parameter for testing
403
+ .example("login", "Logs in to the CodePush server")
404
+ .example("login --accessKey mykey", 'Logs in on behalf of the user who owns and created the access key "mykey"')
405
+ .option("accessKey", {
406
+ alias: "key",
407
+ default: null,
408
+ demand: false,
409
+ description: "Access key to authenticate against the CodePush server with, instead of providing your username and password credentials",
410
+ type: "string",
411
+ })
412
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
413
+ addCommonConfiguration(yargs);
414
+ })
415
+ .command("logout", "Log out of the current session", (yargs) => {
416
+ isValidCommandCategory = true;
417
+ isValidCommand = true;
418
+ yargs
419
+ .usage(USAGE_PREFIX + " logout")
420
+ .demand(/*count*/ 0, /*max*/ 0)
421
+ .example("logout", "Logs out and ends your current session");
422
+ addCommonConfiguration(yargs);
423
+ })
424
+ .command("patch", "Update the metadata for an existing release", (yargs) => {
425
+ yargs
426
+ .usage(USAGE_PREFIX + " patch <ownerName>/<appName> <deploymentName> [options]")
427
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
428
+ .example('patch OrgName/MyApp Production --des "Updated description" -r 50%', 'Updates the description of the latest release for "MyApp" app\'s "Production" deployment and updates the rollout value to 50%')
429
+ .example('patch OrgName/MyApp Production -l v3 --des "Updated description for v3"', 'Updates the description of the release with label v3 for "MyApp" app\'s "Production" deployment')
430
+ .option("label", {
431
+ alias: "l",
432
+ default: null,
433
+ demand: false,
434
+ description: "Label of the release to update. Defaults to the latest release within the specified deployment",
435
+ type: "string",
436
+ })
437
+ .option("description", {
438
+ alias: "des",
439
+ default: null,
440
+ demand: false,
441
+ description: "Description of the changes made to the app with this release",
442
+ type: "string",
443
+ })
444
+ .option("disabled", {
445
+ alias: "x",
446
+ default: null,
447
+ demand: false,
448
+ description: "Specifies whether this release should be immediately downloadable",
449
+ type: "boolean",
450
+ })
451
+ .option("mandatory", {
452
+ alias: "m",
453
+ default: null,
454
+ demand: false,
455
+ description: "Specifies whether this release should be considered mandatory",
456
+ type: "boolean",
457
+ })
458
+ .option("rollout", {
459
+ alias: "r",
460
+ default: null,
461
+ demand: false,
462
+ description: "Percentage of users this release should be immediately available to. This attribute can only be increased from the current value.",
463
+ type: "string",
464
+ })
465
+ .option("targetBinaryVersion", {
466
+ alias: "t",
467
+ default: null,
468
+ demand: false,
469
+ description: "Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3).",
470
+ type: "string",
471
+ })
472
+ .check((argv, _aliases) => {
473
+ return isValidRollout(argv);
474
+ });
475
+ addCommonConfiguration(yargs);
476
+ })
477
+ .command("promote", "Promote the latest release from one app deployment to another", (yargs) => {
478
+ yargs
479
+ .usage(USAGE_PREFIX + " promote <ownerName>/<appName> <sourceDeploymentName> <destDeploymentName> [options]")
480
+ .demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments
481
+ .example("promote OrgName/MyApp Staging Production", 'Promotes the latest release within the "Staging" deployment of "MyApp" to "Production"')
482
+ .example('promote OrgName/MyApp Staging Production --des "Production rollout" -r 25', 'Promotes the latest release within the "Staging" deployment of "MyApp" to "Production", with an updated description, and targeting only 25% of the users')
483
+ .option("description", {
484
+ alias: "des",
485
+ default: null,
486
+ demand: false,
487
+ description: "Description of the changes made to the app with this release. If omitted, the description from the release being promoted will be used.",
488
+ type: "string",
489
+ })
490
+ .option("label", {
491
+ alias: "l",
492
+ default: null,
493
+ demand: false,
494
+ description: "Label of the source release that will be taken. If omitted, the latest release being promoted will be used.",
495
+ type: "string",
496
+ })
497
+ .option("disabled", {
498
+ alias: "x",
499
+ default: null,
500
+ demand: false,
501
+ description: "Specifies whether this release should be immediately downloadable. If omitted, the disabled attribute from the release being promoted will be used.",
502
+ type: "boolean",
503
+ })
504
+ .option("mandatory", {
505
+ alias: "m",
506
+ default: null,
507
+ demand: false,
508
+ description: "Specifies whether this release should be considered mandatory. If omitted, the mandatory property from the release being promoted will be used.",
509
+ type: "boolean",
510
+ })
511
+ .option("noDuplicateReleaseError", {
512
+ default: false,
513
+ demand: false,
514
+ description: "When this flag is set, promoting a package that is identical to the latest release on the target deployment will produce a warning instead of an error",
515
+ type: "boolean",
516
+ })
517
+ .option("rollout", {
518
+ alias: "r",
519
+ default: "100%",
520
+ demand: false,
521
+ description: "Percentage of users this update should be immediately available to",
522
+ type: "string",
523
+ })
524
+ .option("targetBinaryVersion", {
525
+ alias: "t",
526
+ default: null,
527
+ demand: false,
528
+ description: "Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3). If omitted, the target binary version property from the release being promoted will be used.",
529
+ type: "string",
530
+ })
531
+ .check((argv, _aliases) => {
532
+ return isValidRollout(argv);
533
+ });
534
+ addCommonConfiguration(yargs);
535
+ })
536
+ .command("register", "Register a new CodePush account", (yargs) => {
537
+ isValidCommandCategory = true;
538
+ isValidCommand = true;
539
+ yargs
540
+ .usage(USAGE_PREFIX + " register")
541
+ .demand(/*count*/ 0, /*max*/ 1) //set 'max' to one to allow usage of serverUrl undocument parameter for testing
542
+ .example("register", "Registers a new CodePush account")
543
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
544
+ addCommonConfiguration(yargs);
545
+ })
546
+ .command("release", "Release an update to an app deployment", (yargs) => {
547
+ yargs
548
+ .usage(USAGE_PREFIX + " release <ownerName>/<appName> <updateContentsPath> <targetBinaryVersion> [options]")
549
+ .demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments.
550
+ .example('release OrgName/MyApp app.js "*"', 'Releases the "app.js" file to the "MyApp" app\'s "Staging" deployment, targeting any binary version using the "*" wildcard range syntax.')
551
+ .example("release OrgName/MyApp ./platforms/ios/www 1.0.3 -d Production", 'Releases the "./platforms/ios/www" folder and all its contents to the "MyApp" app\'s "Production" deployment, targeting only the 1.0.3 binary version')
552
+ .example("release OrgName/MyApp ./platforms/ios/www 1.0.3 -d Production -r 20", 'Releases the "./platforms/ios/www" folder and all its contents to the "MyApp" app\'s "Production" deployment, targeting the 1.0.3 binary version and rolling out to about 20% of the users')
553
+ .option("deploymentName", {
554
+ alias: "d",
555
+ default: "Staging",
556
+ demand: false,
557
+ description: "Deployment to release the update to",
558
+ type: "string",
559
+ })
560
+ .option("description", {
561
+ alias: "des",
562
+ default: null,
563
+ demand: false,
564
+ description: "Description of the changes made to the app in this release",
565
+ type: "string",
566
+ })
567
+ .option("disabled", {
568
+ alias: "x",
569
+ default: false,
570
+ demand: false,
571
+ description: "Specifies whether this release should be immediately downloadable",
572
+ type: "boolean",
573
+ })
574
+ .option("mandatory", {
575
+ alias: "m",
576
+ default: false,
577
+ demand: false,
578
+ description: "Specifies whether this release should be considered mandatory",
579
+ type: "boolean",
580
+ })
581
+ .option("noDuplicateReleaseError", {
582
+ default: false,
583
+ demand: false,
584
+ description: "When this flag is set, releasing a package that is identical to the latest release will produce a warning instead of an error",
585
+ type: "boolean",
586
+ })
587
+ .option("rollout", {
588
+ alias: "r",
589
+ default: "100%",
590
+ demand: false,
591
+ description: "Percentage of users this release should be available to",
592
+ type: "string",
593
+ })
594
+ .option("isPatch", {
595
+ alias: "p",
596
+ demand: false,
597
+ default: false,
598
+ description: "Specify whether the update is a patch or full bundle. Default is false.",
599
+ type: "boolean"
600
+ })
601
+ .option("compression", {
602
+ alias: "c",
603
+ default: "deflate",
604
+ demand: false,
605
+ description: "Compression algorithm: 'deflate' (default) or 'brotli' (for better compression)",
606
+ type: "string",
607
+ })
608
+ .check((argv, _aliases) => {
609
+ return checkValidReleaseOptions(argv);
610
+ });
611
+ addCommonConfiguration(yargs);
612
+ })
613
+ .command("release-react", "Release a React Native update to an app deployment", (yargs) => {
614
+ yargs
615
+ .usage(USAGE_PREFIX + " release-react <ownerName>/<appName> <platform> [options]")
616
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
617
+ .example("release-react OrgName/MyApp ios", 'Releases the React Native iOS project in the current working directory to the "MyApp" app\'s "Staging" deployment')
618
+ .example("release-react OrgName/MyApp android -d Production", 'Releases the React Native Android project in the current working directory to the "MyApp" app\'s "Production" deployment')
619
+ .example("release-react OrgName/MyApp windows --dev", 'Releases the development bundle of the React Native Windows project in the current working directory to the "MyApp" app\'s "Staging" deployment')
620
+ .option("bundleName", {
621
+ alias: "b",
622
+ default: null,
623
+ demand: false,
624
+ description: 'Name of the generated JS bundle file. If unspecified, the standard bundle name will be used, depending on the specified platform: "main.jsbundle" (iOS), "index.android.bundle" (Android) or "index.windows.bundle" (Windows)',
625
+ type: "string",
626
+ })
627
+ .option("deploymentName", {
628
+ alias: "d",
629
+ default: "Staging",
630
+ demand: false,
631
+ description: "Deployment to release the update to",
632
+ type: "string",
633
+ })
634
+ .option("description", {
635
+ alias: "des",
636
+ default: null,
637
+ demand: false,
638
+ description: "Description of the changes made to the app with this release",
639
+ type: "string",
640
+ })
641
+ .option("development", {
642
+ alias: "dev",
643
+ default: false,
644
+ demand: false,
645
+ description: "Specifies whether to generate a dev or release build",
646
+ type: "boolean",
647
+ })
648
+ .option("disabled", {
649
+ alias: "x",
650
+ default: false,
651
+ demand: false,
652
+ description: "Specifies whether this release should be immediately downloadable",
653
+ type: "boolean",
654
+ })
655
+ .option("entryFile", {
656
+ alias: "e",
657
+ default: null,
658
+ demand: false,
659
+ description: 'Path to the app\'s entry Javascript file. If omitted, "index.<platform>.js" and then "index.js" will be used (if they exist)',
660
+ type: "string",
661
+ })
662
+ .option("gradleFile", {
663
+ alias: "g",
664
+ default: null,
665
+ demand: false,
666
+ description: "Path to the gradle file which specifies the binary version you want to target this release at (android only).",
667
+ })
668
+ .option("mandatory", {
669
+ alias: "m",
670
+ default: false,
671
+ demand: false,
672
+ description: "Specifies whether this release should be considered mandatory",
673
+ type: "boolean",
674
+ })
675
+ .option("noDuplicateReleaseError", {
676
+ default: false,
677
+ demand: false,
678
+ description: "When this flag is set, releasing a package that is identical to the latest release will produce a warning instead of an error",
679
+ type: "boolean",
680
+ })
681
+ .option("plistFile", {
682
+ alias: "p",
683
+ default: null,
684
+ demand: false,
685
+ description: "Path to the plist file which specifies the binary version you want to target this release at (iOS only).",
686
+ })
687
+ .option("plistFilePrefix", {
688
+ alias: "pre",
689
+ default: null,
690
+ demand: false,
691
+ description: "Prefix to append to the file name when attempting to find your app's Info.plist file (iOS only).",
692
+ })
693
+ .option("rollout", {
694
+ alias: "r",
695
+ default: "100%",
696
+ demand: false,
697
+ description: "Percentage of users this release should be immediately available to",
698
+ type: "string",
699
+ })
700
+ .option("sourcemapOutput", {
701
+ alias: "s",
702
+ default: null,
703
+ demand: false,
704
+ description: "Path to where the sourcemap for the resulting bundle should be written. If omitted, a sourcemap will not be generated.",
705
+ type: "string",
706
+ })
707
+ .option("targetBinaryVersion", {
708
+ alias: "t",
709
+ default: null,
710
+ demand: false,
711
+ description: 'Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3). If omitted, the release will target the exact version specified in the "Info.plist" (iOS), "build.gradle" (Android) or "Package.appxmanifest" (Windows) files.',
712
+ type: "string",
713
+ })
714
+ .option("outputDir", {
715
+ alias: "o",
716
+ default: null,
717
+ demand: false,
718
+ description: "Path to where the bundle and sourcemap should be written. If omitted, a bundle and sourcemap will not be written.",
719
+ type: "string",
720
+ })
721
+ .option("useHermes", {
722
+ alias: "h",
723
+ default: false,
724
+ demand: false,
725
+ description: "Enable hermes and bypass automatic checks",
726
+ type: "boolean",
727
+ })
728
+ .option("podFile", {
729
+ alias: "pod",
730
+ default: null,
731
+ demand: false,
732
+ description: "Path to the cocopods config file (iOS only).",
733
+ type: "string",
734
+ })
735
+ .option("extraHermesFlags", {
736
+ alias: "hf",
737
+ default: [],
738
+ demand: false,
739
+ description: "Flags that get passed to Hermes, JavaScript to bytecode compiler. Can be specified multiple times.",
740
+ type: "array",
741
+ })
742
+ .option("privateKeyPath", {
743
+ alias: "k",
744
+ default: null,
745
+ demand: false,
746
+ description: "Path to private key used for code signing.",
747
+ type: "string",
748
+ })
749
+ .option("xcodeProjectFile", {
750
+ alias: "xp",
751
+ default: null,
752
+ demand: false,
753
+ description: "Path to the Xcode project or project.pbxproj file",
754
+ type: "string",
755
+ })
756
+ .option("xcodeTargetName", {
757
+ alias: "xt",
758
+ default: undefined,
759
+ demand: false,
760
+ description: "Name of target (PBXNativeTarget) which specifies the binary version you want to target this release at (iOS only)",
761
+ type: "string",
762
+ })
763
+ .option("buildConfigurationName", {
764
+ alias: "c",
765
+ default: undefined,
766
+ demand: false,
767
+ description: "Name of build configuration which specifies the binary version you want to target this release at. For example, 'Debug' or 'Release' (iOS only)",
768
+ type: "string",
769
+ })
770
+ .check((argv, _aliases) => {
771
+ return checkValidReleaseOptions(argv);
772
+ });
773
+ addCommonConfiguration(yargs);
774
+ })
775
+ .command("rollback", "Rollback the latest release for an app deployment", (yargs) => {
776
+ yargs
777
+ .usage(USAGE_PREFIX + " rollback <ownerName>/<appName> <deploymentName> [options]")
778
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments
779
+ .example("rollback MyApp Production", 'Performs a rollback on the "Production" deployment of "MyApp"')
780
+ .example("rollback MyApp Production --targetRelease v4", 'Performs a rollback on the "Production" deployment of "MyApp" to the v4 release')
781
+ .option("targetRelease", {
782
+ alias: "r",
783
+ default: null,
784
+ demand: false,
785
+ description: "Label of the release to roll the specified deployment back to (e.g. v4). If omitted, the deployment will roll back to the previous release.",
786
+ type: "string",
787
+ });
788
+ addCommonConfiguration(yargs);
789
+ })
790
+ .command("session", "View and manage the current login sessions associated with your account", (yargs) => {
791
+ isValidCommandCategory = true;
792
+ yargs
793
+ .usage(USAGE_PREFIX + " session <command>")
794
+ .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
795
+ .command("remove", "Remove an existing login session", (yargs) => sessionRemove("remove", yargs))
796
+ .command("rm", "Remove an existing login session", (yargs) => sessionRemove("rm", yargs))
797
+ .command("list", "List the current login sessions associated with your account", (yargs) => sessionList("list", yargs))
798
+ .command("ls", "List the current login sessions associated with your account", (yargs) => sessionList("ls", yargs))
799
+ .check((_argv, _aliases) => isValidCommand); // Report unrecognized, non-hyphenated command category.
800
+ addCommonConfiguration(yargs);
801
+ })
802
+ .command("create-patch", "Create a patch file between two files", (yargs) => {
803
+ isValidCommandCategory = true;
804
+ isValidCommand = true;
805
+ yargs
806
+ .usage(USAGE_PREFIX + " create-patch path/to/oldfile path/to/newfile directory/to/save/bundle.patch")
807
+ .demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments
808
+ .example("create-patch .old/index.android.bundle .new/index.android.bundle ./patch-dir", "Create a bundle.patch file using .old/index.android.bundle and .new/index.android.bundle and save it as ./patch-dir/bundle.patch");
809
+ addCommonConfiguration(yargs);
810
+ })
811
+ .command("apply-patch", "Apply a patch to a file", (yargs) => {
812
+ isValidCommandCategory = true;
813
+ isValidCommand = true;
814
+ yargs
815
+ .usage(USAGE_PREFIX + " apply-patch path/to/oldfile path/to/bundle.patch path/to/newfile")
816
+ .demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments
817
+ .example("apply-patch .old/index.android.bundle ./patch-dir/bundle.patch .new/index.android.bundle", "Apply bundle.patch to .old/index.android.bundle and save the result as .new/index.android.bundle");
818
+ addCommonConfiguration(yargs);
819
+ })
820
+ .command("whoami", "Display the account info for the current login session", (yargs) => {
821
+ isValidCommandCategory = true;
822
+ isValidCommand = true;
823
+ yargs
824
+ .usage(USAGE_PREFIX + " whoami")
825
+ .demand(/*count*/ 0, /*max*/ 0)
826
+ .example("whoami", "Display the account info for the current login session");
827
+ addCommonConfiguration(yargs);
828
+ })
829
+ .alias("v", "version")
830
+ .version(packageJson.version)
831
+ .wrap(/*columnLimit*/ null)
832
+ .fail((_msg) => showHelp(/*showRootDescription*/ true)).argv; // Suppress the default error message.
833
+ function createCommand() {
834
+ let cmd;
835
+ const argv = yargs.parseSync();
836
+ //console.log(argv);
837
+ if (!wasHelpShown && argv._ && argv._.length > 0) {
838
+ // Create a command object
839
+ const arg0 = argv._[0];
840
+ const arg1 = argv._[1];
841
+ const arg2 = argv._[2];
842
+ const arg3 = argv._[3];
843
+ const arg4 = argv._[4];
844
+ switch (arg0) {
845
+ case "access-key":
846
+ switch (arg1) {
847
+ case "add":
848
+ if (arg2) {
849
+ cmd = { type: cli.CommandType.accessKeyAdd };
850
+ const accessKeyAddCmd = cmd;
851
+ accessKeyAddCmd.name = arg2;
852
+ const ttlOption = argv["ttl"];
853
+ if (isDefined(ttlOption)) {
854
+ accessKeyAddCmd.ttl = parseDurationMilliseconds(ttlOption);
855
+ }
856
+ }
857
+ break;
858
+ case "patch":
859
+ if (arg2) {
860
+ cmd = { type: cli.CommandType.accessKeyPatch };
861
+ const accessKeyPatchCmd = cmd;
862
+ accessKeyPatchCmd.oldName = arg2;
863
+ const newNameOption = argv["name"];
864
+ const ttlOption = argv["ttl"];
865
+ if (isDefined(newNameOption)) {
866
+ accessKeyPatchCmd.newName = newNameOption;
867
+ }
868
+ if (isDefined(ttlOption)) {
869
+ accessKeyPatchCmd.ttl = parseDurationMilliseconds(ttlOption);
870
+ }
871
+ }
872
+ break;
873
+ case "list":
874
+ case "ls":
875
+ cmd = { type: cli.CommandType.accessKeyList };
876
+ cmd.format = argv["format"];
877
+ break;
878
+ case "remove":
879
+ case "rm":
880
+ if (arg2) {
881
+ cmd = { type: cli.CommandType.accessKeyRemove };
882
+ cmd.accessKey = arg2;
883
+ }
884
+ break;
885
+ }
886
+ break;
887
+ case "org":
888
+ switch (arg1) {
889
+ case "list":
890
+ case "ls":
891
+ cmd = { type: cli.CommandType.orgList };
892
+ cmd.format = argv["format"];
893
+ break;
894
+ case "remove":
895
+ case "rm":
896
+ if (arg2) {
897
+ cmd = { type: cli.CommandType.accessKeyRemove };
898
+ cmd.accessKey = arg2;
899
+ }
900
+ break;
901
+ }
902
+ break;
903
+ case "app":
904
+ switch (arg1) {
905
+ case "add":
906
+ if (arg2) {
907
+ cmd = { type: cli.CommandType.appAdd };
908
+ cmd.appName = arg2;
909
+ }
910
+ break;
911
+ case "list":
912
+ case "ls":
913
+ cmd = { type: cli.CommandType.appList };
914
+ cmd.org = argv["org"];
915
+ cmd.format = argv["format"];
916
+ break;
917
+ case "remove":
918
+ case "rm":
919
+ if (arg2) {
920
+ cmd = { type: cli.CommandType.appRemove };
921
+ cmd.appName = arg2;
922
+ }
923
+ break;
924
+ case "rename":
925
+ if (arg2 && arg3) {
926
+ cmd = { type: cli.CommandType.appRename };
927
+ const appRenameCommand = cmd;
928
+ appRenameCommand.currentAppName = arg2;
929
+ appRenameCommand.newAppName = arg3;
930
+ }
931
+ break;
932
+ case "transfer":
933
+ if (arg2 && arg3) {
934
+ cmd = { type: cli.CommandType.appTransfer };
935
+ const appTransferCommand = cmd;
936
+ appTransferCommand.appName = arg2;
937
+ appTransferCommand.email = arg3;
938
+ }
939
+ break;
940
+ }
941
+ break;
942
+ case "collaborator":
943
+ switch (arg1) {
944
+ case "add":
945
+ if (arg2 && arg3) {
946
+ cmd = { type: cli.CommandType.collaboratorAdd };
947
+ cmd.appName = arg2;
948
+ cmd.email = arg3;
949
+ }
950
+ break;
951
+ case "list":
952
+ case "ls":
953
+ if (arg2) {
954
+ cmd = { type: cli.CommandType.collaboratorList };
955
+ cmd.appName = arg2;
956
+ cmd.format = argv["format"];
957
+ }
958
+ break;
959
+ case "remove":
960
+ case "rm":
961
+ if (arg2 && arg3) {
962
+ cmd = { type: cli.CommandType.collaboratorRemove };
963
+ cmd.appName = arg2;
964
+ cmd.email = arg3;
965
+ }
966
+ break;
967
+ }
968
+ break;
969
+ case "debug":
970
+ cmd = {
971
+ type: cli.CommandType.debug,
972
+ platform: arg1,
973
+ };
974
+ break;
975
+ case "deployment":
976
+ switch (arg1) {
977
+ case "add":
978
+ if (arg2 && arg3) {
979
+ cmd = { type: cli.CommandType.deploymentAdd };
980
+ const deploymentAddCommand = cmd;
981
+ deploymentAddCommand.appName = arg2;
982
+ deploymentAddCommand.deploymentName = arg3;
983
+ if (argv["key"]) {
984
+ deploymentAddCommand.key = argv["key"];
985
+ }
986
+ }
987
+ break;
988
+ case "clear":
989
+ if (arg2 && arg3) {
990
+ cmd = { type: cli.CommandType.deploymentHistoryClear };
991
+ const deploymentHistoryClearCommand = cmd;
992
+ deploymentHistoryClearCommand.appName = arg2;
993
+ deploymentHistoryClearCommand.deploymentName = arg3;
994
+ }
995
+ break;
996
+ case "list":
997
+ case "ls":
998
+ if (arg2) {
999
+ cmd = { type: cli.CommandType.deploymentList };
1000
+ const deploymentListCommand = cmd;
1001
+ deploymentListCommand.appName = arg2;
1002
+ deploymentListCommand.format = argv["format"];
1003
+ deploymentListCommand.displayKeys = argv["displayKeys"];
1004
+ }
1005
+ break;
1006
+ case "remove":
1007
+ case "rm":
1008
+ if (arg2 && arg3) {
1009
+ cmd = { type: cli.CommandType.deploymentRemove };
1010
+ const deploymentRemoveCommand = cmd;
1011
+ deploymentRemoveCommand.appName = arg2;
1012
+ deploymentRemoveCommand.deploymentName = arg3;
1013
+ }
1014
+ break;
1015
+ case "rename":
1016
+ if (arg2 && arg3 && arg4) {
1017
+ cmd = { type: cli.CommandType.deploymentRename };
1018
+ const deploymentRenameCommand = cmd;
1019
+ deploymentRenameCommand.appName = arg2;
1020
+ deploymentRenameCommand.currentDeploymentName = arg3;
1021
+ deploymentRenameCommand.newDeploymentName = arg4;
1022
+ }
1023
+ break;
1024
+ case "history":
1025
+ case "h":
1026
+ if (arg2 && arg3) {
1027
+ cmd = { type: cli.CommandType.deploymentHistory };
1028
+ const deploymentHistoryCommand = cmd;
1029
+ deploymentHistoryCommand.appName = arg2;
1030
+ deploymentHistoryCommand.deploymentName = arg3;
1031
+ deploymentHistoryCommand.format = argv["format"];
1032
+ deploymentHistoryCommand.displayAuthor = argv["displayAuthor"];
1033
+ }
1034
+ break;
1035
+ }
1036
+ break;
1037
+ case "link":
1038
+ cmd = {
1039
+ type: cli.CommandType.link,
1040
+ serverUrl: getServerUrl(arg1),
1041
+ };
1042
+ break;
1043
+ case "login":
1044
+ cmd = { type: cli.CommandType.login };
1045
+ const loginCommand = cmd;
1046
+ loginCommand.serverUrl = getServerUrl(arg1);
1047
+ loginCommand.accessKey = argv["accessKey"];
1048
+ break;
1049
+ case "logout":
1050
+ cmd = { type: cli.CommandType.logout };
1051
+ break;
1052
+ case "patch":
1053
+ if (arg1 && arg2) {
1054
+ cmd = { type: cli.CommandType.patch };
1055
+ const patchCommand = cmd;
1056
+ patchCommand.appName = arg1;
1057
+ patchCommand.deploymentName = arg2;
1058
+ patchCommand.label = argv["label"];
1059
+ // Description must be set to null to indicate that it is not being patched.
1060
+ patchCommand.description = argv["description"] ? backslash(argv["description"]) : null;
1061
+ patchCommand.disabled = argv["disabled"];
1062
+ patchCommand.mandatory = argv["mandatory"];
1063
+ patchCommand.rollout = getRolloutValue(argv["rollout"]);
1064
+ patchCommand.appStoreVersion = argv["targetBinaryVersion"];
1065
+ }
1066
+ break;
1067
+ case "promote":
1068
+ if (arg1 && arg2 && arg3) {
1069
+ cmd = { type: cli.CommandType.promote };
1070
+ const deploymentPromoteCommand = cmd;
1071
+ deploymentPromoteCommand.appName = arg1;
1072
+ deploymentPromoteCommand.sourceDeploymentName = arg2;
1073
+ deploymentPromoteCommand.destDeploymentName = arg3;
1074
+ deploymentPromoteCommand.description = argv["description"] ? backslash(argv["description"]) : "";
1075
+ deploymentPromoteCommand.label = argv["label"];
1076
+ deploymentPromoteCommand.disabled = argv["disabled"];
1077
+ deploymentPromoteCommand.mandatory = argv["mandatory"];
1078
+ deploymentPromoteCommand.noDuplicateReleaseError = argv["noDuplicateReleaseError"];
1079
+ deploymentPromoteCommand.rollout = getRolloutValue(argv["rollout"]);
1080
+ deploymentPromoteCommand.appStoreVersion = argv["targetBinaryVersion"];
1081
+ }
1082
+ break;
1083
+ case "register":
1084
+ cmd = { type: cli.CommandType.register };
1085
+ const registerCommand = cmd;
1086
+ registerCommand.serverUrl = getServerUrl(arg1);
1087
+ break;
1088
+ case "release":
1089
+ //console.log('arg0, arg1, arg2, arg3', arg0, arg1, arg2, arg3);
1090
+ if (arg1 && arg2 && arg3) {
1091
+ //console.log('arg0, arg1, arg2, arg3', arg0, arg1, arg2, arg3);
1092
+ cmd = { type: cli.CommandType.release };
1093
+ const releaseCommand = cmd;
1094
+ releaseCommand.appName = arg1;
1095
+ releaseCommand.package = arg2;
1096
+ releaseCommand.appStoreVersion = arg3;
1097
+ releaseCommand.deploymentName = argv["deploymentName"];
1098
+ releaseCommand.description = argv["description"] ? backslash(argv["description"]) : "";
1099
+ releaseCommand.disabled = argv["disabled"];
1100
+ releaseCommand.mandatory = argv["mandatory"];
1101
+ releaseCommand.noDuplicateReleaseError = argv["noDuplicateReleaseError"];
1102
+ releaseCommand.rollout = getRolloutValue(argv["rollout"]);
1103
+ releaseCommand.compression = argv["compression"];
1104
+ releaseCommand.isPatch = argv["isPatch"];
1105
+ }
1106
+ break;
1107
+ case "release-react":
1108
+ if (arg1 && arg2) {
1109
+ cmd = { type: cli.CommandType.releaseReact };
1110
+ const releaseReactCommand = cmd;
1111
+ releaseReactCommand.appName = arg1;
1112
+ releaseReactCommand.platform = arg2;
1113
+ releaseReactCommand.appStoreVersion = argv["targetBinaryVersion"];
1114
+ releaseReactCommand.bundleName = argv["bundleName"];
1115
+ releaseReactCommand.deploymentName = argv["deploymentName"];
1116
+ releaseReactCommand.disabled = argv["disabled"];
1117
+ releaseReactCommand.description = argv["description"] ? backslash(argv["description"]) : "";
1118
+ releaseReactCommand.development = argv["development"];
1119
+ releaseReactCommand.entryFile = argv["entryFile"];
1120
+ releaseReactCommand.gradleFile = argv["gradleFile"];
1121
+ releaseReactCommand.mandatory = argv["mandatory"];
1122
+ releaseReactCommand.noDuplicateReleaseError = argv["noDuplicateReleaseError"];
1123
+ releaseReactCommand.plistFile = argv["plistFile"];
1124
+ releaseReactCommand.plistFilePrefix = argv["plistFilePrefix"];
1125
+ releaseReactCommand.rollout = getRolloutValue(argv["rollout"]);
1126
+ releaseReactCommand.sourcemapOutput = argv["sourcemapOutput"];
1127
+ releaseReactCommand.outputDir = argv["outputDir"];
1128
+ releaseReactCommand.useHermes = argv["useHermes"];
1129
+ releaseReactCommand.extraHermesFlags = argv["extraHermesFlags"];
1130
+ releaseReactCommand.podFile = argv["podFile"];
1131
+ releaseReactCommand.privateKeyPath = argv["privateKeyPath"];
1132
+ releaseReactCommand.xcodeProjectFile = argv["xcodeProjectFile"];
1133
+ releaseReactCommand.xcodeTargetName = argv["xcodeTargetName"];
1134
+ releaseReactCommand.buildConfigurationName = argv["buildConfigurationName"];
1135
+ }
1136
+ break;
1137
+ case "rollback":
1138
+ if (arg1 && arg2) {
1139
+ cmd = { type: cli.CommandType.rollback };
1140
+ const rollbackCommand = cmd;
1141
+ rollbackCommand.appName = arg1;
1142
+ rollbackCommand.deploymentName = arg2;
1143
+ rollbackCommand.targetRelease = argv["targetRelease"];
1144
+ }
1145
+ break;
1146
+ case "session":
1147
+ switch (arg1) {
1148
+ case "list":
1149
+ case "ls":
1150
+ cmd = { type: cli.CommandType.sessionList };
1151
+ cmd.format = argv["format"];
1152
+ break;
1153
+ case "remove":
1154
+ case "rm":
1155
+ if (arg2) {
1156
+ cmd = { type: cli.CommandType.sessionRemove };
1157
+ cmd.machineName = arg2;
1158
+ }
1159
+ break;
1160
+ }
1161
+ break;
1162
+ case "whoami":
1163
+ cmd = { type: cli.CommandType.whoami };
1164
+ break;
1165
+ case "create-patch":
1166
+ if (arg1 && arg2 && arg3) {
1167
+ cmd = { type: cli.CommandType.createPatch };
1168
+ const createPatchCommand = cmd;
1169
+ createPatchCommand.oldBundle = arg1;
1170
+ createPatchCommand.newBundle = arg2;
1171
+ createPatchCommand.patchFile = arg3;
1172
+ }
1173
+ break;
1174
+ case "apply-patch":
1175
+ if (arg1 && arg2 && arg3) {
1176
+ cmd = { type: cli.CommandType.applyPatch };
1177
+ const applyPatchCommand = cmd;
1178
+ applyPatchCommand.oldBundle = arg1;
1179
+ applyPatchCommand.patchFile = arg2;
1180
+ applyPatchCommand.outputBundle = arg3;
1181
+ }
1182
+ break;
1183
+ }
1184
+ return cmd;
1185
+ }
1186
+ }
1187
+ exports.createCommand = createCommand;
1188
+ function isValidRollout(args) {
1189
+ const rollout = args["rollout"];
1190
+ if (rollout && !ROLLOUT_PERCENTAGE_REGEX.test(rollout)) {
1191
+ return false;
1192
+ }
1193
+ return true;
1194
+ }
1195
+ function isValidCompression(args) {
1196
+ const compression = args["compression"];
1197
+ if (compression !== 'brotli' && compression !== 'deflate') {
1198
+ console.log('Invalid compression mode: ', compression + '. Provide a valid compression mode: brotli or deflate');
1199
+ return false;
1200
+ }
1201
+ return true;
1202
+ }
1203
+ function checkValidReleaseOptions(args) {
1204
+ return isValidRollout(args) && !!args["deploymentName"] && isValidCompression(args);
1205
+ }
1206
+ function getRolloutValue(input) {
1207
+ return input ? parseInt(input.replace("%", "")) : null;
1208
+ }
1209
+ function getServerUrl(url) {
1210
+ if (!url)
1211
+ return null;
1212
+ // Trim whitespace and a trailing slash (/) character.
1213
+ url = url.trim();
1214
+ if (url[url.length - 1] === "/") {
1215
+ url = url.substring(0, url.length - 1);
1216
+ }
1217
+ url = url.replace(/^(https?):\\/, "$1://"); // Replace 'http(s):\' with 'http(s)://' for Windows Git Bash
1218
+ return url;
1219
+ }
1220
+ function isDefined(object) {
1221
+ return object !== undefined && object !== null;
1222
+ }
1223
+ function parseDurationMilliseconds(durationString) {
1224
+ return Math.floor(parseDuration(durationString));
1225
+ }