@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
|
File without changes
|
|
@@ -37,11 +37,7 @@ async function promptForMissingOptions(options) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
const answers = await inquirer.prompt(questions);
|
|
40
|
-
return {
|
|
41
|
-
...options,
|
|
42
|
-
appName: options.appName || answers.appName,
|
|
43
|
-
template: options.template || answers.template,
|
|
44
|
-
};
|
|
40
|
+
return Object.assign(Object.assign({}, options), { appName: options.appName || answers.appName, template: options.template || answers.template });
|
|
45
41
|
}
|
|
46
42
|
export async function create(args) {
|
|
47
43
|
let options = parseArgumentsIntoOptions(args);
|
|
File without changes
|
|
@@ -12,7 +12,7 @@ function copyTemplate(templateDir) {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
export async function setUpTemplate(options) {
|
|
15
|
-
const templateDir = path.resolve(new URL(currentFileUrl).pathname,
|
|
15
|
+
const templateDir = path.resolve(new URL(currentFileUrl).pathname, `../../../../templates/${options.template.toLocaleLowerCase()}`).replace(/\\/g, '\\').replace(/(.):\\(.):/g, '').replace(/%20/g, ' ');
|
|
16
16
|
try {
|
|
17
17
|
const tasks = new Listr([
|
|
18
18
|
{
|
|
File without changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { ConfigPropertiesParser } from './app-template-parsers';
|
|
4
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
4
5
|
import fs from 'fs';
|
|
5
6
|
export class ActionsDeployer {
|
|
6
7
|
async deployActions(appDeclaration, app) {
|
|
@@ -30,12 +31,16 @@ export class ActionsDeployer {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
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
|
+
}
|
|
33
38
|
const newObject = {
|
|
34
39
|
identifier: this.getActionDeclarationIdentifier(actionKey, app),
|
|
35
40
|
name: actionDeclaration.name,
|
|
36
41
|
ownerKey: `app:${app.id}`,
|
|
37
42
|
public: app.public,
|
|
38
|
-
configProperties
|
|
43
|
+
configProperties,
|
|
39
44
|
};
|
|
40
45
|
const functionString = await this.getFunction(actionDeclaration);
|
|
41
46
|
if (functionString) {
|
|
@@ -49,10 +54,17 @@ export class ActionsDeployer {
|
|
|
49
54
|
return actionDefinition;
|
|
50
55
|
}
|
|
51
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
|
+
}
|
|
52
64
|
const updates = {
|
|
53
65
|
name: actionDeclaration.name,
|
|
54
66
|
// public: actionDeclaration.public, // TODO - an actions visibility is allowed to change
|
|
55
|
-
configProperties
|
|
67
|
+
configProperties,
|
|
56
68
|
};
|
|
57
69
|
const functionString = await this.getFunction(actionDeclaration);
|
|
58
70
|
if (functionString) {
|
|
@@ -63,7 +75,7 @@ export class ActionsDeployer {
|
|
|
63
75
|
id: existingActionDefinition.id,
|
|
64
76
|
object: updates,
|
|
65
77
|
});
|
|
66
|
-
console.log(`%s Updated
|
|
78
|
+
console.log(`%s Updated existing action definition: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
|
|
67
79
|
return actionDefinition;
|
|
68
80
|
}
|
|
69
81
|
getActionDeclarationIdentifier(actionKey, app) {
|
|
@@ -77,10 +89,9 @@ export class ActionsDeployer {
|
|
|
77
89
|
throw new Error('Action handler must be a .js file.');
|
|
78
90
|
}
|
|
79
91
|
const CURRENT_DIR = process.cwd();
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const content = fs.readFileSync(functionLocaiton);
|
|
92
|
+
const separator = getSeparatorByPlatform();
|
|
93
|
+
const functionLocation = CURRENT_DIR + separator + actionDeclaration.handler;
|
|
94
|
+
const content = fs.readFileSync(functionLocation);
|
|
84
95
|
return content.toString();
|
|
85
96
|
}
|
|
86
97
|
}
|
|
File without changes
|
|
@@ -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 { TriggerKeyDefinitionParser, ConfigPropertiesParser } from './app-template-parsers';
|
|
6
6
|
export class AppDeployer {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,12 +1,14 @@
|
|
|
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
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
5
6
|
const yaml = require('js-yaml');
|
|
6
7
|
function loadAppConfig() {
|
|
7
8
|
const TARGET_DIR = process.cwd();
|
|
8
9
|
try {
|
|
9
|
-
const
|
|
10
|
+
const separator = getSeparatorByPlatform();
|
|
11
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'app.yml', 'utf8'));
|
|
10
12
|
console.log(doc);
|
|
11
13
|
return doc;
|
|
12
14
|
}
|
|
@@ -31,7 +31,7 @@ export interface AppActionDeclaration {
|
|
|
31
31
|
handler: string;
|
|
32
32
|
name: string;
|
|
33
33
|
description?: string;
|
|
34
|
-
actionConfiguration
|
|
34
|
+
actionConfiguration?: ConfigPropertyElements;
|
|
35
35
|
}
|
|
36
36
|
export interface AppTriggerDeclaration {
|
|
37
37
|
key: string;
|
|
File without changes
|
package/lib/auth/login.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { AuthContext } from './auth';
|
|
2
|
+
export declare function authUser(): Promise<AuthContext>;
|
package/lib/auth/login.js
CHANGED
|
@@ -60,8 +60,8 @@ export async function authUser() {
|
|
|
60
60
|
cognitoUser.authenticateUser(authDetails, {
|
|
61
61
|
onSuccess: async (result) => {
|
|
62
62
|
const user = result;
|
|
63
|
-
await setAuthContext(user, params);
|
|
64
|
-
resolve(
|
|
63
|
+
const config = await setAuthContext(user, params);
|
|
64
|
+
resolve(config);
|
|
65
65
|
},
|
|
66
66
|
onFailure: (err) => {
|
|
67
67
|
reject(err);
|
|
@@ -109,4 +109,5 @@ async function setAuthContext(user, params) {
|
|
|
109
109
|
if (org) {
|
|
110
110
|
Auth.config.orgId = org.orgId || org.id;
|
|
111
111
|
}
|
|
112
|
+
return Object.assign({}, Auth.config);
|
|
112
113
|
}
|
package/lib/cli.js
CHANGED
|
@@ -1,30 +1,120 @@
|
|
|
1
|
-
import { create } from './create-app/create';
|
|
2
|
-
import { deployApp, removeApp } from './deploy-app/deploy';
|
|
1
|
+
import { create } from './apps/create-app/create';
|
|
2
|
+
import { deployApp, removeApp } from './apps/deploy-app/deploy';
|
|
3
|
+
import { getTypes } from './types/types-extractor';
|
|
4
|
+
import { uploadTypes } from './types/types-uploader';
|
|
5
|
+
import { parseOptionSet } from './types/parse-optionSet';
|
|
6
|
+
const cliUsage = require('command-line-usage');
|
|
3
7
|
/**
|
|
4
8
|
* Built using documentation here:
|
|
5
9
|
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
6
10
|
*/
|
|
7
11
|
export async function cli(args) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const fullCommand = args[2];
|
|
13
|
+
let domain;
|
|
14
|
+
let command;
|
|
15
|
+
const commandParts = fullCommand.split('.');
|
|
16
|
+
if (!(commandParts === null || commandParts === void 0 ? void 0 : commandParts.length)) {
|
|
17
|
+
printIllegalCommand();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if ((commandParts === null || commandParts === void 0 ? void 0 : commandParts.length) < 2 && commandParts[0].toLowerCase() !== 'help' && commandParts[0].toLowerCase() !== '-help' && commandParts[0].toLowerCase() !== '--help') {
|
|
21
|
+
printIllegalCommand();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
domain = commandParts[0];
|
|
25
|
+
command = commandParts[1];
|
|
26
|
+
switch (domain) {
|
|
27
|
+
case 'app': {
|
|
28
|
+
switch (command) {
|
|
29
|
+
case 'create': {
|
|
30
|
+
create(args);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'deploy': {
|
|
34
|
+
deployApp(args);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'remove': {
|
|
38
|
+
removeApp(args);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
default: {
|
|
42
|
+
printIllegalCommand();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
16
45
|
break;
|
|
17
46
|
}
|
|
18
|
-
case '
|
|
19
|
-
|
|
47
|
+
case 'types': {
|
|
48
|
+
switch (command) {
|
|
49
|
+
case 'getAll': {
|
|
50
|
+
getTypes(args);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'upload': {
|
|
54
|
+
uploadTypes(args);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case 'parseOptionSet': {
|
|
58
|
+
parseOptionSet(args);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
default: {
|
|
62
|
+
printIllegalCommand();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
20
65
|
break;
|
|
21
66
|
}
|
|
22
|
-
case '
|
|
23
|
-
|
|
67
|
+
case 'help':
|
|
68
|
+
case '-help':
|
|
69
|
+
case '--help': {
|
|
70
|
+
printHelp();
|
|
24
71
|
break;
|
|
25
72
|
}
|
|
26
73
|
default: {
|
|
27
|
-
|
|
74
|
+
printIllegalCommand();
|
|
28
75
|
}
|
|
29
76
|
}
|
|
30
77
|
}
|
|
78
|
+
function printHelp() {
|
|
79
|
+
const sections = [
|
|
80
|
+
{
|
|
81
|
+
header: 'VibeIQ CLI',
|
|
82
|
+
content: 'From your friends at VibeIQ!',
|
|
83
|
+
},
|
|
84
|
+
...helpSections,
|
|
85
|
+
];
|
|
86
|
+
const usage = cliUsage(sections);
|
|
87
|
+
console.log(usage);
|
|
88
|
+
}
|
|
89
|
+
function printIllegalCommand() {
|
|
90
|
+
console.log('Illegal command.');
|
|
91
|
+
const usage = cliUsage(helpSections);
|
|
92
|
+
console.log(usage);
|
|
93
|
+
}
|
|
94
|
+
const helpSections = [
|
|
95
|
+
{
|
|
96
|
+
header: 'General Usage',
|
|
97
|
+
content: [
|
|
98
|
+
'Commands are run by pairing a domain with a command, joining them using a "."',
|
|
99
|
+
'e.g. app.create',
|
|
100
|
+
'',
|
|
101
|
+
'All <File Path> options should use the file path relative to the folder the command is being run in and include the file ext.',
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
header: 'App Commands - Domain: app',
|
|
106
|
+
content: [
|
|
107
|
+
'create Create a new app workspace.',
|
|
108
|
+
'deploy Deploy your app.',
|
|
109
|
+
'remove Remove your app.',
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
header: 'Type Commands - Domain: types',
|
|
114
|
+
content: [
|
|
115
|
+
'getAll Get all OptionSets and Types for your Org.',
|
|
116
|
+
'upload Upload OptionSets and Types for your Org.',
|
|
117
|
+
'parseOptionSet <File Path> Parse a CSV file into OptionSets.',
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
];
|
package/lib/common.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSeparatorByPlatform(): "\\" | "/";
|
package/lib/common.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface ReducedType {
|
|
2
|
+
slug: string;
|
|
3
|
+
label: string;
|
|
4
|
+
typePath: string;
|
|
5
|
+
isArchived: boolean;
|
|
6
|
+
typeProperties: ReducedType[];
|
|
7
|
+
}
|
|
8
|
+
export interface ReducedTypeProperties {
|
|
9
|
+
id: string;
|
|
10
|
+
isArchived: boolean;
|
|
11
|
+
propertyType: PropertyType;
|
|
12
|
+
slug: string;
|
|
13
|
+
label: string;
|
|
14
|
+
editable: boolean;
|
|
15
|
+
core: boolean;
|
|
16
|
+
typePropertyOptionSetName: string;
|
|
17
|
+
formula: string;
|
|
18
|
+
referencedTypeRootSlug: string;
|
|
19
|
+
defaultValue: string;
|
|
20
|
+
propertyLevel: string;
|
|
21
|
+
inherited: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ReducedOptionSet {
|
|
24
|
+
name: string;
|
|
25
|
+
isArchived: boolean;
|
|
26
|
+
optionSet: any[];
|
|
27
|
+
}
|
|
28
|
+
export declare enum PropertyType {
|
|
29
|
+
Text = "text",
|
|
30
|
+
String = "string",
|
|
31
|
+
Number = "number",
|
|
32
|
+
Date = "date",
|
|
33
|
+
Boolean = "boolean",
|
|
34
|
+
MultiSelect = "multi_select",
|
|
35
|
+
SingleSelect = "choice",
|
|
36
|
+
Url = "url",
|
|
37
|
+
Currency = "currency",
|
|
38
|
+
Percent = "percent",
|
|
39
|
+
Rating = "rating",
|
|
40
|
+
Formula = "formula",
|
|
41
|
+
ObjectReference = "object_reference",
|
|
42
|
+
ObjectReferenceList = "object_ref_list",
|
|
43
|
+
DataGrid = "data_grid",
|
|
44
|
+
CascadingSelect = "cascading_select",
|
|
45
|
+
Sequence = "sequence",
|
|
46
|
+
Constant = "constant",
|
|
47
|
+
Composite = "composite",
|
|
48
|
+
UserList = "userList",
|
|
49
|
+
Image = "image"
|
|
50
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uploadOptionSets(): Promise<void>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { getSeparatorByPlatform } from '../common';
|
|
4
|
+
const yaml = require('js-yaml');
|
|
5
|
+
function loadOptionSets() {
|
|
6
|
+
const TARGET_DIR = process.cwd();
|
|
7
|
+
try {
|
|
8
|
+
const separator = getSeparatorByPlatform();
|
|
9
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'option_sets.yml', 'utf8'));
|
|
10
|
+
return doc.optionSets;
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function uploadOptionSets() {
|
|
17
|
+
const optionSets = loadOptionSets();
|
|
18
|
+
const currentOptionSets = await new Entities().get({
|
|
19
|
+
entityName: 'type-property-option-set',
|
|
20
|
+
});
|
|
21
|
+
const currentOptionSetsByName = {};
|
|
22
|
+
for (const currentOptionSet of currentOptionSets) {
|
|
23
|
+
currentOptionSetsByName[currentOptionSet.name] = currentOptionSet;
|
|
24
|
+
}
|
|
25
|
+
const newOptionSetsByName = {};
|
|
26
|
+
for (const optionSet of optionSets) {
|
|
27
|
+
newOptionSetsByName[optionSet.name] = optionSet;
|
|
28
|
+
}
|
|
29
|
+
for (const optionSet of optionSets) {
|
|
30
|
+
try {
|
|
31
|
+
const found = currentOptionSetsByName[optionSet.name];
|
|
32
|
+
if (!found) {
|
|
33
|
+
console.log('Creating: ', optionSet.name);
|
|
34
|
+
await new Entities().create({
|
|
35
|
+
entityName: 'type-property-option-set',
|
|
36
|
+
object: {
|
|
37
|
+
name: optionSet.name,
|
|
38
|
+
optionSet: optionSet.optionSet,
|
|
39
|
+
isArchived: optionSet.isArchived,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log('Updating: ', optionSet.name);
|
|
45
|
+
await new Entities().update({
|
|
46
|
+
entityName: 'type-property-option-set',
|
|
47
|
+
id: found.id,
|
|
48
|
+
object: {
|
|
49
|
+
name: optionSet.name,
|
|
50
|
+
optionSet: optionSet.optionSet,
|
|
51
|
+
isArchived: optionSet.isArchived,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
throw new Error(`Error Uploading OptionSets: ${err}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const currentOptionSet of currentOptionSets) {
|
|
61
|
+
try {
|
|
62
|
+
const found = newOptionSetsByName[currentOptionSet.name];
|
|
63
|
+
if (!found) {
|
|
64
|
+
console.log('Deleting: ', currentOptionSet.name);
|
|
65
|
+
await new Entities().delete({
|
|
66
|
+
entityName: 'type-property-option-set',
|
|
67
|
+
id: currentOptionSet.id,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
throw new Error(`Error Deleting OptionSets: ${err}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { StringUtil } from '@contrail/util';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { getSeparatorByPlatform } from '../common';
|
|
5
|
+
import * as csvToJson from 'csvtojson';
|
|
6
|
+
const yaml = require('js-yaml');
|
|
7
|
+
export async function parseOptionSet(args) {
|
|
8
|
+
try {
|
|
9
|
+
if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
|
|
10
|
+
throw new Error('File name must be included.');
|
|
11
|
+
}
|
|
12
|
+
console.log(`%s Parsing`, chalk.yellow.bold('OPTION SETS'));
|
|
13
|
+
await parseOptionSets(args[3]);
|
|
14
|
+
console.log(`%s Parsed`, chalk.yellow.bold('OPTION SETS'));
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
|
|
21
|
+
}
|
|
22
|
+
async function loadDataFromCSV(fileName) {
|
|
23
|
+
const CURRENT_DIR = process.cwd();
|
|
24
|
+
try {
|
|
25
|
+
const separator = getSeparatorByPlatform();
|
|
26
|
+
const csvData = await csvToJson.default().fromFile(CURRENT_DIR + separator + fileName);
|
|
27
|
+
return csvData;
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
throw new Error(`ERROR PARSING CSV: ${e}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export async function parseOptionSets(fileName) {
|
|
34
|
+
const csvData = await loadDataFromCSV(fileName);
|
|
35
|
+
const removedFields = new Set();
|
|
36
|
+
const valuesByFieldName = {};
|
|
37
|
+
for (const row of csvData) {
|
|
38
|
+
for (const [key, value] of Object.entries(row)) {
|
|
39
|
+
// Dont parse boolean fields - later log removed fields
|
|
40
|
+
if (value.toLowerCase() === 'false' || value.toLowerCase() === 'true') {
|
|
41
|
+
removedFields.add(key);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (!value) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!valuesByFieldName[key]) {
|
|
48
|
+
valuesByFieldName[key] = new Set();
|
|
49
|
+
}
|
|
50
|
+
valuesByFieldName[key].add(value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const removed of removedFields.values()) {
|
|
54
|
+
console.log(`Removed Boolean Field: ${removed}`);
|
|
55
|
+
}
|
|
56
|
+
const reducedOptionSets = [];
|
|
57
|
+
for (const [key, value] of Object.entries(valuesByFieldName)) {
|
|
58
|
+
const optionSet = [];
|
|
59
|
+
for (const entry of value.values()) {
|
|
60
|
+
optionSet.push({
|
|
61
|
+
value: StringUtil.convertToCamelCase(entry),
|
|
62
|
+
display: isUpperCase(entry) ? entry : StringUtil.convertToTitleCase(entry),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const reducedOptionSet = {
|
|
66
|
+
name: StringUtil.convertToTitleCase(key),
|
|
67
|
+
isArchived: false,
|
|
68
|
+
optionSet,
|
|
69
|
+
};
|
|
70
|
+
reducedOptionSets.push(reducedOptionSet);
|
|
71
|
+
}
|
|
72
|
+
const yamlStr = yaml.dump(reducedOptionSets);
|
|
73
|
+
const CURRENT_DIR = process.cwd();
|
|
74
|
+
const separator = getSeparatorByPlatform();
|
|
75
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'parsed_option_sets.yml', yamlStr, 'utf8');
|
|
76
|
+
}
|
|
77
|
+
function isUpperCase(str) {
|
|
78
|
+
return str === str.toUpperCase();
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTypes(args: any): Promise<void>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { authUser } from '../auth/login';
|
|
5
|
+
import { getSeparatorByPlatform } from '../common';
|
|
6
|
+
const yaml = require('js-yaml');
|
|
7
|
+
export async function getTypes(args) {
|
|
8
|
+
try {
|
|
9
|
+
const userConfig = await authUser();
|
|
10
|
+
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
11
|
+
console.log(`%s Retrieving`, chalk.yellow.bold('OPTION SETS'));
|
|
12
|
+
const optionSets = await new Entities().get({
|
|
13
|
+
entityName: 'type-property-option-set',
|
|
14
|
+
});
|
|
15
|
+
await getOptionSets(optionSets);
|
|
16
|
+
console.log(`%s Retrieved`, chalk.yellow.bold('OPTION SETS'));
|
|
17
|
+
console.log(`%s Retrieving`, chalk.yellow.bold('TYPES'));
|
|
18
|
+
await getReducedTypes(optionSets);
|
|
19
|
+
console.log(`%s Retrieved`, chalk.yellow.bold('TYPES'));
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.log(`%s Types Retrieval Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
console.log('%s Types Retrieval Complete.', chalk.green.bold('COMPLETE'));
|
|
26
|
+
}
|
|
27
|
+
async function getOptionSets(optionSets) {
|
|
28
|
+
let reducedOptionSets = [];
|
|
29
|
+
for (const optionSet of optionSets) {
|
|
30
|
+
const reducedOptionSet = {
|
|
31
|
+
name: optionSet.name,
|
|
32
|
+
isArchived: optionSet.isArchived,
|
|
33
|
+
optionSet: optionSet.optionSet,
|
|
34
|
+
};
|
|
35
|
+
reducedOptionSets.push(reducedOptionSet);
|
|
36
|
+
}
|
|
37
|
+
const optionSetsHolder = {
|
|
38
|
+
optionSets: reducedOptionSets,
|
|
39
|
+
};
|
|
40
|
+
reducedOptionSets = reducedOptionSets.sort((one, two) => (one.name < two.name ? -1 : 1));
|
|
41
|
+
const CURRENT_DIR = process.cwd();
|
|
42
|
+
const separator = getSeparatorByPlatform();
|
|
43
|
+
const yamlStr = yaml.dump(optionSetsHolder);
|
|
44
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'option_sets.yml', yamlStr, 'utf8');
|
|
45
|
+
}
|
|
46
|
+
async function getReducedTypes(optionSets) {
|
|
47
|
+
const types = await new Entities().get({
|
|
48
|
+
entityName: 'type',
|
|
49
|
+
});
|
|
50
|
+
console.log('Found types: ', types.length);
|
|
51
|
+
let reducedTypes = [];
|
|
52
|
+
for (const type of types) {
|
|
53
|
+
const typeWithProperties = await new Entities().get({
|
|
54
|
+
entityName: 'type',
|
|
55
|
+
id: type.id,
|
|
56
|
+
relations: ['typeProperties'],
|
|
57
|
+
});
|
|
58
|
+
const optionSetNameById = {};
|
|
59
|
+
for (const optionSet of optionSets) {
|
|
60
|
+
optionSetNameById[optionSet.id] = optionSet.name;
|
|
61
|
+
}
|
|
62
|
+
const reducedTypeProperties = [];
|
|
63
|
+
for (const typeProperty of typeWithProperties.typeProperties) {
|
|
64
|
+
const reducedTypeProperty = {
|
|
65
|
+
slug: typeProperty.slug,
|
|
66
|
+
id: typeProperty.id,
|
|
67
|
+
isArchived: typeProperty.isArchived,
|
|
68
|
+
propertyType: typeProperty.propertyType,
|
|
69
|
+
label: typeProperty.label,
|
|
70
|
+
editable: typeProperty.editable,
|
|
71
|
+
core: typeProperty.core,
|
|
72
|
+
typePropertyOptionSetName: optionSetNameById[typeProperty.typePropertyOptionSetId],
|
|
73
|
+
formula: typeProperty.formula,
|
|
74
|
+
referencedTypeRootSlug: typeProperty.referencedTypeRootSlug,
|
|
75
|
+
defaultValue: typeProperty.defaultValue,
|
|
76
|
+
propertyLevel: typeProperty.propertyLevel,
|
|
77
|
+
inherited: typeProperty.inherited,
|
|
78
|
+
};
|
|
79
|
+
reducedTypeProperties.push(reducedTypeProperty);
|
|
80
|
+
}
|
|
81
|
+
const reducedType = {
|
|
82
|
+
typePath: typeWithProperties.typePath,
|
|
83
|
+
slug: typeWithProperties.slug,
|
|
84
|
+
label: typeWithProperties.label,
|
|
85
|
+
isArchived: typeWithProperties.isArchived,
|
|
86
|
+
typeProperties: reducedTypeProperties,
|
|
87
|
+
};
|
|
88
|
+
reducedTypes.push(reducedType);
|
|
89
|
+
}
|
|
90
|
+
reducedTypes = reducedTypes.sort((one, two) => (one.typePath < two.typePath ? -1 : 1));
|
|
91
|
+
const typesHolder = {
|
|
92
|
+
types: reducedTypes,
|
|
93
|
+
};
|
|
94
|
+
const CURRENT_DIR = process.cwd();
|
|
95
|
+
const separator = getSeparatorByPlatform();
|
|
96
|
+
const yamlStr = yaml.dump(typesHolder);
|
|
97
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'types.yml', yamlStr, 'utf8');
|
|
98
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uploadTypes(args: any): Promise<void>;
|