@contrail/cli 1.0.53 → 1.0.54
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/cli.js +19 -10
- package/lib/types/option-set-hierarchy-exporter.d.ts +1 -0
- package/lib/types/option-set-hierarchy-exporter.js +113 -0
- package/lib/types/option-set-hierarchy-parser.d.ts +2 -2
- package/lib/types/option-set-hierarchy-parser.js +9 -9
- package/package.json +2 -1
- package/src/cli.ts +19 -10
- package/src/types/option-set-hierarchy-exporter.ts +125 -0
- package/src/types/option-set-hierarchy-parser.ts +9 -9
package/lib/cli.js
CHANGED
|
@@ -4,7 +4,8 @@ import { getTypes } from './types/types-extractor';
|
|
|
4
4
|
import { uploadTypes } from './types/types-uploader';
|
|
5
5
|
import { UploadOptionSets } from './types/option-set-uploader';
|
|
6
6
|
import { ParseOptionSetsLocalFiles } from './types/option-set-parser';
|
|
7
|
-
import {
|
|
7
|
+
import { ParseOptionSetsHierarchyLocalFile, UploadOptionSetsHierarchyLocalFile } from './types/option-set-hierarchy-parser';
|
|
8
|
+
import { ExportOptionSetsHierarchies } from './types/option-set-hierarchy-exporter';
|
|
8
9
|
import { MergeOptionSets } from './types/option-set-merger';
|
|
9
10
|
import { MergeTypeProperties } from './types/types-properties-merger';
|
|
10
11
|
import { ParseTypesFromFiles, ParseTypesFromLocalFiles, ParseTypesFromTemplateFromLocalFiles, ParseTypesFromTemplateAndDataFromLocalFiles } from './types/parse-types';
|
|
@@ -93,12 +94,16 @@ export async function cli(args) {
|
|
|
93
94
|
ParseOptionSetsLocalFiles(args);
|
|
94
95
|
break;
|
|
95
96
|
}
|
|
96
|
-
case '
|
|
97
|
-
|
|
97
|
+
case 'parseOptionSetsHierarchyLocalFile': {
|
|
98
|
+
ParseOptionSetsHierarchyLocalFile(args);
|
|
98
99
|
break;
|
|
99
100
|
}
|
|
100
|
-
case '
|
|
101
|
-
|
|
101
|
+
case 'uploadOptionSetsHierarchyLocalFile': {
|
|
102
|
+
UploadOptionSetsHierarchyLocalFile(args);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 'exportOptionSetsHierarchies': {
|
|
106
|
+
ExportOptionSetsHierarchies();
|
|
102
107
|
break;
|
|
103
108
|
}
|
|
104
109
|
case 'parseTypesFromLocalFiles': {
|
|
@@ -384,15 +389,19 @@ const helpSections = [
|
|
|
384
389
|
},
|
|
385
390
|
{
|
|
386
391
|
name: 'parseOptionSetsLocalFiles <File Paths>',
|
|
387
|
-
summary: 'Parse CSV files into OptionSets
|
|
392
|
+
summary: 'Parse CSV files into OptionSets.\n'
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
name: 'parseOptionSetsHierarchyLocalFile <File Path>',
|
|
396
|
+
summary: 'Parse CSV file into OptionSetHierarchy.'
|
|
388
397
|
},
|
|
389
398
|
{
|
|
390
|
-
name: '
|
|
391
|
-
summary: '
|
|
399
|
+
name: 'uploadOptionSetsHierarchyLocalFile <File Path> <name>',
|
|
400
|
+
summary: 'upload CSV file into OptionSetHierarchy.'
|
|
392
401
|
},
|
|
393
402
|
{
|
|
394
|
-
name: '
|
|
395
|
-
summary: '
|
|
403
|
+
name: 'exportOptionSetsHierarchies',
|
|
404
|
+
summary: 'export OptionSetHierarchies into CSVs.\n'
|
|
396
405
|
},
|
|
397
406
|
{
|
|
398
407
|
name: 'parseTypesFromLocalFiles <File Paths>',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ExportOptionSetsHierarchies(): Promise<void>;
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
export async function ExportOptionSetsHierarchies() {
|
|
9
|
+
try {
|
|
10
|
+
await authUser();
|
|
11
|
+
console.log('%s Exporting local file', chalk.yellow.bold('OPTION SET HIERARCHY EXPORT'));
|
|
12
|
+
await exportOptionSetHierarchies();
|
|
13
|
+
console.log('%s Exported', chalk.yellow.bold('OPTION SET HIERARCHY EXPORT'));
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
console.log(`%s EXPORT Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
console.log('%s EXPORT Complete.', chalk.green.bold('COMPLETE'));
|
|
20
|
+
}
|
|
21
|
+
async function exportOptionSetHierarchies() {
|
|
22
|
+
const allOptionSetHierarchies = await new Entities().get({
|
|
23
|
+
entityName: 'option-set-hierarchy',
|
|
24
|
+
});
|
|
25
|
+
const currentOptionSets = await new Entities().get({
|
|
26
|
+
entityName: 'type-property-option-set',
|
|
27
|
+
});
|
|
28
|
+
for (const optionSetHierarchy of allOptionSetHierarchies) {
|
|
29
|
+
const levelNameInOrder = [];
|
|
30
|
+
for (const optionSetId of optionSetHierarchy.hierarchy) {
|
|
31
|
+
const os = currentOptionSets.find(os => os.id === optionSetId);
|
|
32
|
+
levelNameInOrder.push(StringUtil.convertToCamelCase(os.name));
|
|
33
|
+
}
|
|
34
|
+
transformAndSave(optionSetHierarchy, levelNameInOrder);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function transformAndSave(optionSetHierarchy, levelNameInOrder) {
|
|
38
|
+
const finalObjects = [];
|
|
39
|
+
transform(optionSetHierarchy.options, levelNameInOrder, [], finalObjects);
|
|
40
|
+
saveData(optionSetHierarchy.name, finalObjects, levelNameInOrder);
|
|
41
|
+
}
|
|
42
|
+
/*
|
|
43
|
+
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.
|
|
44
|
+
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
|
|
45
|
+
with one field, the name of the field is the first name in levelNameInOrder. These objects are added to the workingObjects list
|
|
46
|
+
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)
|
|
47
|
+
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
|
|
48
|
+
left in the levelNameInOrder list), all the objects are added to the finalObjects list.
|
|
49
|
+
|
|
50
|
+
Initial Input:
|
|
51
|
+
options: {value: "BTP", options: [{value: "The Great"}, {value: "The Best"}]}
|
|
52
|
+
levelNameInOrder: ["name", "title"]
|
|
53
|
+
workingObjects: []
|
|
54
|
+
finalObjects: []
|
|
55
|
+
|
|
56
|
+
Level 2 Input 1:
|
|
57
|
+
options: [{value: "The Great"}]
|
|
58
|
+
levelNameInOrder: ["title"]
|
|
59
|
+
workingObjects: [{name: "BTP"}]
|
|
60
|
+
finalObjects: []
|
|
61
|
+
|
|
62
|
+
Level 2 Input 2:
|
|
63
|
+
options: [{value: "The Best"}]
|
|
64
|
+
levelNameInOrder: ["title"]
|
|
65
|
+
workingObjects: [{name: "BTP"}]
|
|
66
|
+
finalObjects: []
|
|
67
|
+
|
|
68
|
+
Final Objects:
|
|
69
|
+
[{name: "BTP", title: "The Great"}, {name: "BTP", title: "The Best"}]
|
|
70
|
+
*/
|
|
71
|
+
function transform(options, levelNameInOrder, workingObjects, finalObjects) {
|
|
72
|
+
for (const option of options) {
|
|
73
|
+
const localObjects = [];
|
|
74
|
+
if (workingObjects.length === 0) {
|
|
75
|
+
localObjects.push({ [levelNameInOrder[0]]: option.value });
|
|
76
|
+
if (levelNameInOrder.length <= 1) {
|
|
77
|
+
finalObjects.push(...localObjects);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
transform(option.options, levelNameInOrder.slice(1), localObjects, finalObjects);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
for (const workingObject of workingObjects) {
|
|
85
|
+
const clone = ObjectUtil.cloneDeep(workingObject);
|
|
86
|
+
clone[levelNameInOrder[0]] = option.value;
|
|
87
|
+
localObjects.push(clone);
|
|
88
|
+
}
|
|
89
|
+
if (levelNameInOrder.length <= 1) {
|
|
90
|
+
finalObjects.push(...localObjects);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
transform(option.options, levelNameInOrder.slice(1), localObjects, finalObjects);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function saveData(name, data, fieldNames) {
|
|
99
|
+
const CURRENT_DIR = process.cwd();
|
|
100
|
+
const separator = getSeparatorByPlatform();
|
|
101
|
+
const opts = { fieldNames };
|
|
102
|
+
try {
|
|
103
|
+
const parser = new Parser(opts);
|
|
104
|
+
const csv = parser.parse(data);
|
|
105
|
+
fs.mkdirSync(CURRENT_DIR + separator + 'option-set-hierarchies', { recursive: true });
|
|
106
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'option-set-hierarchies' + separator + name + '.csv', csv, {
|
|
107
|
+
flag: 'w',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
console.error(err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export declare function
|
|
1
|
+
export declare function ParseOptionSetsHierarchyLocalFile(args: any): Promise<void>;
|
|
2
|
+
export declare function UploadOptionSetsHierarchyLocalFile(args: any): Promise<void>;
|
|
@@ -5,7 +5,7 @@ const csv = require('csvtojson');
|
|
|
5
5
|
import { Entities } from '@contrail/sdk';
|
|
6
6
|
import { StringUtil } from '@contrail/util';
|
|
7
7
|
import { authUser } from '../auth/login';
|
|
8
|
-
export async function
|
|
8
|
+
export async function ParseOptionSetsHierarchyLocalFile(args) {
|
|
9
9
|
try {
|
|
10
10
|
await authUser();
|
|
11
11
|
if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
|
|
@@ -14,7 +14,7 @@ export async function ParseOptionSetsHierarchyLocalFiles(args) {
|
|
|
14
14
|
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET HIERARCHY PARSE'));
|
|
15
15
|
const fileLocation = args[3];
|
|
16
16
|
console.log('Using File: ', fileLocation);
|
|
17
|
-
await
|
|
17
|
+
await parseAndSaveOptionSetHierarchiesLocalFile(fileLocation);
|
|
18
18
|
console.log('%s Parsed', chalk.yellow.bold('OPTION SET HIERARCHY PARSE'));
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
@@ -23,7 +23,7 @@ export async function ParseOptionSetsHierarchyLocalFiles(args) {
|
|
|
23
23
|
}
|
|
24
24
|
console.log('%s PARSE Complete.', chalk.green.bold('COMPLETE'));
|
|
25
25
|
}
|
|
26
|
-
export async function
|
|
26
|
+
export async function UploadOptionSetsHierarchyLocalFile(args) {
|
|
27
27
|
try {
|
|
28
28
|
await authUser();
|
|
29
29
|
if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
|
|
@@ -34,7 +34,7 @@ export async function UploadOptionSetsHierarchyLocalFiles(args) {
|
|
|
34
34
|
const name = args[4];
|
|
35
35
|
console.log('Using File: ', fileLocation);
|
|
36
36
|
console.log('Using Name: ', name);
|
|
37
|
-
await
|
|
37
|
+
await uploadOptionSetHierarchiesLocalFile(fileLocation, name);
|
|
38
38
|
console.log('%s Uploaded', chalk.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
|
|
39
39
|
}
|
|
40
40
|
catch (e) {
|
|
@@ -55,7 +55,7 @@ async function loadOptionSetHierarchyCSV(fileLocation) {
|
|
|
55
55
|
throw new Error(`ERROR PARSING CSV: ${e}`);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
async function
|
|
58
|
+
async function parseOptionSetHierarchiesLocalFile(fileLocation) {
|
|
59
59
|
const uploadedOptionHierarchyData = await loadOptionSetHierarchyCSV(fileLocation);
|
|
60
60
|
const optionSetHierarchy = {
|
|
61
61
|
hierarchy: [],
|
|
@@ -90,12 +90,12 @@ async function parseOptionSetHierarchiesLocalFiles(fileLocation) {
|
|
|
90
90
|
}
|
|
91
91
|
return optionSetHierarchy;
|
|
92
92
|
}
|
|
93
|
-
async function
|
|
94
|
-
const optionSetHierarchy = await
|
|
93
|
+
async function parseAndSaveOptionSetHierarchiesLocalFile(fileLocation) {
|
|
94
|
+
const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
|
|
95
95
|
saveData(optionSetHierarchy.options);
|
|
96
96
|
}
|
|
97
|
-
async function
|
|
98
|
-
const optionSetHierarchy = await
|
|
97
|
+
async function uploadOptionSetHierarchiesLocalFile(fileLocation, name) {
|
|
98
|
+
const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
|
|
99
99
|
optionSetHierarchy.name = name;
|
|
100
100
|
const currentOptionSetHierarchies = await new Entities().get({
|
|
101
101
|
entityName: 'option-set-hierarchy',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.54",
|
|
4
4
|
"description": "VibeIQ's Contrail Platform CLI.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"execa": "^5.0.0",
|
|
38
38
|
"inquirer": "^8.2.0",
|
|
39
39
|
"js-yaml": "^4.1.0",
|
|
40
|
+
"json2csv": "^5.0.7",
|
|
40
41
|
"listr": "^0.14.3",
|
|
41
42
|
"lodash": "^4.17.21",
|
|
42
43
|
"ncp": "^2.0.0",
|
package/src/cli.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { getTypes } from './types/types-extractor';
|
|
|
5
5
|
import { uploadTypes } from './types/types-uploader';
|
|
6
6
|
import { UploadOptionSets } from './types/option-set-uploader';
|
|
7
7
|
import { ParseOptionSetsLocalFiles } from './types/option-set-parser';
|
|
8
|
-
import {
|
|
8
|
+
import { ParseOptionSetsHierarchyLocalFile, UploadOptionSetsHierarchyLocalFile } from './types/option-set-hierarchy-parser';
|
|
9
|
+
import { ExportOptionSetsHierarchies } from './types/option-set-hierarchy-exporter';
|
|
9
10
|
import { MergeOptionSets } from './types/option-set-merger';
|
|
10
11
|
import { MergeTypeProperties } from './types/types-properties-merger';
|
|
11
12
|
import { ParseTypesFromFiles, ParseTypesFromLocalFiles, ParseTypesFromTemplateFromLocalFiles, ParseTypesFromTemplateAndDataFromLocalFiles } from './types/parse-types';
|
|
@@ -103,12 +104,16 @@ export async function cli(args) {
|
|
|
103
104
|
ParseOptionSetsLocalFiles(args);
|
|
104
105
|
break;
|
|
105
106
|
}
|
|
106
|
-
case '
|
|
107
|
-
|
|
107
|
+
case 'parseOptionSetsHierarchyLocalFile': {
|
|
108
|
+
ParseOptionSetsHierarchyLocalFile(args);
|
|
108
109
|
break;
|
|
109
110
|
}
|
|
110
|
-
case '
|
|
111
|
-
|
|
111
|
+
case 'uploadOptionSetsHierarchyLocalFile': {
|
|
112
|
+
UploadOptionSetsHierarchyLocalFile(args);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case 'exportOptionSetsHierarchies': {
|
|
116
|
+
ExportOptionSetsHierarchies();
|
|
112
117
|
break;
|
|
113
118
|
}
|
|
114
119
|
case 'parseTypesFromLocalFiles': {
|
|
@@ -399,15 +404,19 @@ const helpSections = [
|
|
|
399
404
|
},
|
|
400
405
|
{
|
|
401
406
|
name: 'parseOptionSetsLocalFiles <File Paths>',
|
|
402
|
-
summary: 'Parse CSV files into OptionSets
|
|
407
|
+
summary: 'Parse CSV files into OptionSets.\n'
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
name: 'parseOptionSetsHierarchyLocalFile <File Path>',
|
|
411
|
+
summary: 'Parse CSV file into OptionSetHierarchy.'
|
|
403
412
|
},
|
|
404
413
|
{
|
|
405
|
-
name: '
|
|
406
|
-
summary: '
|
|
414
|
+
name: 'uploadOptionSetsHierarchyLocalFile <File Path> <name>',
|
|
415
|
+
summary: 'upload CSV file into OptionSetHierarchy.'
|
|
407
416
|
},
|
|
408
417
|
{
|
|
409
|
-
name: '
|
|
410
|
-
summary: '
|
|
418
|
+
name: 'exportOptionSetsHierarchies',
|
|
419
|
+
summary: 'export OptionSetHierarchies into CSVs.\n'
|
|
411
420
|
},
|
|
412
421
|
{
|
|
413
422
|
name: 'parseTypesFromLocalFiles <File Paths>',
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
}
|
|
@@ -6,7 +6,7 @@ import { Entities } from '@contrail/sdk';
|
|
|
6
6
|
import { StringUtil } from '@contrail/util';
|
|
7
7
|
import { authUser } from '../auth/login';
|
|
8
8
|
|
|
9
|
-
export async function
|
|
9
|
+
export async function ParseOptionSetsHierarchyLocalFile(args) {
|
|
10
10
|
try {
|
|
11
11
|
await authUser();
|
|
12
12
|
|
|
@@ -17,7 +17,7 @@ export async function ParseOptionSetsHierarchyLocalFiles(args) {
|
|
|
17
17
|
const fileLocation = args[3];
|
|
18
18
|
console.log('Using File: ', fileLocation);
|
|
19
19
|
|
|
20
|
-
await
|
|
20
|
+
await parseAndSaveOptionSetHierarchiesLocalFile(fileLocation);
|
|
21
21
|
console.log('%s Parsed', chalk.yellow.bold('OPTION SET HIERARCHY PARSE'));
|
|
22
22
|
|
|
23
23
|
}
|
|
@@ -29,7 +29,7 @@ export async function ParseOptionSetsHierarchyLocalFiles(args) {
|
|
|
29
29
|
console.log('%s PARSE Complete.', chalk.green.bold('COMPLETE'));
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export async function
|
|
32
|
+
export async function UploadOptionSetsHierarchyLocalFile(args) {
|
|
33
33
|
try {
|
|
34
34
|
await authUser();
|
|
35
35
|
|
|
@@ -42,7 +42,7 @@ export async function UploadOptionSetsHierarchyLocalFiles(args) {
|
|
|
42
42
|
console.log('Using File: ', fileLocation);
|
|
43
43
|
console.log('Using Name: ', name);
|
|
44
44
|
|
|
45
|
-
await
|
|
45
|
+
await uploadOptionSetHierarchiesLocalFile(fileLocation, name);
|
|
46
46
|
console.log('%s Uploaded', chalk.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
|
|
47
47
|
|
|
48
48
|
}
|
|
@@ -68,7 +68,7 @@ async function loadOptionSetHierarchyCSV(fileLocation) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
async function
|
|
71
|
+
async function parseOptionSetHierarchiesLocalFile(fileLocation) {
|
|
72
72
|
const uploadedOptionHierarchyData = await loadOptionSetHierarchyCSV(fileLocation);
|
|
73
73
|
|
|
74
74
|
const optionSetHierarchy = {
|
|
@@ -112,13 +112,13 @@ async function parseOptionSetHierarchiesLocalFiles(fileLocation) {
|
|
|
112
112
|
return optionSetHierarchy;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
async function
|
|
116
|
-
const optionSetHierarchy = await
|
|
115
|
+
async function parseAndSaveOptionSetHierarchiesLocalFile(fileLocation) {
|
|
116
|
+
const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
|
|
117
117
|
saveData(optionSetHierarchy.options);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
async function
|
|
121
|
-
const optionSetHierarchy = await
|
|
120
|
+
async function uploadOptionSetHierarchiesLocalFile(fileLocation, name) {
|
|
121
|
+
const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
|
|
122
122
|
optionSetHierarchy.name = name;
|
|
123
123
|
|
|
124
124
|
const currentOptionSetHierarchies = await new Entities().get({
|