@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
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "@contrail/cli",
3
- "version": "1.0.2",
4
- "description": "VibeIQ's Contrail Platform CLI.",
5
- "main": "lib/index.js",
6
- "bin": {
7
- "@contrail/contrail-cli": "bin/init",
8
- "contrail": "bin/init"
9
- },
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "keywords": [
14
- "cli",
15
- "contrail-cli"
16
- ],
17
- "scripts": {
18
- "build": "tsc",
19
- "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
20
- "lint": "tslint -p tsconfig.json",
21
- "test": "jest --watch"
22
- },
23
- "author": "",
24
- "license": "ISC",
25
- "dependencies": {
26
- "@contrail/sdk": "^1.0.91",
27
- "amazon-cognito-identity-js": "^5.2.3",
28
- "arg": "^4.0.1",
29
- "aws-sdk": "^2.1044.0",
30
- "chalk": "^4.0.0",
31
- "esm": "^3.2.25",
32
- "execa": "^5.0.0",
33
- "inquirer": "^8.2.0",
34
- "js-yaml": "^4.1.0",
35
- "listr": "^0.14.3",
36
- "ncp": "^2.0.0",
37
- "pkg-install": "^1.0.0"
38
- },
39
- "devDependencies": {
40
- "@types/jest": "^23.3.14",
41
- "jest": "^23.6.0",
42
- "prettier": "^1.19.1",
43
- "ts-jest": "^23.10.5",
44
- "tslint": "^5.11.0",
45
- "tslint-config-prettier": "^1.18.0",
46
- "typescript": "^3.0.1",
47
- "@types/node": "^14.6.4"
48
- },
49
- "jest": {
50
- "moduleFileExtensions": [
51
- "js",
52
- "json",
53
- "ts"
54
- ],
55
- "rootDir": "src",
56
- "testRegex": ".spec.ts$",
57
- "transform": {
58
- "^.+\\.(t|j)s$": "ts-jest"
59
- },
60
- "coverageDirectory": "../coverage",
61
- "testEnvironment": "node"
62
- }
63
- }
1
+ {
2
+ "name": "@contrail/cli",
3
+ "version": "1.0.3",
4
+ "description": "VibeIQ's Contrail Platform CLI.",
5
+ "main": "lib/index.js",
6
+ "bin": {
7
+ "@contrail/contrail-cli": "bin/init",
8
+ "contrail": "bin/init"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "keywords": [
14
+ "cli",
15
+ "contrail-cli"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
20
+ "lint": "tslint -p tsconfig.json",
21
+ "test": "jest --watch"
22
+ },
23
+ "author": "",
24
+ "license": "ISC",
25
+ "dependencies": {
26
+ "@contrail/sdk": "^1.0.91",
27
+ "amazon-cognito-identity-js": "^5.2.3",
28
+ "arg": "^4.0.1",
29
+ "aws-sdk": "^2.1044.0",
30
+ "chalk": "^4.0.0",
31
+ "esm": "^3.2.25",
32
+ "execa": "^5.0.0",
33
+ "inquirer": "^8.2.0",
34
+ "js-yaml": "^4.1.0",
35
+ "listr": "^0.14.3",
36
+ "ncp": "^2.0.0",
37
+ "pkg-install": "^1.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/jest": "^23.3.14",
41
+ "jest": "^23.6.0",
42
+ "prettier": "^1.19.1",
43
+ "ts-jest": "^23.10.5",
44
+ "tslint": "^5.11.0",
45
+ "tslint-config-prettier": "^1.18.0",
46
+ "typescript": "^3.0.1",
47
+ "@types/node": "^14.6.4"
48
+ },
49
+ "jest": {
50
+ "moduleFileExtensions": [
51
+ "js",
52
+ "json",
53
+ "ts"
54
+ ],
55
+ "rootDir": "src",
56
+ "testRegex": ".spec.ts$",
57
+ "transform": {
58
+ "^.+\\.(t|j)s$": "ts-jest"
59
+ },
60
+ "coverageDirectory": "../coverage",
61
+ "testEnvironment": "node"
62
+ }
63
+ }
package/publish.sh ADDED
@@ -0,0 +1,5 @@
1
+ rm -rf lib;
2
+ npm install;
3
+ npm run build;
4
+ npm version patch;
5
+ npm publish;
package/src/auth/auth.ts CHANGED
@@ -1,10 +1,10 @@
1
- export interface AuthContext {
2
- apiUserToken: string;
3
- apiGateway?: string;
4
- orgSlug?: string;
5
- orgId?: string;
6
- }
7
-
8
- export class Auth {
9
- public static config: AuthContext;
1
+ export interface AuthContext {
2
+ apiUserToken: string;
3
+ apiGateway?: string;
4
+ orgSlug?: string;
5
+ orgId?: string;
6
+ }
7
+
8
+ export class Auth {
9
+ public static config: AuthContext;
10
10
  }
package/src/auth/login.ts CHANGED
@@ -1,108 +1,125 @@
1
- const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
2
- import inquirer from 'inquirer';
3
- import { Entities, Request, setConfig } from '@contrail/sdk';
4
- import { Auth } from './auth';
5
-
6
- const CONFIGURATION = {
7
- userPoolId: 'us-east-1_x8hXZUsL6',
8
- clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
9
- };
10
-
11
- export async function authUser(){
12
- const questions = [];
13
- if (!process.env.CONTRAIL_CLI_EMAIL) {
14
- questions.push({
15
- type: 'input',
16
- name: 'email',
17
- validate: (val) => !!val,
18
- message: 'Email',
19
- });
20
- }
21
- if (!process.env.CONTRAIL_CLI_PASSWORD) {
22
- questions.push({
23
- type: 'password',
24
- name: 'password',
25
- validate: (val) => !!val,
26
- message: 'Password',
27
- });
28
- }
29
- if (!process.env.CONTRAIL_CLI_ORGSLUG) {
30
- questions.push({
31
- type: 'input',
32
- name: 'orgSlug',
33
- validate: (val) => !!val,
34
- message: 'Org (slug)',
35
- });
36
- }
37
-
38
- const answers = await inquirer.prompt(questions);
39
- const params = {
40
- email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
41
- password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
42
- orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
43
- };
44
- if (!params.email || !params.password){
45
- throw new Error('email and password required');
46
- }
47
-
48
- const poolData = {
49
- UserPoolId: CONFIGURATION.userPoolId,
50
- ClientId: CONFIGURATION.clientId,
51
- };
52
-
53
- const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
54
- const authData = {
55
- Username: params.email,
56
- Password: params.password,
57
- };
58
-
59
- const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
60
- const userData = {
61
- Username: params.email,
62
- Pool: userPool,
63
- };
64
-
65
- const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
66
-
67
- return new Promise( (resolve, reject) => {
68
- cognitoUser.authenticateUser(authDetails, {
69
- onSuccess: async (result) => {
70
- const user = result;
71
- await setAuthContext(user, params);
72
-
73
- resolve({success: true, data: result});
74
- },
75
- onFailure: (err) => {
76
- console.log('authUser error: ' + err);
77
- reject(err);
78
- },
79
- });
80
- });
81
- }
82
-
83
- async function setAuthContext(user, params){
84
-
85
- // Set Auth Config
86
- Auth.config = {
87
- apiUserToken: user.idToken.jwtToken,
88
- apiGateway: process.env.API_GATEWAY,
89
- orgSlug: params.orgSlug,
90
- };
91
- // SET SDK CONFIG
92
- setConfig(Auth.config);
93
-
94
- const currentUser = await Request.request('/users/current', {
95
- method: 'GET',
96
- headers: {
97
- 'Accept': 'application/json',
98
- 'Content-Type': 'application/json',
99
- },
100
- });
101
- if (!currentUser) {
102
- throw Error('Could not get current user');
103
- }
104
- const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
105
- if (org) {
106
- Auth.config.orgId = org.orgId || org.id;
107
- }
1
+ const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
2
+ import inquirer from 'inquirer';
3
+ import { Request, setConfig } from '@contrail/sdk';
4
+ import { Auth } from './auth';
5
+
6
+ const CONFIGURATION = {
7
+ userPoolId: 'us-east-1_x8hXZUsL6',
8
+ clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
9
+ };
10
+
11
+ export async function authUser(){
12
+ const questions = [];
13
+ if (!process.env.CONTRAIL_CLI_EMAIL) {
14
+ questions.push({
15
+ type: 'input',
16
+ name: 'email',
17
+ validate: (val) => !!val,
18
+ message: 'Email',
19
+ });
20
+ }
21
+ if (!process.env.CONTRAIL_CLI_PASSWORD) {
22
+ questions.push({
23
+ type: 'password',
24
+ name: 'password',
25
+ validate: (val) => !!val,
26
+ message: 'Password',
27
+ });
28
+ }
29
+ if (!process.env.CONTRAIL_CLI_ORGSLUG) {
30
+ questions.push({
31
+ type: 'input',
32
+ name: 'orgSlug',
33
+ validate: (val) => !!val,
34
+ message: 'Org (slug)',
35
+ });
36
+ }
37
+
38
+ const answers = await inquirer.prompt(questions);
39
+ const params = {
40
+ email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
41
+ password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
42
+ orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
43
+ };
44
+ if (!params.email || !params.password){
45
+ throw new Error('Email and Password required');
46
+ }
47
+
48
+ const poolData = {
49
+ UserPoolId: CONFIGURATION.userPoolId,
50
+ ClientId: CONFIGURATION.clientId,
51
+ };
52
+
53
+ const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
54
+ const authData = {
55
+ Username: params.email,
56
+ Password: params.password,
57
+ };
58
+
59
+ const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
60
+ const userData = {
61
+ Username: params.email,
62
+ Pool: userPool,
63
+ };
64
+
65
+ const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
66
+
67
+ return new Promise( (resolve, reject) => {
68
+ cognitoUser.authenticateUser(authDetails, {
69
+ onSuccess: async (result) => {
70
+ const user = result;
71
+ await setAuthContext(user, params);
72
+
73
+ resolve({success: true, data: result});
74
+ },
75
+ onFailure: (err) => {
76
+ reject(err);
77
+ },
78
+ });
79
+ });
80
+ }
81
+
82
+ async function setAuthContext(user, params){
83
+
84
+ // TODO Dont allow user to set this - they could set dev
85
+ const questions = [];
86
+ questions.push({
87
+ type: 'list',
88
+ name: 'environment',
89
+ message: 'Which environment would you like to use?',
90
+ choices: ['Dev', 'Prod'],
91
+ default: 'Dev',
92
+ });
93
+
94
+ let apiGateway;
95
+ const answers = await inquirer.prompt(questions);
96
+ if (answers.environment === 'Dev') {
97
+ apiGateway = 'https://api.vibeiq.com/dev/api';
98
+ } else {
99
+ apiGateway = 'https://api.vibeiq.com/prod/api';
100
+ }
101
+
102
+ // Set Auth Config
103
+ Auth.config = {
104
+ apiUserToken: user.idToken.jwtToken,
105
+ apiGateway,
106
+ orgSlug: params.orgSlug,
107
+ };
108
+ // SET SDK CONFIG
109
+ setConfig(Auth.config);
110
+
111
+ const currentUser = await Request.request('/users/current', {
112
+ method: 'GET',
113
+ headers: {
114
+ 'Accept': 'application/json',
115
+ 'Content-Type': 'application/json',
116
+ },
117
+ });
118
+ if (!currentUser) {
119
+ throw Error('Could not get current user');
120
+ }
121
+ const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
122
+ if (org) {
123
+ Auth.config.orgId = org.orgId || org.id;
124
+ }
108
125
  }
package/src/cli.ts CHANGED
@@ -1,33 +1,32 @@
1
-
2
- import { create } from './create-app/create';
3
- import { deployApp, removeApp } from './deploy-app/deploy';
4
- /**
5
- * Built using documentation here:
6
- * https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
7
- */
8
-
9
- export async function cli(args) {
10
- const command = args[2];
11
- switch (command) {
12
- case 'create-app': {
13
- create(args);
14
- break;
15
- }
16
- case 'deploy-app': {
17
- deployApp(args);
18
- break;
19
- }
20
- case 'remove-app': {
21
- removeApp(args);
22
- break;
23
- }
24
- case 'extract-types': {
25
- removeApp(args);
26
- break;
27
- }
28
- default: {
29
- console.log('Illegal command.');
30
- }
31
- }
32
- }
33
-
1
+
2
+ import { create } from './create-app/create';
3
+ import { deployApp, removeApp } from './deploy-app/deploy';
4
+ /**
5
+ * Built using documentation here:
6
+ * https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
7
+ */
8
+
9
+ export async function cli(args) {
10
+ const command = args[2];
11
+ switch (command) {
12
+ case 'create-app': {
13
+ create(args);
14
+ break;
15
+ }
16
+ case 'deploy-app': {
17
+ deployApp(args);
18
+ break;
19
+ }
20
+ case 'remove-app': {
21
+ removeApp(args);
22
+ break;
23
+ }
24
+ case 'extract-types': {
25
+ // TODO
26
+ break;
27
+ }
28
+ default: {
29
+ console.log('Illegal command.');
30
+ }
31
+ }
32
+ }
@@ -1,58 +1,73 @@
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
+ import arg from 'arg';
2
+ import inquirer from 'inquirer';
3
+ import chalk from 'chalk';
4
+ import { setUpTemplate } from './setup-template';
5
+
6
+ function parseArgumentsIntoOptions(rawArgs) {
7
+ const args = arg(
8
+ {
9
+ '--app-name': String,
10
+ '--template': String,
11
+ '-n': '--app-name',
12
+ '-t': '--template',
13
+ },
14
+ {
15
+ argv: rawArgs.slice(3),
16
+ },
17
+ );
18
+ return {
19
+ appName: args['--app-name'],
20
+ template: args['--template'],
21
+ };
22
+ }
23
+ async function promptForMissingOptions(options) {
24
+ const defaultTemplate = 'JavaScript';
25
+
26
+ const questions = [];
27
+ if (!options.appName) {
28
+ questions.push({
29
+ type: 'input',
30
+ name: 'appName',
31
+ validate: (val) => !!val,
32
+ message: 'What is the name of your app?',
33
+ });
34
+ }
35
+
36
+ if (!options.template) {
37
+ questions.push({
38
+ type: 'list',
39
+ name: 'template',
40
+ message: 'Which project template would you like to use?',
41
+ choices: ['JavaScript', 'TypeScript'],
42
+ default: defaultTemplate,
43
+ });
44
+ }
45
+
46
+ const answers = await inquirer.prompt(questions);
47
+ return {
48
+ ...options,
49
+ appName: options.appName || answers.appName,
50
+ template: options.template || answers.template,
51
+ };
52
+ }
53
+
54
+ export async function create(args) {
55
+
56
+ let options = parseArgumentsIntoOptions(args);
57
+ options = await promptForMissingOptions(options);
58
+ console.log('%s Setting up new new contrail application.', chalk.blue.bold('START'));
59
+
60
+ let error;
61
+ try {
62
+ await setUpTemplate(options);
63
+ }
64
+ catch (e) {
65
+ error = e;
66
+ }
67
+
68
+ if (error) {
69
+ console.log('%s Application initialization failed.', chalk.red.bold('FAIL'));
70
+ } else {
71
+ console.log('%s Application initialized successfully.', chalk.green.bold('COMPLETE'));
72
+ }
73
+ }