@contrail/cli 1.0.2 → 1.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.
Files changed (53) hide show
  1. package/.vscode/settings.json +5 -5
  2. package/bin/init +3 -3
  3. package/lib/auth/auth.d.ts +9 -9
  4. package/lib/auth/auth.js +2 -2
  5. package/lib/auth/login.d.ts +1 -1
  6. package/lib/auth/login.js +112 -96
  7. package/lib/cli.d.ts +5 -5
  8. package/lib/cli.js +30 -30
  9. package/lib/create-app/create.d.ts +1 -1
  10. package/lib/create-app/create.js +63 -48
  11. package/lib/create-app/setup-template.d.ts +1 -1
  12. package/lib/create-app/setup-template.js +34 -48
  13. package/lib/deploy-app/actions-deployer.d.ts +10 -10
  14. package/lib/deploy-app/actions-deployer.js +86 -75
  15. package/lib/deploy-app/app-deployer.d.ts +8 -10
  16. package/lib/deploy-app/app-deployer.js +79 -84
  17. package/lib/deploy-app/app-template-parsers.d.ts +7 -0
  18. package/lib/deploy-app/app-template-parsers.js +37 -0
  19. package/lib/deploy-app/deploy.d.ts +2 -2
  20. package/lib/deploy-app/deploy.js +56 -30
  21. package/lib/deploy-app/interfaces.d.ts +74 -43
  22. package/lib/deploy-app/interfaces.js +4 -0
  23. package/package.json +63 -63
  24. package/publish.sh +5 -0
  25. package/src/auth/auth.ts +9 -9
  26. package/src/auth/login.ts +124 -107
  27. package/src/cli.ts +32 -33
  28. package/src/create-app/create.ts +73 -58
  29. package/src/create-app/setup-template.ts +37 -56
  30. package/src/deploy-app/actions-deployer.ts +109 -84
  31. package/src/deploy-app/app-deployer.ts +86 -89
  32. package/src/deploy-app/app-template-parsers.ts +43 -0
  33. package/src/deploy-app/deploy.ts +64 -33
  34. package/src/deploy-app/interfaces.ts +78 -43
  35. package/templates/javascript/actions/example/action.js +37 -37
  36. package/templates/javascript/app.yml +54 -42
  37. package/templates/javascript/package.json +23 -23
  38. package/templates/javascript/set_auth.bat +3 -0
  39. package/templates/javascript/set_auth.sh +3 -0
  40. package/templates/typescript/actions/exampleAction.ts +38 -0
  41. package/templates/typescript/app.yml +56 -0
  42. package/templates/typescript/package.json +24 -0
  43. package/templates/typescript/set_auth.bat +3 -0
  44. package/templates/typescript/set_auth.sh +3 -0
  45. package/templates/typescript/tsconfig.json +31 -0
  46. package/tsconfig.json +22 -22
  47. package/tslint.json +57 -57
  48. package/lib/deploy-app/actions.d.ts +0 -5
  49. package/lib/deploy-app/actions.js +0 -17
  50. package/lib/deploy-app/app-declaration.d.ts +0 -20
  51. package/lib/deploy-app/app-declaration.js +0 -0
  52. package/lib/deploy-app/app.d.ts +0 -8
  53. package/lib/deploy-app/app.js +0 -56
@@ -1,57 +1,38 @@
1
-
2
- import ncp from 'ncp';
3
- import path from 'path';
4
- import { promisify } from 'util';
5
- import execa from 'execa';
6
- const Listr = require('listr');
7
- import { projectInstall } from 'pkg-install';
8
- const copy = promisify(ncp);
9
- const TARGET_DIR = process.cwd();
10
-
11
- const currentFileUrl = import .meta.url;
12
- const TEMPLATE_DIR = path.resolve(new URL(currentFileUrl).pathname, '../../../templates/javascript').replace(/\\/g, '\\').replace(/(.):\\(.):/g, '');
13
- // console.log('TEMPLATE_DIR: ', TEMPLATE_DIR);
14
- // console.log('TARGET_DIR: ', TARGET_DIR);
15
-
16
- function copyTemplate(){
17
- return copy(TEMPLATE_DIR, TARGET_DIR, {
18
- clobber: false,
19
- });
20
- }
21
-
22
- function npmInstall(){
23
- async function initGit(options) {
24
- const result = await execa('git', ['init'], {
25
- cwd: options.targetDirectory,
26
- });
27
- if (result.failed) {
28
- return Promise.reject(new Error('Failed to initialize git'));
29
- }
30
- return;
31
- }
32
- }
33
-
34
- export async function setUpTemplate() {
35
- try {
36
- const tasks = new Listr([
37
- {
38
- title: 'Copy template files',
39
- task: () => copyTemplate(),
40
- },
41
- {
42
- title: 'Install dependencies',
43
- task: () =>
44
- projectInstall({
45
- cwd: TARGET_DIR,
46
- }),
47
- // skip: () =>
48
- // !options.runInstall
49
- // ? 'Pass --install to automatically install dependencies'
50
- // : undefined,
51
- },
52
- ]);
53
- await tasks.run();
54
- } catch (e) {
55
- console.log('Error copying template: ', e);
56
- }
1
+
2
+ import ncp from 'ncp';
3
+ import path from 'path';
4
+ import { promisify } from 'util';
5
+ const Listr = require('listr');
6
+ import { projectInstall } from 'pkg-install';
7
+ const copy = promisify(ncp);
8
+
9
+ const TARGET_DIR = process.cwd();
10
+ const currentFileUrl = import .meta.url;
11
+
12
+ function copyTemplate(templateDir){
13
+ return copy(templateDir, TARGET_DIR, {
14
+ clobber: false,
15
+ });
16
+ }
17
+
18
+ export async function setUpTemplate(options) {
19
+ const templateDir = path.resolve(new URL(currentFileUrl).pathname, `../../../templates/${options.template.toLocaleLowerCase()}`).replace(/\\/g, '\\').replace(/(.):\\(.):/g, '').replace(/%20/g, ' ');
20
+ try {
21
+ const tasks = new Listr([
22
+ {
23
+ title: 'Copy template files',
24
+ task: () => copyTemplate(templateDir),
25
+ },
26
+ {
27
+ title: 'Install dependencies',
28
+ task: () =>
29
+ projectInstall({
30
+ cwd: TARGET_DIR,
31
+ }),
32
+ },
33
+ ]);
34
+ await tasks.run();
35
+ } catch (e) {
36
+ throw new Error(`Error copying template: ${e}`);
37
+ }
57
38
  }
@@ -1,84 +1,109 @@
1
- import { Entities } from '@contrail/sdk';
2
- import chalk from 'chalk';
3
- import { App, AppDeclartion, AppActionDeclaration, EventWorkflowActionDefinition } from './interfaces';
4
- import fs from 'fs';
5
-
6
- export class ActionsDeployer {
7
- async deployActions(appDeclaration: AppDeclartion, app: App) {
8
-
9
- // FETCH ALL ACTIONS FROM THE API.
10
- const existingActions = await this.getActionsForApp(app);
11
- // UPSERT / DELETE BASED ON ACTION IDENTIFIER
12
- console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
13
- for (const actionKey of Object.keys(appDeclaration.actions)) {
14
- await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
15
- }
16
- }
17
-
18
- async getActionsForApp(app: App){
19
- return await new Entities().get({ entityName: 'event-workflow-action-definition',
20
- criteria: { ownerKey: `app:${app.id}`}});
21
- }
22
-
23
- async deployAction(actionKey: string,
24
- actionDeclaration: AppActionDeclaration,
25
- app: App,
26
- existingActions: Array<any>){
27
- console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
28
- const identifier = this.getActionDeclarationIdentifier(actionKey, app);
29
- const existingDefinition = existingActions.find(ad => ad.identifier === identifier);
30
- if (!existingDefinition) {
31
- await this.createNewActionDefinition(actionKey, actionDeclaration, app);
32
- } else {
33
- await this.updateActionDefinition(existingDefinition, actionDeclaration);
34
- }
35
- }
36
- private async createNewActionDefinition(actionKey: string,
37
- actionDeclaration: AppActionDeclaration,
38
- app: App) {
39
- const newObject: EventWorkflowActionDefinition = {
40
- identifier: this.getActionDeclarationIdentifier(actionKey, app),
41
- name: actionDeclaration.name,
42
- ownerKey: `app:${app.id}`,
43
- public: !app.private,
44
- };
45
- const functionString = await this.getFunction(actionDeclaration);
46
- if (functionString) {
47
- newObject.executeFunctionString = functionString;
48
- }
49
- const actionDefinition = await new Entities().create({
50
- entityName: 'event-workflow-action-definition',
51
- object: newObject });
52
- console.log(`%s Created new action defintion: ${actionKey}`, chalk.yellow.bold('APP'));
53
- return actionDefinition;
54
- }
55
- private async updateActionDefinition(existingActionDefinition: EventWorkflowActionDefinition,
56
- actionDeclaration: AppActionDeclaration) {
57
- const updates: EventWorkflowActionDefinition = {
58
- name: actionDeclaration.name,
59
- };
60
- const functionString = await this.getFunction(actionDeclaration);
61
- if (functionString) {
62
- updates.executeFunctionString = functionString;
63
- }
64
- const actionDefinition = await new Entities().update({
65
- entityName: 'event-workflow-action-definition',
66
- id: existingActionDefinition.id,
67
- object: updates });
68
- console.log(`%s Updated existingaction defintion: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
69
- return actionDefinition;
70
- }
71
- getActionDeclarationIdentifier(actionKey, app: App) {
72
- return app.identifier + ':' + actionKey;
73
- }
74
-
75
- async getFunction(actionDeclaration: AppActionDeclaration): Promise<string> {
76
- if (!actionDeclaration.handler) {
77
- return;
78
- }
79
- const CURRENT_DIR = process.cwd();
80
- const functionLocaiton = CURRENT_DIR + '\\' + actionDeclaration.handler;
81
- const content = fs.readFileSync(functionLocaiton);
82
- return content.toString();
83
- }
84
- }
1
+ import { Entities } from '@contrail/sdk';
2
+ import chalk from 'chalk';
3
+ import { App, AppDeclaration, AppActionDeclaration, EventWorkflowActionDefinition } from './interfaces';
4
+ import { ConfigPropertiesParser } from './app-template-parsers';
5
+ import fs from 'fs';
6
+
7
+ export class ActionsDeployer {
8
+ async deployActions(appDeclaration: AppDeclaration, app: App) {
9
+
10
+ // FETCH ALL ACTIONS FROM THE API.
11
+ const existingActions = await this.getActionsForApp(app);
12
+
13
+ // UPSERT / DELETE BASED ON ACTION IDENTIFIER
14
+ console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
15
+
16
+ for (const actionKey of Object.keys(appDeclaration.actions)) {
17
+ await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
18
+ }
19
+ }
20
+
21
+ async getActionsForApp(app: App) {
22
+ return await new Entities().get({
23
+ entityName: 'event-workflow-action-definition',
24
+ criteria: { ownerKey: `app:${app.id}` },
25
+ });
26
+ }
27
+
28
+ async deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>) {
29
+ console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
30
+
31
+ const identifier = this.getActionDeclarationIdentifier(actionKey, app);
32
+ const existingDefinition = existingActions.find(ad => ad.identifier === identifier);
33
+
34
+ if (!existingDefinition) {
35
+ await this.createNewActionDefinition(actionKey, actionDeclaration, app);
36
+ } else {
37
+ await this.updateActionDefinition(existingDefinition, actionDeclaration);
38
+ }
39
+ }
40
+
41
+ private async createNewActionDefinition(actionKey: string, actionDeclaration: AppActionDeclaration, app: App) {
42
+ const newObject: EventWorkflowActionDefinition = {
43
+ identifier: this.getActionDeclarationIdentifier(actionKey, app),
44
+ name: actionDeclaration.name,
45
+ ownerKey: `app:${app.id}`,
46
+ public: app.public, // TODO - an actions visibility is not tied to the visibility of the app
47
+ configProperties: ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration),
48
+ };
49
+
50
+ const functionString = await this.getFunction(actionDeclaration);
51
+ if (functionString) {
52
+ newObject.executeFunctionString = functionString;
53
+ }
54
+
55
+ const actionDefinition = await new Entities().create({
56
+ entityName: 'event-workflow-action-definition',
57
+ object: newObject,
58
+ });
59
+
60
+ console.log(`%s Created new action definition: ${actionKey}`, chalk.yellow.bold('APP'));
61
+
62
+ return actionDefinition;
63
+ }
64
+
65
+ private async updateActionDefinition(existingActionDefinition: EventWorkflowActionDefinition,
66
+ actionDeclaration: AppActionDeclaration) {
67
+ const updates: EventWorkflowActionDefinition = {
68
+ name: actionDeclaration.name,
69
+ // public: actionDeclaration.public, // TODO - an actions visibility is allowed to change
70
+ configProperties: ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration),
71
+ };
72
+
73
+ const functionString = await this.getFunction(actionDeclaration);
74
+ if (functionString) {
75
+ updates.executeFunctionString = functionString;
76
+ }
77
+
78
+ const actionDefinition = await new Entities().update({
79
+ entityName: 'event-workflow-action-definition',
80
+ id: existingActionDefinition.id,
81
+ object: updates,
82
+ });
83
+
84
+ console.log(`%s Updated existingaction defintion: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
85
+
86
+ return actionDefinition;
87
+ }
88
+
89
+ getActionDeclarationIdentifier(actionKey, app: App) {
90
+ return app.identifier + ':' + actionKey;
91
+ }
92
+
93
+ async getFunction(actionDeclaration: AppActionDeclaration): Promise<string> {
94
+ if (!actionDeclaration.handler) {
95
+ return;
96
+ }
97
+
98
+ if (!actionDeclaration.handler.endsWith('.js')) {
99
+ throw new Error('Action handler must be a .js file.');
100
+ }
101
+ const CURRENT_DIR = process.cwd();
102
+ const isWin = process.platform === 'win32';
103
+ const separator = isWin ? '\\' : '/';
104
+
105
+ const functionLocaiton = CURRENT_DIR + separator + actionDeclaration.handler;
106
+ const content = fs.readFileSync(functionLocaiton);
107
+ return content.toString();
108
+ }
109
+ }
@@ -1,89 +1,86 @@
1
- import { Entities } from '@contrail/sdk';
2
- import chalk from 'chalk';
3
- import { config } from 'process';
4
- import { Auth } from '../auth/auth';
5
- import { ActionsDeployer } from './actions-deployer';
6
- import { App, AppDeclartion } from './interfaces';
7
-
8
- export class AppDeployer {
9
- private app: App;
10
- public async deploy(appDeclaration: AppDeclartion) {
11
- let app = await this.getExistingApp(appDeclaration);
12
- if (!app) {
13
- app = await this.createNewApp(appDeclaration);
14
- } else {
15
- app = await this.updateExistingApp(appDeclaration, app);
16
- }
17
- this.app = app;
18
- await new ActionsDeployer().deployActions(appDeclaration, this.app);
19
- }
20
-
21
- public async remove(appDeclaration: AppDeclartion) {
22
- let app = await this.getExistingApp(appDeclaration);
23
- if (app) {
24
- app = await new Entities().delete({ entityName: 'app', id: app.id});
25
- console.log(`%s Deleted app: ${app.name}`, chalk.yellow.bold('APP'));
26
- } else {
27
- console.log(`%s App not found. Can not remove`, chalk.red.bold('APP'));
28
- }
29
- }
30
-
31
- public async getExistingApp(appDeclaration: AppDeclartion) {
32
- const orgId = Auth.config.orgId;
33
- const apps = await new Entities().get({ entityName: 'app', criteria: {
34
- orgId,
35
- private: (appDeclaration.visibility === 'private')},
36
- });
37
- // console.log('Existing: ', apps);
38
- return apps.find(app => app.identifier === appDeclaration.appIdentifier);
39
- }
40
- public async updateExistingApp(appDeclaration: AppDeclartion, existingApp) {
41
- const updates = {
42
- name: appDeclaration.appName,
43
- public: appDeclaration.visibility === 'public',
44
- description: appDeclaration.appDescription,
45
- publisher: appDeclaration.publisher,
46
- thumbnail: appDeclaration.thumbnail,
47
- eventWorkflowTriggerKeyMapping: 'NONE',
48
- keywords: appDeclaration.keywords,
49
- configProperties: this.getAppConfigProperties(appDeclaration),
50
- };
51
- const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
52
- console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
53
- return app;
54
- }
55
- private async createNewApp(appDeclaration: AppDeclartion) {
56
- const newApp = {
57
- identifier: appDeclaration.appIdentifier,
58
- name: appDeclaration.appName,
59
- public: appDeclaration.visibility === 'public',
60
- description: appDeclaration.appDescription,
61
- publisher: appDeclaration.publisher,
62
- thumbnail: appDeclaration.thumbnail,
63
- eventWorkflowTriggerKeyMapping: 'NONE',
64
- keywords: appDeclaration.keywords,
65
- configProperties: this.getAppConfigProperties(appDeclaration),
66
- };
67
- const app = await new Entities().create({ entityName: 'app', object: newApp });
68
- console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
69
- return app;
70
-
71
- }
72
- private getAppConfigProperties(appDeclaration: AppDeclartion){
73
- const appConfiguration = [];
74
- for (const configKey of Object.keys(appDeclaration.appConfiguration)) {
75
- const declaration = appDeclaration.appConfiguration[configKey];
76
- const config: any = {
77
- label: declaration.label,
78
- slug: configKey,
79
- propertyType: declaration.propertyType,
80
- };
81
- if (declaration.options) {
82
- config.options = declaration.options;
83
- }
84
- appConfiguration.push(config);
85
- }
86
- return appConfiguration;
87
- }
88
-
89
- }
1
+ import { Entities } from '@contrail/sdk';
2
+ import chalk from 'chalk';
3
+ import { Auth } from '../auth/auth';
4
+ import { ActionsDeployer } from './actions-deployer';
5
+ import { App, AppDeclaration } from './interfaces';
6
+ import { TriggerKeyDefinitionParser, ConfigPropertiesParser } from './app-template-parsers';
7
+
8
+ export class AppDeployer {
9
+ public async deploy(appDeclaration: AppDeclaration) {
10
+ let app = await this.getExistingApp(appDeclaration);
11
+ if (!app) {
12
+ app = await this.createNewApp(appDeclaration);
13
+ } else {
14
+ app = await this.updateExistingApp(appDeclaration, app);
15
+ }
16
+ await new ActionsDeployer().deployActions(appDeclaration, app);
17
+ }
18
+
19
+ public async getExistingApp(appDeclaration: AppDeclaration): Promise<App> {
20
+ const orgId = Auth.config.orgId;
21
+ const apps = [];
22
+
23
+ apps.push(...await new Entities().get({
24
+ entityName: 'app',
25
+ criteria: {
26
+ orgId,
27
+ private: true,
28
+ },
29
+ }));
30
+ apps.push(...await new Entities().get({
31
+ entityName: 'app',
32
+ criteria: {
33
+ orgId,
34
+ private: false,
35
+ },
36
+ }));
37
+
38
+ return apps.find(app => app.identifier === appDeclaration.appIdentifier);
39
+ }
40
+
41
+ private async createNewApp(appDeclaration: AppDeclaration) {
42
+ const newApp = {
43
+ identifier: appDeclaration.appIdentifier,
44
+ name: appDeclaration.appName,
45
+ public: appDeclaration.visibility === 'public',
46
+ description: appDeclaration.appDescription,
47
+ publisher: appDeclaration.publisher,
48
+ thumbnail: appDeclaration.thumbnail,
49
+ eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
50
+ keywords: appDeclaration.keywords,
51
+ configProperties: ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration),
52
+ triggerKeyDefinitions: TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration),
53
+ };
54
+ const app = await new Entities().create({ entityName: 'app', object: newApp });
55
+ console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
56
+ return app;
57
+ }
58
+
59
+ public async updateExistingApp(appDeclaration: AppDeclaration, existingApp) {
60
+ const updates = {
61
+ name: appDeclaration.appName,
62
+ public: appDeclaration.visibility === 'public',
63
+ description: appDeclaration.appDescription,
64
+ publisher: appDeclaration.publisher,
65
+ thumbnail: appDeclaration.thumbnail,
66
+ eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
67
+ keywords: appDeclaration.keywords,
68
+ configProperties: ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration),
69
+ triggerKeyDefinitions: TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration),
70
+ };
71
+ const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
72
+ console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
73
+ return app;
74
+ }
75
+
76
+ public async remove(appDeclaration: AppDeclaration) {
77
+ let app = await this.getExistingApp(appDeclaration);
78
+ if (app) {
79
+ app = await new Entities().delete({ entityName: 'app', id: app.id });
80
+ console.log(`%s Deleted app: ${app.name}`, chalk.yellow.bold('APP'));
81
+ } else {
82
+ throw new Error('App not found.');
83
+ }
84
+ }
85
+
86
+ }
@@ -0,0 +1,43 @@
1
+ import { AppDeclaration, TriggerKeyDefinition, ConfigPropertyElements } from './interfaces';
2
+
3
+ export class TriggerKeyDefinitionParser {
4
+ public static buildTriggersArray(appDeclaration: AppDeclaration): Array<TriggerKeyDefinition> {
5
+ const triggers: Array<TriggerKeyDefinition> = [];
6
+
7
+ for (const triggerName of Object.keys(appDeclaration.triggers)) {
8
+ const triggerDeclaration = appDeclaration.triggers[triggerName];
9
+
10
+ const triggerDefinition = {
11
+ triggerKey: triggerDeclaration.external ? `${appDeclaration.appIdentifier}:${triggerDeclaration.key}` : triggerDeclaration.key,
12
+ name: triggerDeclaration.name,
13
+ external: triggerDeclaration.external,
14
+ description: triggerDeclaration.description,
15
+ };
16
+ if (!triggerDefinition.triggerKey || !triggerDefinition.name) {
17
+ throw new Error('Illegal trigger declaration: must have key and name');
18
+ }
19
+ triggers.push(triggerDefinition);
20
+
21
+ }
22
+ return triggers;
23
+ }
24
+ }
25
+
26
+ export class ConfigPropertiesParser {
27
+ public static getConfigProperties(configPropertyElements: ConfigPropertyElements) {
28
+ const appConfiguration = [];
29
+ for (const configKey of Object.keys(configPropertyElements)) {
30
+ const declaration = configPropertyElements[configKey];
31
+ const config: any = {
32
+ label: declaration.label,
33
+ slug: configKey,
34
+ propertyType: declaration.propertyType, // TODO should support options
35
+ };
36
+ if (declaration.options) {
37
+ config.options = declaration.options;
38
+ }
39
+ appConfiguration.push(config);
40
+ }
41
+ return appConfiguration;
42
+ }
43
+ }
@@ -1,34 +1,65 @@
1
- import chalk from 'chalk';
2
- import fs from 'fs';
3
- import { authUser } from '../auth/login';
4
- import { AppDeployer } from './app-deployer';
5
- import { AppDeclartion } from './interfaces';
6
- const yaml = require('js-yaml');
7
-
8
- function loadAppConfig(){
9
- const TARGET_DIR = process.cwd();
10
- try {
11
- const doc = yaml.load(fs.readFileSync(TARGET_DIR + '/app.yml', 'utf8'));
12
- console.log(doc);
13
- return doc;
14
- } catch (e) {
15
- console.log('ERROR PARSING YAML: ', e);
16
- }
17
- }
18
-
19
- export async function deployApp(args) {
20
- const appDeclaration: AppDeclartion = loadAppConfig();
21
-
22
- console.log(`%s Deploying application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
23
- const user = await authUser();
24
- await new AppDeployer().deploy(appDeclaration);
25
- console.log('%s Deployment complete.', chalk.green.bold('COMPLETE'));
26
- }
27
-
28
- export async function removeApp(args) {
29
- const appDeclaration: AppDeclartion = loadAppConfig();
30
- console.log(`%s Removing application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
31
- await authUser();
32
- await new AppDeployer().remove(appDeclaration);
33
- console.log('%s Removing complete.', chalk.green.bold('COMPLETE'));
1
+ import chalk from 'chalk';
2
+ import fs from 'fs';
3
+ import { authUser } from '../auth/login';
4
+ import { AppDeployer } from './app-deployer';
5
+ import { AppDeclaration } from './interfaces';
6
+ const yaml = require('js-yaml');
7
+
8
+ function loadAppConfig(){
9
+ const TARGET_DIR = process.cwd();
10
+ try {
11
+ const doc = yaml.load(fs.readFileSync(TARGET_DIR + '/app.yml', 'utf8'));
12
+ console.log(doc);
13
+ return doc;
14
+ } catch (e) {
15
+ throw new Error(`ERROR PARSING YAML: ${e}`);
16
+ }
17
+ }
18
+
19
+ export async function deployApp(args) {
20
+ let appDeclaration: AppDeclaration;
21
+ try {
22
+ appDeclaration = loadAppConfig();
23
+ }
24
+ catch (e) {
25
+ console.log(`%s Application Deployment Failed. ${e}`, chalk.red.bold('FAIL'));
26
+ return;
27
+ }
28
+
29
+ console.log(`%s Deploying Application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
30
+
31
+ try {
32
+ await authUser();
33
+ await new AppDeployer().deploy(appDeclaration);
34
+ }
35
+ catch (e) {
36
+ console.log(`%s Application Deployment Failed. ${e}`, chalk.red.bold('FAIL'));
37
+ return;
38
+ }
39
+
40
+ console.log('%s Deployment Complete.', chalk.green.bold('COMPLETE'));
41
+ }
42
+
43
+ export async function removeApp(args) {
44
+ let appDeclaration: AppDeclaration;
45
+ try {
46
+ appDeclaration = loadAppConfig();
47
+ }
48
+ catch (e) {
49
+ console.log(`%s Application Removal Failed. ${e}`, chalk.red.bold('FAIL'));
50
+ return;
51
+ }
52
+
53
+ console.log(`%s Removing Application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
54
+
55
+ try {
56
+ await authUser();
57
+ await new AppDeployer().remove(appDeclaration);
58
+ }
59
+ catch (e) {
60
+ console.log(`%s Application Removal Failed. ${e}`, chalk.red.bold('FAIL'));
61
+ return;
62
+ }
63
+
64
+ console.log('%s Application Removal Complete.', chalk.green.bold('COMPLETE'));
34
65
  }