@contrail/cli 1.0.55 → 1.0.57
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 +9 -0
- package/lib/types/allUploader.d.ts +1 -0
- package/lib/types/allUploader.js +24 -0
- package/lib/types/interfaces.d.ts +1 -0
- package/lib/types/option-set-hierarchy-uploader.js +7 -4
- package/lib/types/option-set-uploader.js +7 -4
- package/lib/types/rule-set-uploader.js +10 -13
- package/lib/types/type-property-policy-uploader.js +9 -4
- package/lib/types/types-extractor.js +34 -18
- package/lib/types/types-uploader.js +7 -4
- package/lib/types/usage-info-uploader.js +3 -4
- package/package.json +1 -1
- package/src/cli.ts +9 -0
- package/src/types/allUploader.ts +28 -0
- package/src/types/interfaces.ts +1 -0
- package/src/types/option-set-hierarchy-uploader.ts +7 -4
- package/src/types/option-set-uploader.ts +7 -4
- package/src/types/rule-set-uploader.ts +10 -13
- package/src/types/type-property-policy-uploader.ts +9 -5
- package/src/types/types-extractor.ts +34 -20
- package/src/types/types-uploader.ts +7 -4
- package/src/types/usage-info-uploader.ts +3 -4
package/lib/cli.js
CHANGED
|
@@ -22,6 +22,7 @@ import { uploadUsageInfo } from './types/usage-info-uploader';
|
|
|
22
22
|
import { uploadRuleSets } from './types/rule-set-uploader';
|
|
23
23
|
import { UploadOptionSetHierarchies } from './types/option-set-hierarchy-uploader';
|
|
24
24
|
import { uploadTypePropertyPolicies } from './types/type-property-policy-uploader';
|
|
25
|
+
import { uploadAll } from './types/allUploader';
|
|
25
26
|
const cliUsage = require('command-line-usage');
|
|
26
27
|
/**
|
|
27
28
|
* Built using documentation here:
|
|
@@ -86,6 +87,10 @@ export async function cli(args) {
|
|
|
86
87
|
getAll(args);
|
|
87
88
|
break;
|
|
88
89
|
}
|
|
90
|
+
case 'uploadAll': {
|
|
91
|
+
uploadAll();
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
89
94
|
case 'uploadTypes': {
|
|
90
95
|
uploadTypes();
|
|
91
96
|
break;
|
|
@@ -423,6 +428,10 @@ const helpSections = [
|
|
|
423
428
|
name: 'exportOptionSetsHierarchies',
|
|
424
429
|
summary: 'export OptionSetHierarchies into CSVs.\n'
|
|
425
430
|
},
|
|
431
|
+
{
|
|
432
|
+
name: 'uploadAll',
|
|
433
|
+
summary: 'Upload an extracted archive of types:getAll.'
|
|
434
|
+
},
|
|
426
435
|
{
|
|
427
436
|
name: 'uploadOptionSetsHierarchies',
|
|
428
437
|
summary: 'Upload an extracted option set hierarchies.'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uploadAll(): Promise<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { authUser } from '../auth/login';
|
|
3
|
+
import { UploadOptionSets } from './option-set-uploader';
|
|
4
|
+
import { UploadOptionSetHierarchies } from './option-set-hierarchy-uploader';
|
|
5
|
+
import { uploadTypes } from './types-uploader';
|
|
6
|
+
import { uploadUsageInfo } from './usage-info-uploader';
|
|
7
|
+
import { uploadRuleSets } from './rule-set-uploader';
|
|
8
|
+
import { uploadTypePropertyPolicies } from './type-property-policy-uploader';
|
|
9
|
+
export async function uploadAll() {
|
|
10
|
+
try {
|
|
11
|
+
await authUser();
|
|
12
|
+
await UploadOptionSets(null);
|
|
13
|
+
await UploadOptionSetHierarchies(null);
|
|
14
|
+
await uploadTypes();
|
|
15
|
+
await uploadUsageInfo(null);
|
|
16
|
+
await uploadRuleSets(null);
|
|
17
|
+
await uploadTypePropertyPolicies(null);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
24
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import * as path from 'path';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
const yaml = require('js-yaml');
|
|
@@ -21,9 +21,12 @@ export async function UploadOptionSetHierarchies(args) {
|
|
|
21
21
|
function loadOptionSetHierarchies() {
|
|
22
22
|
const TARGET_DIR = process.cwd();
|
|
23
23
|
try {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
24
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'option-set-hierarchies'));
|
|
25
|
+
const OSHs = [];
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
OSHs.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'option-set-hierarchies', file), 'utf8')));
|
|
28
|
+
}
|
|
29
|
+
return OSHs;
|
|
27
30
|
}
|
|
28
31
|
catch (e) {
|
|
29
32
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import * as path from 'path';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
const yaml = require('js-yaml');
|
|
@@ -21,9 +21,12 @@ export async function UploadOptionSets(args) {
|
|
|
21
21
|
function loadOptionSets() {
|
|
22
22
|
const TARGET_DIR = process.cwd();
|
|
23
23
|
try {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
24
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'option-sets'));
|
|
25
|
+
const optionSets = [];
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
optionSets.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'option-sets', file), 'utf8')));
|
|
28
|
+
}
|
|
29
|
+
return optionSets;
|
|
27
30
|
}
|
|
28
31
|
catch (e) {
|
|
29
32
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import * as path from 'path';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
const yaml = require('js-yaml');
|
|
@@ -20,11 +20,16 @@ export async function uploadRuleSets(args) {
|
|
|
20
20
|
console.log('%s Rule set Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
21
21
|
}
|
|
22
22
|
function loadReducedRuleSets() {
|
|
23
|
+
const ruleSets = [];
|
|
24
|
+
let ruleSetLinks = [];
|
|
23
25
|
const TARGET_DIR = process.cwd();
|
|
24
26
|
try {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'rule-sets'));
|
|
28
|
+
for (const file of files) {
|
|
29
|
+
ruleSets.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'rule-sets', file), 'utf8')));
|
|
30
|
+
}
|
|
31
|
+
ruleSetLinks = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'rule-set-links.yml'), 'utf8'));
|
|
32
|
+
return [ruleSets, ruleSetLinks];
|
|
28
33
|
}
|
|
29
34
|
catch (e) {
|
|
30
35
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -127,15 +132,7 @@ async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
|
127
132
|
if (!transformReducedLink(loadedRuleSetLink, types, currentRuleSets)) {
|
|
128
133
|
continue;
|
|
129
134
|
}
|
|
130
|
-
console.log('
|
|
131
|
-
await new Entities().update({
|
|
132
|
-
entityName: 'type-rule-set-link',
|
|
133
|
-
id: found.id,
|
|
134
|
-
object: {
|
|
135
|
-
typeRuleSetId: loadedRuleSetLink.ruleSet,
|
|
136
|
-
typeId: loadedRuleSetLink.type,
|
|
137
|
-
},
|
|
138
|
-
});
|
|
135
|
+
console.log('skipping updating existing rule set link: ', loadedRuleSetLink);
|
|
139
136
|
}
|
|
140
137
|
}
|
|
141
138
|
catch (err) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import * as path from 'path';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import { getTypes } from './types-extractor';
|
|
@@ -21,11 +21,16 @@ export async function uploadTypePropertyPolicies(args) {
|
|
|
21
21
|
console.log('%s Type Property Policy Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
22
22
|
}
|
|
23
23
|
function loadTPPolicies() {
|
|
24
|
+
const tpps = [];
|
|
25
|
+
let tppLinks = [];
|
|
24
26
|
const TARGET_DIR = process.cwd();
|
|
25
27
|
try {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'type-property-policies'));
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
tpps.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'type-property-policies', file), 'utf8')));
|
|
31
|
+
}
|
|
32
|
+
tppLinks = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'type-property-policy-links.yml'), 'utf8'));
|
|
33
|
+
return [tpps, tppLinks];
|
|
29
34
|
}
|
|
30
35
|
catch (e) {
|
|
31
36
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -2,7 +2,7 @@ import { Entities } from '@contrail/sdk';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
|
-
import
|
|
5
|
+
import * as path from 'path';
|
|
6
6
|
import pLimit from 'p-limit';
|
|
7
7
|
const limit = pLimit(30);
|
|
8
8
|
const yaml = require('js-yaml');
|
|
@@ -11,7 +11,7 @@ export async function getAll(args) {
|
|
|
11
11
|
const userConfig = await authUser();
|
|
12
12
|
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
13
13
|
// make directory to house exports
|
|
14
|
-
const dir = `./
|
|
14
|
+
const dir = `./contrail-export-${Date.now()}`;
|
|
15
15
|
fs.mkdirSync(dir);
|
|
16
16
|
const data = {
|
|
17
17
|
types: await getTypes(),
|
|
@@ -24,7 +24,6 @@ export async function getAll(args) {
|
|
|
24
24
|
typePropertyPolicyLinks: await getTypePropertyPolicyLinks(),
|
|
25
25
|
};
|
|
26
26
|
const reducedData = reduceData(data);
|
|
27
|
-
storeOptionSets(data, dir);
|
|
28
27
|
saveData(reducedData, dir);
|
|
29
28
|
console.log('%s Retrieved', chalk.yellow.bold('TYPES'));
|
|
30
29
|
}
|
|
@@ -215,6 +214,7 @@ export function reduceTypes(dataHolder) {
|
|
|
215
214
|
inherited: typeProperty.inherited,
|
|
216
215
|
formulaFunction: typeProperty.formulaFunction,
|
|
217
216
|
validationFunction: typeProperty.validationFunction,
|
|
217
|
+
numberFormat: typeProperty.numberFormat,
|
|
218
218
|
};
|
|
219
219
|
reducedTypeProperties.push(reducedTypeProperty);
|
|
220
220
|
}
|
|
@@ -242,20 +242,36 @@ export function reduceData(data) {
|
|
|
242
242
|
reducedTypePropertyPolicyLinks: reduceTypePropertyPolicyLinks(data),
|
|
243
243
|
};
|
|
244
244
|
}
|
|
245
|
-
function storeOptionSets(data, dir) {
|
|
246
|
-
let reducedOptionSets = reduceOptionSets(data);
|
|
247
|
-
reducedOptionSets = reducedOptionSets.sort((one, two) => (one.name < two.name ? -1 : 1));
|
|
248
|
-
const optionSetsHolder = {
|
|
249
|
-
reducedOptionSets,
|
|
250
|
-
};
|
|
251
|
-
const CURRENT_DIR = process.cwd();
|
|
252
|
-
const separator = getSeparatorByPlatform();
|
|
253
|
-
const yamlStr = yaml.dump(optionSetsHolder);
|
|
254
|
-
fs.writeFileSync(CURRENT_DIR + separator + dir + separator + 'option_sets.yml', yamlStr, 'utf8');
|
|
255
|
-
}
|
|
256
245
|
function saveData(reducedData, dir) {
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
246
|
+
const propertyToFolderMap = {
|
|
247
|
+
reducedTypes: { filename: 'types', split: true, fileLabel: 'slug' },
|
|
248
|
+
reducedOptionSets: { filename: 'option-sets', split: true, fileLabel: 'name' },
|
|
249
|
+
reducedOptionSetHierarchies: { filename: 'option-set-hierarchies', split: true, fileLabel: 'name' },
|
|
250
|
+
reducedRuleSets: { filename: 'rule-sets', split: true, fileLabel: 'name' },
|
|
251
|
+
reducedRuleSetLinks: { filename: 'rule-set-links', split: false, fileLabel: '' },
|
|
252
|
+
reducedUsageInfo: { filename: 'usage-info', split: false, fileLabel: '' },
|
|
253
|
+
reducedTypePropertyPolicies: { filename: 'type-property-policies', split: true, fileLabel: 'label' },
|
|
254
|
+
reducedTypePropertyPolicyLinks: { filename: 'type-property-policy-links', split: false, fileLabel: '' },
|
|
255
|
+
};
|
|
256
|
+
for (const [key, folder] of Object.entries(propertyToFolderMap)) {
|
|
257
|
+
const CURRENT_DIR = process.cwd();
|
|
258
|
+
if (folder.split) {
|
|
259
|
+
const subDir = path.join(CURRENT_DIR, dir, folder.filename);
|
|
260
|
+
if (!fs.existsSync(subDir)) {
|
|
261
|
+
fs.mkdirSync(subDir);
|
|
262
|
+
}
|
|
263
|
+
for (const item of reducedData[key]) {
|
|
264
|
+
const yamlStr = yaml.dump(item);
|
|
265
|
+
const fileLabel = item[folder.fileLabel];
|
|
266
|
+
if (!fileLabel) {
|
|
267
|
+
console.warn('skipping bad data:', item);
|
|
268
|
+
}
|
|
269
|
+
fs.writeFileSync(path.join(subDir, `${fileLabel}.yml`), yamlStr, 'utf8');
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
const yamlStr = yaml.dump(reducedData[key]);
|
|
274
|
+
fs.writeFileSync(path.join(CURRENT_DIR, dir, `${folder.filename}.yml`), yamlStr, 'utf8');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
261
277
|
}
|
|
@@ -2,7 +2,7 @@ import { Entities, Request } from '@contrail/sdk';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
|
-
import
|
|
5
|
+
import * as path from 'path';
|
|
6
6
|
import * as _ from 'lodash';
|
|
7
7
|
import yaml from 'js-yaml';
|
|
8
8
|
export async function uploadTypes() {
|
|
@@ -22,9 +22,12 @@ export async function uploadTypes() {
|
|
|
22
22
|
function loadReducedTypes() {
|
|
23
23
|
const TARGET_DIR = process.cwd();
|
|
24
24
|
try {
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
25
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'types'));
|
|
26
|
+
const types = [];
|
|
27
|
+
for (const file of files) {
|
|
28
|
+
types.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
|
|
29
|
+
}
|
|
30
|
+
return types;
|
|
28
31
|
}
|
|
29
32
|
catch (e) {
|
|
30
33
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import { getSeparatorByPlatform } from '../common';
|
|
4
3
|
import { authUser } from '../auth/login';
|
|
5
4
|
import chalk from 'chalk';
|
|
6
5
|
import { getTypes } from './types-extractor';
|
|
6
|
+
import * as path from 'path';
|
|
7
7
|
const yaml = require('js-yaml');
|
|
8
8
|
export async function uploadUsageInfo(args) {
|
|
9
9
|
try {
|
|
@@ -22,9 +22,8 @@ export async function uploadUsageInfo(args) {
|
|
|
22
22
|
function loadUsageInfo() {
|
|
23
23
|
const TARGET_DIR = process.cwd();
|
|
24
24
|
try {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
return doc.reducedUsageInfo;
|
|
25
|
+
const doc = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'usage-info.yml'), 'utf8'));
|
|
26
|
+
return doc;
|
|
28
27
|
}
|
|
29
28
|
catch (e) {
|
|
30
29
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { uploadUsageInfo } from './types/usage-info-uploader';
|
|
|
23
23
|
import { uploadRuleSets } from './types/rule-set-uploader';
|
|
24
24
|
import { UploadOptionSetHierarchies } from './types/option-set-hierarchy-uploader';
|
|
25
25
|
import { uploadTypePropertyPolicies } from './types/type-property-policy-uploader';
|
|
26
|
+
import { uploadAll } from './types/allUploader';
|
|
26
27
|
|
|
27
28
|
const cliUsage = require('command-line-usage');
|
|
28
29
|
|
|
@@ -96,6 +97,10 @@ export async function cli(args) {
|
|
|
96
97
|
getAll(args);
|
|
97
98
|
break;
|
|
98
99
|
}
|
|
100
|
+
case 'uploadAll': {
|
|
101
|
+
uploadAll();
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
99
104
|
case 'uploadTypes': {
|
|
100
105
|
uploadTypes();
|
|
101
106
|
break;
|
|
@@ -438,6 +443,10 @@ const helpSections = [
|
|
|
438
443
|
name: 'exportOptionSetsHierarchies',
|
|
439
444
|
summary: 'export OptionSetHierarchies into CSVs.\n'
|
|
440
445
|
},
|
|
446
|
+
{
|
|
447
|
+
name: 'uploadAll',
|
|
448
|
+
summary: 'Upload an extracted archive of types:getAll.'
|
|
449
|
+
},
|
|
441
450
|
{
|
|
442
451
|
name: 'uploadOptionSetsHierarchies',
|
|
443
452
|
summary: 'Upload an extracted option set hierarchies.'
|
|
@@ -0,0 +1,28 @@
|
|
|
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/interfaces.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import * as path from 'path';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
|
|
@@ -27,9 +27,12 @@ export async function UploadOptionSetHierarchies(args) {
|
|
|
27
27
|
function loadOptionSetHierarchies() {
|
|
28
28
|
const TARGET_DIR = process.cwd();
|
|
29
29
|
try {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
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;
|
|
33
36
|
} catch (e) {
|
|
34
37
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
35
38
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import { ReducedOptionSet } from './interfaces';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
-
import
|
|
4
|
+
import * as path from 'path';
|
|
5
5
|
import { authUser } from '../auth/login';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
|
|
@@ -28,9 +28,12 @@ export async function UploadOptionSets(args) {
|
|
|
28
28
|
function loadOptionSets(){
|
|
29
29
|
const TARGET_DIR = process.cwd();
|
|
30
30
|
try {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
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;
|
|
34
37
|
} catch (e) {
|
|
35
38
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
36
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import * as path from 'path';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
|
|
@@ -26,11 +26,16 @@ export async function uploadRuleSets(args) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function loadReducedRuleSets() {
|
|
29
|
+
const ruleSets = [];
|
|
30
|
+
let ruleSetLinks = [];
|
|
29
31
|
const TARGET_DIR = process.cwd();
|
|
30
32
|
try {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
33
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'rule-sets'));
|
|
34
|
+
for(const file of files) {
|
|
35
|
+
ruleSets.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'rule-sets', file), 'utf8')));
|
|
36
|
+
}
|
|
37
|
+
ruleSetLinks = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'rule-set-links.yml'), 'utf8'));
|
|
38
|
+
return [ruleSets, ruleSetLinks];
|
|
34
39
|
} catch (e) {
|
|
35
40
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
36
41
|
}
|
|
@@ -140,15 +145,7 @@ async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
|
140
145
|
});
|
|
141
146
|
} else {
|
|
142
147
|
if (!transformReducedLink(loadedRuleSetLink, types, currentRuleSets)) { continue; }
|
|
143
|
-
console.log('
|
|
144
|
-
await new Entities().update({
|
|
145
|
-
entityName: 'type-rule-set-link',
|
|
146
|
-
id: found.id,
|
|
147
|
-
object: {
|
|
148
|
-
typeRuleSetId: loadedRuleSetLink.ruleSet,
|
|
149
|
-
typeId: loadedRuleSetLink.type,
|
|
150
|
-
},
|
|
151
|
-
});
|
|
148
|
+
console.log('skipping updating existing rule set link: ', loadedRuleSetLink);
|
|
152
149
|
}
|
|
153
150
|
} catch (err) {
|
|
154
151
|
throw new Error(`Error Uploading rule set links: ${err}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import * as path from 'path';
|
|
4
4
|
import { authUser } from '../auth/login';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import { getTypes } from './types-extractor';
|
|
@@ -27,11 +27,16 @@ export async function uploadTypePropertyPolicies(args) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function loadTPPolicies() {
|
|
30
|
+
const tpps = [];
|
|
31
|
+
let tppLinks = [];
|
|
30
32
|
const TARGET_DIR = process.cwd();
|
|
31
33
|
try {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
34
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'type-property-policies'));
|
|
35
|
+
for(const file of files) {
|
|
36
|
+
tpps.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'type-property-policies', file), 'utf8')));
|
|
37
|
+
}
|
|
38
|
+
tppLinks = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'type-property-policy-links.yml'), 'utf8'));
|
|
39
|
+
return [tpps, tppLinks];
|
|
35
40
|
} catch (e) {
|
|
36
41
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
37
42
|
}
|
|
@@ -102,7 +107,6 @@ async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
|
|
|
102
107
|
.map(t => t.typeProperties)
|
|
103
108
|
.reduce((a, b) => a.concat(b));
|
|
104
109
|
|
|
105
|
-
|
|
106
110
|
const currentTPPs = await new Entities().get({
|
|
107
111
|
entityName: 'type-property-policy',
|
|
108
112
|
});
|
|
@@ -3,7 +3,7 @@ import { ReducedType, ReducedTypeProperty } from './interfaces';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import { authUser } from '../auth/login';
|
|
6
|
-
import
|
|
6
|
+
import * as path from 'path';
|
|
7
7
|
import pLimit from 'p-limit';
|
|
8
8
|
const limit = pLimit(30);
|
|
9
9
|
|
|
@@ -26,7 +26,7 @@ export async function getAll(args) {
|
|
|
26
26
|
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
27
27
|
|
|
28
28
|
// make directory to house exports
|
|
29
|
-
const dir = `./
|
|
29
|
+
const dir = `./contrail-export-${Date.now()}`;
|
|
30
30
|
fs.mkdirSync(dir);
|
|
31
31
|
|
|
32
32
|
const data: DataHolder = {
|
|
@@ -40,7 +40,6 @@ export async function getAll(args) {
|
|
|
40
40
|
typePropertyPolicyLinks: await getTypePropertyPolicyLinks(),
|
|
41
41
|
};
|
|
42
42
|
const reducedData = reduceData(data);
|
|
43
|
-
storeOptionSets(data, dir);
|
|
44
43
|
saveData(reducedData, dir);
|
|
45
44
|
|
|
46
45
|
console.log('%s Retrieved', chalk.yellow.bold('TYPES'));
|
|
@@ -243,6 +242,7 @@ export function reduceTypes(dataHolder: DataHolder) {
|
|
|
243
242
|
inherited: typeProperty.inherited,
|
|
244
243
|
formulaFunction: typeProperty.formulaFunction,
|
|
245
244
|
validationFunction: typeProperty.validationFunction,
|
|
245
|
+
numberFormat: typeProperty.numberFormat,
|
|
246
246
|
};
|
|
247
247
|
|
|
248
248
|
reducedTypeProperties.push(reducedTypeProperty);
|
|
@@ -276,23 +276,37 @@ export function reduceData(data: DataHolder) {
|
|
|
276
276
|
};
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
-
function
|
|
280
|
-
let reducedOptionSets = reduceOptionSets(data);
|
|
281
|
-
reducedOptionSets = reducedOptionSets.sort((one, two) => (one.name < two.name ? -1 : 1));
|
|
282
|
-
const optionSetsHolder = {
|
|
283
|
-
reducedOptionSets,
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
const CURRENT_DIR = process.cwd();
|
|
287
|
-
const separator = getSeparatorByPlatform();
|
|
279
|
+
function saveData(reducedData, dir: string) {
|
|
288
280
|
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
}
|
|
281
|
+
const propertyToFolderMap = {
|
|
282
|
+
reducedTypes: { filename: 'types', split: true, fileLabel: 'slug' },
|
|
283
|
+
reducedOptionSets: { filename: 'option-sets', split: true, fileLabel: 'name' },
|
|
284
|
+
reducedOptionSetHierarchies: { filename: 'option-set-hierarchies', split: true, fileLabel: 'name' },
|
|
285
|
+
reducedRuleSets: { filename: 'rule-sets', split: true, fileLabel: 'name' },
|
|
286
|
+
reducedRuleSetLinks: { filename: 'rule-set-links', split: false, fileLabel: '' },
|
|
287
|
+
reducedUsageInfo: { filename: 'usage-info', split: false, fileLabel: '' },
|
|
288
|
+
reducedTypePropertyPolicies: { filename: 'type-property-policies', split: true, fileLabel: 'label' },
|
|
289
|
+
reducedTypePropertyPolicyLinks: { filename: 'type-property-policy-links', split: false, fileLabel: '' },
|
|
290
|
+
};
|
|
291
|
+
for(const [key, folder] of Object.entries(propertyToFolderMap)) {
|
|
292
|
+
const CURRENT_DIR = process.cwd();
|
|
293
|
+
if(folder.split) {
|
|
294
|
+
const subDir = path.join(CURRENT_DIR, dir, folder.filename);
|
|
295
|
+
if(!fs.existsSync(subDir)) {
|
|
296
|
+
fs.mkdirSync(subDir);
|
|
297
|
+
}
|
|
298
|
+
for(const item of reducedData[key]) {
|
|
299
|
+
const yamlStr = yaml.dump(item);
|
|
300
|
+
const fileLabel = item[folder.fileLabel];
|
|
301
|
+
if(!fileLabel) {
|
|
302
|
+
console.warn('skipping bad data:', item);
|
|
303
|
+
}
|
|
304
|
+
fs.writeFileSync(path.join(subDir, `${fileLabel}.yml`), yamlStr, 'utf8');
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
const yamlStr = yaml.dump(reducedData[key]);
|
|
308
|
+
fs.writeFileSync(path.join(CURRENT_DIR, dir, `${folder.filename}.yml`), yamlStr, 'utf8');
|
|
309
|
+
}
|
|
292
310
|
|
|
293
|
-
|
|
294
|
-
const yamlStr = yaml.dump(reducedData);
|
|
295
|
-
const CURRENT_DIR = process.cwd();
|
|
296
|
-
const separator = getSeparatorByPlatform();
|
|
297
|
-
fs.writeFileSync(CURRENT_DIR + separator + dir + separator + 'types.yml', yamlStr, 'utf8');
|
|
311
|
+
}
|
|
298
312
|
}
|
|
@@ -3,7 +3,7 @@ import { ReducedType } from './interfaces';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import { authUser } from '../auth/login';
|
|
6
|
-
import
|
|
6
|
+
import * as path from 'path';
|
|
7
7
|
import * as _ from 'lodash';
|
|
8
8
|
|
|
9
9
|
import yaml from 'js-yaml';
|
|
@@ -29,9 +29,12 @@ export async function uploadTypes() {
|
|
|
29
29
|
function loadReducedTypes(){
|
|
30
30
|
const TARGET_DIR = process.cwd();
|
|
31
31
|
try {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
32
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'types'));
|
|
33
|
+
const types = [];
|
|
34
|
+
for(const file of files) {
|
|
35
|
+
types.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
|
|
36
|
+
}
|
|
37
|
+
return types;
|
|
35
38
|
} catch (e) {
|
|
36
39
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
37
40
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import { getSeparatorByPlatform } from '../common';
|
|
4
3
|
import { authUser } from '../auth/login';
|
|
5
4
|
import chalk from 'chalk';
|
|
6
5
|
import { getTypes } from './types-extractor';
|
|
6
|
+
import * as path from 'path';
|
|
7
7
|
|
|
8
8
|
const yaml = require('js-yaml');
|
|
9
9
|
|
|
@@ -28,9 +28,8 @@ export async function uploadUsageInfo(args) {
|
|
|
28
28
|
function loadUsageInfo() {
|
|
29
29
|
const TARGET_DIR = process.cwd();
|
|
30
30
|
try {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
return doc.reducedUsageInfo;
|
|
31
|
+
const doc = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'usage-info.yml'), 'utf8'));
|
|
32
|
+
return doc;
|
|
34
33
|
} catch (e) {
|
|
35
34
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
36
35
|
}
|