multicloud_rule_manager 1.1.41 → 1.1.43
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/commands/retrievedatamap.js +77 -26
- package/package.json +1 -1
|
@@ -8,6 +8,62 @@ export default {
|
|
|
8
8
|
output: { type: "string", default: "retrieve.json", describe: "File di output" }
|
|
9
9
|
},
|
|
10
10
|
handler: async (argv) => {
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
function buildNodes(children) {
|
|
14
|
+
if (!Array.isArray(children) || children.length === 0) return [];
|
|
15
|
+
|
|
16
|
+
const sorted = sortNodes(children);
|
|
17
|
+
|
|
18
|
+
return sorted.map(child => {
|
|
19
|
+
const template = {
|
|
20
|
+
key: child._key || "products",
|
|
21
|
+
attributes: [],
|
|
22
|
+
children: []
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (Array.isArray(child._attributes)) {
|
|
26
|
+
template.attributes = sortNodes(
|
|
27
|
+
child._attributes.map(({ _jsonrelkey, ...rest }) => rest)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (Array.isArray(child._children) && child._children.length > 0) {
|
|
32
|
+
template.children = buildNodes(child._children); // ricorsione
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return template;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function sortNodes(nodes) {
|
|
42
|
+
if (!Array.isArray(nodes)) return nodes;
|
|
43
|
+
|
|
44
|
+
// ordina alfabeticamente per _key
|
|
45
|
+
nodes.sort((a, b) => {
|
|
46
|
+
const ka = (a._key || "").toLowerCase();
|
|
47
|
+
const kb = (b._key || "").toLowerCase();
|
|
48
|
+
return ka.localeCompare(kb);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// ricorsione su nodi annidati
|
|
52
|
+
for (const node of nodes) {
|
|
53
|
+
if (Array.isArray(node._children)) {
|
|
54
|
+
node._children = sortNodes(node._children);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (Array.isArray(node._attributes)) {
|
|
58
|
+
node._attributes = sortNodes(node._attributes);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return nodes;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
11
67
|
try {
|
|
12
68
|
console.log("🔹 Retrieve Datamap in corso..");
|
|
13
69
|
console.log("🔹 Recupero credenziali per alias:", argv.alias);
|
|
@@ -97,37 +153,32 @@ export default {
|
|
|
97
153
|
var map = mapData?.map_j2j_published;
|
|
98
154
|
|
|
99
155
|
// costruzione JSON finale
|
|
100
|
-
const result = {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if(map){
|
|
105
|
-
//if (!Array.isArray(children)) {
|
|
106
|
-
if (Array.isArray(map._children)) {
|
|
107
|
-
/*var children = map._children;
|
|
108
|
-
for (const child of children) {
|
|
109
|
-
if (child._key && child._attributes) {
|
|
110
|
-
result[child._key] = child._attributes;
|
|
111
|
-
}
|
|
112
|
-
}*/
|
|
113
|
-
result["children"] = map._children;
|
|
114
|
-
}
|
|
115
|
-
if (Array.isArray(map._attributes)) {
|
|
116
|
-
//var children = map._children;
|
|
117
|
-
result["attributes"] = map._attributes;
|
|
118
|
-
}
|
|
156
|
+
const result = {
|
|
157
|
+
attributes: [],
|
|
158
|
+
children: []
|
|
159
|
+
};
|
|
119
160
|
|
|
161
|
+
if (map) {
|
|
120
162
|
|
|
163
|
+
if (Array.isArray(map._attributes)) {
|
|
164
|
+
result.attributes = sortNodes(map._attributes);
|
|
165
|
+
}
|
|
121
166
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
167
|
+
if (Array.isArray(map._children) && map._children.length > 0) {
|
|
168
|
+
result.children = buildNodes(map._children);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
if (Object.keys(result).length === 0) {
|
|
174
|
+
console.warn(`⚠️ Nessun dato valido per ${record.name}`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
126
177
|
|
|
127
|
-
|
|
178
|
+
fs.writeFileSync(filePath, JSON.stringify(result, null, 2), "utf8");
|
|
128
179
|
|
|
129
|
-
|
|
130
|
-
}else{
|
|
180
|
+
console.log(`📝 File scritto: ${fileName}`);
|
|
181
|
+
} else {
|
|
131
182
|
console.log(`📝 Datamap: ${fileName} - ${record.guid} non valido, salto`);
|
|
132
183
|
}
|
|
133
184
|
}
|