@contrail/cli 1.0.63 → 1.0.64
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.
|
@@ -8,49 +8,20 @@ export interface DataHolder {
|
|
|
8
8
|
typePropertyPolicies: any[];
|
|
9
9
|
typePropertyPolicyLinks: any[];
|
|
10
10
|
}
|
|
11
|
+
export interface ReducedDataHolder {
|
|
12
|
+
reducedTypes: any[];
|
|
13
|
+
reducedOptionSets: any[];
|
|
14
|
+
reducedOptionSetHierarchies: any[];
|
|
15
|
+
reducedRuleSets: any[];
|
|
16
|
+
reducedRuleSetLinks: any[];
|
|
17
|
+
reducedUsageInfo: any[];
|
|
18
|
+
reducedTypePropertyPolicies: any[];
|
|
19
|
+
reducedTypePropertyPolicyLinks: any[];
|
|
20
|
+
}
|
|
11
21
|
export declare function getAll(args: any): Promise<void>;
|
|
12
22
|
/**
|
|
13
23
|
* stores reduced option sets and returns full option sets */
|
|
14
24
|
export declare function getOptionSets(): Promise<any>;
|
|
15
25
|
export declare function getTypes(): Promise<any[]>;
|
|
16
26
|
export declare function reduceTypes(dataHolder: DataHolder): any[];
|
|
17
|
-
export declare function reduceData(data: DataHolder):
|
|
18
|
-
reducedTypes: any[];
|
|
19
|
-
reducedOptionSets: {
|
|
20
|
-
name: any;
|
|
21
|
-
isArchived: any;
|
|
22
|
-
optionSet: any;
|
|
23
|
-
}[];
|
|
24
|
-
reducedOptionSetHierarchies: {
|
|
25
|
-
hierarchy: any;
|
|
26
|
-
options: any;
|
|
27
|
-
name: any;
|
|
28
|
-
}[];
|
|
29
|
-
reducedRuleSets: {
|
|
30
|
-
ruleSet: any;
|
|
31
|
-
name: any;
|
|
32
|
-
}[];
|
|
33
|
-
reducedRuleSetLinks: any[];
|
|
34
|
-
reducedUsageInfo: {
|
|
35
|
-
used: any;
|
|
36
|
-
editable: any;
|
|
37
|
-
formulaFunction: any;
|
|
38
|
-
validationFunction: any;
|
|
39
|
-
numberFormat: any;
|
|
40
|
-
defaultValue: any;
|
|
41
|
-
label: any;
|
|
42
|
-
typeSlug: any;
|
|
43
|
-
typePropertySlug: any;
|
|
44
|
-
}[];
|
|
45
|
-
reducedTypePropertyPolicies: {
|
|
46
|
-
label: any;
|
|
47
|
-
policy: {
|
|
48
|
-
version: any;
|
|
49
|
-
statements: any;
|
|
50
|
-
};
|
|
51
|
-
}[];
|
|
52
|
-
reducedTypePropertyPolicyLinks: {
|
|
53
|
-
typePropertySlug: any;
|
|
54
|
-
typePropertyPolicyLabel: any;
|
|
55
|
-
}[];
|
|
56
|
-
};
|
|
27
|
+
export declare function reduceData(data: DataHolder): ReducedDataHolder;
|
|
@@ -247,9 +247,38 @@ export function reduceData(data) {
|
|
|
247
247
|
reducedTypePropertyPolicyLinks: reduceTypePropertyPolicyLinks(data),
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
+
const saveTypesFunction = function (data, dir) {
|
|
251
|
+
const roots = {};
|
|
252
|
+
for (const type of data.reducedTypes) {
|
|
253
|
+
const typePathParts = type.typePath.split(':');
|
|
254
|
+
if (!typePathParts) {
|
|
255
|
+
console.warn('skipping bad type with no path', type);
|
|
256
|
+
}
|
|
257
|
+
const root = typePathParts[0];
|
|
258
|
+
if (roots[root]) {
|
|
259
|
+
roots[root].push(type);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
roots[root] = [type];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
for (const [root, types] of Object.entries(roots)) {
|
|
266
|
+
const CURRENT_DIR = process.cwd();
|
|
267
|
+
const subDir = path.join(CURRENT_DIR, dir, 'types');
|
|
268
|
+
if (!fs.existsSync(subDir)) {
|
|
269
|
+
fs.mkdirSync(subDir);
|
|
270
|
+
}
|
|
271
|
+
const yamlStr = yaml.dump(types);
|
|
272
|
+
const fileLabel = root;
|
|
273
|
+
if (!fileLabel) {
|
|
274
|
+
console.warn('skipping bad type root:', root);
|
|
275
|
+
}
|
|
276
|
+
fs.writeFileSync(path.join(subDir, `${removeSlash(fileLabel)}.yml`), yamlStr, 'utf8');
|
|
277
|
+
}
|
|
278
|
+
};
|
|
250
279
|
function saveData(reducedData, dir) {
|
|
251
280
|
const propertyToFolderMap = {
|
|
252
|
-
reducedTypes: { filename: 'types', split:
|
|
281
|
+
reducedTypes: { filename: 'types', split: false, fileLabel: 'slug', saveFunction: saveTypesFunction },
|
|
253
282
|
reducedOptionSets: { filename: 'option-sets', split: true, fileLabel: 'name' },
|
|
254
283
|
reducedOptionSetHierarchies: { filename: 'option-set-hierarchies', split: true, fileLabel: 'name' },
|
|
255
284
|
reducedRuleSets: { filename: 'rule-sets', split: true, fileLabel: 'name' },
|
|
@@ -260,7 +289,10 @@ function saveData(reducedData, dir) {
|
|
|
260
289
|
};
|
|
261
290
|
for (const [key, folder] of Object.entries(propertyToFolderMap)) {
|
|
262
291
|
const CURRENT_DIR = process.cwd();
|
|
263
|
-
if (folder
|
|
292
|
+
if (folder['saveFunction']) {
|
|
293
|
+
folder['saveFunction'](reducedData, dir);
|
|
294
|
+
}
|
|
295
|
+
else if (folder.split) {
|
|
264
296
|
const subDir = path.join(CURRENT_DIR, dir, folder.filename);
|
|
265
297
|
if (!fs.existsSync(subDir)) {
|
|
266
298
|
fs.mkdirSync(subDir);
|
|
@@ -25,7 +25,7 @@ function loadReducedTypes() {
|
|
|
25
25
|
const files = fs.readdirSync(path.join(TARGET_DIR, 'types'));
|
|
26
26
|
const types = [];
|
|
27
27
|
for (const file of files) {
|
|
28
|
-
types.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
|
|
28
|
+
types.push(...yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
|
|
29
29
|
}
|
|
30
30
|
return types;
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -8,6 +8,10 @@ import pLimit from 'p-limit';
|
|
|
8
8
|
const limit = pLimit(30);
|
|
9
9
|
|
|
10
10
|
const yaml = require('js-yaml');
|
|
11
|
+
interface StoreFunction
|
|
12
|
+
{
|
|
13
|
+
(data: ReducedDataHolder, dir: string): void;
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
export interface DataHolder {
|
|
13
17
|
types: any[],
|
|
@@ -20,6 +24,17 @@ export interface DataHolder {
|
|
|
20
24
|
typePropertyPolicyLinks: any[],
|
|
21
25
|
}
|
|
22
26
|
|
|
27
|
+
export interface ReducedDataHolder {
|
|
28
|
+
reducedTypes: any[],
|
|
29
|
+
reducedOptionSets: any[],
|
|
30
|
+
reducedOptionSetHierarchies: any[],
|
|
31
|
+
reducedRuleSets: any[],
|
|
32
|
+
reducedRuleSetLinks: any[],
|
|
33
|
+
reducedUsageInfo: any[],
|
|
34
|
+
reducedTypePropertyPolicies: any[],
|
|
35
|
+
reducedTypePropertyPolicyLinks: any[],
|
|
36
|
+
}
|
|
37
|
+
|
|
23
38
|
export async function getAll(args) {
|
|
24
39
|
try {
|
|
25
40
|
const userConfig = await authUser();
|
|
@@ -268,7 +283,7 @@ export function reduceTypes(dataHolder: DataHolder) {
|
|
|
268
283
|
return reducedTypes;
|
|
269
284
|
}
|
|
270
285
|
|
|
271
|
-
export function reduceData(data: DataHolder) {
|
|
286
|
+
export function reduceData(data: DataHolder): ReducedDataHolder {
|
|
272
287
|
return {
|
|
273
288
|
reducedTypes: reduceTypes(data),
|
|
274
289
|
reducedOptionSets: reduceOptionSets(data),
|
|
@@ -281,10 +296,40 @@ export function reduceData(data: DataHolder) {
|
|
|
281
296
|
};
|
|
282
297
|
}
|
|
283
298
|
|
|
299
|
+
const saveTypesFunction: StoreFunction = function (data: ReducedDataHolder, dir: string) {
|
|
300
|
+
const roots = {};
|
|
301
|
+
for(const type of data.reducedTypes) {
|
|
302
|
+
const typePathParts = type.typePath.split(':');
|
|
303
|
+
if(!typePathParts) {
|
|
304
|
+
console.warn('skipping bad type with no path', type);
|
|
305
|
+
}
|
|
306
|
+
const root = typePathParts[0];
|
|
307
|
+
if(roots[root]) {
|
|
308
|
+
roots[root].push(type);
|
|
309
|
+
} else {
|
|
310
|
+
roots[root] = [type];
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
for(const [root, types] of Object.entries(roots)) {
|
|
314
|
+
const CURRENT_DIR = process.cwd();
|
|
315
|
+
const subDir = path.join(CURRENT_DIR, dir, 'types');
|
|
316
|
+
if(!fs.existsSync(subDir)) {
|
|
317
|
+
fs.mkdirSync(subDir);
|
|
318
|
+
}
|
|
319
|
+
const yamlStr = yaml.dump(types);
|
|
320
|
+
const fileLabel = root;
|
|
321
|
+
if(!fileLabel) {
|
|
322
|
+
console.warn('skipping bad type root:', root);
|
|
323
|
+
}
|
|
324
|
+
fs.writeFileSync(path.join(subDir, `${removeSlash(fileLabel)}.yml`), yamlStr, 'utf8');
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
};
|
|
328
|
+
|
|
284
329
|
function saveData(reducedData, dir: string) {
|
|
285
330
|
|
|
286
331
|
const propertyToFolderMap = {
|
|
287
|
-
reducedTypes: { filename: 'types', split:
|
|
332
|
+
reducedTypes: { filename: 'types', split: false, fileLabel: 'slug', saveFunction: saveTypesFunction},
|
|
288
333
|
reducedOptionSets: { filename: 'option-sets', split: true, fileLabel: 'name' },
|
|
289
334
|
reducedOptionSetHierarchies: { filename: 'option-set-hierarchies', split: true, fileLabel: 'name' },
|
|
290
335
|
reducedRuleSets: { filename: 'rule-sets', split: true, fileLabel: 'name' },
|
|
@@ -295,7 +340,9 @@ function saveData(reducedData, dir: string) {
|
|
|
295
340
|
};
|
|
296
341
|
for(const [key, folder] of Object.entries(propertyToFolderMap)) {
|
|
297
342
|
const CURRENT_DIR = process.cwd();
|
|
298
|
-
if(folder
|
|
343
|
+
if(folder['saveFunction']) {
|
|
344
|
+
folder['saveFunction'](reducedData, dir);
|
|
345
|
+
} else if(folder.split) {
|
|
299
346
|
const subDir = path.join(CURRENT_DIR, dir, folder.filename);
|
|
300
347
|
if(!fs.existsSync(subDir)) {
|
|
301
348
|
fs.mkdirSync(subDir);
|
|
@@ -32,7 +32,7 @@ function loadReducedTypes(){
|
|
|
32
32
|
const files = fs.readdirSync(path.join(TARGET_DIR, 'types'));
|
|
33
33
|
const types = [];
|
|
34
34
|
for(const file of files) {
|
|
35
|
-
types.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
|
|
35
|
+
types.push(...yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
|
|
36
36
|
}
|
|
37
37
|
return types;
|
|
38
38
|
} catch (e) {
|