@appcircle/codepush-cli 0.0.2 → 0.0.3

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/bin/test/cli.js CHANGED
@@ -256,138 +256,6 @@ describe("CLI", () => {
256
256
  afterEach(() => {
257
257
  sandbox.restore();
258
258
  });
259
- it("accessKeyAdd creates access key with name and default ttl", (done) => {
260
- var command = {
261
- type: cli.CommandType.accessKeyAdd,
262
- name: "Test name",
263
- };
264
- cmdexec.execute(command).done(() => {
265
- sinon.assert.calledTwice(log);
266
- assert.equal(log.args[0].length, 1);
267
- var actual = log.args[0][0];
268
- var expected = `Successfully created the "Test name" access key: key123`;
269
- assert.equal(actual, expected);
270
- actual = log.args[1][0];
271
- expected = "Make sure to save this key value somewhere safe, since you won't be able to view it from the CLI again!";
272
- assert.equal(actual, expected);
273
- done();
274
- });
275
- });
276
- it("accessKeyAdd creates access key with name and specified ttl", (done) => {
277
- var ttl = 10000;
278
- var command = {
279
- type: cli.CommandType.accessKeyAdd,
280
- name: "Test name",
281
- ttl,
282
- };
283
- cmdexec.execute(command).done(() => {
284
- sinon.assert.calledTwice(log);
285
- assert.equal(log.args[0].length, 1);
286
- var actual = log.args[0][0];
287
- var expected = `Successfully created the "Test name" access key: key123`;
288
- assert.equal(actual, expected);
289
- actual = log.args[1][0];
290
- expected = "Make sure to save this key value somewhere safe, since you won't be able to view it from the CLI again!";
291
- assert.equal(actual, expected);
292
- done();
293
- });
294
- });
295
- it("accessKeyPatch updates access key with new name", (done) => {
296
- var command = {
297
- type: cli.CommandType.accessKeyPatch,
298
- oldName: "Test name",
299
- newName: "Updated name",
300
- };
301
- cmdexec.execute(command).done(() => {
302
- sinon.assert.calledOnce(log);
303
- assert.equal(log.args[0].length, 1);
304
- var actual = log.args[0][0];
305
- var expected = `Successfully renamed the access key "Test name" to "Updated name".`;
306
- assert.equal(actual, expected);
307
- done();
308
- });
309
- });
310
- it("accessKeyPatch updates access key with new ttl", (done) => {
311
- var ttl = 10000;
312
- var command = {
313
- type: cli.CommandType.accessKeyPatch,
314
- oldName: "Test name",
315
- ttl,
316
- };
317
- cmdexec.execute(command).done(() => {
318
- sinon.assert.calledOnce(log);
319
- assert.equal(log.args[0].length, 1);
320
- var actual = log.args[0][0];
321
- var expected = `Successfully changed the expiration date of the "Test name" access key to Wednesday, August 17, 2016 12:07 PM.`;
322
- assert.equal(actual, expected);
323
- done();
324
- });
325
- });
326
- it("accessKeyPatch updates access key with new name and ttl", (done) => {
327
- var ttl = 10000;
328
- var command = {
329
- type: cli.CommandType.accessKeyPatch,
330
- oldName: "Test name",
331
- newName: "Updated name",
332
- ttl,
333
- };
334
- cmdexec.execute(command).done(() => {
335
- sinon.assert.calledOnce(log);
336
- assert.equal(log.args[0].length, 1);
337
- var actual = log.args[0][0];
338
- var expected = `Successfully renamed the access key "Test name" to "Updated name" and changed its expiration date to Wednesday, August 17, 2016 12:07 PM.`;
339
- assert.equal(actual, expected);
340
- done();
341
- });
342
- });
343
- it("accessKeyList lists access key name and expires fields", (done) => {
344
- var command = {
345
- type: cli.CommandType.accessKeyList,
346
- format: "json",
347
- };
348
- cmdexec.execute(command).done(() => {
349
- sinon.assert.calledOnce(log);
350
- assert.equal(log.args[0].length, 1);
351
- var actual = log.args[0][0];
352
- var expected = [
353
- {
354
- createdTime: 0,
355
- name: "Test name",
356
- expires: NOW + DEFAULT_ACCESS_KEY_MAX_AGE,
357
- },
358
- ];
359
- assertJsonDescribesObject(actual, expected);
360
- done();
361
- });
362
- });
363
- it("accessKeyRemove removes access key", (done) => {
364
- var command = {
365
- type: cli.CommandType.accessKeyRemove,
366
- accessKey: "8",
367
- };
368
- var removeAccessKey = sandbox.spy(cmdexec.sdk, "removeAccessKey");
369
- cmdexec.execute(command).done(() => {
370
- sinon.assert.calledOnce(removeAccessKey);
371
- sinon.assert.calledWithExactly(removeAccessKey, "8");
372
- sinon.assert.calledOnce(log);
373
- sinon.assert.calledWithExactly(log, 'Successfully removed the "8" access key.');
374
- done();
375
- });
376
- });
377
- it("accessKeyRemove does not remove access key if cancelled", (done) => {
378
- var command = {
379
- type: cli.CommandType.accessKeyRemove,
380
- accessKey: "8",
381
- };
382
- var removeAccessKey = sandbox.spy(cmdexec.sdk, "removeAccessKey");
383
- wasConfirmed = false;
384
- cmdexec.execute(command).done(() => {
385
- sinon.assert.notCalled(removeAccessKey);
386
- sinon.assert.calledOnce(log);
387
- sinon.assert.calledWithExactly(log, "Access key removal cancelled.");
388
- done();
389
- });
390
- });
391
259
  it("appAdd reports new app name and ID", (done) => {
392
260
  var command = {
393
261
  type: cli.CommandType.appAdd,
@@ -1202,72 +1070,6 @@ describe("CLI", () => {
1202
1070
  })
1203
1071
  .done();
1204
1072
  });
1205
- it("sessionList lists session name and expires fields", (done) => {
1206
- var command = {
1207
- type: cli.CommandType.sessionList,
1208
- format: "json",
1209
- };
1210
- cmdexec.execute(command).done(() => {
1211
- sinon.assert.calledOnce(log);
1212
- assert.equal(log.args[0].length, 1);
1213
- var actual = log.args[0][0];
1214
- var expected = [
1215
- {
1216
- loggedInTime: 0,
1217
- machineName: TEST_MACHINE_NAME,
1218
- },
1219
- ];
1220
- assertJsonDescribesObject(actual, expected);
1221
- done();
1222
- });
1223
- });
1224
- it("sessionRemove removes session", (done) => {
1225
- var machineName = TEST_MACHINE_NAME;
1226
- var command = {
1227
- type: cli.CommandType.sessionRemove,
1228
- machineName: machineName,
1229
- };
1230
- var removeSession = sandbox.spy(cmdexec.sdk, "removeSession");
1231
- cmdexec.execute(command).done(() => {
1232
- sinon.assert.calledOnce(removeSession);
1233
- sinon.assert.calledWithExactly(removeSession, machineName);
1234
- sinon.assert.calledOnce(log);
1235
- sinon.assert.calledWithExactly(log, `Successfully removed the login session for "${machineName}".`);
1236
- done();
1237
- });
1238
- });
1239
- it("sessionRemove does not remove session if cancelled", (done) => {
1240
- var machineName = TEST_MACHINE_NAME;
1241
- var command = {
1242
- type: cli.CommandType.sessionRemove,
1243
- machineName: machineName,
1244
- };
1245
- var removeSession = sandbox.spy(cmdexec.sdk, "removeSession");
1246
- wasConfirmed = false;
1247
- cmdexec.execute(command).done(() => {
1248
- sinon.assert.notCalled(removeSession);
1249
- sinon.assert.calledOnce(log);
1250
- sinon.assert.calledWithExactly(log, "Session removal cancelled.");
1251
- done();
1252
- });
1253
- });
1254
- it("sessionRemove does not remove current session", (done) => {
1255
- var machineName = os.hostname();
1256
- var command = {
1257
- type: cli.CommandType.sessionRemove,
1258
- machineName: machineName,
1259
- };
1260
- wasConfirmed = false;
1261
- cmdexec
1262
- .execute(command)
1263
- .then(() => {
1264
- done(new Error("Did not throw error."));
1265
- })
1266
- .catch(() => {
1267
- done();
1268
- })
1269
- .done();
1270
- });
1271
1073
  function releaseHelperFunction(command, done, expectedError) {
1272
1074
  cmdexec.execute(command).done(() => {
1273
1075
  throw "Error Expected";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcircle/codepush-cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Management CLI for the CodePush service",
5
5
  "main": "./script/cli.js",
6
6
  "scripts": {
@@ -49,6 +49,7 @@ import {
49
49
  isBinaryOrZip,
50
50
  fileExists
51
51
  } from "./utils/file-utils";
52
+ import { DeploymentKey } from "./types/rest-definitions";
52
53
 
53
54
  const configFilePath: string = path.join(process.env.LOCALAPPDATA || process.env.HOME, ".code-push.config");
54
55
  const emailValidator = require("email-validator");
@@ -121,60 +122,6 @@ export const confirm = (message: string = "Are you sure?"): Promise<boolean> =>
121
122
  });
122
123
  };
123
124
 
124
- function accessKeyAdd(command: cli.IAccessKeyAddCommand): Promise<void> {
125
- return sdk.addAccessKey(command.name, command.ttl).then((accessKey: AccessKey) => {
126
- log(`Successfully created the "${command.name}" access key: ${accessKey.key}`);
127
- log("Make sure to save this key value somewhere safe, since you won't be able to view it from the CLI again!");
128
- });
129
- }
130
-
131
- function accessKeyPatch(command: cli.IAccessKeyPatchCommand): Promise<void> {
132
- const willUpdateName: boolean = isCommandOptionSpecified(command.newName) && command.oldName !== command.newName;
133
- const willUpdateTtl: boolean = isCommandOptionSpecified(command.ttl);
134
-
135
- if (!willUpdateName && !willUpdateTtl) {
136
- throw new Error("A new name and/or TTL must be provided.");
137
- }
138
-
139
- return sdk.patchAccessKey(command.oldName, command.newName, command.ttl).then((accessKey: AccessKey) => {
140
- let logMessage: string = "Successfully ";
141
- if (willUpdateName) {
142
- logMessage += `renamed the access key "${command.oldName}" to "${command.newName}"`;
143
- }
144
-
145
- if (willUpdateTtl) {
146
- const expirationDate = moment(accessKey.expires).format("LLLL");
147
- if (willUpdateName) {
148
- logMessage += ` and changed its expiration date to ${expirationDate}`;
149
- } else {
150
- logMessage += `changed the expiration date of the "${command.oldName}" access key to ${expirationDate}`;
151
- }
152
- }
153
-
154
- log(`${logMessage}.`);
155
- });
156
- }
157
-
158
- function accessKeyList(command: cli.IAccessKeyListCommand): Promise<void> {
159
- throwForInvalidOutputFormat(command.format);
160
-
161
- return sdk.getAccessKeys().then((accessKeys: AccessKey[]): void => {
162
- printAccessKeys(command.format, accessKeys);
163
- });
164
- }
165
-
166
- function accessKeyRemove(command: cli.IAccessKeyRemoveCommand): Promise<void> {
167
- return confirm().then((wasConfirmed: boolean): Promise<void> => {
168
- if (wasConfirmed) {
169
- return sdk.removeAccessKey(command.accessKey).then((): void => {
170
- log(`Successfully removed the "${command.accessKey}" access key.`);
171
- });
172
- }
173
-
174
- log("Access key removal cancelled.");
175
- });
176
- }
177
-
178
125
  function appAdd(command: cli.IAppAddCommand): Promise<void> {
179
126
  return sdk.addApp(command.appName).then((app: App): Promise<void> => {
180
127
  log('Successfully added the "' + command.appName + '" app, along with the following default deployments:');
@@ -196,6 +143,12 @@ function appList(command: cli.IAppListCommand): Promise<void> {
196
143
  });
197
144
  }
198
145
 
146
+ function appDeploymentKeyList(command: cli.IAppDeploymentKeysCommand): Promise<void> {
147
+ return sdk.getDeploymentKeys(command.appName).then((retrievedKeys: DeploymentKey[]): void => {
148
+ printAppDeploymentKeyList(retrievedKeys);
149
+ });
150
+ }
151
+
199
152
  function appRemove(command: cli.IAppRemoveCommand): Promise<void> {
200
153
  return confirm("Are you sure you want to remove this app? Note that its deployment keys will be PERMANENTLY unrecoverable.").then(
201
154
  (wasConfirmed: boolean): Promise<void> => {
@@ -439,15 +392,6 @@ export function execute(command: cli.ICommand) {
439
392
  switch (command.type) {
440
393
  // Must not be logged in
441
394
  case cli.CommandType.login:
442
- case cli.CommandType.register:
443
- if (connectionInfo) {
444
- throw new Error("You are already logged in from this machine.");
445
- }
446
- break;
447
-
448
- // It does not matter whether you are logged in or not
449
- case cli.CommandType.link:
450
- break;
451
395
 
452
396
  // Must be logged in
453
397
  default:
@@ -464,23 +408,14 @@ export function execute(command: cli.ICommand) {
464
408
  }
465
409
 
466
410
  switch (command.type) {
467
- case cli.CommandType.accessKeyAdd:
468
- return accessKeyAdd(<cli.IAccessKeyAddCommand>command);
469
-
470
- case cli.CommandType.accessKeyPatch:
471
- return accessKeyPatch(<cli.IAccessKeyPatchCommand>command);
472
-
473
- case cli.CommandType.accessKeyList:
474
- return accessKeyList(<cli.IAccessKeyListCommand>command);
475
-
476
- case cli.CommandType.accessKeyRemove:
477
- return accessKeyRemove(<cli.IAccessKeyRemoveCommand>command);
478
-
479
411
  case cli.CommandType.appAdd:
480
412
  return appAdd(<cli.IAppAddCommand>command);
481
413
 
482
414
  case cli.CommandType.appList:
483
415
  return appList(<cli.IAppListCommand>command);
416
+
417
+ case cli.CommandType.appDeploymentKeyList:
418
+ return appDeploymentKeyList(<cli.IAppDeploymentKeysCommand>command);
484
419
 
485
420
  case cli.CommandType.appRemove:
486
421
  return appRemove(<cli.IAppRemoveCommand>command);
@@ -509,9 +444,6 @@ export function execute(command: cli.ICommand) {
509
444
  case cli.CommandType.deploymentRename:
510
445
  return deploymentRename(<cli.IDeploymentRenameCommand>command);
511
446
 
512
- case cli.CommandType.link:
513
- return link(<cli.ILinkCommand>command);
514
-
515
447
  case cli.CommandType.login:
516
448
  return login(<cli.ILoginCommand>command);
517
449
 
@@ -524,9 +456,6 @@ export function execute(command: cli.ICommand) {
524
456
  case cli.CommandType.promote:
525
457
  return promote(<cli.IPromoteCommand>command);
526
458
 
527
- case cli.CommandType.register:
528
- return register(<cli.IRegisterCommand>command);
529
-
530
459
  case cli.CommandType.release:
531
460
  return release(<cli.IReleaseCommand>command);
532
461
 
@@ -536,12 +465,6 @@ export function execute(command: cli.ICommand) {
536
465
  case cli.CommandType.rollback:
537
466
  return rollback(<cli.IRollbackCommand>command);
538
467
 
539
- case cli.CommandType.sessionList:
540
- return sessionList(<cli.ISessionListCommand>command);
541
-
542
- case cli.CommandType.sessionRemove:
543
- return sessionRemove(<cli.ISessionRemoveCommand>command);
544
-
545
468
  default:
546
469
  // We should never see this message as invalid commands should be caught by the argument parser.
547
470
  throw new Error("Invalid command: " + JSON.stringify(command));
@@ -656,6 +579,16 @@ function printAppList(format: string, apps: App[]): void {
656
579
  }
657
580
  }
658
581
 
582
+ function printAppDeploymentKeyList(deploymentKeys: DeploymentKey[]): void {
583
+ const headers = ["Name", "Deployment Key"];
584
+ printTable(headers, (dataSource: any[]): void => {
585
+ deploymentKeys.forEach((deploymentKey: DeploymentKey, index: number): void => {
586
+ const row = [deploymentKey.name, wordwrap(50)(deploymentKey.deploymentKey)];
587
+ dataSource.push(row);
588
+ });
589
+ });
590
+ }
591
+
659
592
  function getCollaboratorDisplayName(email: string, collaboratorProperties: CollaboratorProperties): string {
660
593
  return collaboratorProperties.permission === AccountManager.AppPermission.OWNER ? email + chalk.magenta(" (Owner)") : email;
661
594
  }