@contrail/cli 1.0.71 → 2.0.1
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/LICENSE +21 -0
- package/README.md +1034 -5
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/{lib → dist}/api/apps.d.ts +13 -13
- package/dist/api/apps.js +96 -0
- package/{lib → dist}/api/event-workflow-action-definition.d.ts +1 -1
- package/dist/api/event-workflow-action-definition.js +11 -0
- package/{lib → dist}/api/event-workflow-template-definition.d.ts +6 -6
- package/dist/api/event-workflow-template-definition.js +26 -0
- package/{lib → dist}/api/event-workflow-templates.d.ts +7 -7
- package/dist/api/event-workflow-templates.js +32 -0
- package/dist/api/types.d.ts +7 -0
- package/dist/api/types.js +52 -0
- package/{lib → dist}/auth/auth.d.ts +9 -9
- package/dist/auth/auth.js +6 -0
- package/{lib → dist}/auth/login.d.ts +2 -2
- package/{lib → dist}/auth/login.js +146 -141
- package/dist/commands/app/create.d.ts +6 -0
- package/dist/commands/app/create.js +15 -0
- package/dist/commands/app/delete.d.ts +7 -0
- package/dist/commands/app/delete.js +38 -0
- package/dist/commands/app/install.d.ts +11 -0
- package/dist/commands/app/install.js +117 -0
- package/dist/commands/app/publish.d.ts +7 -0
- package/dist/commands/app/publish.js +45 -0
- package/dist/commands/app/uninstall.d.ts +10 -0
- package/dist/commands/app/uninstall.js +58 -0
- package/dist/commands/app/upgrade.d.ts +11 -0
- package/dist/commands/app/upgrade.js +79 -0
- package/dist/commands/colors/deleteAll.d.ts +6 -0
- package/dist/commands/colors/deleteAll.js +30 -0
- package/dist/commands/colors/load.d.ts +6 -0
- package/dist/commands/colors/load.js +29 -0
- package/dist/commands/config/list.d.ts +6 -0
- package/dist/commands/config/list.js +15 -0
- package/dist/commands/config/remove.d.ts +14 -0
- package/dist/commands/config/remove.js +26 -0
- package/dist/commands/config/set.d.ts +13 -0
- package/dist/commands/config/set.js +29 -0
- package/dist/commands/loader-process/load.d.ts +9 -0
- package/dist/commands/loader-process/load.js +33 -0
- package/dist/commands/loader-process/upload-and-load.d.ts +10 -0
- package/dist/commands/loader-process/upload-and-load.js +35 -0
- package/dist/commands/projects/export.d.ts +10 -0
- package/dist/commands/projects/export.js +34 -0
- package/dist/commands/projects/list.d.ts +6 -0
- package/dist/commands/projects/list.js +34 -0
- package/dist/commands/projects/load.d.ts +9 -0
- package/{lib/projects/project-uploader.js → dist/commands/projects/load.js} +106 -105
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +7 -0
- package/{lib/types/option-set-hierarchy-exporter.js → dist/commands/types/exportOptionSetHierarchies.js} +130 -113
- package/{lib/types/types-extractor.d.ts → dist/commands/types/getAll.d.ts} +29 -27
- package/{lib/types/types-extractor.js → dist/commands/types/getAll.js} +267 -318
- package/dist/commands/types/loadAll.d.ts +7 -0
- package/dist/commands/types/loadAll.js +41 -0
- package/dist/commands/types/mergeOptionSets.d.ts +9 -0
- package/{lib/types/option-set-merger.js → dist/commands/types/mergeOptionSets.js} +114 -105
- package/dist/commands/types/mergeTypeProperties.d.ts +11 -0
- package/dist/commands/types/mergeTypeProperties.js +89 -0
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +112 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +14 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.js +153 -0
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsToFolderStructure.js +104 -0
- package/dist/commands/types/parseTypesFromFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromFiles.js +34 -0
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromLocalFiles.js +34 -0
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +11 -0
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +36 -0
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +35 -0
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +7 -0
- package/{lib/types/option-set-hierarchy-uploader.js → dist/commands/types/uploadOptionSetHierarchies.js} +130 -113
- package/dist/commands/types/uploadOptionSets.d.ts +7 -0
- package/{lib/types/option-set-uploader.js → dist/commands/types/uploadOptionSets.js} +115 -98
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +11 -0
- package/{lib/types/option-set-hierarchy-parser.js → dist/commands/types/uploadOptionSetsHierarchyLocalFile.js} +128 -140
- package/dist/commands/types/uploadRuleSets.d.ts +7 -0
- package/{lib/types/rule-set-uploader.js → dist/commands/types/uploadRuleSets.js} +189 -172
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +7 -0
- package/{lib/types/type-property-policy-uploader.js → dist/commands/types/uploadTypePropertyPolicies.js} +195 -178
- package/dist/commands/types/uploadUsageInfo.d.ts +7 -0
- package/{lib/types/usage-info-uploader.js → dist/commands/types/uploadUsageInfo.js} +149 -132
- package/dist/commands/users/export.d.ts +9 -0
- package/dist/commands/users/export.js +60 -0
- package/dist/commands/users/upload.d.ts +9 -0
- package/dist/commands/users/upload.js +65 -0
- package/dist/commands/workflow-template-definitions/install.d.ts +6 -0
- package/dist/commands/workflow-template-definitions/install.js +17 -0
- package/dist/commands/workflow-template-definitions/list.d.ts +6 -0
- package/dist/commands/workflow-template-definitions/list.js +17 -0
- package/dist/commands/workflow-templates/delete.d.ts +6 -0
- package/dist/commands/workflow-templates/delete.js +17 -0
- package/dist/commands/workflow-templates/list.d.ts +6 -0
- package/dist/commands/workflow-templates/list.js +17 -0
- package/dist/commands/workflow-templates/load.d.ts +9 -0
- package/dist/commands/workflow-templates/load.js +21 -0
- package/{lib → dist}/common.d.ts +1 -1
- package/dist/common.js +9 -0
- package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.d.ts +11 -11
- package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.js +122 -114
- package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.d.ts +8 -8
- package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.js +98 -93
- package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.d.ts +7 -7
- package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.js +43 -38
- package/dist/helpers/app/load-app-config.d.ts +1 -0
- package/dist/helpers/app/load-app-config.js +18 -0
- package/dist/helpers/app/setup-template.d.ts +1 -0
- package/dist/helpers/app/setup-template.js +38 -0
- package/dist/helpers/colors/helpers.d.ts +4 -0
- package/dist/helpers/colors/helpers.js +74 -0
- package/{lib → dist/helpers}/config/config.d.ts +6 -6
- package/dist/helpers/config/config.js +76 -0
- package/dist/helpers/loader-process/helpers.d.ts +2 -0
- package/{lib/loader-process/loader-process.js → dist/helpers/loader-process/helpers.js} +98 -120
- package/dist/helpers/projects/helpers.d.ts +2 -0
- package/{lib/projects/project-exporter.js → dist/helpers/projects/helpers.js} +165 -187
- package/{lib → dist/helpers}/types/csv-parser.d.ts +1 -1
- package/{lib → dist/helpers}/types/csv-parser.js +56 -51
- package/dist/helpers/types/type-extractor.d.ts +1 -0
- package/dist/helpers/types/type-extractor.js +32 -0
- package/dist/helpers/types/type-parser.d.ts +4 -0
- package/dist/helpers/types/type-parser.js +118 -0
- package/{lib/types/types-uploader.d.ts → dist/helpers/types/type-uploader.d.ts} +1 -1
- package/{lib/types/types-uploader.js → dist/helpers/types/type-uploader.js} +244 -239
- package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
- package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.js +156 -151
- package/{lib/workflow-templates/local-workflow-template-deployer.d.ts → dist/helpers/workflow-templates/helper.d.ts} +17 -11
- package/dist/helpers/workflow-templates/helper.js +166 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/{lib → dist}/interfaces.d.ts +323 -191
- package/dist/interfaces.js +63 -0
- package/{templates → dist/templates}/typescript/Dockerfile +15 -15
- package/{templates → dist/templates}/typescript/README.md +10 -10
- package/{templates → dist/templates}/typescript/app.yml +49 -49
- package/{templates → dist/templates}/typescript/docker_deploy.bat +1 -1
- package/{templates → dist/templates}/typescript/package.json +54 -54
- package/{templates → dist/templates}/typescript/src/actions/logItem.ts +25 -25
- package/{templates → dist/templates}/typescript/src/framework/action-dispatcher.ts +89 -89
- package/{templates → dist/templates}/typescript/src/framework/app-config.ts +26 -26
- package/{templates → dist/templates}/typescript/src/framework/handler.ts +11 -11
- package/{templates → dist/templates}/typescript/src/framework/index.ts +2 -2
- package/{templates → dist/templates}/typescript/src/framework/interfaces.ts +32 -32
- package/{templates → dist/templates}/typescript/src/framework/logger.ts +21 -21
- package/{templates → dist/templates}/typescript/src/framework/mock-server.ts +31 -31
- package/{templates → dist/templates}/typescript/tsconfig.json +28 -28
- package/oclif.manifest.json +821 -0
- package/package.json +116 -72
- package/.eslintrc.js +0 -53
- package/.vscode/settings.json +0 -6
- package/bin/init +0 -4
- package/lib/api/apps.js +0 -85
- package/lib/api/event-workflow-action-definition.js +0 -7
- package/lib/api/event-workflow-template-definition.js +0 -20
- package/lib/api/event-workflow-templates.js +0 -25
- package/lib/apps/create-app/create.d.ts +0 -1
- package/lib/apps/create-app/create.js +0 -60
- package/lib/apps/create-app/setup-template.d.ts +0 -1
- package/lib/apps/create-app/setup-template.js +0 -34
- package/lib/apps/deploy-app/deploy.d.ts +0 -2
- package/lib/apps/deploy-app/deploy.js +0 -58
- package/lib/apps/install-app/app-installer.d.ts +0 -2
- package/lib/apps/install-app/app-installer.js +0 -120
- package/lib/apps/upgrade-app/app-upgrader.d.ts +0 -3
- package/lib/apps/upgrade-app/app-upgrader.js +0 -126
- package/lib/auth/auth.js +0 -2
- package/lib/cli.d.ts +0 -5
- package/lib/cli.js +0 -524
- package/lib/colors/color-loader.d.ts +0 -2
- package/lib/colors/color-loader.js +0 -96
- package/lib/common.js +0 -5
- package/lib/config/config.js +0 -70
- package/lib/config/configCommands.d.ts +0 -3
- package/lib/config/configCommands.js +0 -34
- package/lib/interfaces.js +0 -25
- package/lib/loader-process/loader-process.d.ts +0 -2
- package/lib/projects/interfaces.d.ts +0 -77
- package/lib/projects/interfaces.js +0 -23
- package/lib/projects/project-exporter.d.ts +0 -2
- package/lib/projects/project-uploader.d.ts +0 -1
- package/lib/types/allUploader.d.ts +0 -1
- package/lib/types/allUploader.js +0 -24
- package/lib/types/interfaces.d.ts +0 -55
- package/lib/types/interfaces.js +0 -1
- package/lib/types/option-set-hierarchy-exporter.d.ts +0 -1
- package/lib/types/option-set-hierarchy-parser.d.ts +0 -2
- package/lib/types/option-set-hierarchy-uploader.d.ts +0 -1
- package/lib/types/option-set-merger.d.ts +0 -1
- package/lib/types/option-set-parser.d.ts +0 -3
- package/lib/types/option-set-parser.js +0 -140
- package/lib/types/option-set-uploader.d.ts +0 -1
- package/lib/types/parse-types.d.ts +0 -4
- package/lib/types/parse-types.js +0 -189
- package/lib/types/rule-set-uploader.d.ts +0 -1
- package/lib/types/type-property-policy-uploader.d.ts +0 -1
- package/lib/types/types-properties-merger.d.ts +0 -1
- package/lib/types/types-properties-merger.js +0 -75
- package/lib/types/usage-info-uploader.d.ts +0 -1
- package/lib/users/user-exporter.d.ts +0 -1
- package/lib/users/user-exporter.js +0 -41
- package/lib/users/user-uploader.d.ts +0 -1
- package/lib/users/user-uploader.js +0 -45
- package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +0 -2
- package/lib/workflow-template-definitions/workflow-template-definition-commands.js +0 -10
- package/lib/workflow-templates/local-workflow-template-deployer.js +0 -102
- package/lib/workflow-templates/workflow-template-commands.d.ts +0 -4
- package/lib/workflow-templates/workflow-template-commands.js +0 -51
- package/lib/workflow-templates/workflow-template-deployer.d.ts +0 -4
- package/lib/workflow-templates/workflow-template-deployer.js +0 -26
- package/publish.bat +0 -5
- package/publish.sh +0 -5
- package/src/api/apps.ts +0 -97
- package/src/api/event-workflow-action-definition.ts +0 -8
- package/src/api/event-workflow-template-definition.ts +0 -23
- package/src/api/event-workflow-templates.ts +0 -29
- package/src/apps/create-app/create.ts +0 -74
- package/src/apps/create-app/setup-template.ts +0 -38
- package/src/apps/deploy-app/actions-deployer.ts +0 -140
- package/src/apps/deploy-app/app-deployer.ts +0 -105
- package/src/apps/deploy-app/app-template-parsers.ts +0 -44
- package/src/apps/deploy-app/deploy.ts +0 -66
- package/src/apps/install-app/app-installer.ts +0 -126
- package/src/apps/upgrade-app/app-upgrader.ts +0 -132
- package/src/auth/auth.ts +0 -10
- package/src/auth/login.ts +0 -155
- package/src/cli.ts +0 -540
- package/src/colors/color-loader.ts +0 -112
- package/src/colors/colors.csv +0 -866
- package/src/common.ts +0 -5
- package/src/config/config.ts +0 -74
- package/src/config/configCommands.ts +0 -38
- package/src/interfaces.ts +0 -200
- package/src/loader-process/loader-process.ts +0 -152
- package/src/projects/interfaces.ts +0 -73
- package/src/projects/project-exporter.ts +0 -225
- package/src/projects/project-uploader.ts +0 -131
- package/src/types/allUploader.ts +0 -28
- package/src/types/csv-parser.ts +0 -59
- package/src/types/interfaces.ts +0 -58
- package/src/types/option-set-hierarchy-exporter.ts +0 -125
- package/src/types/option-set-hierarchy-parser.ts +0 -169
- package/src/types/option-set-hierarchy-uploader.ts +0 -122
- package/src/types/option-set-merger.ts +0 -124
- package/src/types/option-set-parser.ts +0 -166
- package/src/types/option-set-uploader.ts +0 -108
- package/src/types/parse-types.ts +0 -227
- package/src/types/rule-set-uploader.ts +0 -187
- package/src/types/type-property-policy-uploader.ts +0 -192
- package/src/types/types-extractor.ts +0 -369
- package/src/types/types-properties-merger.ts +0 -90
- package/src/types/types-uploader.ts +0 -271
- package/src/types/usage-info-uploader.ts +0 -139
- package/src/users/user-exporter.ts +0 -52
- package/src/users/user-uploader.ts +0 -58
- package/src/workflow-template-definitions/workflow-template-definition-commands.ts +0 -13
- package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +0 -184
- package/src/workflow-templates/local-workflow-template-deployer.ts +0 -126
- package/src/workflow-templates/workflow-template-commands.ts +0 -59
- package/src/workflow-templates/workflow-template-deployer.ts +0 -30
- package/templates/javascript/actions/example/action.js +0 -38
- package/templates/javascript/app.yml +0 -53
- package/templates/javascript/package.json +0 -23
- package/templates/typescript/package-lock.json +0 -14
- package/tsconfig.json +0 -32
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { getSeparatorByPlatform } from '../common';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
const csv = require('csvtojson');
|
|
5
|
-
import { Entities } from '@contrail/sdk';
|
|
6
|
-
import { StringUtil } from '@contrail/util';
|
|
7
|
-
import { authUser } from '../auth/login';
|
|
8
|
-
|
|
9
|
-
export async function ParseOptionSetsHierarchyLocalFile(args) {
|
|
10
|
-
try {
|
|
11
|
-
await authUser();
|
|
12
|
-
|
|
13
|
-
if (args?.length < 4) {
|
|
14
|
-
throw new Error('File name must be included.');
|
|
15
|
-
}
|
|
16
|
-
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET HIERARCHY PARSE'));
|
|
17
|
-
const fileLocation = args[3];
|
|
18
|
-
console.log('Using File: ', fileLocation);
|
|
19
|
-
|
|
20
|
-
await parseAndSaveOptionSetHierarchiesLocalFile(fileLocation);
|
|
21
|
-
console.log('%s Parsed', chalk.yellow.bold('OPTION SET HIERARCHY PARSE'));
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.log(`%s PARSE Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
console.log('%s PARSE Complete.', chalk.green.bold('COMPLETE'));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function UploadOptionSetsHierarchyLocalFile(args) {
|
|
33
|
-
try {
|
|
34
|
-
await authUser();
|
|
35
|
-
|
|
36
|
-
if (args?.length < 4) {
|
|
37
|
-
throw new Error('File name must be included.');
|
|
38
|
-
}
|
|
39
|
-
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
|
|
40
|
-
const fileLocation = args[3];
|
|
41
|
-
const name = args[4];
|
|
42
|
-
console.log('Using File: ', fileLocation);
|
|
43
|
-
console.log('Using Name: ', name);
|
|
44
|
-
|
|
45
|
-
await uploadOptionSetHierarchiesLocalFile(fileLocation, name);
|
|
46
|
-
console.log('%s Uploaded', chalk.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
console.log(`%s UPLOAD Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
console.log('%s UPLOAD Complete.', chalk.green.bold('COMPLETE'));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function loadOptionSetHierarchyCSV(fileLocation) {
|
|
58
|
-
const TARGET_DIR = process.cwd();
|
|
59
|
-
try {
|
|
60
|
-
const separator = getSeparatorByPlatform();
|
|
61
|
-
|
|
62
|
-
const fullPath = TARGET_DIR + separator + fileLocation;
|
|
63
|
-
console.log('Getting file from path: ', fullPath);
|
|
64
|
-
|
|
65
|
-
return await csv().fromFile(fullPath);
|
|
66
|
-
} catch (e) {
|
|
67
|
-
throw new Error(`ERROR PARSING CSV: ${e}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function parseOptionSetHierarchiesLocalFile(fileLocation) {
|
|
72
|
-
const uploadedOptionHierarchyData = await loadOptionSetHierarchyCSV(fileLocation);
|
|
73
|
-
|
|
74
|
-
const optionSetHierarchy = {
|
|
75
|
-
hierarchy:[],
|
|
76
|
-
maxDepth: 0,
|
|
77
|
-
name: 'No Name',
|
|
78
|
-
options: []
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
if (!(uploadedOptionHierarchyData?.length > 0)) {
|
|
82
|
-
return optionSetHierarchy;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
|
|
86
|
-
const currentOptionSets = await new Entities().get({
|
|
87
|
-
entityName: 'type-property-option-set',
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const currentOptionSetsByName = {};
|
|
91
|
-
for (const currentOptionSet of currentOptionSets) {
|
|
92
|
-
currentOptionSetsByName[StringUtil.convertToCamelCase(currentOptionSet.name)] = currentOptionSet;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const optionSetIds = [];
|
|
96
|
-
for(const key of keysInOrder) {
|
|
97
|
-
if (currentOptionSetsByName[key]) {
|
|
98
|
-
optionSetIds.push(currentOptionSetsByName[key].id);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
throw new Error(`No OptionSet found for ${key}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
optionSetHierarchy.maxDepth = keysInOrder.length;
|
|
106
|
-
optionSetHierarchy.hierarchy = optionSetIds;
|
|
107
|
-
|
|
108
|
-
for (const row of uploadedOptionHierarchyData) {
|
|
109
|
-
addRowToOptions(optionSetHierarchy, keysInOrder, row);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return optionSetHierarchy;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async function parseAndSaveOptionSetHierarchiesLocalFile(fileLocation) {
|
|
116
|
-
const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
|
|
117
|
-
saveData(optionSetHierarchy.options);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async function uploadOptionSetHierarchiesLocalFile(fileLocation, name) {
|
|
121
|
-
const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
|
|
122
|
-
optionSetHierarchy.name = name;
|
|
123
|
-
|
|
124
|
-
const currentOptionSetHierarchies = await new Entities().get({
|
|
125
|
-
entityName: 'option-set-hierarchy',
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const existing = currentOptionSetHierarchies.find(osh => osh.name === name);
|
|
129
|
-
|
|
130
|
-
if (existing) {
|
|
131
|
-
console.log('Updating: ', optionSetHierarchy.name);
|
|
132
|
-
await new Entities().update({
|
|
133
|
-
entityName: 'option-set-hierarchy',
|
|
134
|
-
id: existing.id,
|
|
135
|
-
object: optionSetHierarchy,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
console.log('Creating: ', optionSetHierarchy.name);
|
|
140
|
-
await new Entities().create({
|
|
141
|
-
entityName: 'option-set-hierarchy',
|
|
142
|
-
object: optionSetHierarchy,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function addRowToOptions(optionSetHierarchy, keysInOrder, row) {
|
|
148
|
-
let options: any[] = optionSetHierarchy.options;
|
|
149
|
-
|
|
150
|
-
for (let i = 0; i < keysInOrder.length; i++) {
|
|
151
|
-
const optionValues = options.map(op => op.value);
|
|
152
|
-
const value = row[keysInOrder[i]];
|
|
153
|
-
if (!optionValues.includes(value)) {
|
|
154
|
-
const obj = i === (keysInOrder.length - 1) ? {value: value} : {value: value, options: []};
|
|
155
|
-
options.push(obj);
|
|
156
|
-
options = obj.options;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
const optionObj = options.find(op => op.value === value);
|
|
160
|
-
options = optionObj.options;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function saveData(data) {
|
|
166
|
-
const CURRENT_DIR = process.cwd();
|
|
167
|
-
const separator = getSeparatorByPlatform();
|
|
168
|
-
fs.writeFileSync(CURRENT_DIR + separator + 'parsed_local_optionSetHierarchy.json', JSON.stringify(data), 'utf8');
|
|
169
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
|
|
7
|
-
const yaml = require('js-yaml');
|
|
8
|
-
|
|
9
|
-
export async function UploadOptionSetHierarchies(args) {
|
|
10
|
-
try {
|
|
11
|
-
await authUser();
|
|
12
|
-
|
|
13
|
-
console.log('%s Uploading', chalk.yellow.bold('OPTION SET HIERARCHIES'));
|
|
14
|
-
const optionSetHierarchies = await loadOptionSetHierarchies();
|
|
15
|
-
await uploadOptionSetHierarchies(optionSetHierarchies);
|
|
16
|
-
console.log('%s Uploaded', chalk.yellow.bold('OPTION SET HIERARCHIES'));
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
console.log(`%s Option set hierarchy Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
console.log('%s Option set hierarchy Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function loadOptionSetHierarchies() {
|
|
28
|
-
const TARGET_DIR = process.cwd();
|
|
29
|
-
try {
|
|
30
|
-
const files = fs.readdirSync(path.join(TARGET_DIR, 'option-set-hierarchies'));
|
|
31
|
-
const OSHs = [];
|
|
32
|
-
for(const file of files) {
|
|
33
|
-
OSHs.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'option-set-hierarchies', file), 'utf8')));
|
|
34
|
-
}
|
|
35
|
-
return OSHs;
|
|
36
|
-
} catch (e) {
|
|
37
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function uploadOptionSetHierarchies(loadedOSHs) {
|
|
42
|
-
|
|
43
|
-
const optionSets = await new Entities().get({
|
|
44
|
-
entityName: 'type-property-option-set',
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const currentOSHs = await new Entities().get({
|
|
48
|
-
entityName: 'option-set-hierarchy',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const optionSetsByName = {};
|
|
52
|
-
for (const optionSet of optionSets) {
|
|
53
|
-
optionSetsByName[optionSet.name] = optionSet;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const currentOSHByName = {};
|
|
57
|
-
for (const currentOSH of currentOSHs) {
|
|
58
|
-
currentOSHByName[currentOSH.name] = currentOSH;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const loadedOSHByName = {};
|
|
62
|
-
for (const loadedOSH of loadedOSHs) {
|
|
63
|
-
loadedOSHByName[loadedOSH.name] = loadedOSH;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.debug('current OSH:', currentOSHs);
|
|
67
|
-
console.debug('loaded OSH:', loadedOSHs);
|
|
68
|
-
|
|
69
|
-
for (const osh of loadedOSHs) {
|
|
70
|
-
try {
|
|
71
|
-
const found = currentOSHByName[osh.name];
|
|
72
|
-
if (!found) {
|
|
73
|
-
if (!transformOSHNameToID(osh.hierarchy, optionSets)) { continue; }
|
|
74
|
-
console.log('Creating: ', osh);
|
|
75
|
-
await new Entities().create({
|
|
76
|
-
entityName: 'option-set-hierarchy',
|
|
77
|
-
object: osh
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
if (!transformOSHNameToID(osh.hierarchy, optionSets)) { continue; }
|
|
81
|
-
console.log('Updating: ', osh);
|
|
82
|
-
await new Entities().update({
|
|
83
|
-
entityName: 'option-set-hierarchy',
|
|
84
|
-
id: found.id,
|
|
85
|
-
object: osh,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
} catch (err) {
|
|
89
|
-
throw new Error(`Error Uploading option set hierarchy: ${err}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
for (const currentOSH of currentOSHs) {
|
|
94
|
-
try {
|
|
95
|
-
const found = loadedOSHByName[currentOSH.name];
|
|
96
|
-
if (!found) {
|
|
97
|
-
console.log('Deleting: ', currentOSH.name);
|
|
98
|
-
await new Entities().delete({
|
|
99
|
-
entityName: 'option-set-hierarchy',
|
|
100
|
-
id: currentOSH.id,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
} catch (err) {
|
|
104
|
-
throw new Error(`Error Deleting Option set hierarchy: ${err}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// transforms the passed hierarchy from names to ids, and returns true if operation succeeded.
|
|
111
|
-
function transformOSHNameToID(hierarchy, optionSets) {
|
|
112
|
-
console.log('passed hierarhy:', hierarchy);
|
|
113
|
-
for (let i = 0; i < hierarchy.length; i++) {
|
|
114
|
-
const os = optionSets.find(os => os.name === hierarchy[i]);
|
|
115
|
-
if (!os) {
|
|
116
|
-
console.error('could not find option set with name', hierarchy[i], ' at position', i, 'skipping...');
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
hierarchy[i] = os.id;
|
|
120
|
-
}
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import { ReducedOptionSet } from './interfaces';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { getSeparatorByPlatform } from '../common';
|
|
5
|
-
import { authUser } from '../auth/login';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
const yaml = require('js-yaml');
|
|
8
|
-
|
|
9
|
-
export async function MergeOptionSets(args) {
|
|
10
|
-
try {
|
|
11
|
-
if (args?.length < 4) {
|
|
12
|
-
throw new Error('File name must be included.');
|
|
13
|
-
}
|
|
14
|
-
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET MERGE'));
|
|
15
|
-
const fileLocation = args[3];
|
|
16
|
-
console.log('Using File: ', fileLocation);
|
|
17
|
-
|
|
18
|
-
await mergeOptionSets(fileLocation);
|
|
19
|
-
console.log('%s Merged', chalk.yellow.bold('OPTION SET MERGE'));
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
console.log('%s Merge Complete.', chalk.green.bold('COMPLETE'));
|
|
28
|
-
}
|
|
29
|
-
function loadOptionSets(fileLocation) {
|
|
30
|
-
const TARGET_DIR = process.cwd();
|
|
31
|
-
try {
|
|
32
|
-
const separator = getSeparatorByPlatform();
|
|
33
|
-
|
|
34
|
-
const fullPath = TARGET_DIR + separator + fileLocation;
|
|
35
|
-
console.log('Getting file from path: ', fullPath);
|
|
36
|
-
|
|
37
|
-
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + fileLocation, 'utf8'));
|
|
38
|
-
return doc;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function mergeOptionSets(fileLocation) {
|
|
45
|
-
const uploadedOptionSets: ReducedOptionSet[] = loadOptionSets(fileLocation);
|
|
46
|
-
|
|
47
|
-
await authUser();
|
|
48
|
-
|
|
49
|
-
const currentOptionSetsFull: any[] = await new Entities().get({
|
|
50
|
-
entityName: 'type-property-option-set',
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const currentOptionSets = currentOptionSetsFull.map(os => Object.assign({}, {
|
|
54
|
-
name: os.name,
|
|
55
|
-
isArchived: os.isArchived,
|
|
56
|
-
optionSet: os.optionSet,
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
const currentOptionSetsByName = {};
|
|
60
|
-
for (const currentOptionSet of currentOptionSets) {
|
|
61
|
-
currentOptionSetsByName[currentOptionSet.name] = currentOptionSet;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const uploadedOptionSetsByName = {};
|
|
65
|
-
for (const optionSet of uploadedOptionSets) {
|
|
66
|
-
uploadedOptionSetsByName[optionSet.name] = optionSet;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const mergedOptionSets: any[] = [];
|
|
70
|
-
for (const uploadedOptionSet of uploadedOptionSets) {
|
|
71
|
-
const existing = currentOptionSetsByName[uploadedOptionSet.name];
|
|
72
|
-
if (!existing) {
|
|
73
|
-
if (!uploadedOptionSet.optionSet) {
|
|
74
|
-
console.log('No OptionSet for: ', uploadedOptionSet.name);
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
console.log('Adding New: ', uploadedOptionSet.name);
|
|
78
|
-
mergedOptionSets.push(uploadedOptionSet);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
console.log('Merging: ', uploadedOptionSet.name);
|
|
82
|
-
mergedOptionSets.push(mergeOptionSet(existing, uploadedOptionSet));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
for (const currentOptionSet of currentOptionSets) {
|
|
87
|
-
const found = uploadedOptionSetsByName[currentOptionSet.name];
|
|
88
|
-
if (!found) {
|
|
89
|
-
console.log('Adding Existing: ', currentOptionSet.name);
|
|
90
|
-
mergedOptionSets.push(currentOptionSet);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
saveData(mergedOptionSets);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function mergeOptionSet(existingOptionSet: ReducedOptionSet, uploadedOptionSet: ReducedOptionSet) {
|
|
98
|
-
const merged = {
|
|
99
|
-
name: uploadedOptionSet.name,
|
|
100
|
-
optionSet: uploadedOptionSet.optionSet,
|
|
101
|
-
isArchived: uploadedOptionSet.isArchived,
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
if (existingOptionSet?.optionSet?.length > 0) {
|
|
105
|
-
for (const keyVal of existingOptionSet.optionSet) {
|
|
106
|
-
const value = keyVal.value;
|
|
107
|
-
const display = keyVal.display;
|
|
108
|
-
|
|
109
|
-
const found = merged.optionSet.find(keyVal => keyVal.value === value);
|
|
110
|
-
if (!found) {
|
|
111
|
-
merged.optionSet.push({value, display});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return merged;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function saveData(data) {
|
|
120
|
-
const yamlStr = yaml.dump(data);
|
|
121
|
-
const CURRENT_DIR = process.cwd();
|
|
122
|
-
const separator = getSeparatorByPlatform();
|
|
123
|
-
fs.writeFileSync(CURRENT_DIR + separator + 'merged_optionSets.yml', yamlStr, 'utf8');
|
|
124
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { getSeparatorByPlatform } from '../common';
|
|
3
|
-
import { parseOptionSets } from '@contrail/types';
|
|
4
|
-
import { StringUtil } from '@contrail/util';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
const csv = require('csvtojson');
|
|
7
|
-
const yaml = require('js-yaml');
|
|
8
|
-
import * as path from 'path';
|
|
9
|
-
|
|
10
|
-
export async function ParseOptionSetsLocalFiles(args) {
|
|
11
|
-
try {
|
|
12
|
-
if (args?.length < 4) {
|
|
13
|
-
throw new Error('File name must be included.');
|
|
14
|
-
}
|
|
15
|
-
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET PARSE'));
|
|
16
|
-
const fileLocation = args[3];
|
|
17
|
-
const csvStyle = args[4];
|
|
18
|
-
console.log('Using File: ', fileLocation);
|
|
19
|
-
|
|
20
|
-
await parseOptionSetsLocalFiles(fileLocation, csvStyle);
|
|
21
|
-
console.log('%s Parsed', chalk.yellow.bold('OPTION SET PARSE'));
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.log(`%s PARSE Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
console.log('%s PARSE Complete.', chalk.green.bold('COMPLETE'));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function ParseOptionSetsToFolderStructure(args) {
|
|
33
|
-
try {
|
|
34
|
-
if (args?.length < 4) {
|
|
35
|
-
throw new Error('File name must be included.');
|
|
36
|
-
}
|
|
37
|
-
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET PARSE'));
|
|
38
|
-
const fileLocation = args[3];
|
|
39
|
-
console.log('Using File: ', fileLocation);
|
|
40
|
-
|
|
41
|
-
await parseOptionSetsToFolderStructure(fileLocation);
|
|
42
|
-
console.log('%s Parsed', chalk.yellow.bold('OPTION SET PARSE'));
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
console.log(`%s PARSE Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
console.log('%s PARSE Complete.', chalk.green.bold('COMPLETE'));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function loadOptionSetCSV(fileLocation) {
|
|
54
|
-
const TARGET_DIR = process.cwd();
|
|
55
|
-
try {
|
|
56
|
-
const separator = getSeparatorByPlatform();
|
|
57
|
-
|
|
58
|
-
const fullPath = TARGET_DIR + separator + fileLocation;
|
|
59
|
-
console.log('Getting file from path: ', fullPath);
|
|
60
|
-
|
|
61
|
-
return await csv().fromFile(fullPath);
|
|
62
|
-
} catch (e) {
|
|
63
|
-
throw new Error(`ERROR PARSING CSV: ${e}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function loadOptionSets(fileLocation) {
|
|
68
|
-
const TARGET_DIR = process.cwd();
|
|
69
|
-
try {
|
|
70
|
-
const separator = getSeparatorByPlatform();
|
|
71
|
-
|
|
72
|
-
const fullPath = TARGET_DIR + separator + fileLocation;
|
|
73
|
-
console.log('Getting file from path: ', fullPath);
|
|
74
|
-
|
|
75
|
-
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + fileLocation, 'utf8'));
|
|
76
|
-
return doc;
|
|
77
|
-
} catch (e) {
|
|
78
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function parseOptionSetsLocalFiles(fileLocation, csvStyle) {
|
|
83
|
-
const uploadedOptionData = await loadOptionSetCSV(fileLocation);
|
|
84
|
-
|
|
85
|
-
if (csvStyle === 'NameAndLabel') {
|
|
86
|
-
const parsedOptionSets = parseOptionSets(uploadedOptionData);
|
|
87
|
-
saveData(parsedOptionSets);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (csvStyle === 'LabelsInColumn') {
|
|
91
|
-
const parsedOptionSets = parseLabelsInColumn(uploadedOptionData);
|
|
92
|
-
saveData(parsedOptionSets);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function parseOptionSetsToFolderStructure(fileLocation) {
|
|
97
|
-
const uploadedOptionData = await loadOptionSets(fileLocation);
|
|
98
|
-
saveDataInFolders(uploadedOptionData);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function saveData(data) {
|
|
102
|
-
const yamlStr = yaml.dump(data);
|
|
103
|
-
const CURRENT_DIR = process.cwd();
|
|
104
|
-
const separator = getSeparatorByPlatform();
|
|
105
|
-
fs.writeFileSync(CURRENT_DIR + separator + 'parsed_local_optionSets.yml', yamlStr, 'utf8');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function saveDataInFolders(data) {
|
|
109
|
-
const folder = { filename: 'option-sets', split: true, fileLabel: 'name' };
|
|
110
|
-
const dir = 'merged_option_sets';
|
|
111
|
-
|
|
112
|
-
const CURRENT_DIR = process.cwd();
|
|
113
|
-
|
|
114
|
-
const subDir = path.join(CURRENT_DIR, dir, folder.filename);
|
|
115
|
-
if(!fs.existsSync(subDir)) {
|
|
116
|
-
fs.mkdirSync(subDir, { recursive: true });
|
|
117
|
-
}
|
|
118
|
-
for(const item of data) {
|
|
119
|
-
const yamlStr = yaml.dump(item);
|
|
120
|
-
const fileLabel = item[folder.fileLabel];
|
|
121
|
-
if(!fileLabel) {
|
|
122
|
-
console.warn('skipping bad data:', item);
|
|
123
|
-
}
|
|
124
|
-
fs.writeFileSync(path.join(subDir, `${removeSlash(fileLabel)}.yml`), yamlStr, 'utf8');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function removeSlash(string) {
|
|
129
|
-
const re = /\//gi;
|
|
130
|
-
return string.replace(re, '-');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function parseLabelsInColumn(uploadedOptionData) {
|
|
134
|
-
const optionSets = [];
|
|
135
|
-
const optionSetNames = Object.keys(uploadedOptionData[0]);
|
|
136
|
-
for (const optionSetName of optionSetNames) {
|
|
137
|
-
const uniqueOptionSetValues = new Set<string>();
|
|
138
|
-
for (const data of uploadedOptionData) {
|
|
139
|
-
const label = data[optionSetName];
|
|
140
|
-
uniqueOptionSetValues.add(label);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const optionSet: any[] = [];
|
|
144
|
-
if (uniqueOptionSetValues) {
|
|
145
|
-
for (const entry of uniqueOptionSetValues.values()) {
|
|
146
|
-
if (entry === '') {
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
optionSet.push({
|
|
150
|
-
value: StringUtil.convertToCamelCase(entry),
|
|
151
|
-
display: entry,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const reducedOptionSet = {
|
|
157
|
-
name: optionSetName,
|
|
158
|
-
isArchived: false,
|
|
159
|
-
optionSet,
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
optionSets.push(reducedOptionSet);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return optionSets;
|
|
166
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import { ReducedOptionSet } from './interfaces';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import * as path from 'path';
|
|
5
|
-
import { authUser } from '../auth/login';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
|
|
8
|
-
const yaml = require('js-yaml');
|
|
9
|
-
|
|
10
|
-
export async function UploadOptionSets(args) {
|
|
11
|
-
try {
|
|
12
|
-
const userConfig = await authUser();
|
|
13
|
-
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
14
|
-
|
|
15
|
-
console.log('%s Uploading', chalk.yellow.bold('OPTION SETS'));
|
|
16
|
-
await uploadOptionSets();
|
|
17
|
-
console.log('%s Uploaded', chalk.yellow.bold('OPTION SETS'));
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function loadOptionSets(){
|
|
29
|
-
const TARGET_DIR = process.cwd();
|
|
30
|
-
try {
|
|
31
|
-
const files = fs.readdirSync(path.join(TARGET_DIR, 'option-sets'));
|
|
32
|
-
const optionSets = [];
|
|
33
|
-
for(const file of files) {
|
|
34
|
-
optionSets.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'option-sets', file), 'utf8')));
|
|
35
|
-
}
|
|
36
|
-
return optionSets;
|
|
37
|
-
} catch (e) {
|
|
38
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function uploadOptionSets() {
|
|
43
|
-
const optionSets: ReducedOptionSet[] = loadOptionSets();
|
|
44
|
-
|
|
45
|
-
const currentOptionSets = await new Entities().get({
|
|
46
|
-
entityName: 'type-property-option-set',
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const currentOptionSetsByName = {};
|
|
50
|
-
for (const currentOptionSet of currentOptionSets) {
|
|
51
|
-
currentOptionSetsByName[currentOptionSet.name] = currentOptionSet;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const newOptionSetsByName = {};
|
|
55
|
-
for (const optionSet of optionSets) {
|
|
56
|
-
newOptionSetsByName[optionSet.name] = optionSet;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for (const optionSet of optionSets) {
|
|
60
|
-
try {
|
|
61
|
-
const found = currentOptionSetsByName[optionSet.name];
|
|
62
|
-
if (!found) {
|
|
63
|
-
if (!optionSet.optionSet) {
|
|
64
|
-
console.log('No OptionSet for: ', optionSet.name);
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
console.log('Creating: ', optionSet.name);
|
|
68
|
-
await new Entities().create({
|
|
69
|
-
entityName: 'type-property-option-set',
|
|
70
|
-
object: {
|
|
71
|
-
name: optionSet.name,
|
|
72
|
-
optionSet: optionSet.optionSet,
|
|
73
|
-
isArchived: optionSet.isArchived,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
} else {
|
|
77
|
-
console.log('Updating: ', optionSet.name);
|
|
78
|
-
await new Entities().update({
|
|
79
|
-
entityName: 'type-property-option-set',
|
|
80
|
-
id: found.id,
|
|
81
|
-
object: {
|
|
82
|
-
name: optionSet.name,
|
|
83
|
-
optionSet: optionSet.optionSet,
|
|
84
|
-
isArchived: optionSet.isArchived,
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
} catch (err) {
|
|
89
|
-
throw new Error(`Error Uploading OptionSets: ${err}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
for (const currentOptionSet of currentOptionSets) {
|
|
94
|
-
try {
|
|
95
|
-
const found = newOptionSetsByName[currentOptionSet.name];
|
|
96
|
-
if (!found) {
|
|
97
|
-
console.log('Deleting: ', currentOptionSet.name);
|
|
98
|
-
await new Entities().delete({
|
|
99
|
-
entityName: 'type-property-option-set',
|
|
100
|
-
id: currentOptionSet.id,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
} catch (err) {
|
|
104
|
-
throw new Error(`Error Deleting OptionSets: ${err}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|