@optimizely/ocp-cli 1.0.4 → 1.0.6

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.
Files changed (37) hide show
  1. package/dist/commands/app/Init.js +18 -12
  2. package/dist/commands/app/Init.js.map +1 -1
  3. package/dist/commands/app/Package.js +21 -15
  4. package/dist/commands/app/Package.js.map +1 -1
  5. package/dist/commands/app/Prepare.js +56 -49
  6. package/dist/commands/app/Prepare.js.map +1 -1
  7. package/dist/commands/app/Register.d.ts +0 -1
  8. package/dist/commands/app/Register.js +42 -10
  9. package/dist/commands/app/Register.js.map +1 -1
  10. package/dist/commands/app/Validate.js +9 -2
  11. package/dist/commands/app/Validate.js.map +1 -1
  12. package/dist/commands/directory/Publish.js +1 -3
  13. package/dist/commands/directory/Publish.js.map +1 -1
  14. package/dist/commands/directory/Unpublish.js +1 -3
  15. package/dist/commands/directory/Unpublish.js.map +1 -1
  16. package/dist/commands/env/GetEnvironment.js +10 -3
  17. package/dist/commands/env/GetEnvironment.js.map +1 -1
  18. package/dist/commands/env/SetEnvironment.js +26 -19
  19. package/dist/commands/env/SetEnvironment.js.map +1 -1
  20. package/dist/index.js +2 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/lib/AppContext.d.ts +2 -1
  23. package/dist/lib/AppContext.js +3 -3
  24. package/dist/lib/AppContext.js.map +1 -1
  25. package/dist/oo-cli.manifest.json +3 -14
  26. package/package.json +1 -1
  27. package/src/commands/app/Init.ts +17 -12
  28. package/src/commands/app/Package.ts +21 -16
  29. package/src/commands/app/Prepare.ts +65 -59
  30. package/src/commands/app/Register.ts +39 -10
  31. package/src/commands/app/Validate.ts +8 -2
  32. package/src/commands/directory/Publish.ts +1 -3
  33. package/src/commands/directory/Unpublish.ts +1 -3
  34. package/src/commands/env/GetEnvironment.ts +9 -3
  35. package/src/commands/env/SetEnvironment.ts +26 -20
  36. package/src/index.ts +2 -0
  37. package/src/lib/AppContext.ts +8 -4
@@ -13,6 +13,8 @@ const path = require("path");
13
13
  const chalk = require("chalk");
14
14
  const oo_cli_1 = require("oo-cli");
15
15
  const Config_1 = require("../../lib/Config");
16
+ const die_1 = require("../../lib/die");
17
+ const formatError_1 = require("../../lib/formatError");
16
18
  const STAGING_ENV = {
17
19
  'OCP_ENV': 'staging',
18
20
  'RIVENDELL': 'https://rivendell.staging.zaius.com',
@@ -22,29 +24,34 @@ const STAGING_ENV = {
22
24
  const ENV_WHITELIST = ['staging', 'production'];
23
25
  let SetEnvironmentCommand = class SetEnvironmentCommand {
24
26
  set() {
25
- if (ENV_WHITELIST.includes(this.env)) {
26
- const envPath = path.join(os.homedir(), '.ocp');
27
- const envFile = path.join(envPath, `.env`);
28
- const setEnvFile = `${envFile}.${this.env}`;
29
- if (fs.existsSync(envFile)) {
30
- fs.renameSync(envFile, `${envFile}.${(0, Config_1.getEnv)()}`);
31
- }
32
- if (fs.existsSync(setEnvFile)) {
33
- fs.renameSync(setEnvFile, envFile);
34
- }
35
- else if (this.env === 'staging') {
36
- try {
37
- fs.statSync(envPath);
27
+ try {
28
+ if (ENV_WHITELIST.includes(this.env)) {
29
+ const envPath = path.join(os.homedir(), '.ocp');
30
+ const envFile = path.join(envPath, `.env`);
31
+ const setEnvFile = `${envFile}.${this.env}`;
32
+ if (fs.existsSync(envFile)) {
33
+ fs.renameSync(envFile, `${envFile}.${(0, Config_1.getEnv)()}`);
38
34
  }
39
- catch (_a) {
40
- fs.mkdirSync(envPath);
35
+ if (fs.existsSync(setEnvFile)) {
36
+ fs.renameSync(setEnvFile, envFile);
41
37
  }
42
- fs.writeFileSync(envFile, Object.entries(STAGING_ENV).map((x) => x.join('=')).join('\n'));
38
+ else if (this.env === 'staging') {
39
+ try {
40
+ fs.statSync(envPath);
41
+ }
42
+ catch (_a) {
43
+ fs.mkdirSync(envPath);
44
+ }
45
+ fs.writeFileSync(envFile, Object.entries(STAGING_ENV).map((x) => x.join('=')).join('\n'));
46
+ }
47
+ console.log(chalk.yellow(`using ${this.env} environment`));
48
+ }
49
+ else {
50
+ console.log(chalk.red(`Could not switch to environment ${this.env}. Permitted environments are ${ENV_WHITELIST}`));
43
51
  }
44
- console.log(chalk.yellow(`using ${this.env} environment`));
45
52
  }
46
- else {
47
- console.log(chalk.red(`Could not switch to environment ${this.env}. Permitted environments are ${ENV_WHITELIST}`));
53
+ catch (e) {
54
+ (0, die_1.die)((0, formatError_1.formatError)(e));
48
55
  }
49
56
  }
50
57
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SetEnvironment.js","sourceRoot":"","sources":["../../../src/commands/env/SetEnvironment.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yBAAyB;AACzB,yBAAyB;AACzB,6BAA6B;AAC7B,+BAA+B;AAC/B,mCAAuD;AACvD,6CAA0C;AAE1C,MAAM,WAAW,GAAG;IAClB,SAAS,EAAE,SAAS;IACpB,WAAW,EAAE,qCAAqC;IAClD,YAAY,EAAE,WAAW;IACzB,eAAe,EAAE,oBAAoB;CACtC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAGzC,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAOzB,GAAG;QACR,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACpC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;YAChD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC3C,MAAM,UAAU,GAAG,GAAG,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YAE5C,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;gBAC1B,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,OAAO,IAAI,IAAA,eAAM,GAAE,EAAE,CAAC,CAAC;aAClD;YAED,IAAI,EAAE,CA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,CAAC;iBAC3F;gBAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;aAC5D;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CACnB,mCAAmC,IAAI,CAAC,GAAG,gCAAgC,aAAa,EAAE,CAAC,CAAC,CAAC;aAChG;SACF;QAAC,OAAO,CAAM,EAAE;YACf,IAAA,SAAG,EAAC,IAAA,yBAAW,EAAC,CAAC,CAAC,CAAC,CAAC;SACrB;IACH,CAAC;CACF,CAAA;AAnCC;IAFC,cAAK;IACL,IAAA,aAAI,EAAC,sBAAsB,CAAC;kDACT;AAIpB;IAFC,gBAAO;IACP,IAAA,aAAI,EAAC,yCAAyC,CAAC;gDA+B/C;AArCU,qBAAqB;IADjC,IAAA,kBAAS,EAAC,KAAK,CAAC;GACJ,qBAAqB,CAsCjC;AAtCY,sDAAqB"}
package/dist/index.js CHANGED
@@ -27,5 +27,7 @@ async function run() {
27
27
  await (0, checkForUpdate_1.checkForUpdate)(manifest);
28
28
  new oo_cli_1.Runner(__dirname, manifest).run();
29
29
  }
30
+ // catch does not work here sadly for async functions as oo-cli lib does not wait for the promise to resolve
31
+ // use try/catch instead in every command
30
32
  run().catch((e) => (0, die_1.die)((0, formatError_1.formatError)(e)));
31
33
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,mCAAgC;AAChC,6BAA6B;AAC7B,mEAA4D;AAC5D,yDAAsD;AACtD,yBAAyB;AACzB,yBAAyB;AACzB,mDAA8C;AAC9C,yDAAoD;AACpD,mCAA8B;AAC9B,+BAA+B;AAE/B,KAAK,UAAU,GAAG;IAChB,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,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FAA4F,CAAC,CAC9G,CAAC;KACH;IAED,MAAM,IAAA,+BAAc,GAAE,CAAC;IAEvB,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;IACrD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;QAC9B,IAAA,SAAG,EACD,iCAAiC;YACjC,4BAA4B;YAC5B,2FAA2F;YAC3F,yCAAyC,CAC1C,CAAC;KACL;IAED,IAAA,qCAAe,GAAE,CAAC;IAElB,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,wBAAwB,CAAC,CAAC,CAAC;IACzE,MAAM,IAAA,+BAAc,EAAC,QAAQ,CAAC,CAAC;IAE/B,IAAI,eAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC;AACxC,CAAC;AAED,4GAA4G;AAC5G,yCAAyC;AACzC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,SAAG,EAAC,IAAA,yBAAW,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { AppManifest } from '@zaiusinc/app-sdk';
1
2
  export interface AppContext {
2
3
  appId?: string;
3
4
  displayName?: string;
@@ -6,4 +7,4 @@ export interface AppContext {
6
7
  runtime?: string;
7
8
  }
8
9
  export declare function appContext(appId?: string, vendor?: string, runtime?: string): AppContext;
9
- export declare function readAppYaml(): any;
10
+ export declare function readAppYaml(): AppManifest;
@@ -34,10 +34,10 @@ function appContext(appId, vendor, runtime) {
34
34
  exports.appContext = appContext;
35
35
  function readAppYaml() {
36
36
  const file = path.join(process.cwd(), 'app.yml');
37
- if (fs.existsSync(file)) {
38
- return jsYaml.safeLoad(fs.readFileSync(file, 'utf8'));
37
+ if (!fs.existsSync(file)) {
38
+ throw new Error(`Can not find app manifest (app.yaml) in working directory. Please run this command from the root of your app.`);
39
39
  }
40
- return false;
40
+ return jsYaml.safeLoad(fs.readFileSync(file, 'utf8'));
41
41
  }
42
42
  exports.readAppYaml = readAppYaml;
43
43
  //# sourceMappingURL=AppContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AppContext.js","sourceRoot":"","sources":["../../src/lib/AppContext.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,kCAAkC;AAClC,6BAA6B;AAU7B,SAAgB,UAAU,CAAC,KAAc,EAAE,MAAe,EAAE,OAAgB;IAC1E,IAAI,KAAK,EAAE;QACT,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACvB,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACvC,OAAO;gBACL,KAAK,EAAE,EAAE;gBACT,OAAO;gBACP,MAAM;gBACN,OAAO;aACR,CAAC;SACH;aAAM;YACL,OAAO,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAC,CAAC;SACjC;KACF;IAED,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC;IAC3B,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;QACrB,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;YACvB,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY;YACnC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;YAC1B,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;YACxB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;KACH;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AA1BD,gCA0BC;AAED,SAAgB,WAAW;IACzB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;IACjD,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,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I,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CACb,+GAA+G,CAChH,CAAC;KACH;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC;AATD,kCASC"}
@@ -324,7 +324,7 @@
324
324
  "key": "register",
325
325
  "command": "register",
326
326
  "aliases": [],
327
- "help": "Register an app version",
327
+ "help": "Register an app in all shards",
328
328
  "documentation": "TBD",
329
329
  "flags": [
330
330
  {
@@ -337,18 +337,7 @@
337
337
  "invertible": false
338
338
  }
339
339
  ],
340
- "options": [
341
- {
342
- "name": "availability",
343
- "key": "availability",
344
- "aliases": [
345
- "a"
346
- ],
347
- "help": "The availability zone that will be targeted (default: us)",
348
- "optional": true,
349
- "multiple": false
350
- }
351
- ],
340
+ "options": [],
352
341
  "params": [
353
342
  {
354
343
  "name": "id",
@@ -1238,7 +1227,7 @@
1238
1227
  },
1239
1228
  "commands": [],
1240
1229
  "package": {
1241
- "version": "1.0.4",
1230
+ "version": "1.0.6",
1242
1231
  "name": "@optimizely/ocp-cli",
1243
1232
  "license": "Apache-2.0",
1244
1233
  "executable": "ocp"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimizely/ocp-cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Optimizely Connect Platform command line interface",
5
5
  "repository": "https://github.com/ZaiusInc/ocp-cli",
6
6
  "license": "Apache-2.0",
@@ -21,6 +21,7 @@ import titleCase = require('title-case');
21
21
  import { getDependencyFileUrl } from '../../lib/Config';
22
22
  import {Rivendell} from '../../lib/Rivendell';
23
23
  import {die} from '../../lib/die';
24
+ import {formatError} from '../../lib/formatError';
24
25
 
25
26
  @namespace('app')
26
27
  export class CreateCommand {
@@ -38,21 +39,25 @@ export class CreateCommand {
38
39
  @command
39
40
  @help('Create a new app project')
40
41
  public async init() {
41
- handleInterrupt();
42
- this.manifest = await fetchTemplatesManifest();
42
+ try {
43
+ handleInterrupt();
44
+ this.manifest = await fetchTemplatesManifest();
43
45
 
44
- // start with base variables
45
- this.variables = this.manifest.baseTemplateVariables;
46
+ // start with base variables
47
+ this.variables = this.manifest.baseTemplateVariables;
46
48
 
47
- // setting developer vendor
48
- this.variables.find((v) => v.name === 'vendor')!.suggest = (await Rivendell.whoami()).vendor;
49
+ // setting developer vendor
50
+ this.variables.find((v) => v.name === 'vendor')!.suggest = (await Rivendell.whoami()).vendor;
49
51
 
50
- this.variables.push({
51
- name: 'template',
52
- question: 'Select a template project'
53
- });
54
- if (!await this.askQuestion()) {
55
- process.exit(1);
52
+ this.variables.push({
53
+ name: 'template',
54
+ question: 'Select a template project'
55
+ });
56
+ if (!await this.askQuestion()) {
57
+ process.exit(1);
58
+ }
59
+ } catch (e: any) {
60
+ die(formatError(e));
56
61
  }
57
62
  }
58
63
 
@@ -5,6 +5,7 @@ import {appContext} from '../../lib/AppContext';
5
5
  import {AppPackager} from '../../lib/AppPackager';
6
6
  import {die} from '../../lib/die';
7
7
  import {directoryExists} from '../../lib/directoryExists';
8
+ import {formatError} from '../../lib/formatError';
8
9
 
9
10
  @namespace('app')
10
11
  export class PackageCommand {
@@ -16,24 +17,28 @@ export class PackageCommand {
16
17
  @command
17
18
  @help('Prepare a package for manual upload')
18
19
  public package() {
19
- const workingDir = process.cwd();
20
- if (!directoryExists(this.path)) {
21
- die('Specified path to app does not exist');
22
- return;
23
- }
24
- process.chdir(this.path);
20
+ try {
21
+ const workingDir = process.cwd();
22
+ if (!directoryExists(this.path)) {
23
+ die('Specified path to app does not exist');
24
+ return;
25
+ }
26
+ process.chdir(this.path);
25
27
 
26
- const context = appContext();
27
- if (!context.appId || !context.version) {
28
- die('Unable to read App ID or version info. Ensure you are uploading the right directory.');
29
- return;
30
- }
28
+ const context = appContext();
29
+ if (!context.appId || !context.version) {
30
+ die('Unable to read App ID or version info. Ensure you are uploading the right directory.');
31
+ return;
32
+ }
31
33
 
32
- if (context) {
33
- const packageData = new AppPackager('./').package();
34
- const zipFileName = `${context.appId}@${context.version}.zip`;
35
- fs.writeFileSync(path.join(workingDir, zipFileName), packageData);
36
- console.log(`Created package ${zipFileName}`);
34
+ if (context) {
35
+ const packageData = new AppPackager('./').package();
36
+ const zipFileName = `${context.appId}@${context.version}.zip`;
37
+ fs.writeFileSync(path.join(workingDir, zipFileName), packageData);
38
+ console.log(`Created package ${zipFileName}`);
39
+ }
40
+ } catch (e: any) {
41
+ die(formatError(e));
37
42
  }
38
43
  }
39
44
  }
@@ -9,6 +9,8 @@ import * as fs from 'fs';
9
9
  import * as path from 'path';
10
10
  import {Rivendell} from '../../lib/Rivendell';
11
11
  import AppReview = Rivendell.AppReview;
12
+ import {formatError} from '../../lib/formatError';
13
+ import {die} from '../../lib/die';
12
14
 
13
15
  @namespace('app')
14
16
  export class PrepareCommand extends BaseBuildCommand {
@@ -27,78 +29,82 @@ export class PrepareCommand extends BaseBuildCommand {
27
29
  @command
28
30
  @help('Validate, package, upload and build an app to prepare for publishing')
29
31
  public async prepare() {
30
- const context = appContext();
31
- if (!context.appId || !context.version) {
32
- console.log(chalk.gray('App id or version missing in the manifest\n'));
33
- return;
34
- }
35
- const requiresReview = await this.requiresReview(context.version);
36
- if (requiresReview) {
37
- const isInReview = await this.isInReview(context.appId, context.version);
38
- const reviewMessage = isInReview ?
39
- chalk.gray(
40
- 'The app version is already in review. This will update the review and the app can\'t be published until it is approved. ' +
41
- `${chalk.yellow('Are you sure?')}`
42
- ) :
43
- chalk.gray(
44
- 'You are uploading a release version of the app. ' +
45
- 'This will start a review process and the app can\'t be published until it is approved. ' +
46
- `${chalk.yellow('Are you sure?')}`
47
- );
48
-
49
- const reviewConfirmation = await TerminalConfirm.ask(reviewMessage);
50
- if (!reviewConfirmation) {
32
+ try {
33
+ const context = appContext();
34
+ if (!context.appId || !context.version) {
35
+ console.log(chalk.gray('App id or version missing in the manifest\n'));
51
36
  return;
52
37
  }
53
- }
38
+ const requiresReview = await this.requiresReview(context.version);
39
+ if (requiresReview) {
40
+ const isInReview = await this.isInReview(context.appId, context.version);
41
+ const reviewMessage = isInReview ?
42
+ chalk.gray(
43
+ 'The app version is already in review. This will update the review and the app can\'t be published until it is approved. ' +
44
+ `${chalk.yellow('Are you sure?')}`
45
+ ) :
46
+ chalk.gray(
47
+ 'You are uploading a release version of the app. ' +
48
+ 'This will start a review process and the app can\'t be published until it is approved. ' +
49
+ `${chalk.yellow('Are you sure?')}`
50
+ );
54
51
 
55
- if (context.version && this.bumpDevVersion) {
56
- if (this.isDevVersion(context.version)) {
57
- const bumpedVersion = semver.parse(context.version)?.inc('prerelease', 'dev').format();
58
- if (!bumpedVersion) {
59
- console.log(chalk.red(`Cannot parse app version: ${context.version}`));
52
+ const reviewConfirmation = await TerminalConfirm.ask(reviewMessage);
53
+ if (!reviewConfirmation) {
60
54
  return;
61
55
  }
56
+ }
62
57
 
63
- console.log(chalk.gray(`Bumping dev version to ${bumpedVersion}`));
58
+ if (context.version && this.bumpDevVersion) {
59
+ if (this.isDevVersion(context.version)) {
60
+ const bumpedVersion = semver.parse(context.version)?.inc('prerelease', 'dev').format();
61
+ if (!bumpedVersion) {
62
+ console.log(chalk.red(`Cannot parse app version: ${context.version}`));
63
+ return;
64
+ }
64
65
 
65
- this.updateVersionInAppManifest(context.version, bumpedVersion);
66
- context.version = bumpedVersion;
67
- } else {
68
- console.log(chalk.yellow('Not a dev version. Ignoring --bump-dev-version flag'));
69
- }
70
- }
66
+ console.log(chalk.gray(`Bumping dev version to ${bumpedVersion}`));
71
67
 
72
- await this.run(true, true, this.usePreviousAppEnvValues);
73
- await this.reviewAppVersion(context.appId as string, context.version as string);
68
+ this.updateVersionInAppManifest(context.version, bumpedVersion);
69
+ context.version = bumpedVersion;
70
+ } else {
71
+ console.log(chalk.yellow('Not a dev version. Ignoring --bump-dev-version flag'));
72
+ }
73
+ }
74
74
 
75
- if (this.publish) {
76
- const cmd = new PublishCommand();
77
- cmd.appVersion = `${context.appId}@${context.version}`;
78
- await cmd.publish();
79
- } else {
80
- if (requiresReview) {
81
- const appVersion = `${context.appId}@${context.version}`;
82
- const appReview = await Rivendell.getReviewUrl(appVersion);
83
- const reviewUrl = (appReview as AppReview).url;
75
+ await this.run(true, true, this.usePreviousAppEnvValues);
76
+ await this.reviewAppVersion(context.appId as string, context.version as string);
84
77
 
85
- console.log(chalk.gray(`\nYour app has been sent to review. Your code will be available in a private repository on GitHub, ` +
86
- `and you will receive an invitation from GitHub by email for access.` +
87
- `It is important you accept this invitation in order to receive communications about your app from the review team.`));
88
- console.log(chalk.gray(`\nOnce the review is approved, your app can be deployed to app directory.\n`));
89
- console.log(chalk.gray(`You can run ${chalk.white(`ocp review open ${appVersion}`)} to open the review URL at any time.`));
90
- console.log(chalk.gray(`The URL for your repo is ${chalk.white(`${reviewUrl}`)}\n`));
78
+ if (this.publish) {
79
+ const cmd = new PublishCommand();
80
+ cmd.appVersion = `${context.appId}@${context.version}`;
81
+ await cmd.publish();
91
82
  } else {
92
- console.log(chalk.gray(
93
- `\nUse ${chalk.white(
94
- `ocp directory publish ${context.appId}@${context.version}`
95
- )} to publish and release your app\n`
96
- ));
83
+ if (requiresReview) {
84
+ const appVersion = `${context.appId}@${context.version}`;
85
+ const appReview = await Rivendell.getReviewUrl(appVersion);
86
+ const reviewUrl = (appReview as AppReview).url;
87
+
88
+ console.log(chalk.gray(`\nYour app has been sent to review. Your code will be available in a private repository on GitHub, ` +
89
+ `and you will receive an invitation from GitHub by email for access.` +
90
+ `It is important you accept this invitation in order to receive communications about your app from the review team.`));
91
+ console.log(chalk.gray(`\nOnce the review is approved, your app can be deployed to app directory.\n`));
92
+ console.log(chalk.gray(`You can run ${chalk.white(`ocp review open ${appVersion}`)} to open the review URL at any time.`));
93
+ console.log(chalk.gray(`The URL for your repo is ${chalk.white(`${reviewUrl}`)}\n`));
94
+ } else {
95
+ console.log(chalk.gray(
96
+ `\nUse ${chalk.white(
97
+ `ocp directory publish ${context.appId}@${context.version}`
98
+ )} to publish and release your app\n`
99
+ ));
100
+ }
97
101
  }
98
- }
99
102
 
100
- // explicitly exit because we're using terminal kit
101
- process.exit(0);
103
+ // explicitly exit because we're using terminal kit
104
+ process.exit(0);
105
+ } catch (e: any) {
106
+ die(formatError(e));
107
+ }
102
108
  }
103
109
 
104
110
  private updateVersionInAppManifest(oldVersion: string, newVersion: string) {
@@ -1,8 +1,10 @@
1
- import {command, flag, help, namespace, option, param} from 'oo-cli';
1
+ import {command, flag, help, namespace, param} from 'oo-cli';
2
2
  import {die} from '../../lib/die';
3
3
  import {formatError} from '../../lib/formatError';
4
4
  import {Rivendell} from '../../lib/Rivendell';
5
- import {applicableShards} from '../../lib/Shards';
5
+ import {RivendellApi} from '../../lib/RivendellApi';
6
+ import ApiError = RivendellApi.ApiError;
7
+ import {constants as httpConstants} from 'http2';
6
8
 
7
9
  @namespace('app')
8
10
  export class RegisterCommand {
@@ -21,18 +23,45 @@ export class RegisterCommand {
21
23
  )
22
24
  public personal: boolean = false;
23
25
 
24
- @option('a')
25
- @help('The availability zone that will be targeted (default: us)')
26
- private availability: string = '';
27
-
28
26
  @command
29
- @help('Register an app version')
27
+ @help('Register an app in all shards')
30
28
  public async register() {
31
29
  try {
32
- const shards = await applicableShards(this.availability);
30
+ const shards = await Rivendell.shards();
31
+ shards.sort((first, second) => {
32
+ if (first.id === 'us') {
33
+ return -1;
34
+ } else if (second.id === 'us') {
35
+ return 1;
36
+ } else {
37
+ return first.id.localeCompare(second.id);
38
+ }
39
+ });
40
+ console.log(`Registering app ${this.id} in all shards`);
33
41
  for (const shard of shards) {
34
- const app = await Rivendell.registerApp(this.id, this.name, this.personal, shard);
35
- console.log(`Registered app ${app.id} with name "${app.name} in ${shard}`);
42
+ try {
43
+ const app = await Rivendell.registerApp(this.id, this.name, this.personal, shard.id);
44
+ console.log(`Registered app ${app.id} with name "${app.name} in ${shard.id}`);
45
+ } catch (e: any) {
46
+ if (e instanceof ApiError && e.response?.status === httpConstants.HTTP_STATUS_CONFLICT) {
47
+ // check the developer has access to already registered app
48
+ try {
49
+ await Rivendell.fetchApp(this.id, shard.id);
50
+ } catch (fetchError: any) {
51
+ if (
52
+ fetchError instanceof ApiError && fetchError.response?.status === httpConstants.HTTP_STATUS_NOT_FOUND
53
+ ) {
54
+ throw new Error(`App ${this.id} already registered by another vendor`);
55
+ } else {
56
+ throw e;
57
+ }
58
+ }
59
+
60
+ console.log(`App ${this.id} is already registered in shard ${shard.id}`);
61
+ } else {
62
+ throw e;
63
+ }
64
+ }
36
65
  }
37
66
  } catch (e: any) {
38
67
  die(formatError(e));
@@ -1,13 +1,19 @@
1
1
  import * as chalk from 'chalk';
2
2
  import {command, help, namespace} from 'oo-cli';
3
3
  import {BaseBuildCommand} from './BaseBuildCommand';
4
+ import {die} from '../../lib/die';
5
+ import {formatError} from '../../lib/formatError';
4
6
 
5
7
  @namespace('app')
6
8
  export class ValidateCommand extends BaseBuildCommand {
7
9
  @command
8
10
  @help('Validate an app locally')
9
11
  public async validate() {
10
- await this.run(false, false, false);
11
- console.log(chalk.gray(`\nUse ${chalk.white('ocp app prepare')} to upload and build your app\n`));
12
+ try {
13
+ await this.run(false, false, false);
14
+ console.log(chalk.gray(`\nUse ${chalk.white('ocp app prepare')} to upload and build your app\n`));
15
+ } catch (e: any) {
16
+ die(formatError(e));
17
+ }
12
18
  }
13
19
  }
@@ -150,7 +150,6 @@ export class PublishCommand {
150
150
  if (spinner) {
151
151
  spinner.stop();
152
152
  }
153
- clearInterval(interval);
154
153
  if (state === AppVersionState.RUNNING) {
155
154
  console.log(chalk.green(`${context.appId}@${context.version} has been published to ${shard}.`));
156
155
  } else {
@@ -164,11 +163,11 @@ export class PublishCommand {
164
163
  }
165
164
  if (spinner) {
166
165
  spinner.update(`Status: ${formatVersionState(state)}`);
166
+ setTimeout(checkStatus, 2000);
167
167
  }
168
168
  }
169
169
  })
170
170
  .catch((e) => {
171
- clearInterval(interval);
172
171
  if (spinner) {
173
172
  spinner.stop();
174
173
  }
@@ -176,7 +175,6 @@ export class PublishCommand {
176
175
  });
177
176
  };
178
177
 
179
- const interval = setInterval(checkStatus, 2000);
180
178
  checkStatus();
181
179
  });
182
180
  }
@@ -166,7 +166,6 @@ export class UnpublishCommand {
166
166
  if (spinner) {
167
167
  spinner.stop();
168
168
  }
169
- clearInterval(interval);
170
169
  console.log(chalk.green(`${context.appId}@${context.version} has been unpublished in ${shard}.`));
171
170
  resolve();
172
171
  } else {
@@ -175,18 +174,17 @@ export class UnpublishCommand {
175
174
  }
176
175
  if (spinner) {
177
176
  spinner.update(`Status: ${formatVersionState(state)}`);
177
+ setTimeout(checkStatus, 2000);
178
178
  }
179
179
  }
180
180
  })
181
181
  .catch((e) => {
182
- clearInterval(interval);
183
182
  if (spinner) {
184
183
  spinner.stop();
185
184
  }
186
185
  reject(e);
187
186
  });
188
187
  };
189
- const interval = setInterval(checkStatus, 2000);
190
188
  checkStatus();
191
189
  });
192
190
  }
@@ -1,14 +1,20 @@
1
1
  import * as chalk from 'chalk';
2
2
  import {command, help, namespace} from 'oo-cli';
3
3
  import {getEnv, runtimeConfig} from '../../lib/Config';
4
+ import {die} from '../../lib/die';
5
+ import {formatError} from '../../lib/formatError';
4
6
 
5
7
  @namespace('env')
6
8
  export class GetEnvironmentCommand {
7
9
  @command
8
10
  @help('Get the current environment of the CLI')
9
11
  public get() {
10
- console.log(`Using ${chalk.yellow(getEnv())} environment\n`);
11
- console.log('Configuration:');
12
- console.log(chalk.gray(require('js-yaml').dump(runtimeConfig())));
12
+ try {
13
+ console.log(`Using ${chalk.yellow(getEnv())} environment\n`);
14
+ console.log('Configuration:');
15
+ console.log(chalk.gray(require('js-yaml').dump(runtimeConfig())));
16
+ } catch (e: any) {
17
+ die(formatError(e));
18
+ }
13
19
  }
14
20
  }