@contrail/cli 1.0.2 → 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/.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 -75
- package/lib/apps/deploy-app/app-deployer.d.ts +8 -0
- package/lib/{deploy-app → apps/deploy-app}/app-deployer.js +79 -84
- 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 -9
- package/lib/auth/auth.js +2 -2
- package/lib/auth/login.d.ts +2 -1
- package/lib/auth/login.js +113 -96
- 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 +95 -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 -84
- package/src/{deploy-app → apps/deploy-app}/app-deployer.ts +86 -89
- 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 +9 -9
- package/src/auth/login.ts +126 -107
- 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 +120 -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 +39 -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 -10
- 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 -43
- package/src/create-app/create.ts +0 -58
- package/src/create-app/setup-template.ts +0 -57
- package/src/deploy-app/deploy.ts +0 -34
- package/src/deploy-app/interfaces.ts +0 -43
package/lib/deploy-app/app.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
export class AppDeployer {
|
|
4
|
-
async deploy(appDeclaration) {
|
|
5
|
-
let app = await this.getExistingApp(appDeclaration);
|
|
6
|
-
if (!app) {
|
|
7
|
-
app = await this.createNewApp(appDeclaration);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
app = await this.updateExistingApp(appDeclaration, app);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
async remove(appDeclaration) {
|
|
14
|
-
const app = await this.getExistingApp(appDeclaration);
|
|
15
|
-
if (app) {
|
|
16
|
-
await new Entities().delete({ entityName: 'app', id: app.id });
|
|
17
|
-
console.log(`%s Deleted app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
console.log(`%s App not found. Can not remove`, chalk.red.bold('APP'));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
async getExistingApp(appDeclaration) {
|
|
24
|
-
const apps = await new Entities().get({ entityName: 'app', criteria: { orgId: '-VMrLJrt3clDKPi0', private: (appDeclaration.visibility === 'private') } });
|
|
25
|
-
console.log('Existing: ', apps);
|
|
26
|
-
const existing = apps.find(app => app.identifier === appDeclaration.appIdentifier);
|
|
27
|
-
return existing;
|
|
28
|
-
}
|
|
29
|
-
async updateExistingApp(appDeclaration, existingApp) {
|
|
30
|
-
const updates = {
|
|
31
|
-
name: appDeclaration.appName,
|
|
32
|
-
public: appDeclaration.visibility === 'public',
|
|
33
|
-
description: appDeclaration.appDescription,
|
|
34
|
-
publisher: appDeclaration.publisher,
|
|
35
|
-
thumbnail: appDeclaration.thumbnail,
|
|
36
|
-
eventWorkflowTriggerKeyMapping: 'NONE',
|
|
37
|
-
};
|
|
38
|
-
const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
|
|
39
|
-
console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
40
|
-
return app;
|
|
41
|
-
}
|
|
42
|
-
async createNewApp(appDeclaration) {
|
|
43
|
-
const newApp = {
|
|
44
|
-
identifier: appDeclaration.appIdentifier,
|
|
45
|
-
name: appDeclaration.appName,
|
|
46
|
-
public: appDeclaration.visibility === 'public',
|
|
47
|
-
description: appDeclaration.appDescription,
|
|
48
|
-
publisher: appDeclaration.publisher,
|
|
49
|
-
thumbnail: appDeclaration.thumbnail,
|
|
50
|
-
eventWorkflowTriggerKeyMapping: 'NONE',
|
|
51
|
-
};
|
|
52
|
-
const app = await new Entities().create({ entityName: 'app', object: newApp });
|
|
53
|
-
console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
54
|
-
return app;
|
|
55
|
-
}
|
|
56
|
-
}
|
package/lib/deploy-app/deploy.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { authUser } from '../auth/login';
|
|
4
|
-
import { AppDeployer } from './app-deployer';
|
|
5
|
-
const yaml = require('js-yaml');
|
|
6
|
-
function loadAppConfig() {
|
|
7
|
-
const TARGET_DIR = process.cwd();
|
|
8
|
-
try {
|
|
9
|
-
const doc = yaml.load(fs.readFileSync(TARGET_DIR + '/app.yml', 'utf8'));
|
|
10
|
-
console.log(doc);
|
|
11
|
-
return doc;
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
console.log('ERROR PARSING YAML: ', e);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export async function deployApp(args) {
|
|
18
|
-
const appDeclaration = loadAppConfig();
|
|
19
|
-
console.log(`%s Deploying application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
|
|
20
|
-
const user = await authUser();
|
|
21
|
-
await new AppDeployer().deploy(appDeclaration);
|
|
22
|
-
console.log('%s Deployment complete.', chalk.green.bold('COMPLETE'));
|
|
23
|
-
}
|
|
24
|
-
export async function removeApp(args) {
|
|
25
|
-
const appDeclaration = loadAppConfig();
|
|
26
|
-
console.log(`%s Removing application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
|
|
27
|
-
await authUser();
|
|
28
|
-
await new AppDeployer().remove(appDeclaration);
|
|
29
|
-
console.log('%s Removing complete.', chalk.green.bold('COMPLETE'));
|
|
30
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/** Describes the derivative JSON / object represented
|
|
2
|
-
* in app.yml file.
|
|
3
|
-
*/
|
|
4
|
-
export interface AppDeclartion {
|
|
5
|
-
appIdentifier: string;
|
|
6
|
-
appName: string;
|
|
7
|
-
appDescription?: string;
|
|
8
|
-
visibility: 'private' | 'public';
|
|
9
|
-
publisher: string;
|
|
10
|
-
version: string;
|
|
11
|
-
thumbnail?: string;
|
|
12
|
-
keywords?: Array<string>;
|
|
13
|
-
actions?: {
|
|
14
|
-
[key: string]: AppActionDeclaration;
|
|
15
|
-
};
|
|
16
|
-
appConfiguration: {
|
|
17
|
-
[key: string]: AppConfigurationElement;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export interface AppConfigurationElement {
|
|
21
|
-
propertyType: string;
|
|
22
|
-
options?: any[];
|
|
23
|
-
label: string;
|
|
24
|
-
}
|
|
25
|
-
export interface AppActionDeclaration {
|
|
26
|
-
handler: string;
|
|
27
|
-
name: string;
|
|
28
|
-
description?: string;
|
|
29
|
-
}
|
|
30
|
-
export interface App {
|
|
31
|
-
id: string;
|
|
32
|
-
identifier: string;
|
|
33
|
-
name: string;
|
|
34
|
-
private: boolean;
|
|
35
|
-
}
|
|
36
|
-
export interface EventWorkflowActionDefinition {
|
|
37
|
-
id?: string;
|
|
38
|
-
identifier?: string;
|
|
39
|
-
name?: string;
|
|
40
|
-
executeFunctionString?: string;
|
|
41
|
-
ownerKey?: string;
|
|
42
|
-
public?: boolean;
|
|
43
|
-
}
|
package/src/create-app/create.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import arg from 'arg';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import ncp from 'ncp';
|
|
4
|
-
import chalk from 'chalk'
|
|
5
|
-
import { setUpTemplate } from './setup-template';
|
|
6
|
-
|
|
7
|
-
function parseArgumentsIntoOptions(rawArgs) {
|
|
8
|
-
const args = arg(
|
|
9
|
-
{
|
|
10
|
-
'--create-app': Boolean,
|
|
11
|
-
'--app-name': String,
|
|
12
|
-
'-c': '--create-app',
|
|
13
|
-
'-n': '--app-name',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
argv: rawArgs.slice(2),
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
return {
|
|
20
|
-
createApp: args['--create-app'] || false,
|
|
21
|
-
appName: args['--app-name']
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
async function promptForMissingOptions(options) {
|
|
25
|
-
const defaultTemplate = 'JavaScript';
|
|
26
|
-
if (options.skipPrompts) {
|
|
27
|
-
return {
|
|
28
|
-
...options,
|
|
29
|
-
template: options.template || defaultTemplate,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const questions = [];
|
|
34
|
-
if (!options.appName) {
|
|
35
|
-
questions.push({
|
|
36
|
-
type: 'input',
|
|
37
|
-
name: 'appName',
|
|
38
|
-
validate: (val) => { return !!val },
|
|
39
|
-
message: 'What is the name of your app?',
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const answers = await inquirer.prompt(questions);
|
|
44
|
-
return {
|
|
45
|
-
...options,
|
|
46
|
-
appName: options.appName || answers.appName,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export async function create(args) {
|
|
52
|
-
|
|
53
|
-
let options = parseArgumentsIntoOptions(args);
|
|
54
|
-
options = await promptForMissingOptions(options);
|
|
55
|
-
console.log("%s Setting up new new contrail application.", chalk.blue.bold('START'));
|
|
56
|
-
await setUpTemplate();
|
|
57
|
-
console.log('%s Application initialized successfully.', chalk.green.bold('COMPLETE'));
|
|
58
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
}
|
|
57
|
-
}
|
package/src/deploy-app/deploy.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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'));
|
|
34
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/** Describes the derivative JSON / object represented
|
|
2
|
-
* in app.yml file.
|
|
3
|
-
*/
|
|
4
|
-
export interface AppDeclartion {
|
|
5
|
-
appIdentifier: string;
|
|
6
|
-
appName: string;
|
|
7
|
-
appDescription?: string;
|
|
8
|
-
visibility: 'private' | 'public';
|
|
9
|
-
publisher: string;
|
|
10
|
-
version: string;
|
|
11
|
-
thumbnail?: string;
|
|
12
|
-
keywords?: Array<string>;
|
|
13
|
-
actions?: { [key: string]: AppActionDeclaration };
|
|
14
|
-
appConfiguration: { [key: string]: AppConfigurationElement };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface AppConfigurationElement {
|
|
18
|
-
propertyType: string;
|
|
19
|
-
options?: any[];
|
|
20
|
-
label: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface AppActionDeclaration {
|
|
24
|
-
handler: string;
|
|
25
|
-
name: string;
|
|
26
|
-
description?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface App {
|
|
30
|
-
id: string;
|
|
31
|
-
identifier: string;
|
|
32
|
-
name: string;
|
|
33
|
-
private: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface EventWorkflowActionDefinition {
|
|
37
|
-
id?: string;
|
|
38
|
-
identifier?: string;
|
|
39
|
-
name?: string;
|
|
40
|
-
executeFunctionString?: string;
|
|
41
|
-
ownerKey?: string;
|
|
42
|
-
public?: boolean;
|
|
43
|
-
}
|