@contrail/cli 1.0.54 → 1.0.56
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 +51 -2
- package/lib/types/allUploader.d.ts +1 -0
- package/lib/types/allUploader.js +24 -0
- package/lib/types/option-set-hierarchy-uploader.d.ts +1 -0
- package/lib/types/option-set-hierarchy-uploader.js +113 -0
- package/lib/types/option-set-uploader.js +7 -4
- package/lib/types/rule-set-uploader.d.ts +1 -0
- package/lib/types/rule-set-uploader.js +172 -0
- package/lib/types/type-property-policy-uploader.d.ts +1 -0
- package/lib/types/type-property-policy-uploader.js +178 -0
- package/lib/types/types-extractor.d.ts +51 -2
- package/lib/types/types-extractor.js +223 -52
- package/lib/types/types-properties-merger.js +14 -8
- package/lib/types/types-uploader.js +7 -4
- package/lib/types/usage-info-uploader.d.ts +1 -0
- package/lib/types/usage-info-uploader.js +127 -0
- package/package.json +1 -1
- package/src/cli.ts +51 -2
- package/src/types/allUploader.ts +28 -0
- package/src/types/option-set-hierarchy-uploader.ts +122 -0
- package/src/types/option-set-uploader.ts +8 -7
- package/src/types/rule-set-uploader.ts +187 -0
- package/src/types/type-property-policy-uploader.ts +192 -0
- package/src/types/types-extractor.ts +238 -57
- package/src/types/types-properties-merger.ts +14 -9
- package/src/types/types-uploader.ts +7 -4
- package/src/types/usage-info-uploader.ts +134 -0
- /package/src/colors/{color-example.csv → colors.csv} +0 -0
|
@@ -2,24 +2,29 @@ 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
|
+
import pLimit from 'p-limit';
|
|
7
|
+
const limit = pLimit(30);
|
|
6
8
|
const yaml = require('js-yaml');
|
|
7
|
-
export async function
|
|
9
|
+
export async function getAll(args) {
|
|
8
10
|
try {
|
|
9
11
|
const userConfig = await authUser();
|
|
10
12
|
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
// make directory to house exports
|
|
14
|
+
const dir = `./contrail-export-${Date.now()}`;
|
|
15
|
+
fs.mkdirSync(dir);
|
|
16
|
+
const data = {
|
|
17
|
+
types: await getTypes(),
|
|
18
|
+
optionSets: await getOptionSets(),
|
|
19
|
+
optionSetHierarchies: await getOptionSetHierarchies(),
|
|
20
|
+
ruleSets: await getRuleSets(),
|
|
21
|
+
ruleSetLinks: await getRuleSetLinks(),
|
|
22
|
+
usageInfo: await getUsageInfo(),
|
|
23
|
+
typePropertyPolicies: await getTypePropertyPolicies(),
|
|
24
|
+
typePropertyPolicyLinks: await getTypePropertyPolicyLinks(),
|
|
21
25
|
};
|
|
22
|
-
|
|
26
|
+
const reducedData = reduceData(data);
|
|
27
|
+
saveData(reducedData, dir);
|
|
23
28
|
console.log('%s Retrieved', chalk.yellow.bold('TYPES'));
|
|
24
29
|
}
|
|
25
30
|
catch (e) {
|
|
@@ -28,43 +33,170 @@ export async function getTypes(args) {
|
|
|
28
33
|
}
|
|
29
34
|
console.log('%s Types Retrieval Complete.', chalk.green.bold('COMPLETE'));
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
/**
|
|
37
|
+
* stores reduced option sets and returns full option sets */
|
|
38
|
+
export async function getOptionSets() {
|
|
39
|
+
console.log('%s Retrieving', chalk.yellow.bold('OPTION SETS'));
|
|
40
|
+
const optionSets = await new Entities().get({
|
|
41
|
+
entityName: 'type-property-option-set',
|
|
42
|
+
});
|
|
43
|
+
console.log('%s Retrieved', chalk.yellow.bold('OPTION SETS'));
|
|
44
|
+
return optionSets;
|
|
45
|
+
}
|
|
46
|
+
export async function getTypes() {
|
|
47
|
+
console.log('%s Retrieving', chalk.yellow.bold('TYPES'));
|
|
48
|
+
const entitiesClient = new Entities();
|
|
49
|
+
const types = await entitiesClient.get({
|
|
50
|
+
entityName: 'type',
|
|
51
|
+
});
|
|
52
|
+
console.log(`${chalk.yellow.bold('TYPES')} Found ${types.length} types`);
|
|
53
|
+
const typesWithProperties = [];
|
|
54
|
+
const promises = [];
|
|
55
|
+
for (const type of types) {
|
|
56
|
+
const promise = limit(async () => {
|
|
57
|
+
const t = await entitiesClient.get({
|
|
58
|
+
entityName: 'type',
|
|
59
|
+
id: type.id,
|
|
60
|
+
relations: ['typeProperties'],
|
|
61
|
+
});
|
|
62
|
+
typesWithProperties.push(t);
|
|
63
|
+
});
|
|
64
|
+
promises.push(promise);
|
|
65
|
+
}
|
|
66
|
+
await Promise.all(promises);
|
|
67
|
+
return typesWithProperties;
|
|
68
|
+
}
|
|
69
|
+
async function getOptionSetHierarchies() {
|
|
70
|
+
const entitiesClient = new Entities();
|
|
71
|
+
return await entitiesClient.get({
|
|
72
|
+
entityName: 'option-set-hierarchy',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async function getRuleSets() {
|
|
76
|
+
const entitiesClient = new Entities();
|
|
77
|
+
return await entitiesClient.get({
|
|
78
|
+
entityName: 'type-rule-set',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async function getRuleSetLinks() {
|
|
82
|
+
const entitiesClient = new Entities();
|
|
83
|
+
return await entitiesClient.get({
|
|
84
|
+
entityName: 'type-rule-set-link',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async function getUsageInfo() {
|
|
88
|
+
const entitiesClient = new Entities();
|
|
89
|
+
return await entitiesClient.get({
|
|
90
|
+
entityName: 'type-property-usage-info',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async function getTypePropertyPolicies() {
|
|
94
|
+
const entitiesClient = new Entities();
|
|
95
|
+
return await entitiesClient.get({
|
|
96
|
+
entityName: 'type-property-policy',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async function getTypePropertyPolicyLinks() {
|
|
100
|
+
const entitiesClient = new Entities();
|
|
101
|
+
return await entitiesClient.get({
|
|
102
|
+
entityName: 'type-property-policy-link',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function reduceTypePropertyPolicies(data) {
|
|
106
|
+
var _a;
|
|
107
|
+
return (_a = data === null || data === void 0 ? void 0 : data.typePropertyPolicies) === null || _a === void 0 ? void 0 : _a.map(x => {
|
|
108
|
+
return {
|
|
109
|
+
label: x.label,
|
|
110
|
+
policy: {
|
|
111
|
+
version: x.policy.version,
|
|
112
|
+
statements: x.policy.statements,
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function reduceTypePropertyPolicyLinks(data) {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
const typeProperties = (_a = data === null || data === void 0 ? void 0 : data.types) === null || _a === void 0 ? void 0 : _a.map(x => x.typeProperties).reduce((x, y) => x.concat(y));
|
|
120
|
+
return (_b = data === null || data === void 0 ? void 0 : data.typePropertyPolicyLinks) === null || _b === void 0 ? void 0 : _b.map(x => {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
return {
|
|
123
|
+
typePropertySlug: (_a = typeProperties.find(y => y.id === x.typePropertyId)) === null || _a === void 0 ? void 0 : _a.slug,
|
|
124
|
+
typePropertyPolicyLabel: (_b = data.typePropertyPolicies.find(y => y.id === x.typePropertyPolicyId)) === null || _b === void 0 ? void 0 : _b.label,
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function reduceUsageInfo(data) {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
const typeProperties = (_a = data === null || data === void 0 ? void 0 : data.types) === null || _a === void 0 ? void 0 : _a.map(x => x.typeProperties).reduce((x, y) => x.concat(y));
|
|
131
|
+
return (_b = data === null || data === void 0 ? void 0 : data.usageInfo) === null || _b === void 0 ? void 0 : _b.map(x => {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
return {
|
|
134
|
+
used: x.used,
|
|
135
|
+
editable: x.editable,
|
|
136
|
+
typeSlug: (_a = data.types.find(y => y.id === x.typeId)) === null || _a === void 0 ? void 0 : _a.slug,
|
|
137
|
+
typePropertySlug: (_b = typeProperties.find(y => y.id === x.typePropertyId)) === null || _b === void 0 ? void 0 : _b.slug,
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function reduceRuleSetLinks(data) {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
const reducedRuleSetLinks = [];
|
|
144
|
+
if (!(data === null || data === void 0 ? void 0 : data.ruleSetLinks.length)) {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
for (const ruleSetLink of data.ruleSetLinks) {
|
|
148
|
+
const ruleSet = (_a = data === null || data === void 0 ? void 0 : data.ruleSets) === null || _a === void 0 ? void 0 : _a.find(x => x.id === ruleSetLink.typeRuleSetId);
|
|
149
|
+
const type = (_b = data === null || data === void 0 ? void 0 : data.types) === null || _b === void 0 ? void 0 : _b.find(x => x.id === ruleSetLink.typeId);
|
|
150
|
+
if (!ruleSet || !type) {
|
|
151
|
+
console.log('%s Skipping bad rule set link', ruleSetLink.id, chalk.red.bold('TYPES'));
|
|
152
|
+
}
|
|
153
|
+
reducedRuleSetLinks.push({
|
|
154
|
+
ruleSet: ruleSet.name,
|
|
155
|
+
type: type.slug
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return reducedRuleSetLinks;
|
|
159
|
+
}
|
|
160
|
+
function reduceRuleSets(data) {
|
|
161
|
+
var _a;
|
|
162
|
+
return (_a = data === null || data === void 0 ? void 0 : data.ruleSets) === null || _a === void 0 ? void 0 : _a.map(x => {
|
|
163
|
+
return {
|
|
164
|
+
ruleSet: x.ruleSet,
|
|
165
|
+
name: x.name,
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function reduceOptionSets(data) {
|
|
170
|
+
var _a;
|
|
171
|
+
return (_a = data.optionSets) === null || _a === void 0 ? void 0 : _a.map(optionSet => {
|
|
172
|
+
return {
|
|
35
173
|
name: optionSet.name,
|
|
36
174
|
isArchived: optionSet.isArchived,
|
|
37
175
|
optionSet: optionSet.optionSet,
|
|
38
176
|
};
|
|
39
|
-
reducedOptionSets.push(reducedOptionSet);
|
|
40
|
-
}
|
|
41
|
-
const optionSetsHolder = {
|
|
42
|
-
optionSets: reducedOptionSets,
|
|
43
|
-
};
|
|
44
|
-
reducedOptionSets = reducedOptionSets.sort((one, two) => (one.name < two.name ? -1 : 1));
|
|
45
|
-
const CURRENT_DIR = process.cwd();
|
|
46
|
-
const separator = getSeparatorByPlatform();
|
|
47
|
-
const yamlStr = yaml.dump(optionSetsHolder);
|
|
48
|
-
fs.writeFileSync(CURRENT_DIR + separator + 'option_sets.yml', yamlStr, 'utf8');
|
|
49
|
-
}
|
|
50
|
-
export async function getReducedTypes(optionSets) {
|
|
51
|
-
const types = await new Entities().get({
|
|
52
|
-
entityName: 'type',
|
|
53
177
|
});
|
|
54
|
-
|
|
178
|
+
}
|
|
179
|
+
function reduceOptionSetHierarchies(data) {
|
|
180
|
+
var _a;
|
|
181
|
+
return (_a = data.optionSetHierarchies) === null || _a === void 0 ? void 0 : _a.map(x => {
|
|
182
|
+
const hierarchyByName = x.hierarchy.map(optionSetId => { var _a, _b; return (_b = (_a = data.optionSets) === null || _a === void 0 ? void 0 : _a.find(x => x.id === optionSetId)) === null || _b === void 0 ? void 0 : _b.name; });
|
|
183
|
+
return {
|
|
184
|
+
hierarchy: hierarchyByName,
|
|
185
|
+
options: x.options,
|
|
186
|
+
name: x.name
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
export function reduceTypes(dataHolder) {
|
|
191
|
+
console.log('Found types: ', dataHolder.types.length);
|
|
55
192
|
let reducedTypes = [];
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
const optionSetNameById = {};
|
|
63
|
-
for (const optionSet of optionSets) {
|
|
64
|
-
optionSetNameById[optionSet.id] = optionSet.name;
|
|
65
|
-
}
|
|
193
|
+
const optionSetNameById = {};
|
|
194
|
+
for (const optionSet of dataHolder.optionSets) {
|
|
195
|
+
optionSetNameById[optionSet.id] = optionSet.name;
|
|
196
|
+
}
|
|
197
|
+
for (const type of dataHolder.types) {
|
|
66
198
|
const reducedTypeProperties = [];
|
|
67
|
-
for (const typeProperty of
|
|
199
|
+
for (const typeProperty of type.typeProperties) {
|
|
68
200
|
const reducedTypeProperty = {
|
|
69
201
|
slug: typeProperty.slug,
|
|
70
202
|
id: typeProperty.id,
|
|
@@ -86,10 +218,10 @@ export async function getReducedTypes(optionSets) {
|
|
|
86
218
|
reducedTypeProperties.push(reducedTypeProperty);
|
|
87
219
|
}
|
|
88
220
|
const reducedType = {
|
|
89
|
-
typePath:
|
|
90
|
-
slug:
|
|
91
|
-
label:
|
|
92
|
-
isArchived:
|
|
221
|
+
typePath: type.typePath,
|
|
222
|
+
slug: type.slug,
|
|
223
|
+
label: type.label,
|
|
224
|
+
isArchived: type.isArchived,
|
|
93
225
|
typeProperties: reducedTypeProperties,
|
|
94
226
|
};
|
|
95
227
|
reducedTypes.push(reducedType);
|
|
@@ -97,9 +229,48 @@ export async function getReducedTypes(optionSets) {
|
|
|
97
229
|
reducedTypes = reducedTypes.sort((one, two) => (one.typePath < two.typePath ? -1 : 1));
|
|
98
230
|
return reducedTypes;
|
|
99
231
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
232
|
+
export function reduceData(data) {
|
|
233
|
+
return {
|
|
234
|
+
reducedTypes: reduceTypes(data),
|
|
235
|
+
reducedOptionSets: reduceOptionSets(data),
|
|
236
|
+
reducedOptionSetHierarchies: reduceOptionSetHierarchies(data),
|
|
237
|
+
reducedRuleSets: reduceRuleSets(data),
|
|
238
|
+
reducedRuleSetLinks: reduceRuleSetLinks(data),
|
|
239
|
+
reducedUsageInfo: reduceUsageInfo(data),
|
|
240
|
+
reducedTypePropertyPolicies: reduceTypePropertyPolicies(data),
|
|
241
|
+
reducedTypePropertyPolicyLinks: reduceTypePropertyPolicyLinks(data),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function saveData(reducedData, dir) {
|
|
245
|
+
const propertyToFolderMap = {
|
|
246
|
+
reducedTypes: { filename: 'types', split: true, fileLabel: 'slug' },
|
|
247
|
+
reducedOptionSets: { filename: 'option-sets', split: true, fileLabel: 'name' },
|
|
248
|
+
reducedOptionSetHierarchies: { filename: 'option-set-hierarchies', split: true, fileLabel: 'name' },
|
|
249
|
+
reducedRuleSets: { filename: 'rule-sets', split: true, fileLabel: 'name' },
|
|
250
|
+
reducedRuleSetLinks: { filename: 'rule-set-links', split: false, fileLabel: '' },
|
|
251
|
+
reducedUsageInfo: { filename: 'usage-info', split: false, fileLabel: '' },
|
|
252
|
+
reducedTypePropertyPolicies: { filename: 'type-property-policies', split: true, fileLabel: 'label' },
|
|
253
|
+
reducedTypePropertyPolicyLinks: { filename: 'type-property-policy-links', split: false, fileLabel: '' },
|
|
254
|
+
};
|
|
255
|
+
for (const [key, folder] of Object.entries(propertyToFolderMap)) {
|
|
256
|
+
const CURRENT_DIR = process.cwd();
|
|
257
|
+
if (folder.split) {
|
|
258
|
+
const subDir = path.join(CURRENT_DIR, dir, folder.filename);
|
|
259
|
+
if (!fs.existsSync(subDir)) {
|
|
260
|
+
fs.mkdirSync(subDir);
|
|
261
|
+
}
|
|
262
|
+
for (const item of reducedData[key]) {
|
|
263
|
+
const yamlStr = yaml.dump(item);
|
|
264
|
+
const fileLabel = item[folder.fileLabel];
|
|
265
|
+
if (!fileLabel) {
|
|
266
|
+
console.warn('skipping bad data:', item);
|
|
267
|
+
}
|
|
268
|
+
fs.writeFileSync(path.join(subDir, `${fileLabel}.yml`), yamlStr, 'utf8');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
const yamlStr = yaml.dump(reducedData[key]);
|
|
273
|
+
fs.writeFileSync(path.join(CURRENT_DIR, dir, `${folder.filename}.yml`), yamlStr, 'utf8');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
105
276
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getReducedTypes } from './types-extractor';
|
|
1
|
+
import { getOptionSets, getTypes, reduceData } from './types-extractor';
|
|
3
2
|
import fs from 'fs';
|
|
4
3
|
import { getSeparatorByPlatform } from '../common';
|
|
5
4
|
import { authUser } from '../auth/login';
|
|
@@ -40,18 +39,25 @@ function loadTypeProperties(fileLocation) {
|
|
|
40
39
|
async function mergeTypeProperties(fileLocation, typePaths) {
|
|
41
40
|
const uploadedTypeProperties = loadTypeProperties(fileLocation);
|
|
42
41
|
await authUser();
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const data = {
|
|
43
|
+
types: await getTypes(),
|
|
44
|
+
optionSets: await getOptionSets(),
|
|
45
|
+
optionSetHierarchies: [],
|
|
46
|
+
ruleSets: [],
|
|
47
|
+
ruleSetLinks: [],
|
|
48
|
+
usageInfo: [],
|
|
49
|
+
typePropertyPolicies: [],
|
|
50
|
+
typePropertyPolicyLinks: [],
|
|
51
|
+
};
|
|
52
|
+
const reducedData = await reduceData(data);
|
|
47
53
|
for (const typePath of typePaths) {
|
|
48
|
-
const foundType = reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
|
|
54
|
+
const foundType = reducedData.reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
|
|
49
55
|
if (!foundType) {
|
|
50
56
|
console.log(`%s No Type found for: ${typePath}`, chalk.red.bold('WARNING'));
|
|
51
57
|
}
|
|
52
58
|
mergeType(foundType, uploadedTypeProperties);
|
|
53
59
|
}
|
|
54
|
-
saveData({ types: reducedTypes });
|
|
60
|
+
saveData({ types: reducedData.reducedTypes });
|
|
55
61
|
}
|
|
56
62
|
function mergeType(reducedType, typePropertiesToAdd) {
|
|
57
63
|
for (const typeProperty of typePropertiesToAdd) {
|
|
@@ -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}`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uploadUsageInfo(args: any): Promise<void>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { authUser } from '../auth/login';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { getTypes } from './types-extractor';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
const yaml = require('js-yaml');
|
|
8
|
+
export async function uploadUsageInfo(args) {
|
|
9
|
+
try {
|
|
10
|
+
await authUser();
|
|
11
|
+
console.log('%s Uploading', chalk.yellow.bold('USAGE INFO'));
|
|
12
|
+
const reducedUsageInfo = await loadUsageInfo();
|
|
13
|
+
await uploadUsageInfoObjects(reducedUsageInfo);
|
|
14
|
+
console.log('%s Uploaded', chalk.yellow.bold('USAGE INFO'));
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.log(`%s Usage Info Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
console.log('%s Usage Info Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
21
|
+
}
|
|
22
|
+
function loadUsageInfo() {
|
|
23
|
+
const TARGET_DIR = process.cwd();
|
|
24
|
+
try {
|
|
25
|
+
const doc = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'usage-info.yml'), 'utf8'));
|
|
26
|
+
return doc;
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function uploadUsageInfoObjects(loadedUsageInfo) {
|
|
33
|
+
const typesWithProperties = await getTypes();
|
|
34
|
+
const typeProperties = typesWithProperties
|
|
35
|
+
.filter(t => !!t.typeProperties)
|
|
36
|
+
.map(t => t.typeProperties)
|
|
37
|
+
.reduce((a, b) => a.concat(b));
|
|
38
|
+
const currentUsageInfo = await new Entities().get({
|
|
39
|
+
entityName: 'type-property-usage-info',
|
|
40
|
+
});
|
|
41
|
+
const currentUsageInfosHashes = {};
|
|
42
|
+
for (const currentUI of currentUsageInfo) {
|
|
43
|
+
const foundType = typesWithProperties.find(t => t.id === currentUI.typeId);
|
|
44
|
+
const foundTypeProperty = typeProperties.find(tp => tp.id === currentUI.typePropertyId);
|
|
45
|
+
if (!foundType || !foundTypeProperty) {
|
|
46
|
+
console.log('skipping unhashable, invalid usage info:', currentUI);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const hash = `${foundType.slug}|${foundTypeProperty.slug}`;
|
|
50
|
+
currentUsageInfosHashes[hash] = currentUI;
|
|
51
|
+
}
|
|
52
|
+
const reducedUsageInfoHashes = {};
|
|
53
|
+
for (const loadedUI of loadedUsageInfo) {
|
|
54
|
+
const hash = `${loadedUI.typeSlug}|${loadedUI.typePropertySlug}`;
|
|
55
|
+
reducedUsageInfoHashes[hash] = loadedUI;
|
|
56
|
+
}
|
|
57
|
+
console.debug('current usage info:', currentUsageInfo);
|
|
58
|
+
console.debug('loaded usage info:', loadedUsageInfo);
|
|
59
|
+
for (const loadedUI of loadedUsageInfo) {
|
|
60
|
+
try {
|
|
61
|
+
const found = currentUsageInfosHashes[`${loadedUI.typeSlug}|${loadedUI.typePropertySlug}`];
|
|
62
|
+
if (!found) {
|
|
63
|
+
if (!transformReducedUI(loadedUI, typesWithProperties, typeProperties)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
console.debug('Creating: ', loadedUI);
|
|
67
|
+
await new Entities().create({
|
|
68
|
+
entityName: 'type-property-usage-info',
|
|
69
|
+
object: {
|
|
70
|
+
typePropertyId: loadedUI.typePropertyId,
|
|
71
|
+
typeId: loadedUI.typeId,
|
|
72
|
+
editable: loadedUI.editable,
|
|
73
|
+
used: loadedUI.used,
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (!transformReducedUI(loadedUI, typesWithProperties, typeProperties)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
console.log('Updating: ', loadedUI);
|
|
82
|
+
await new Entities().update({
|
|
83
|
+
entityName: 'type-property-usage-info',
|
|
84
|
+
id: found.id,
|
|
85
|
+
object: {
|
|
86
|
+
editable: loadedUI.editable,
|
|
87
|
+
used: loadedUI.used,
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
throw new Error(`Error Uploading usage info: ${err}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const [hash, currentUI] of Object.entries(currentUsageInfosHashes)) {
|
|
97
|
+
try {
|
|
98
|
+
const found = reducedUsageInfoHashes[hash];
|
|
99
|
+
if (!found) {
|
|
100
|
+
console.debug('Deleting: ', hash);
|
|
101
|
+
await new Entities().delete({
|
|
102
|
+
entityName: 'type-property-usage-info',
|
|
103
|
+
id: currentUI['id'],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
throw new Error(`Error Deleting usage info: ${err}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// transforms the reduced Usage Info from name slugs to ids
|
|
113
|
+
function transformReducedUI(reducedUsageInfo, types, typeProperties) {
|
|
114
|
+
const foundType = types.find(t => t.slug === reducedUsageInfo.typeSlug);
|
|
115
|
+
if (!foundType) {
|
|
116
|
+
console.error('Could not find type with slug', reducedUsageInfo.typeSlug, 'while transforming', reducedUsageInfo);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
reducedUsageInfo.typeId = foundType.id;
|
|
120
|
+
const foundTypeProperty = typeProperties.find(tp => tp.slug === reducedUsageInfo.typePropertySlug);
|
|
121
|
+
if (!foundTypeProperty) {
|
|
122
|
+
console.error('Could not find type property with slug', reducedUsageInfo.typePropertySlug, 'while transforming', reducedUsageInfo);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
reducedUsageInfo.typePropertyId = foundTypeProperty.id;
|
|
126
|
+
return true;
|
|
127
|
+
}
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { create } from './apps/create-app/create';
|
|
3
3
|
import { deployApp, removeApp } from './apps/deploy-app/deploy';
|
|
4
|
-
import {
|
|
4
|
+
import { getAll } 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';
|
|
@@ -19,6 +19,11 @@ import { cliInstallWorkflowTemplateDefinitions, listWorkflowTemplateDefinitions
|
|
|
19
19
|
import { configureProject } from './projects/project-uploader';
|
|
20
20
|
import { ListProjects, ExportProject } from './projects/project-exporter';
|
|
21
21
|
import { Load, UploadAndLoad } from './loader-process/loader-process';
|
|
22
|
+
import { uploadUsageInfo } from './types/usage-info-uploader';
|
|
23
|
+
import { uploadRuleSets } from './types/rule-set-uploader';
|
|
24
|
+
import { UploadOptionSetHierarchies } from './types/option-set-hierarchy-uploader';
|
|
25
|
+
import { uploadTypePropertyPolicies } from './types/type-property-policy-uploader';
|
|
26
|
+
import { uploadAll } from './types/allUploader';
|
|
22
27
|
|
|
23
28
|
const cliUsage = require('command-line-usage');
|
|
24
29
|
|
|
@@ -89,7 +94,11 @@ export async function cli(args) {
|
|
|
89
94
|
case 'types': {
|
|
90
95
|
switch (command) {
|
|
91
96
|
case 'getAll': {
|
|
92
|
-
|
|
97
|
+
getAll(args);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case 'uploadAll': {
|
|
101
|
+
uploadAll();
|
|
93
102
|
break;
|
|
94
103
|
}
|
|
95
104
|
case 'uploadTypes': {
|
|
@@ -116,6 +125,22 @@ export async function cli(args) {
|
|
|
116
125
|
ExportOptionSetsHierarchies();
|
|
117
126
|
break;
|
|
118
127
|
}
|
|
128
|
+
case 'uploadOptionSetsHierarchies': {
|
|
129
|
+
UploadOptionSetHierarchies(args);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case 'uploadRuleSets': {
|
|
133
|
+
uploadRuleSets(args);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case 'uploadUsageInfo': {
|
|
137
|
+
uploadUsageInfo(args);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case 'uploadTypePropertyPolicies': {
|
|
141
|
+
uploadTypePropertyPolicies(args);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
119
144
|
case 'parseTypesFromLocalFiles': {
|
|
120
145
|
ParseTypesFromLocalFiles(args);
|
|
121
146
|
break;
|
|
@@ -418,6 +443,30 @@ const helpSections = [
|
|
|
418
443
|
name: 'exportOptionSetsHierarchies',
|
|
419
444
|
summary: 'export OptionSetHierarchies into CSVs.\n'
|
|
420
445
|
},
|
|
446
|
+
{
|
|
447
|
+
name: 'uploadAll',
|
|
448
|
+
summary: 'Upload an extracted archive of types:getAll.'
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
name: 'uploadOptionSetsHierarchies',
|
|
452
|
+
summary: 'Upload an extracted option set hierarchies.'
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
name: 'uploadRuleSets',
|
|
456
|
+
summary: 'Upload an extracted rule set.'
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
name: 'uploadUsageInfo',
|
|
460
|
+
summary: 'Upload extracted usage info.'
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
name: 'uploadTypePropertyPolicies',
|
|
464
|
+
summary: 'Upload type property policies.'
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
name: 'uploadOptionSetsHierarchyLocalFiles <File Paths> <name>',
|
|
468
|
+
summary: 'upload CSV files into OptionSetHierarchies.'
|
|
469
|
+
},
|
|
421
470
|
{
|
|
422
471
|
name: 'parseTypesFromLocalFiles <File Paths>',
|
|
423
472
|
summary: 'Parse CSV files into Types and OptionSets from local files.\n'
|
|
@@ -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
|
+
}
|