@contrail/cli 1.0.3 → 1.0.7
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/lib/{create-app → apps/create-app}/create.d.ts +0 -0
- package/lib/{create-app → apps/create-app}/create.js +1 -5
- package/lib/{create-app → apps/create-app}/setup-template.d.ts +0 -0
- package/lib/{create-app → apps/create-app}/setup-template.js +1 -1
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.d.ts +0 -0
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.js +18 -7
- package/lib/{deploy-app → apps/deploy-app}/app-deployer.d.ts +0 -0
- package/lib/{deploy-app → apps/deploy-app}/app-deployer.js +1 -1
- package/lib/{deploy-app → apps/deploy-app}/app-template-parsers.d.ts +0 -0
- package/lib/{deploy-app → apps/deploy-app}/app-template-parsers.js +0 -0
- package/lib/{deploy-app → apps/deploy-app}/deploy.d.ts +0 -0
- package/lib/{deploy-app → apps/deploy-app}/deploy.js +4 -2
- package/lib/{deploy-app → apps/deploy-app}/interfaces.d.ts +1 -1
- package/lib/{deploy-app → apps/deploy-app}/interfaces.js +0 -0
- package/lib/auth/login.d.ts +2 -1
- package/lib/auth/login.js +3 -2
- package/lib/cli.js +105 -15
- package/lib/common.d.ts +1 -0
- package/lib/common.js +5 -0
- package/lib/types/interfaces.d.ts +50 -0
- package/lib/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/parse-optionSet.d.ts +2 -0
- package/lib/types/parse-optionSet.js +79 -0
- package/lib/types/types-extractor.d.ts +1 -0
- package/lib/types/types-extractor.js +98 -0
- package/lib/types/types-uploader.d.ts +1 -0
- package/lib/types/types-uploader.js +228 -0
- package/package.json +8 -3
- package/src/{create-app → apps/create-app}/create.ts +0 -0
- package/src/{create-app → apps/create-app}/setup-template.ts +1 -1
- package/src/{deploy-app → apps/deploy-app}/actions-deployer.ts +22 -9
- package/src/{deploy-app → apps/deploy-app}/app-deployer.ts +1 -1
- package/src/{deploy-app → apps/deploy-app}/app-template-parsers.ts +0 -0
- package/src/{deploy-app → apps/deploy-app}/deploy.ts +4 -2
- package/src/{deploy-app → apps/deploy-app}/interfaces.ts +1 -1
- package/src/auth/login.ts +7 -5
- package/src/cli.ts +115 -15
- package/src/common.ts +5 -0
- package/src/types/interfaces.ts +53 -0
- package/src/types/option-set-uploader.ts +83 -0
- package/src/types/parse-optionSet.ts +96 -0
- package/src/types/types-extractor.ts +125 -0
- package/src/types/types-uploader.ts +261 -0
- package/templates/javascript/actions/example/action.js +1 -1
- package/templates/typescript/actions/exampleAction.ts +38 -37
- package/tsconfig.json +10 -2
- package/templates/javascript/set_auth.bat +0 -3
- package/templates/javascript/set_auth.sh +0 -3
- package/templates/typescript/set_auth.bat +0 -3
- package/templates/typescript/set_auth.sh +0 -3
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Entities, Request } from '@contrail/sdk';
|
|
2
|
+
import { uploadOptionSets } from './option-set-uploader';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import { authUser } from '../auth/login';
|
|
6
|
+
import { getSeparatorByPlatform } from '../common';
|
|
7
|
+
import * as _ from 'lodash';
|
|
8
|
+
const yaml = require('js-yaml');
|
|
9
|
+
export async function uploadTypes(args) {
|
|
10
|
+
try {
|
|
11
|
+
const userConfig = await authUser();
|
|
12
|
+
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
13
|
+
console.log(`%s Uploading`, chalk.yellow.bold('OPTION SETS'));
|
|
14
|
+
await uploadOptionSets();
|
|
15
|
+
console.log(`%s Uploaded`, chalk.yellow.bold('OPTION SETS'));
|
|
16
|
+
console.log(`%s Uploading`, chalk.yellow.bold('TYPES'));
|
|
17
|
+
await uploadReducedTypes();
|
|
18
|
+
console.log(`%s Uploaded`, chalk.yellow.bold('TYPES'));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
25
|
+
}
|
|
26
|
+
function loadReducedTypes() {
|
|
27
|
+
const TARGET_DIR = process.cwd();
|
|
28
|
+
try {
|
|
29
|
+
const separator = getSeparatorByPlatform();
|
|
30
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'types.yml', 'utf8'));
|
|
31
|
+
return doc.types;
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function uploadReducedTypes() {
|
|
38
|
+
const types = loadReducedTypes();
|
|
39
|
+
const currentTypesWithoutProperties = await new Entities().get({
|
|
40
|
+
entityName: 'type',
|
|
41
|
+
});
|
|
42
|
+
const currentTypes = [];
|
|
43
|
+
for (const currentTypeWithoutProperties of currentTypesWithoutProperties) {
|
|
44
|
+
const typeWithProperties = await new Entities().get({
|
|
45
|
+
entityName: 'type',
|
|
46
|
+
id: currentTypeWithoutProperties.id,
|
|
47
|
+
relations: ['typeProperties'],
|
|
48
|
+
});
|
|
49
|
+
currentTypes.push(typeWithProperties);
|
|
50
|
+
}
|
|
51
|
+
const currentTypesBySlug = {};
|
|
52
|
+
for (const currentType of currentTypes) {
|
|
53
|
+
currentTypesBySlug[currentType.slug] = currentType;
|
|
54
|
+
}
|
|
55
|
+
const newTypesBySlug = {};
|
|
56
|
+
for (const type of types) {
|
|
57
|
+
newTypesBySlug[type.slug] = type;
|
|
58
|
+
}
|
|
59
|
+
for (const type of types) {
|
|
60
|
+
try {
|
|
61
|
+
const found = currentTypesBySlug[type.slug];
|
|
62
|
+
if (!found) {
|
|
63
|
+
if (!type.typePath.includes(':')) {
|
|
64
|
+
console.log('Cannot create a base type. Skipping: ', type.slug);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
console.log('Creating Type: ', type.slug);
|
|
68
|
+
const createdType = await new Entities().create({
|
|
69
|
+
entityName: 'type',
|
|
70
|
+
object: {
|
|
71
|
+
slug: type.slug,
|
|
72
|
+
label: type.label,
|
|
73
|
+
typePath: type.typePath,
|
|
74
|
+
isArchived: type.isArchived,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
await uploadReducedTypeProperties(createdType, [], type.typeProperties);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.log('Updating Type: ', type.slug);
|
|
81
|
+
const updatedType = await new Entities().update({
|
|
82
|
+
entityName: 'type',
|
|
83
|
+
id: found.id,
|
|
84
|
+
object: {
|
|
85
|
+
slug: type.slug,
|
|
86
|
+
label: type.label,
|
|
87
|
+
typePath: type.typePath,
|
|
88
|
+
isArchived: type.isArchived,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
await uploadReducedTypeProperties(updatedType, found.typeProperties, type.typeProperties);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
console.log('Error Uploading Types: ', err);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const currentType of currentTypes) {
|
|
99
|
+
try {
|
|
100
|
+
const found = newTypesBySlug[currentType.slug];
|
|
101
|
+
if (!found) {
|
|
102
|
+
console.log('Deleting Type: ', currentType.slug);
|
|
103
|
+
await new Entities().delete({
|
|
104
|
+
entityName: 'type',
|
|
105
|
+
id: currentType.id,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
throw new Error(`Error Deleting Types: ${err}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function uploadReducedTypeProperties(type, currentPropertyTypes, newPropertyTypes) {
|
|
115
|
+
const currentPropertyTypeBySlug = {};
|
|
116
|
+
for (const currentPropertyType of currentPropertyTypes) {
|
|
117
|
+
currentPropertyTypeBySlug[currentPropertyType.slug] = currentPropertyType;
|
|
118
|
+
}
|
|
119
|
+
const newPropertyTypesBySlug = {};
|
|
120
|
+
for (const newPropertyType of newPropertyTypes) {
|
|
121
|
+
newPropertyTypesBySlug[newPropertyType.slug] = newPropertyType;
|
|
122
|
+
}
|
|
123
|
+
const optionSets = await new Entities().get({
|
|
124
|
+
entityName: 'type-property-option-set',
|
|
125
|
+
});
|
|
126
|
+
const optionSetIdByName = {};
|
|
127
|
+
for (const optionSet of optionSets) {
|
|
128
|
+
optionSetIdByName[optionSet.name] = optionSet.id;
|
|
129
|
+
}
|
|
130
|
+
for (const newPropertyType of newPropertyTypes) {
|
|
131
|
+
try {
|
|
132
|
+
const found = currentPropertyTypeBySlug[newPropertyType.slug];
|
|
133
|
+
if (!found && !newPropertyType.inherited) {
|
|
134
|
+
console.log('Creating Type-Property: ', newPropertyType.slug);
|
|
135
|
+
await Request.request(`/types/${type.id}/type-properties`, {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
body: JSON.stringify({
|
|
138
|
+
isArchived: newPropertyType.isArchived,
|
|
139
|
+
propertyType: newPropertyType.propertyType,
|
|
140
|
+
slug: newPropertyType.slug,
|
|
141
|
+
label: newPropertyType.label,
|
|
142
|
+
editable: newPropertyType.editable,
|
|
143
|
+
core: newPropertyType.core,
|
|
144
|
+
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
145
|
+
formula: newPropertyType.formula,
|
|
146
|
+
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
147
|
+
defaultValue: newPropertyType.defaultValue,
|
|
148
|
+
propertyLevel: newPropertyType.propertyLevel,
|
|
149
|
+
}),
|
|
150
|
+
headers: {
|
|
151
|
+
'Accept': 'application/json',
|
|
152
|
+
'Content-Type': 'application/json',
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else if (found && !newPropertyType.inherited && !typePropertiesEqual(found, newPropertyType, optionSetIdByName)) {
|
|
157
|
+
console.log('Updating Type-Property: ', newPropertyType.slug);
|
|
158
|
+
await new Entities().update({
|
|
159
|
+
entityName: 'type-property',
|
|
160
|
+
id: found.id,
|
|
161
|
+
object: {
|
|
162
|
+
isArchived: newPropertyType.isArchived,
|
|
163
|
+
propertyType: newPropertyType.propertyType,
|
|
164
|
+
slug: newPropertyType.slug,
|
|
165
|
+
label: newPropertyType.label,
|
|
166
|
+
editable: newPropertyType.editable,
|
|
167
|
+
core: newPropertyType.core,
|
|
168
|
+
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
169
|
+
formula: newPropertyType.formula,
|
|
170
|
+
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
171
|
+
defaultValue: newPropertyType.defaultValue,
|
|
172
|
+
propertyLevel: newPropertyType.propertyLevel,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
console.log('Error Creating Properties: ', err);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const currentPropertyType of currentPropertyTypes) {
|
|
182
|
+
try {
|
|
183
|
+
const found = newPropertyTypesBySlug[currentPropertyType.slug];
|
|
184
|
+
if (!found && !currentPropertyType.inherited) {
|
|
185
|
+
console.log('Deleting Type-Property: ', currentPropertyType.slug);
|
|
186
|
+
await Request.request(`/types/${type.id}/type-properties/${currentPropertyType.id}`, {
|
|
187
|
+
method: 'DELETE',
|
|
188
|
+
headers: {
|
|
189
|
+
'Accept': 'application/json',
|
|
190
|
+
'Content-Type': 'application/json',
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
throw new Error(`Error Deleting Properties: ${err}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
|
|
201
|
+
const reducedProperty1 = {
|
|
202
|
+
isArchived: typeProperty1.isArchived,
|
|
203
|
+
propertyType: typeProperty1.propertyType,
|
|
204
|
+
slug: typeProperty1.slug,
|
|
205
|
+
label: typeProperty1.label,
|
|
206
|
+
editable: typeProperty1.editable,
|
|
207
|
+
core: typeProperty1.core,
|
|
208
|
+
typePropertyOptionSetId: optionSetIdByName[typeProperty1.typePropertyOptionSetName],
|
|
209
|
+
formula: typeProperty1.formula,
|
|
210
|
+
referencedTypeRootSlug: typeProperty1.referencedTypeRootSlug,
|
|
211
|
+
defaultValue: typeProperty1.defaultValue,
|
|
212
|
+
propertyLevel: typeProperty1.propertyLevel,
|
|
213
|
+
};
|
|
214
|
+
const reducedProperty2 = {
|
|
215
|
+
isArchived: typeProperty2.isArchived,
|
|
216
|
+
propertyType: typeProperty2.propertyType,
|
|
217
|
+
slug: typeProperty2.slug,
|
|
218
|
+
label: typeProperty2.label,
|
|
219
|
+
editable: typeProperty2.editable,
|
|
220
|
+
core: typeProperty2.core,
|
|
221
|
+
typePropertyOptionSetId: optionSetIdByName[typeProperty2.typePropertyOptionSetName],
|
|
222
|
+
formula: typeProperty2.formula,
|
|
223
|
+
referencedTypeRootSlug: typeProperty2.referencedTypeRootSlug,
|
|
224
|
+
defaultValue: typeProperty2.defaultValue,
|
|
225
|
+
propertyLevel: typeProperty2.propertyLevel,
|
|
226
|
+
};
|
|
227
|
+
return _.isEqual(reducedProperty1, reducedProperty2);
|
|
228
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "VibeIQ's Contrail Platform CLI.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -24,27 +24,32 @@
|
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@contrail/sdk": "^1.0.91",
|
|
27
|
+
"@contrail/util": "^1.0.17",
|
|
27
28
|
"amazon-cognito-identity-js": "^5.2.3",
|
|
28
29
|
"arg": "^4.0.1",
|
|
29
30
|
"aws-sdk": "^2.1044.0",
|
|
30
31
|
"chalk": "^4.0.0",
|
|
32
|
+
"command-line-usage": "^6.1.1",
|
|
33
|
+
"csvtojson": "^2.0.10",
|
|
31
34
|
"esm": "^3.2.25",
|
|
32
35
|
"execa": "^5.0.0",
|
|
33
36
|
"inquirer": "^8.2.0",
|
|
34
37
|
"js-yaml": "^4.1.0",
|
|
35
38
|
"listr": "^0.14.3",
|
|
39
|
+
"lodash": "^4.17.21",
|
|
36
40
|
"ncp": "^2.0.0",
|
|
37
41
|
"pkg-install": "^1.0.0"
|
|
38
42
|
},
|
|
39
43
|
"devDependencies": {
|
|
40
44
|
"@types/jest": "^23.3.14",
|
|
45
|
+
"@types/lodash": "^4.14.178",
|
|
46
|
+
"@types/node": "^14.6.4",
|
|
41
47
|
"jest": "^23.6.0",
|
|
42
48
|
"prettier": "^1.19.1",
|
|
43
49
|
"ts-jest": "^23.10.5",
|
|
44
50
|
"tslint": "^5.11.0",
|
|
45
51
|
"tslint-config-prettier": "^1.18.0",
|
|
46
|
-
"typescript": "^3.0.1"
|
|
47
|
-
"@types/node": "^14.6.4"
|
|
52
|
+
"typescript": "^3.0.1"
|
|
48
53
|
},
|
|
49
54
|
"jest": {
|
|
50
55
|
"moduleFileExtensions": [
|
|
File without changes
|
|
@@ -16,7 +16,7 @@ function copyTemplate(templateDir){
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export async function setUpTemplate(options) {
|
|
19
|
-
const templateDir = path.resolve(new URL(currentFileUrl).pathname,
|
|
19
|
+
const templateDir = path.resolve(new URL(currentFileUrl).pathname, `../../../../templates/${options.template.toLocaleLowerCase()}`).replace(/\\/g, '\\').replace(/(.):\\(.):/g, '').replace(/%20/g, ' ');
|
|
20
20
|
try {
|
|
21
21
|
const tasks = new Listr([
|
|
22
22
|
{
|
|
@@ -2,6 +2,8 @@ import { Entities } from '@contrail/sdk';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { App, AppDeclaration, AppActionDeclaration, EventWorkflowActionDefinition } from './interfaces';
|
|
4
4
|
import { ConfigPropertiesParser } from './app-template-parsers';
|
|
5
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
6
|
+
|
|
5
7
|
import fs from 'fs';
|
|
6
8
|
|
|
7
9
|
export class ActionsDeployer {
|
|
@@ -39,12 +41,16 @@ export class ActionsDeployer {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
private async createNewActionDefinition(actionKey: string, actionDeclaration: AppActionDeclaration, app: App) {
|
|
44
|
+
let configProperties;
|
|
45
|
+
if (actionDeclaration?.actionConfiguration) {
|
|
46
|
+
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
47
|
+
}
|
|
42
48
|
const newObject: EventWorkflowActionDefinition = {
|
|
43
49
|
identifier: this.getActionDeclarationIdentifier(actionKey, app),
|
|
44
50
|
name: actionDeclaration.name,
|
|
45
51
|
ownerKey: `app:${app.id}`,
|
|
46
52
|
public: app.public, // TODO - an actions visibility is not tied to the visibility of the app
|
|
47
|
-
configProperties
|
|
53
|
+
configProperties,
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
const functionString = await this.getFunction(actionDeclaration);
|
|
@@ -62,12 +68,20 @@ export class ActionsDeployer {
|
|
|
62
68
|
return actionDefinition;
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
private async updateActionDefinition(existingActionDefinition: EventWorkflowActionDefinition,
|
|
66
|
-
|
|
71
|
+
private async updateActionDefinition(existingActionDefinition: EventWorkflowActionDefinition, actionDeclaration: AppActionDeclaration) {
|
|
72
|
+
|
|
73
|
+
let configProperties;
|
|
74
|
+
if (actionDeclaration?.actionConfiguration) {
|
|
75
|
+
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
76
|
+
}
|
|
77
|
+
else if (!actionDeclaration?.actionConfiguration && existingActionDefinition.configProperties) {
|
|
78
|
+
configProperties = null;
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
const updates: EventWorkflowActionDefinition = {
|
|
68
82
|
name: actionDeclaration.name,
|
|
69
83
|
// public: actionDeclaration.public, // TODO - an actions visibility is allowed to change
|
|
70
|
-
configProperties
|
|
84
|
+
configProperties,
|
|
71
85
|
};
|
|
72
86
|
|
|
73
87
|
const functionString = await this.getFunction(actionDeclaration);
|
|
@@ -81,7 +95,7 @@ export class ActionsDeployer {
|
|
|
81
95
|
object: updates,
|
|
82
96
|
});
|
|
83
97
|
|
|
84
|
-
console.log(`%s Updated
|
|
98
|
+
console.log(`%s Updated existing action definition: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
|
|
85
99
|
|
|
86
100
|
return actionDefinition;
|
|
87
101
|
}
|
|
@@ -99,11 +113,10 @@ export class ActionsDeployer {
|
|
|
99
113
|
throw new Error('Action handler must be a .js file.');
|
|
100
114
|
}
|
|
101
115
|
const CURRENT_DIR = process.cwd();
|
|
102
|
-
const
|
|
103
|
-
const separator = isWin ? '\\' : '/';
|
|
116
|
+
const separator = getSeparatorByPlatform();
|
|
104
117
|
|
|
105
|
-
const
|
|
106
|
-
const content = fs.readFileSync(
|
|
118
|
+
const functionLocation = CURRENT_DIR + separator + actionDeclaration.handler;
|
|
119
|
+
const content = fs.readFileSync(functionLocation);
|
|
107
120
|
return content.toString();
|
|
108
121
|
}
|
|
109
122
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import { Auth } from '
|
|
3
|
+
import { Auth } from '../../auth/auth';
|
|
4
4
|
import { ActionsDeployer } from './actions-deployer';
|
|
5
5
|
import { App, AppDeclaration } from './interfaces';
|
|
6
6
|
import { TriggerKeyDefinitionParser, ConfigPropertiesParser } from './app-template-parsers';
|
|
File without changes
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import { authUser } from '
|
|
3
|
+
import { authUser } from '../../auth/login';
|
|
4
4
|
import { AppDeployer } from './app-deployer';
|
|
5
5
|
import { AppDeclaration } from './interfaces';
|
|
6
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
6
7
|
const yaml = require('js-yaml');
|
|
7
8
|
|
|
8
9
|
function loadAppConfig(){
|
|
9
10
|
const TARGET_DIR = process.cwd();
|
|
10
11
|
try {
|
|
11
|
-
const
|
|
12
|
+
const separator = getSeparatorByPlatform();
|
|
13
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'app.yml', 'utf8'));
|
|
12
14
|
console.log(doc);
|
|
13
15
|
return doc;
|
|
14
16
|
} catch (e) {
|
package/src/auth/login.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
3
|
import { Request, setConfig } from '@contrail/sdk';
|
|
4
|
-
import { Auth } from './auth';
|
|
4
|
+
import { Auth, AuthContext } from './auth';
|
|
5
5
|
|
|
6
6
|
const CONFIGURATION = {
|
|
7
7
|
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
8
8
|
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export async function authUser(){
|
|
11
|
+
export async function authUser(): Promise<AuthContext>{
|
|
12
12
|
const questions = [];
|
|
13
13
|
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
14
14
|
questions.push({
|
|
@@ -68,9 +68,9 @@ export async function authUser(){
|
|
|
68
68
|
cognitoUser.authenticateUser(authDetails, {
|
|
69
69
|
onSuccess: async (result) => {
|
|
70
70
|
const user = result;
|
|
71
|
-
await setAuthContext(user, params);
|
|
71
|
+
const config = await setAuthContext(user, params);
|
|
72
72
|
|
|
73
|
-
resolve(
|
|
73
|
+
resolve(config);
|
|
74
74
|
},
|
|
75
75
|
onFailure: (err) => {
|
|
76
76
|
reject(err);
|
|
@@ -79,7 +79,7 @@ export async function authUser(){
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
async function setAuthContext(user, params){
|
|
82
|
+
async function setAuthContext(user, params): Promise<AuthContext> {
|
|
83
83
|
|
|
84
84
|
// TODO Dont allow user to set this - they could set dev
|
|
85
85
|
const questions = [];
|
|
@@ -122,4 +122,6 @@ async function setAuthContext(user, params){
|
|
|
122
122
|
if (org) {
|
|
123
123
|
Auth.config.orgId = org.orgId || org.id;
|
|
124
124
|
}
|
|
125
|
+
|
|
126
|
+
return Object.assign({}, Auth.config);
|
|
125
127
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,32 +1,132 @@
|
|
|
1
1
|
|
|
2
|
-
import { create } from './create-app/create';
|
|
3
|
-
import { deployApp, removeApp } from './deploy-app/deploy';
|
|
2
|
+
import { create } from './apps/create-app/create';
|
|
3
|
+
import { deployApp, removeApp } from './apps/deploy-app/deploy';
|
|
4
|
+
import { getTypes } from './types/types-extractor';
|
|
5
|
+
import { uploadTypes } from './types/types-uploader';
|
|
6
|
+
import { parseOptionSet } from './types/parse-optionSet';
|
|
7
|
+
const cliUsage = require('command-line-usage');
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* Built using documentation here:
|
|
6
11
|
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
7
12
|
*/
|
|
8
13
|
|
|
9
14
|
export async function cli(args) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const fullCommand = args[2];
|
|
16
|
+
let domain;
|
|
17
|
+
let command;
|
|
18
|
+
const commandParts = fullCommand.split('.');
|
|
19
|
+
|
|
20
|
+
if (!commandParts?.length) {
|
|
21
|
+
printIllegalCommand();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (commandParts?.length < 2 && commandParts[0].toLowerCase() !== 'help' && commandParts[0].toLowerCase() !== '-help' && commandParts[0].toLowerCase() !== '--help') {
|
|
26
|
+
printIllegalCommand();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
domain = commandParts[0];
|
|
31
|
+
command = commandParts[1];
|
|
32
|
+
|
|
33
|
+
switch (domain) {
|
|
34
|
+
case 'app': {
|
|
35
|
+
switch (command) {
|
|
36
|
+
case 'create': {
|
|
37
|
+
create(args);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case 'deploy': {
|
|
41
|
+
deployApp(args);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case 'remove': {
|
|
45
|
+
removeApp(args);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
default: {
|
|
49
|
+
printIllegalCommand();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
18
52
|
break;
|
|
19
53
|
}
|
|
20
|
-
case '
|
|
21
|
-
|
|
54
|
+
case 'types': {
|
|
55
|
+
switch (command) {
|
|
56
|
+
case 'getAll': {
|
|
57
|
+
getTypes(args);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'upload': {
|
|
61
|
+
uploadTypes(args);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'parseOptionSet': {
|
|
65
|
+
parseOptionSet(args);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
default: {
|
|
69
|
+
printIllegalCommand();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
22
72
|
break;
|
|
23
73
|
}
|
|
24
|
-
case '
|
|
25
|
-
|
|
74
|
+
case 'help':
|
|
75
|
+
case '-help':
|
|
76
|
+
case '--help': {
|
|
77
|
+
printHelp();
|
|
26
78
|
break;
|
|
27
79
|
}
|
|
28
80
|
default: {
|
|
29
|
-
|
|
81
|
+
printIllegalCommand();
|
|
30
82
|
}
|
|
31
83
|
}
|
|
32
84
|
}
|
|
85
|
+
|
|
86
|
+
function printHelp() {
|
|
87
|
+
const sections = [
|
|
88
|
+
{
|
|
89
|
+
header: 'VibeIQ CLI',
|
|
90
|
+
content: 'From your friends at VibeIQ!',
|
|
91
|
+
},
|
|
92
|
+
...helpSections,
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
const usage = cliUsage(sections);
|
|
96
|
+
console.log(usage);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function printIllegalCommand() {
|
|
100
|
+
console.log('Illegal command.');
|
|
101
|
+
|
|
102
|
+
const usage = cliUsage(helpSections);
|
|
103
|
+
console.log(usage);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const helpSections = [
|
|
107
|
+
{
|
|
108
|
+
header: 'General Usage',
|
|
109
|
+
content: [
|
|
110
|
+
'Commands are run by pairing a domain with a command, joining them using a "."',
|
|
111
|
+
'e.g. app.create',
|
|
112
|
+
'',
|
|
113
|
+
'All <File Path> options should use the file path relative to the folder the command is being run in and include the file ext.',
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
header: 'App Commands - Domain: app',
|
|
118
|
+
content: [
|
|
119
|
+
'create Create a new app workspace.',
|
|
120
|
+
'deploy Deploy your app.',
|
|
121
|
+
'remove Remove your app.',
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
header: 'Type Commands - Domain: types',
|
|
126
|
+
content: [
|
|
127
|
+
'getAll Get all OptionSets and Types for your Org.',
|
|
128
|
+
'upload Upload OptionSets and Types for your Org.',
|
|
129
|
+
'parseOptionSet <File Path> Parse a CSV file into OptionSets.',
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
];
|
package/src/common.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface ReducedType {
|
|
2
|
+
slug: string;
|
|
3
|
+
label: string;
|
|
4
|
+
typePath: string;
|
|
5
|
+
isArchived: boolean;
|
|
6
|
+
typeProperties: ReducedType[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ReducedTypeProperties {
|
|
10
|
+
id: string;
|
|
11
|
+
isArchived: boolean;
|
|
12
|
+
propertyType: PropertyType;
|
|
13
|
+
slug: string;
|
|
14
|
+
label: string;
|
|
15
|
+
editable: boolean;
|
|
16
|
+
core: boolean;
|
|
17
|
+
typePropertyOptionSetName: string;
|
|
18
|
+
formula: string;
|
|
19
|
+
referencedTypeRootSlug: string;
|
|
20
|
+
defaultValue: string;
|
|
21
|
+
propertyLevel: string;
|
|
22
|
+
inherited: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ReducedOptionSet {
|
|
26
|
+
name: string;
|
|
27
|
+
isArchived: boolean;
|
|
28
|
+
optionSet: any[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare enum PropertyType {
|
|
32
|
+
Text = 'text',
|
|
33
|
+
String = 'string',
|
|
34
|
+
Number = 'number',
|
|
35
|
+
Date = 'date',
|
|
36
|
+
Boolean = 'boolean',
|
|
37
|
+
MultiSelect = 'multi_select',
|
|
38
|
+
SingleSelect = 'choice',
|
|
39
|
+
Url = 'url',
|
|
40
|
+
Currency = 'currency',
|
|
41
|
+
Percent = 'percent',
|
|
42
|
+
Rating = 'rating',
|
|
43
|
+
Formula = 'formula',
|
|
44
|
+
ObjectReference = 'object_reference',
|
|
45
|
+
ObjectReferenceList = 'object_ref_list',
|
|
46
|
+
DataGrid = 'data_grid',
|
|
47
|
+
CascadingSelect = 'cascading_select',
|
|
48
|
+
Sequence = 'sequence',
|
|
49
|
+
Constant = 'constant',
|
|
50
|
+
Composite = 'composite',
|
|
51
|
+
UserList = 'userList',
|
|
52
|
+
Image = 'image',
|
|
53
|
+
}
|