@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
@@ -4,6 +4,8 @@ import * as path from 'path';
4
4
  import * as chalk from 'chalk';
5
5
  import {command, help, namespace, param} from 'oo-cli';
6
6
  import { getEnv } from '../../lib/Config';
7
+ import {die} from '../../lib/die';
8
+ import {formatError} from '../../lib/formatError';
7
9
 
8
10
  const STAGING_ENV = {
9
11
  'OCP_ENV': 'staging',
@@ -23,30 +25,34 @@ export class SetEnvironmentCommand {
23
25
  @command
24
26
  @help('Set the current environment for the CLI')
25
27
  public set() {
26
- if (ENV_WHITELIST.includes(this.env)) {
27
- const envPath = path.join(os.homedir(), '.ocp');
28
- const envFile = path.join(envPath, `.env`);
29
- const setEnvFile = `${envFile}.${this.env}`;
28
+ try {
29
+ if (ENV_WHITELIST.includes(this.env)) {
30
+ const envPath = path.join(os.homedir(), '.ocp');
31
+ const envFile = path.join(envPath, `.env`);
32
+ const setEnvFile = `${envFile}.${this.env}`;
30
33
 
31
- if (fs.existsSync(envFile)) {
32
- fs.renameSync(envFile, `${envFile}.${getEnv()}`);
33
- }
34
+ if (fs.existsSync(envFile)) {
35
+ fs.renameSync(envFile, `${envFile}.${getEnv()}`);
36
+ }
34
37
 
35
- if (fs.existsSync(setEnvFile)) {
36
- fs.renameSync(setEnvFile, envFile);
37
- } else if (this.env === 'staging') {
38
- try {
39
- fs.statSync(envPath);
40
- } catch {
41
- fs.mkdirSync(envPath);
38
+ if (fs.existsSync(setEnvFile)) {
39
+ fs.renameSync(setEnvFile, envFile);
40
+ } else if (this.env === 'staging') {
41
+ try {
42
+ fs.statSync(envPath);
43
+ } catch {
44
+ fs.mkdirSync(envPath);
45
+ }
46
+ fs.writeFileSync(envFile, Object.entries(STAGING_ENV).map((x) => x.join('=')).join('\n'));
42
47
  }
43
- fs.writeFileSync(envFile, Object.entries(STAGING_ENV).map((x) => x.join('=')).join('\n'));
44
- }
45
48
 
46
- console.log(chalk.yellow(`using ${this.env} environment`));
47
- } else {
48
- console.log(chalk.red(
49
- `Could not switch to environment ${this.env}. Permitted environments are ${ENV_WHITELIST}`));
49
+ console.log(chalk.yellow(`using ${this.env} environment`));
50
+ } else {
51
+ console.log(chalk.red(
52
+ `Could not switch to environment ${this.env}. Permitted environments are ${ENV_WHITELIST}`));
53
+ }
54
+ } catch (e: any) {
55
+ die(formatError(e));
50
56
  }
51
57
  }
52
58
  }
package/src/index.ts CHANGED
@@ -36,4 +36,6 @@ async function run() {
36
36
  new Runner(__dirname, manifest).run();
37
37
  }
38
38
 
39
+ // catch does not work here sadly for async functions as oo-cli lib does not wait for the promise to resolve
40
+ // use try/catch instead in every command
39
41
  run().catch((e) => die(formatError(e)));
@@ -1,6 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import * as jsYaml from 'js-yaml';
3
3
  import * as path from 'path';
4
+ import {AppManifest} from '@zaiusinc/app-sdk';
4
5
 
5
6
  export interface AppContext {
6
7
  appId?: string;
@@ -38,10 +39,13 @@ export function appContext(appId?: string, vendor?: string, runtime?: string): A
38
39
  return {};
39
40
  }
40
41
 
41
- export function readAppYaml() {
42
+ export function readAppYaml(): AppManifest {
42
43
  const file = path.join(process.cwd(), 'app.yml');
43
- if (fs.existsSync(file)) {
44
- return jsYaml.safeLoad(fs.readFileSync(file, 'utf8'));
44
+ if (!fs.existsSync(file)) {
45
+ throw new Error(
46
+ `Can not find app manifest (app.yaml) in working directory. Please run this command from the root of your app.`
47
+ );
45
48
  }
46
- return false;
49
+
50
+ return jsYaml.safeLoad(fs.readFileSync(file, 'utf8'));
47
51
  }