@contrail/cli 1.0.0 → 1.0.5
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/.vscode/settings.json +5 -5
- package/bin/init +3 -3
- package/lib/{create-app → apps/create-app}/create.d.ts +1 -1
- package/lib/apps/create-app/create.js +59 -0
- package/lib/apps/create-app/setup-template.d.ts +1 -0
- package/lib/apps/create-app/setup-template.js +34 -0
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.d.ts +10 -10
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.js +97 -78
- package/lib/apps/deploy-app/app-deployer.d.ts +8 -0
- package/lib/{deploy-app → apps/deploy-app}/app-deployer.js +79 -58
- package/lib/apps/deploy-app/app-template-parsers.d.ts +7 -0
- package/lib/apps/deploy-app/app-template-parsers.js +37 -0
- package/lib/{deploy-app → apps/deploy-app}/deploy.d.ts +2 -2
- package/lib/apps/deploy-app/deploy.js +58 -0
- package/lib/apps/deploy-app/interfaces.d.ts +74 -0
- package/lib/apps/deploy-app/interfaces.js +4 -0
- package/lib/auth/auth.d.ts +9 -0
- package/lib/auth/auth.js +2 -0
- package/lib/auth/login.d.ts +2 -1
- package/lib/auth/login.js +113 -79
- package/lib/cli.d.ts +5 -5
- package/lib/cli.js +36 -30
- package/lib/common.d.ts +1 -0
- package/lib/common.js +5 -0
- package/lib/types/interfaces.d.ts +51 -0
- package/lib/{deploy-app → types}/interfaces.js +0 -0
- package/lib/types/option-set-uploader.d.ts +1 -0
- package/lib/types/option-set-uploader.js +75 -0
- package/lib/types/types-extractor.d.ts +1 -0
- package/lib/types/types-extractor.js +93 -0
- package/lib/types/types-uploader.d.ts +1 -0
- package/lib/types/types-uploader.js +171 -0
- package/package.json +63 -63
- package/publish.sh +5 -0
- package/src/apps/create-app/create.ts +73 -0
- package/src/apps/create-app/setup-template.ts +38 -0
- package/src/{deploy-app → apps/deploy-app}/actions-deployer.ts +122 -87
- package/src/{deploy-app → apps/deploy-app}/app-deployer.ts +86 -63
- package/src/apps/deploy-app/app-template-parsers.ts +43 -0
- package/src/apps/deploy-app/deploy.ts +67 -0
- package/src/apps/deploy-app/interfaces.ts +78 -0
- package/src/auth/auth.ts +10 -0
- package/src/auth/login.ts +127 -89
- package/src/cli.ts +38 -33
- package/src/common.ts +5 -0
- package/src/types/interfaces.ts +54 -0
- package/src/types/option-set-uploader.ts +83 -0
- package/src/types/types-extractor.ts +116 -0
- package/src/types/types-uploader.ts +198 -0
- package/templates/javascript/actions/example/action.js +37 -37
- package/templates/javascript/app.yml +54 -42
- package/templates/javascript/package.json +23 -23
- package/templates/typescript/actions/exampleAction.ts +38 -0
- package/templates/typescript/app.yml +56 -0
- package/templates/typescript/package.json +24 -0
- package/templates/typescript/tsconfig.json +31 -0
- package/tsconfig.json +30 -22
- package/tslint.json +57 -57
- package/lib/create-app/create.js +0 -48
- package/lib/create-app/setup-template.d.ts +0 -1
- package/lib/create-app/setup-template.js +0 -48
- package/lib/deploy-app/actions.d.ts +0 -5
- package/lib/deploy-app/actions.js +0 -17
- package/lib/deploy-app/app-declaration.d.ts +0 -20
- package/lib/deploy-app/app-declaration.js +0 -0
- package/lib/deploy-app/app-deployer.d.ts +0 -9
- package/lib/deploy-app/app.d.ts +0 -8
- package/lib/deploy-app/app.js +0 -56
- package/lib/deploy-app/deploy.js +0 -30
- package/lib/deploy-app/interfaces.d.ts +0 -34
- package/src/create-app/create.ts +0 -58
- package/src/create-app/setup-template.ts +0 -61
- package/src/deploy-app/deploy.ts +0 -34
- package/src/deploy-app/interfaces.ts +0 -35
package/.vscode/settings.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"editor.tabSize": 2,
|
|
3
|
-
"editor.codeActionsOnSave": {
|
|
4
|
-
"source.fixAll.tslint": true
|
|
5
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"editor.tabSize": 2,
|
|
3
|
+
"editor.codeActionsOnSave": {
|
|
4
|
+
"source.fixAll.tslint": true
|
|
5
|
+
}
|
|
6
6
|
}
|
package/bin/init
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
require = require('esm')(module /*, options*/);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
require = require('esm')(module /*, options*/);
|
|
4
4
|
require('../lib/cli').cli(process.argv);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function create(args: any): Promise<void>;
|
|
1
|
+
export declare function create(args: any): Promise<void>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import arg from 'arg';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { setUpTemplate } from './setup-template';
|
|
5
|
+
function parseArgumentsIntoOptions(rawArgs) {
|
|
6
|
+
const args = arg({
|
|
7
|
+
'--app-name': String,
|
|
8
|
+
'--template': String,
|
|
9
|
+
'-n': '--app-name',
|
|
10
|
+
'-t': '--template',
|
|
11
|
+
}, {
|
|
12
|
+
argv: rawArgs.slice(3),
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
appName: args['--app-name'],
|
|
16
|
+
template: args['--template'],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async function promptForMissingOptions(options) {
|
|
20
|
+
const defaultTemplate = 'JavaScript';
|
|
21
|
+
const questions = [];
|
|
22
|
+
if (!options.appName) {
|
|
23
|
+
questions.push({
|
|
24
|
+
type: 'input',
|
|
25
|
+
name: 'appName',
|
|
26
|
+
validate: (val) => !!val,
|
|
27
|
+
message: 'What is the name of your app?',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (!options.template) {
|
|
31
|
+
questions.push({
|
|
32
|
+
type: 'list',
|
|
33
|
+
name: 'template',
|
|
34
|
+
message: 'Which project template would you like to use?',
|
|
35
|
+
choices: ['JavaScript', 'TypeScript'],
|
|
36
|
+
default: defaultTemplate,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const answers = await inquirer.prompt(questions);
|
|
40
|
+
return Object.assign(Object.assign({}, options), { appName: options.appName || answers.appName, template: options.template || answers.template });
|
|
41
|
+
}
|
|
42
|
+
export async function create(args) {
|
|
43
|
+
let options = parseArgumentsIntoOptions(args);
|
|
44
|
+
options = await promptForMissingOptions(options);
|
|
45
|
+
console.log('%s Setting up new new contrail application.', chalk.blue.bold('START'));
|
|
46
|
+
let error;
|
|
47
|
+
try {
|
|
48
|
+
await setUpTemplate(options);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
error = e;
|
|
52
|
+
}
|
|
53
|
+
if (error) {
|
|
54
|
+
console.log('%s Application initialization failed.', chalk.red.bold('FAIL'));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log('%s Application initialized successfully.', chalk.green.bold('COMPLETE'));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setUpTemplate(options: any): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import ncp from 'ncp';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
const Listr = require('listr');
|
|
5
|
+
import { projectInstall } from 'pkg-install';
|
|
6
|
+
const copy = promisify(ncp);
|
|
7
|
+
const TARGET_DIR = process.cwd();
|
|
8
|
+
const currentFileUrl = import.meta.url;
|
|
9
|
+
function copyTemplate(templateDir) {
|
|
10
|
+
return copy(templateDir, TARGET_DIR, {
|
|
11
|
+
clobber: false,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export async function setUpTemplate(options) {
|
|
15
|
+
const templateDir = path.resolve(new URL(currentFileUrl).pathname, `../../../../templates/${options.template.toLocaleLowerCase()}`).replace(/\\/g, '\\').replace(/(.):\\(.):/g, '').replace(/%20/g, ' ');
|
|
16
|
+
try {
|
|
17
|
+
const tasks = new Listr([
|
|
18
|
+
{
|
|
19
|
+
title: 'Copy template files',
|
|
20
|
+
task: () => copyTemplate(templateDir),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: 'Install dependencies',
|
|
24
|
+
task: () => projectInstall({
|
|
25
|
+
cwd: TARGET_DIR,
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
await tasks.run();
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw new Error(`Error copying template: ${e}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { App,
|
|
2
|
-
export declare class ActionsDeployer {
|
|
3
|
-
deployActions(appDeclaration:
|
|
4
|
-
getActionsForApp(app: App): Promise<any>;
|
|
5
|
-
deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>): Promise<void>;
|
|
6
|
-
private createNewActionDefinition;
|
|
7
|
-
private updateActionDefinition;
|
|
8
|
-
getActionDeclarationIdentifier(actionKey: any, app: App): string;
|
|
9
|
-
getFunction(actionDeclaration: AppActionDeclaration): Promise<string>;
|
|
10
|
-
}
|
|
1
|
+
import { App, AppDeclaration, AppActionDeclaration } from './interfaces';
|
|
2
|
+
export declare class ActionsDeployer {
|
|
3
|
+
deployActions(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
4
|
+
getActionsForApp(app: App): Promise<any>;
|
|
5
|
+
deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>): Promise<void>;
|
|
6
|
+
private createNewActionDefinition;
|
|
7
|
+
private updateActionDefinition;
|
|
8
|
+
getActionDeclarationIdentifier(actionKey: any, app: App): string;
|
|
9
|
+
getFunction(actionDeclaration: AppActionDeclaration): Promise<string>;
|
|
10
|
+
}
|
|
@@ -1,78 +1,97 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
await this.
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { ConfigPropertiesParser } from './app-template-parsers';
|
|
4
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
export class ActionsDeployer {
|
|
7
|
+
async deployActions(appDeclaration, app) {
|
|
8
|
+
// FETCH ALL ACTIONS FROM THE API.
|
|
9
|
+
const existingActions = await this.getActionsForApp(app);
|
|
10
|
+
// UPSERT / DELETE BASED ON ACTION IDENTIFIER
|
|
11
|
+
console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
|
|
12
|
+
for (const actionKey of Object.keys(appDeclaration.actions)) {
|
|
13
|
+
await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async getActionsForApp(app) {
|
|
17
|
+
return await new Entities().get({
|
|
18
|
+
entityName: 'event-workflow-action-definition',
|
|
19
|
+
criteria: { ownerKey: `app:${app.id}` },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async deployAction(actionKey, actionDeclaration, app, existingActions) {
|
|
23
|
+
console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
|
|
24
|
+
const identifier = this.getActionDeclarationIdentifier(actionKey, app);
|
|
25
|
+
const existingDefinition = existingActions.find(ad => ad.identifier === identifier);
|
|
26
|
+
if (!existingDefinition) {
|
|
27
|
+
await this.createNewActionDefinition(actionKey, actionDeclaration, app);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
await this.updateActionDefinition(existingDefinition, actionDeclaration);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async createNewActionDefinition(actionKey, actionDeclaration, app) {
|
|
34
|
+
let configProperties;
|
|
35
|
+
if (actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) {
|
|
36
|
+
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
37
|
+
}
|
|
38
|
+
const newObject = {
|
|
39
|
+
identifier: this.getActionDeclarationIdentifier(actionKey, app),
|
|
40
|
+
name: actionDeclaration.name,
|
|
41
|
+
ownerKey: `app:${app.id}`,
|
|
42
|
+
public: app.public,
|
|
43
|
+
configProperties,
|
|
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
|
+
});
|
|
53
|
+
console.log(`%s Created new action definition: ${actionKey}`, chalk.yellow.bold('APP'));
|
|
54
|
+
return actionDefinition;
|
|
55
|
+
}
|
|
56
|
+
async updateActionDefinition(existingActionDefinition, actionDeclaration) {
|
|
57
|
+
let configProperties;
|
|
58
|
+
if (actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) {
|
|
59
|
+
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
60
|
+
}
|
|
61
|
+
else if (!(actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) && existingActionDefinition.configProperties) {
|
|
62
|
+
configProperties = null;
|
|
63
|
+
}
|
|
64
|
+
const updates = {
|
|
65
|
+
name: actionDeclaration.name,
|
|
66
|
+
// public: actionDeclaration.public, // TODO - an actions visibility is allowed to change
|
|
67
|
+
configProperties,
|
|
68
|
+
};
|
|
69
|
+
const functionString = await this.getFunction(actionDeclaration);
|
|
70
|
+
if (functionString) {
|
|
71
|
+
updates.executeFunctionString = functionString;
|
|
72
|
+
}
|
|
73
|
+
const actionDefinition = await new Entities().update({
|
|
74
|
+
entityName: 'event-workflow-action-definition',
|
|
75
|
+
id: existingActionDefinition.id,
|
|
76
|
+
object: updates,
|
|
77
|
+
});
|
|
78
|
+
console.log(`%s Updated existingaction defintion: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
|
|
79
|
+
return actionDefinition;
|
|
80
|
+
}
|
|
81
|
+
getActionDeclarationIdentifier(actionKey, app) {
|
|
82
|
+
return app.identifier + ':' + actionKey;
|
|
83
|
+
}
|
|
84
|
+
async getFunction(actionDeclaration) {
|
|
85
|
+
if (!actionDeclaration.handler) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!actionDeclaration.handler.endsWith('.js')) {
|
|
89
|
+
throw new Error('Action handler must be a .js file.');
|
|
90
|
+
}
|
|
91
|
+
const CURRENT_DIR = process.cwd();
|
|
92
|
+
const separator = getSeparatorByPlatform();
|
|
93
|
+
const functionLocation = CURRENT_DIR + separator + actionDeclaration.handler;
|
|
94
|
+
const content = fs.readFileSync(functionLocation);
|
|
95
|
+
return content.toString();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { App, AppDeclaration } from './interfaces';
|
|
2
|
+
export declare class AppDeployer {
|
|
3
|
+
deploy(appDeclaration: AppDeclaration): Promise<void>;
|
|
4
|
+
getExistingApp(appDeclaration: AppDeclaration): Promise<App>;
|
|
5
|
+
private createNewApp;
|
|
6
|
+
updateExistingApp(appDeclaration: AppDeclaration, existingApp: any): Promise<any>;
|
|
7
|
+
remove(appDeclaration: AppDeclaration): Promise<void>;
|
|
8
|
+
}
|
|
@@ -1,58 +1,79 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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 { TriggerKeyDefinitionParser, ConfigPropertiesParser } from './app-template-parsers';
|
|
6
|
+
export class AppDeployer {
|
|
7
|
+
async deploy(appDeclaration) {
|
|
8
|
+
let app = await this.getExistingApp(appDeclaration);
|
|
9
|
+
if (!app) {
|
|
10
|
+
app = await this.createNewApp(appDeclaration);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
app = await this.updateExistingApp(appDeclaration, app);
|
|
14
|
+
}
|
|
15
|
+
await new ActionsDeployer().deployActions(appDeclaration, app);
|
|
16
|
+
}
|
|
17
|
+
async getExistingApp(appDeclaration) {
|
|
18
|
+
const orgId = Auth.config.orgId;
|
|
19
|
+
const apps = [];
|
|
20
|
+
apps.push(...await new Entities().get({
|
|
21
|
+
entityName: 'app',
|
|
22
|
+
criteria: {
|
|
23
|
+
orgId,
|
|
24
|
+
private: true,
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
apps.push(...await new Entities().get({
|
|
28
|
+
entityName: 'app',
|
|
29
|
+
criteria: {
|
|
30
|
+
orgId,
|
|
31
|
+
private: false,
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
return apps.find(app => app.identifier === appDeclaration.appIdentifier);
|
|
35
|
+
}
|
|
36
|
+
async createNewApp(appDeclaration) {
|
|
37
|
+
const newApp = {
|
|
38
|
+
identifier: appDeclaration.appIdentifier,
|
|
39
|
+
name: appDeclaration.appName,
|
|
40
|
+
public: appDeclaration.visibility === 'public',
|
|
41
|
+
description: appDeclaration.appDescription,
|
|
42
|
+
publisher: appDeclaration.publisher,
|
|
43
|
+
thumbnail: appDeclaration.thumbnail,
|
|
44
|
+
eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
|
|
45
|
+
keywords: appDeclaration.keywords,
|
|
46
|
+
configProperties: ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration),
|
|
47
|
+
triggerKeyDefinitions: TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration),
|
|
48
|
+
};
|
|
49
|
+
const app = await new Entities().create({ entityName: 'app', object: newApp });
|
|
50
|
+
console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
51
|
+
return app;
|
|
52
|
+
}
|
|
53
|
+
async updateExistingApp(appDeclaration, existingApp) {
|
|
54
|
+
const updates = {
|
|
55
|
+
name: appDeclaration.appName,
|
|
56
|
+
public: appDeclaration.visibility === 'public',
|
|
57
|
+
description: appDeclaration.appDescription,
|
|
58
|
+
publisher: appDeclaration.publisher,
|
|
59
|
+
thumbnail: appDeclaration.thumbnail,
|
|
60
|
+
eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
|
|
61
|
+
keywords: appDeclaration.keywords,
|
|
62
|
+
configProperties: ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration),
|
|
63
|
+
triggerKeyDefinitions: TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration),
|
|
64
|
+
};
|
|
65
|
+
const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
|
|
66
|
+
console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
67
|
+
return app;
|
|
68
|
+
}
|
|
69
|
+
async remove(appDeclaration) {
|
|
70
|
+
let app = await this.getExistingApp(appDeclaration);
|
|
71
|
+
if (app) {
|
|
72
|
+
app = await new Entities().delete({ entityName: 'app', id: app.id });
|
|
73
|
+
console.log(`%s Deleted app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw new Error('App not found.');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AppDeclaration, TriggerKeyDefinition, ConfigPropertyElements } from './interfaces';
|
|
2
|
+
export declare class TriggerKeyDefinitionParser {
|
|
3
|
+
static buildTriggersArray(appDeclaration: AppDeclaration): Array<TriggerKeyDefinition>;
|
|
4
|
+
}
|
|
5
|
+
export declare class ConfigPropertiesParser {
|
|
6
|
+
static getConfigProperties(configPropertyElements: ConfigPropertyElements): any[];
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class TriggerKeyDefinitionParser {
|
|
2
|
+
static buildTriggersArray(appDeclaration) {
|
|
3
|
+
const triggers = [];
|
|
4
|
+
for (const triggerName of Object.keys(appDeclaration.triggers)) {
|
|
5
|
+
const triggerDeclaration = appDeclaration.triggers[triggerName];
|
|
6
|
+
const triggerDefinition = {
|
|
7
|
+
triggerKey: triggerDeclaration.external ? `${appDeclaration.appIdentifier}:${triggerDeclaration.key}` : triggerDeclaration.key,
|
|
8
|
+
name: triggerDeclaration.name,
|
|
9
|
+
external: triggerDeclaration.external,
|
|
10
|
+
description: triggerDeclaration.description,
|
|
11
|
+
};
|
|
12
|
+
if (!triggerDefinition.triggerKey || !triggerDefinition.name) {
|
|
13
|
+
throw new Error('Illegal trigger declaration: must have key and name');
|
|
14
|
+
}
|
|
15
|
+
triggers.push(triggerDefinition);
|
|
16
|
+
}
|
|
17
|
+
return triggers;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class ConfigPropertiesParser {
|
|
21
|
+
static getConfigProperties(configPropertyElements) {
|
|
22
|
+
const appConfiguration = [];
|
|
23
|
+
for (const configKey of Object.keys(configPropertyElements)) {
|
|
24
|
+
const declaration = configPropertyElements[configKey];
|
|
25
|
+
const config = {
|
|
26
|
+
label: declaration.label,
|
|
27
|
+
slug: configKey,
|
|
28
|
+
propertyType: declaration.propertyType,
|
|
29
|
+
};
|
|
30
|
+
if (declaration.options) {
|
|
31
|
+
config.options = declaration.options;
|
|
32
|
+
}
|
|
33
|
+
appConfiguration.push(config);
|
|
34
|
+
}
|
|
35
|
+
return appConfiguration;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function deployApp(args: any): Promise<void>;
|
|
2
|
-
export declare function removeApp(args: any): Promise<void>;
|
|
1
|
+
export declare function deployApp(args: any): Promise<void>;
|
|
2
|
+
export declare function removeApp(args: any): Promise<void>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { authUser } from '../../auth/login';
|
|
4
|
+
import { AppDeployer } from './app-deployer';
|
|
5
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
6
|
+
const yaml = require('js-yaml');
|
|
7
|
+
function loadAppConfig() {
|
|
8
|
+
const TARGET_DIR = process.cwd();
|
|
9
|
+
try {
|
|
10
|
+
const separator = getSeparatorByPlatform();
|
|
11
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'app.yml', 'utf8'));
|
|
12
|
+
console.log(doc);
|
|
13
|
+
return doc;
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function deployApp(args) {
|
|
20
|
+
let 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
|
+
console.log(`%s Deploying Application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
|
|
29
|
+
try {
|
|
30
|
+
await authUser();
|
|
31
|
+
await new AppDeployer().deploy(appDeclaration);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
console.log(`%s Application Deployment Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
console.log('%s Deployment Complete.', chalk.green.bold('COMPLETE'));
|
|
38
|
+
}
|
|
39
|
+
export async function removeApp(args) {
|
|
40
|
+
let appDeclaration;
|
|
41
|
+
try {
|
|
42
|
+
appDeclaration = loadAppConfig();
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.log(`%s Application Removal Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log(`%s Removing Application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
|
|
49
|
+
try {
|
|
50
|
+
await authUser();
|
|
51
|
+
await new AppDeployer().remove(appDeclaration);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.log(`%s Application Removal Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
console.log('%s Application Removal Complete.', chalk.green.bold('COMPLETE'));
|
|
58
|
+
}
|