@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,225 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import { ObjectUtil } from '@contrail/util';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import { authUser } from '../auth/login';
|
|
6
|
-
import { getSeparatorByPlatform } from '../common';
|
|
7
|
-
import yaml from 'js-yaml';
|
|
8
|
-
|
|
9
|
-
export async function ListProjects() {
|
|
10
|
-
try {
|
|
11
|
-
await authUser();
|
|
12
|
-
console.log('%s Getting Projects.', chalk.blue.bold('START'));
|
|
13
|
-
|
|
14
|
-
await listProjects();
|
|
15
|
-
console.log('%s Done', chalk.yellow.bold('PROJECTS'));
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
console.log(`%s Project download Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
console.log('%s Project download Complete.', chalk.green.bold('COMPLETE'));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function ExportProject(args) {
|
|
27
|
-
try {
|
|
28
|
-
await authUser();
|
|
29
|
-
console.log('%s Exporting Project.', chalk.blue.bold('START'));
|
|
30
|
-
|
|
31
|
-
console.log('%s Exporting', chalk.yellow.bold('PROJECT'));
|
|
32
|
-
const projectName = args[3];
|
|
33
|
-
await exportProject(projectName);
|
|
34
|
-
console.log('%s Exported', chalk.yellow.bold('PROJECT'));
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
console.log(`%s Project Export Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
console.log('%s Project Export Complete.', chalk.green.bold('COMPLETE'));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function listProjects() {
|
|
46
|
-
const allWorkspaces = await new Entities().get({
|
|
47
|
-
entityName: 'workspace',
|
|
48
|
-
criteria: {isArchived: false}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
console.log('%s', chalk.green.bold('PROJECTS:'));
|
|
52
|
-
//console.log(allWorkspaces.map(w => Object.assign({}, {name: w.name, id: w.id}))); // if we want ids
|
|
53
|
-
console.log(allWorkspaces.map(w => w.name));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function exportProject(name) {
|
|
57
|
-
const allWorkspaces = await new Entities().get({
|
|
58
|
-
entityName: 'workspace',
|
|
59
|
-
useSearch: false,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const workspace = allWorkspaces.find(w => w.name === name);
|
|
63
|
-
if (!workspace) {
|
|
64
|
-
throw new Error('Project was not found.');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const projectConfiguration = {
|
|
68
|
-
projectName: workspace.name,
|
|
69
|
-
identifier: workspace.identifier,
|
|
70
|
-
principals: [],
|
|
71
|
-
commonConfig: {},
|
|
72
|
-
assortments: [],
|
|
73
|
-
subFolders: []
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
projectConfiguration.principals = await getFolderPrincipals(workspace);
|
|
77
|
-
|
|
78
|
-
const allAssortments = [];
|
|
79
|
-
await getAssortmentsAndSubFolders(workspace.id, projectConfiguration.assortments, projectConfiguration.subFolders, allAssortments);
|
|
80
|
-
await convertRelationshipsInFolders(projectConfiguration, allAssortments);
|
|
81
|
-
saveData({projectConfiguration: projectConfiguration}, name);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function getAssortmentsAndSubFolders(parentId, assortments, subFolders, allAssortments) {
|
|
85
|
-
const workspaceAssortments = await new Entities().get({
|
|
86
|
-
entityName: 'assortment',
|
|
87
|
-
criteria: {
|
|
88
|
-
workspaceId: parentId,
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const integrationAssortments = workspaceAssortments?.filter(a => a.assortmentType === 'INTEGRATION');
|
|
93
|
-
|
|
94
|
-
if (integrationAssortments?.length > 0) {
|
|
95
|
-
allAssortments.push(...integrationAssortments);
|
|
96
|
-
for (const a of integrationAssortments) {
|
|
97
|
-
const integrationAssortmentsCopy = ObjectUtil.cloneDeep(a);
|
|
98
|
-
deleteNonUserKeys(integrationAssortmentsCopy);
|
|
99
|
-
const converted = {
|
|
100
|
-
identifier: a.identifier,
|
|
101
|
-
name: a.name,
|
|
102
|
-
type: 'ASSORTMENT',
|
|
103
|
-
sourceAssortmentIdentifier: [],
|
|
104
|
-
sourceAssortmentIds: a.sourceAssortmentIds,
|
|
105
|
-
composedFromAssortmentIdentifiers: [],
|
|
106
|
-
composedFromAssortmentIds: a.composedFromAssortmentIds,
|
|
107
|
-
assortmentAtts: Object.assign({}, integrationAssortmentsCopy),
|
|
108
|
-
};
|
|
109
|
-
assortments.push(converted);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
console.log('workspaceFolderLinks call');
|
|
114
|
-
|
|
115
|
-
const workspaceFolderLinks = await new Entities().get({
|
|
116
|
-
entityName: 'workspace-entity',
|
|
117
|
-
criteria: {
|
|
118
|
-
workspaceId: parentId,
|
|
119
|
-
entityType: 'workspace'
|
|
120
|
-
},
|
|
121
|
-
relations: ['entity']
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const workspaceFolders = workspaceFolderLinks?.map(wfl => wfl.entity);
|
|
125
|
-
|
|
126
|
-
if (workspaceFolders?.length > 0) {
|
|
127
|
-
for (const folder of workspaceFolders) {
|
|
128
|
-
const converted = {
|
|
129
|
-
identifier: folder.identifier,
|
|
130
|
-
name: folder.name,
|
|
131
|
-
principals: [],
|
|
132
|
-
assortments: [],
|
|
133
|
-
subFolders: [],
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
converted.principals = await getFolderPrincipals(folder);
|
|
137
|
-
await getAssortmentsAndSubFolders(folder.id, converted.assortments, converted.subFolders, allAssortments);
|
|
138
|
-
subFolders.push(converted);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async function convertRelationshipsInFolders(folder, allAssortments) {
|
|
145
|
-
if (!(allAssortments.length > 0)) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
convertRelationshipsToIdentifiers(folder.assortments, allAssortments);
|
|
150
|
-
|
|
151
|
-
for (const f of folder.subFolders) {
|
|
152
|
-
convertRelationshipsInFolders(f, allAssortments);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function convertRelationshipsToIdentifiers(assortments, allAssortments) {
|
|
158
|
-
if (!(allAssortments.length > 0)) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
for (const assortment of assortments) {
|
|
163
|
-
if (assortment.sourceAssortmentIds) {
|
|
164
|
-
assortment.sourceAssortmentIdentifier = assortment.sourceAssortmentIds.map(id => allAssortments.find(a => a.id === id)?.identifier);
|
|
165
|
-
}
|
|
166
|
-
delete assortment.sourceAssortmentIds;
|
|
167
|
-
|
|
168
|
-
if (assortment.composedFromAssortmentIds) {
|
|
169
|
-
assortment.composedFromAssortmentIdentifiers = assortment.composedFromAssortmentIds.map(id => allAssortments.find(a => a.id === id)?.identifier);
|
|
170
|
-
}
|
|
171
|
-
delete assortment.composedFromAssortmentIds;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async function getFolderPrincipals(folder) {
|
|
176
|
-
const principals = [];
|
|
177
|
-
if (!folder.policyOwner) {
|
|
178
|
-
return ['INHERIT'];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const workspacePrincipals = await new Entities().get({
|
|
182
|
-
entityName: 'workspace-principal',
|
|
183
|
-
criteria: {workspaceId: folder.id},
|
|
184
|
-
relations: ['principal']
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
for (const workspacePrincipal of workspacePrincipals) {
|
|
188
|
-
|
|
189
|
-
if (workspacePrincipal.principal.email) {
|
|
190
|
-
principals.push(workspacePrincipal.principal.email + '|' + workspacePrincipal.role);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
principals.push(workspacePrincipal.principal.name + '|' + workspacePrincipal.role);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return principals;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function deleteNonUserKeys(assortment) {
|
|
201
|
-
delete assortment.name;
|
|
202
|
-
delete assortment.identifier;
|
|
203
|
-
delete assortment.assortmentType;
|
|
204
|
-
delete assortment.createdById;
|
|
205
|
-
delete assortment.createdForReference;
|
|
206
|
-
delete assortment.createdOn;
|
|
207
|
-
delete assortment.entityType;
|
|
208
|
-
delete assortment.id;
|
|
209
|
-
delete assortment.orgId;
|
|
210
|
-
delete assortment.rootWorkspaceId;
|
|
211
|
-
delete assortment.composedFromAssortmentIds;
|
|
212
|
-
delete assortment.sourceAssortmentIds;
|
|
213
|
-
delete assortment.typeId;
|
|
214
|
-
delete assortment.typePath;
|
|
215
|
-
delete assortment.updatedById;
|
|
216
|
-
delete assortment.updatedOn;
|
|
217
|
-
delete assortment.workspaceId;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function saveData(data, name) {
|
|
221
|
-
const yamlStr = yaml.dump(data);
|
|
222
|
-
const CURRENT_DIR = process.cwd();
|
|
223
|
-
const separator = getSeparatorByPlatform();
|
|
224
|
-
fs.writeFileSync(CURRENT_DIR + separator + name + '-export.yml', yamlStr, 'utf8');
|
|
225
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { Request } 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
|
-
import { ProjectConfiguration, ProjectConfigurationTemplate } from './interfaces';
|
|
7
|
-
|
|
8
|
-
import yaml from 'js-yaml';
|
|
9
|
-
|
|
10
|
-
export async function configureProject(args) {
|
|
11
|
-
try {
|
|
12
|
-
await authUser();
|
|
13
|
-
console.log('%s Parsing Template.', chalk.blue.bold('START'));
|
|
14
|
-
|
|
15
|
-
console.log('%s Uploading', chalk.yellow.bold('PROJECT'));
|
|
16
|
-
const templateFileLocation = args[3];
|
|
17
|
-
console.log('Using Template File Location: ', templateFileLocation);
|
|
18
|
-
await uploadProject(templateFileLocation);
|
|
19
|
-
console.log('%s Uploaded', chalk.yellow.bold('PROJECT'));
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.log(`%s Project Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
console.log('%s Project Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function getProjectFile(fileName){
|
|
31
|
-
const CURRENT_DIR = process.cwd();
|
|
32
|
-
try {
|
|
33
|
-
const separator = getSeparatorByPlatform();
|
|
34
|
-
const fullPath = CURRENT_DIR + separator + fileName;
|
|
35
|
-
console.log('Getting file from path: ', fullPath);
|
|
36
|
-
|
|
37
|
-
const doc = yaml.load(fs.readFileSync(fullPath, 'utf8'));
|
|
38
|
-
return doc.projectConfiguration;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function uploadProject(templateFileLocation) {
|
|
45
|
-
const projectConfigurationFromFile = getProjectFile(templateFileLocation);
|
|
46
|
-
const projectConfiguration: ProjectConfiguration = getProjectConfiguration(projectConfigurationFromFile);
|
|
47
|
-
|
|
48
|
-
console.log('Configuring Project.');
|
|
49
|
-
|
|
50
|
-
await Request.request(
|
|
51
|
-
'/project-configurator',
|
|
52
|
-
{
|
|
53
|
-
method: 'POST',
|
|
54
|
-
body: JSON.stringify(projectConfiguration),
|
|
55
|
-
headers: {
|
|
56
|
-
Accept: 'application/json',
|
|
57
|
-
'Content-Type': 'application/json',
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function getProjectConfiguration(projectConfigurationFromFile): ProjectConfiguration {
|
|
63
|
-
if (!projectConfigurationFromFile.allFolders && !projectConfigurationFromFile.allAssortments && !projectConfigurationFromFile.allAssortmentRelationships) {
|
|
64
|
-
return projectConfigurationFromFile;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const parsed = parseToProjectConfiguration(projectConfigurationFromFile);
|
|
68
|
-
return parsed;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function parseToProjectConfiguration(projectConfigurationFromFile: ProjectConfigurationTemplate): ProjectConfiguration {
|
|
72
|
-
|
|
73
|
-
const projectConfiguration: ProjectConfiguration = {
|
|
74
|
-
projectName: projectConfigurationFromFile.projectName,
|
|
75
|
-
identifier: projectConfigurationFromFile.identifier,
|
|
76
|
-
commonConfig: projectConfigurationFromFile.commonConfig,
|
|
77
|
-
principals: projectConfigurationFromFile.principals,
|
|
78
|
-
assortments: [],
|
|
79
|
-
subFolders: [],
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const foldersByIdentifier: any = {[projectConfiguration.identifier]: projectConfiguration};
|
|
83
|
-
for (const folder of projectConfigurationFromFile.allFolders) {
|
|
84
|
-
foldersByIdentifier[folder.identifier] = folder;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const assortmentsByIdentifier = {};
|
|
88
|
-
for (const assortment of projectConfigurationFromFile.allAssortments) {
|
|
89
|
-
assortmentsByIdentifier[assortment.identifier] = assortment;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
for (const assortmentRelationships of projectConfigurationFromFile.allAssortmentRelationships) {
|
|
93
|
-
const assortment = assortmentsByIdentifier[assortmentRelationships.identifier];
|
|
94
|
-
if (!assortment) {
|
|
95
|
-
console.warn('Relationship defined for assortment that is not defined.', assortmentRelationships);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
Object.assign(assortment, assortmentRelationships);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
for (const assortment of projectConfigurationFromFile.allAssortments) {
|
|
103
|
-
const folder = foldersByIdentifier[assortment.folderIdentifier];
|
|
104
|
-
if (!folder) {
|
|
105
|
-
console.warn('Assortment defined for folder that is not defined.', assortment);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!folder.assortments) {
|
|
109
|
-
folder.assortments = [];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
delete assortment.folderIdentifier;
|
|
113
|
-
folder.assortments.push(assortment);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
for (const folderSlim of projectConfigurationFromFile.allFolders) {
|
|
117
|
-
const folder = foldersByIdentifier[folderSlim.folderIdentifier];
|
|
118
|
-
if (!folder) {
|
|
119
|
-
console.warn('Folder defined for folder that is not defined.', folderSlim);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!folder.subFolders) {
|
|
123
|
-
folder.subFolders = [];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
delete folderSlim.folderIdentifier;
|
|
127
|
-
folder.subFolders.push(folderSlim);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return projectConfiguration;
|
|
131
|
-
}
|
package/src/types/allUploader.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { authUser } from '../auth/login';
|
|
3
|
-
|
|
4
|
-
import { UploadOptionSets } from './option-set-uploader';
|
|
5
|
-
import { UploadOptionSetHierarchies } from './option-set-hierarchy-uploader';
|
|
6
|
-
import { uploadTypes } from './types-uploader';
|
|
7
|
-
import { uploadUsageInfo } from './usage-info-uploader';
|
|
8
|
-
import { uploadRuleSets } from './rule-set-uploader';
|
|
9
|
-
import { uploadTypePropertyPolicies } from './type-property-policy-uploader';
|
|
10
|
-
|
|
11
|
-
export async function uploadAll() {
|
|
12
|
-
try {
|
|
13
|
-
await authUser();
|
|
14
|
-
await UploadOptionSets(null);
|
|
15
|
-
await UploadOptionSetHierarchies(null);
|
|
16
|
-
await uploadTypes();
|
|
17
|
-
await uploadUsageInfo(null);
|
|
18
|
-
await uploadRuleSets(null);
|
|
19
|
-
await uploadTypePropertyPolicies(null);
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
28
|
-
}
|
package/src/types/csv-parser.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import csvToJson from 'csvtojson';
|
|
2
|
-
import * as client from 'https';
|
|
3
|
-
import { Entities } from '@contrail/sdk';
|
|
4
|
-
|
|
5
|
-
export async function getCSVFromFile(loadFileId: string): Promise<any[]> {
|
|
6
|
-
|
|
7
|
-
let file;
|
|
8
|
-
try {
|
|
9
|
-
file = await new Entities().get({ entityName: 'file', id: loadFileId });
|
|
10
|
-
console.log('Got file: ', file);
|
|
11
|
-
} catch (e) {
|
|
12
|
-
console.log(`Failed to get file: ${loadFileId}`, JSON.stringify(e));
|
|
13
|
-
throw new Error(`Failed to get file: ${loadFileId} - ` + JSON.stringify(e));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (!file || !file.downloadUrl) {
|
|
17
|
-
console.log(`File: ${loadFileId} does not have a downloadUrl`);
|
|
18
|
-
throw new Error(`File: ${loadFileId} does not have a downloadUrl`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// get csv
|
|
22
|
-
let response;
|
|
23
|
-
try {
|
|
24
|
-
response = await new Promise((resolve, reject) => {
|
|
25
|
-
client.get(file.downloadUrl, function(res) {
|
|
26
|
-
console.log('Status code:', res.statusCode);
|
|
27
|
-
console.log('Status text:', res.statusMessage);
|
|
28
|
-
|
|
29
|
-
let body = '';
|
|
30
|
-
|
|
31
|
-
res.on('data', (data) => {
|
|
32
|
-
body += data.toString();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
res.on('end', () => {
|
|
36
|
-
console.log('Response body:');
|
|
37
|
-
//console.log(body);
|
|
38
|
-
resolve(body);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
}).on('error', function(e) {
|
|
42
|
-
console.error(e);
|
|
43
|
-
reject(e);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.log(`Failed to get data from downloadUrl: ${file.downloadUrl}`, e);
|
|
48
|
-
throw e;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!response) {
|
|
52
|
-
console.log('Response is empty');
|
|
53
|
-
throw new Error('Response is empty');
|
|
54
|
-
}
|
|
55
|
-
const csvJson = await csvToJson({flatKeys: true}).fromString(response);
|
|
56
|
-
// console.log('csvJson', csvJson);
|
|
57
|
-
|
|
58
|
-
return csvJson;
|
|
59
|
-
}
|
package/src/types/interfaces.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export interface ReducedType {
|
|
2
|
-
slug: string;
|
|
3
|
-
label: string;
|
|
4
|
-
typePath: string;
|
|
5
|
-
isArchived: boolean;
|
|
6
|
-
typeProperties: ReducedTypeProperty[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface ReducedTypeProperty {
|
|
10
|
-
id: string;
|
|
11
|
-
isArchived: boolean;
|
|
12
|
-
propertyType: PropertyType;
|
|
13
|
-
slug: string;
|
|
14
|
-
label: string;
|
|
15
|
-
editable: boolean;
|
|
16
|
-
searchable: boolean;
|
|
17
|
-
core: boolean;
|
|
18
|
-
typePropertyOptionSetName: string;
|
|
19
|
-
formula: string;
|
|
20
|
-
referencedTypeRootSlug: string;
|
|
21
|
-
defaultValue: string;
|
|
22
|
-
propertyLevel: string;
|
|
23
|
-
inherited: boolean;
|
|
24
|
-
formulaFunction?: string;
|
|
25
|
-
validationFunction?: string;
|
|
26
|
-
numberFormat?: any;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface ReducedOptionSet {
|
|
30
|
-
name: string;
|
|
31
|
-
isArchived: boolean;
|
|
32
|
-
optionSet: any[];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export declare enum PropertyType {
|
|
36
|
-
Text = 'text',
|
|
37
|
-
String = 'string',
|
|
38
|
-
Number = 'number',
|
|
39
|
-
Date = 'date',
|
|
40
|
-
Boolean = 'boolean',
|
|
41
|
-
MultiSelect = 'multi_select',
|
|
42
|
-
SingleSelect = 'choice',
|
|
43
|
-
Url = 'url',
|
|
44
|
-
Currency = 'currency',
|
|
45
|
-
Percent = 'percent',
|
|
46
|
-
Rating = 'rating',
|
|
47
|
-
Formula = 'formula',
|
|
48
|
-
ObjectReference = 'object_reference',
|
|
49
|
-
ObjectReferenceList = 'object_ref_list',
|
|
50
|
-
DataGrid = 'data_grid',
|
|
51
|
-
CascadingSelect = 'cascading_select',
|
|
52
|
-
Sequence = 'sequence',
|
|
53
|
-
Constant = 'constant',
|
|
54
|
-
Composite = 'composite',
|
|
55
|
-
UserList = 'userList',
|
|
56
|
-
Image = 'image',
|
|
57
|
-
Json = 'json',
|
|
58
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { getSeparatorByPlatform } from '../common';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { Entities } from '@contrail/sdk';
|
|
5
|
-
import { authUser } from '../auth/login';
|
|
6
|
-
import { ObjectUtil, StringUtil } from '@contrail/util';
|
|
7
|
-
const { Parser } = require('json2csv');
|
|
8
|
-
|
|
9
|
-
export async function ExportOptionSetsHierarchies() {
|
|
10
|
-
try {
|
|
11
|
-
await authUser();
|
|
12
|
-
|
|
13
|
-
console.log('%s Exporting local file', chalk.yellow.bold('OPTION SET HIERARCHY EXPORT'));
|
|
14
|
-
await exportOptionSetHierarchies();
|
|
15
|
-
console.log('%s Exported', chalk.yellow.bold('OPTION SET HIERARCHY EXPORT'));
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
console.log(`%s EXPORT Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
console.log('%s EXPORT Complete.', chalk.green.bold('COMPLETE'));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function exportOptionSetHierarchies() {
|
|
27
|
-
const allOptionSetHierarchies = await new Entities().get({
|
|
28
|
-
entityName: 'option-set-hierarchy',
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const currentOptionSets = await new Entities().get({
|
|
32
|
-
entityName: 'type-property-option-set',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
for (const optionSetHierarchy of allOptionSetHierarchies) {
|
|
36
|
-
const levelNameInOrder = [];
|
|
37
|
-
for (const optionSetId of optionSetHierarchy.hierarchy) {
|
|
38
|
-
const os = currentOptionSets.find(os => os.id === optionSetId);
|
|
39
|
-
levelNameInOrder.push(StringUtil.convertToCamelCase(os.name));
|
|
40
|
-
}
|
|
41
|
-
transformAndSave(optionSetHierarchy, levelNameInOrder);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function transformAndSave(optionSetHierarchy, levelNameInOrder) {
|
|
46
|
-
const finalObjects = [];
|
|
47
|
-
transform(optionSetHierarchy.options, levelNameInOrder, [], finalObjects);
|
|
48
|
-
saveData(optionSetHierarchy.name, finalObjects, levelNameInOrder);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/*
|
|
52
|
-
Transform will take in a set if options, the names left to process, the partly completed objects, and the list to place the final objects.
|
|
53
|
-
On the first pass the list of names will be full and the list of partial objects will be empty. On this pass we create objects
|
|
54
|
-
with one field, the name of the field is the first name in levelNameInOrder. These objects are added to the workingObjects list
|
|
55
|
-
for the next run. On the following (recursive) runs there will be one less name in the levelNameInOrder (we remove the name we just processed)
|
|
56
|
-
and there will be objects to clone and add to in the workingObjects list. When all the objects have been created (There are no names
|
|
57
|
-
left in the levelNameInOrder list), all the objects are added to the finalObjects list.
|
|
58
|
-
|
|
59
|
-
Initial Input:
|
|
60
|
-
options: {value: "BTP", options: [{value: "The Great"}, {value: "The Best"}]}
|
|
61
|
-
levelNameInOrder: ["name", "title"]
|
|
62
|
-
workingObjects: []
|
|
63
|
-
finalObjects: []
|
|
64
|
-
|
|
65
|
-
Level 2 Input 1:
|
|
66
|
-
options: [{value: "The Great"}]
|
|
67
|
-
levelNameInOrder: ["title"]
|
|
68
|
-
workingObjects: [{name: "BTP"}]
|
|
69
|
-
finalObjects: []
|
|
70
|
-
|
|
71
|
-
Level 2 Input 2:
|
|
72
|
-
options: [{value: "The Best"}]
|
|
73
|
-
levelNameInOrder: ["title"]
|
|
74
|
-
workingObjects: [{name: "BTP"}]
|
|
75
|
-
finalObjects: []
|
|
76
|
-
|
|
77
|
-
Final Objects:
|
|
78
|
-
[{name: "BTP", title: "The Great"}, {name: "BTP", title: "The Best"}]
|
|
79
|
-
*/
|
|
80
|
-
function transform(options, levelNameInOrder, workingObjects, finalObjects) {
|
|
81
|
-
for (const option of options) {
|
|
82
|
-
const localObjects = [];
|
|
83
|
-
if (workingObjects.length === 0) {
|
|
84
|
-
localObjects.push({[levelNameInOrder[0]]: option.value});
|
|
85
|
-
if (levelNameInOrder.length <= 1) {
|
|
86
|
-
finalObjects.push(...localObjects);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
transform(option.options, levelNameInOrder.slice(1,), localObjects, finalObjects);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
for (const workingObject of workingObjects) {
|
|
94
|
-
const clone = ObjectUtil.cloneDeep(workingObject);
|
|
95
|
-
clone[levelNameInOrder[0]] = option.value;
|
|
96
|
-
localObjects.push(clone);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (levelNameInOrder.length <= 1) {
|
|
100
|
-
finalObjects.push(...localObjects);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
transform(option.options, levelNameInOrder.slice(1,), localObjects, finalObjects);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function saveData(name, data, fieldNames) {
|
|
111
|
-
const CURRENT_DIR = process.cwd();
|
|
112
|
-
const separator = getSeparatorByPlatform();
|
|
113
|
-
const opts = { fieldNames };
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
const parser = new Parser(opts);
|
|
117
|
-
const csv = parser.parse(data);
|
|
118
|
-
fs.mkdirSync(CURRENT_DIR + separator + 'option-set-hierarchies', { recursive: true });
|
|
119
|
-
fs.writeFileSync(CURRENT_DIR + separator + 'option-set-hierarchies' + separator + name + '.csv', csv, {
|
|
120
|
-
flag: 'w',
|
|
121
|
-
});
|
|
122
|
-
} catch (err) {
|
|
123
|
-
console.error(err);
|
|
124
|
-
}
|
|
125
|
-
}
|