@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.
- package/dist/commands/app/Init.js +18 -12
- package/dist/commands/app/Init.js.map +1 -1
- package/dist/commands/app/Package.js +21 -15
- package/dist/commands/app/Package.js.map +1 -1
- package/dist/commands/app/Prepare.js +56 -49
- package/dist/commands/app/Prepare.js.map +1 -1
- package/dist/commands/app/Register.d.ts +0 -1
- package/dist/commands/app/Register.js +42 -10
- package/dist/commands/app/Register.js.map +1 -1
- package/dist/commands/app/Validate.js +9 -2
- package/dist/commands/app/Validate.js.map +1 -1
- package/dist/commands/directory/Publish.js +1 -3
- package/dist/commands/directory/Publish.js.map +1 -1
- package/dist/commands/directory/Unpublish.js +1 -3
- package/dist/commands/directory/Unpublish.js.map +1 -1
- package/dist/commands/env/GetEnvironment.js +10 -3
- package/dist/commands/env/GetEnvironment.js.map +1 -1
- package/dist/commands/env/SetEnvironment.js +26 -19
- package/dist/commands/env/SetEnvironment.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/AppContext.d.ts +2 -1
- package/dist/lib/AppContext.js +3 -3
- package/dist/lib/AppContext.js.map +1 -1
- package/dist/oo-cli.manifest.json +3 -14
- package/package.json +1 -1
- package/src/commands/app/Init.ts +17 -12
- package/src/commands/app/Package.ts +21 -16
- package/src/commands/app/Prepare.ts +65 -59
- package/src/commands/app/Register.ts +39 -10
- package/src/commands/app/Validate.ts +8 -2
- package/src/commands/directory/Publish.ts +1 -3
- package/src/commands/directory/Unpublish.ts +1 -3
- package/src/commands/env/GetEnvironment.ts +9 -3
- package/src/commands/env/SetEnvironment.ts +26 -20
- package/src/index.ts +2 -0
- 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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
if (fs.existsSync(envFile)) {
|
|
35
|
+
fs.renameSync(envFile, `${envFile}.${getEnv()}`);
|
|
36
|
+
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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)));
|
package/src/lib/AppContext.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
49
|
+
|
|
50
|
+
return jsYaml.safeLoad(fs.readFileSync(file, 'utf8'));
|
|
47
51
|
}
|