@contrail/cli 3.5.2 → 3.5.3-alpha.317fe63
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/README.md +10 -28
- package/dist/api/types.d.ts +0 -5
- package/dist/api/types.js +1 -36
- package/dist/commands/projects/export.d.ts +1 -0
- package/dist/commands/projects/export.js +19 -5
- package/dist/commands/types/getAll.js +0 -18
- package/dist/commands/types/loadAll.js +0 -2
- package/dist/commands/types/mergeTypeProperties.js +0 -5
- package/dist/commands/types/uploadOptionSetHierarchies.js +0 -117
- package/dist/commands/types/uploadOptionSets.js +1 -1
- package/dist/commands/types/uploadRuleSets.js +2 -85
- package/dist/commands/types/uploadTypeOverrides.js +10 -2
- package/dist/commands/types/uploadTypePolicies.js +2 -86
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +0 -1
- package/dist/commands/types/uploadTypePropertyPolicies.js +3 -139
- package/dist/helpers/projects/helpers.d.ts +2 -1
- package/dist/helpers/projects/helpers.js +37 -2
- package/dist/helpers/projects/post-processor.d.ts +131 -0
- package/dist/helpers/projects/post-processor.js +519 -0
- package/dist/helpers/types/type-uploader.js +1 -1
- package/dist/interfaces.d.ts +0 -25
- package/dist/templates/typescript/tsup.config.ts +0 -0
- package/node_modules/@contrail/org-config-migration/.github/workflows/publish-to-npm.yml +117 -0
- package/node_modules/@contrail/org-config-migration/.husky/pre-commit +0 -0
- package/node_modules/@contrail/org-config-migration/lib/index.d.ts +3 -3
- package/node_modules/@contrail/org-config-migration/lib/index.js +19 -19
- package/node_modules/@contrail/org-config-migration/lib/interfaces.d.ts +87 -97
- package/node_modules/@contrail/org-config-migration/lib/interfaces.js +2 -2
- package/node_modules/@contrail/org-config-migration/lib/services/index.d.ts +1 -1
- package/node_modules/@contrail/org-config-migration/lib/services/index.js +17 -17
- package/node_modules/@contrail/org-config-migration/lib/services/types.d.ts +12 -17
- package/node_modules/@contrail/org-config-migration/lib/services/types.js +115 -155
- package/node_modules/@contrail/org-config-migration/lib/types/exportAll.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportAll.js +34 -40
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSet.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSet.js +20 -20
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSetHierarchies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSetHierarchies.js +16 -47
- package/node_modules/@contrail/org-config-migration/lib/types/exportOverrides.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportOverrides.js +8 -8
- package/node_modules/@contrail/org-config-migration/lib/types/exportRuleSets.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportRuleSets.js +14 -39
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePolicies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePolicies.js +44 -56
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePropertyPolicies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePropertyPolicies.js +44 -71
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypes.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypes.js +85 -85
- package/node_modules/@contrail/org-config-migration/lib/types/importAll.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/importAll.js +386 -451
- package/node_modules/@contrail/org-config-migration/lib/types/index.d.ts +8 -9
- package/node_modules/@contrail/org-config-migration/lib/types/index.js +24 -25
- package/node_modules/@contrail/org-config-migration/lib/types/parseOptionSetHierarchy.d.ts +3 -3
- package/node_modules/@contrail/org-config-migration/lib/types/parseOptionSetHierarchy.js +210 -210
- package/node_modules/@contrail/org-config-migration/lib/users/export.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/export.js +40 -40
- package/node_modules/@contrail/org-config-migration/lib/users/import.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/import.js +41 -41
- package/node_modules/@contrail/org-config-migration/lib/users/index.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/index.js +18 -18
- package/node_modules/@contrail/org-config-migration/package.json +1 -1
- package/oclif.manifest.json +11 -55
- package/package.json +2 -2
- package/dist/commands/types/uploadUsageInfo.d.ts +0 -15
- package/dist/commands/types/uploadUsageInfo.js +0 -180
- package/dist/commands/types/uploadUsageInfo.spec.d.ts +0 -1
- package/dist/commands/types/uploadUsageInfo.spec.js +0 -249
- package/node_modules/@contrail/org-config-migration/lib/types/exportUsageInfo.d.ts +0 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportUsageInfo.js +0 -39
|
@@ -8,7 +8,6 @@ const path = tslib_1.__importStar(require("path"));
|
|
|
8
8
|
const login_1 = require("../../auth/login");
|
|
9
9
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
10
10
|
const core_1 = require("@oclif/core");
|
|
11
|
-
const type_extractor_1 = require("../../helpers/types/type-extractor");
|
|
12
11
|
const users_1 = require("../../api/users");
|
|
13
12
|
const basecommand_1 = require("../../basecommand");
|
|
14
13
|
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
@@ -37,9 +36,8 @@ async function uploadTypePolicies(dir) {
|
|
|
37
36
|
try {
|
|
38
37
|
await (0, login_1.authUser)();
|
|
39
38
|
logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE POLICY')} Uploading`);
|
|
40
|
-
const
|
|
39
|
+
const reducedTypePolicies = await loadTypePolicies(dir);
|
|
41
40
|
await uploadTypePolicyObjects(reducedTypePolicies);
|
|
42
|
-
await uploadTypePolicyLinks(reducedTypePolicyLinks);
|
|
43
41
|
logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE POLICY')} Uploaded`);
|
|
44
42
|
}
|
|
45
43
|
catch (e) {
|
|
@@ -51,15 +49,13 @@ async function uploadTypePolicies(dir) {
|
|
|
51
49
|
exports.uploadTypePolicies = uploadTypePolicies;
|
|
52
50
|
function loadTypePolicies(fromDir) {
|
|
53
51
|
const tps = [];
|
|
54
|
-
let tpLinks = [];
|
|
55
52
|
const dir = path.join(fromDir, 'type-policies');
|
|
56
53
|
try {
|
|
57
54
|
const files = fs_1.default.readdirSync(dir);
|
|
58
55
|
for (const file of files) {
|
|
59
56
|
tps.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
return [tps, tpLinks];
|
|
58
|
+
return tps;
|
|
63
59
|
}
|
|
64
60
|
catch (e) {
|
|
65
61
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -152,83 +148,3 @@ async function uploadTypePolicyObjects(reducedTypePolicies) {
|
|
|
152
148
|
}
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
|
-
async function uploadTypePolicyLinks(reducedTypePolicyLinks) {
|
|
156
|
-
const types = await (0, type_extractor_1.getTypes)();
|
|
157
|
-
const currentTypePolicies = await new sdk_1.Entities().get({
|
|
158
|
-
entityName: 'type-policy',
|
|
159
|
-
});
|
|
160
|
-
const currentTypePolicyLinks = await new sdk_1.Entities().get({
|
|
161
|
-
entityName: 'type-policy-link',
|
|
162
|
-
});
|
|
163
|
-
const currentLinksHashes = {};
|
|
164
|
-
for (const currentLink of currentTypePolicyLinks) {
|
|
165
|
-
const foundType = types.find((type) => type.id === currentLink.typeId);
|
|
166
|
-
const foundTypePolicy = currentTypePolicies.find((tp) => tp.id === currentLink.typePolicyId);
|
|
167
|
-
if (!foundType || !foundTypePolicy) {
|
|
168
|
-
logger_1.default.info(`skipping unhashable, invalid policy link: ${JSON.stringify(currentLink, null, 2)}`);
|
|
169
|
-
}
|
|
170
|
-
const hash = `${foundType.slug}|${foundTypePolicy.identifier}`;
|
|
171
|
-
currentLinksHashes[hash] = currentLink;
|
|
172
|
-
}
|
|
173
|
-
const reducedLinksByHashes = {};
|
|
174
|
-
for (const loadedLink of reducedTypePolicyLinks) {
|
|
175
|
-
const hash = `${loadedLink.typeSlug}|${loadedLink.typePolicyIdentifier}`;
|
|
176
|
-
reducedLinksByHashes[hash] = loadedLink;
|
|
177
|
-
}
|
|
178
|
-
for (const loadedTPLink of reducedTypePolicyLinks) {
|
|
179
|
-
try {
|
|
180
|
-
const found = currentLinksHashes[`${loadedTPLink.typeSlug}|${loadedTPLink.typePolicyIdentifier}`];
|
|
181
|
-
if (!found) {
|
|
182
|
-
if (!transformReducedLink(loadedTPLink, types, currentTypePolicies)) {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
logger_1.default.info(`Creating: ${loadedTPLink.typeSlug}|${loadedTPLink.typePolicyIdentifier}`);
|
|
186
|
-
await new sdk_1.Entities().create({
|
|
187
|
-
entityName: 'type-policy-link',
|
|
188
|
-
object: {
|
|
189
|
-
typePolicyId: loadedTPLink.typePolicyId,
|
|
190
|
-
typeId: loadedTPLink.typeId,
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
if (!transformReducedLink(loadedTPLink, types, currentTypePolicies)) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
logger_1.default.error(`Error Uploading type policy links: ${err}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
for (const [currentLinkHash, currentLink] of Object.entries(currentLinksHashes)) {
|
|
205
|
-
try {
|
|
206
|
-
const found = reducedLinksByHashes[currentLinkHash];
|
|
207
|
-
if (!found) {
|
|
208
|
-
logger_1.default.info(`Deleting: ${currentLinkHash}`);
|
|
209
|
-
await new sdk_1.Entities().delete({
|
|
210
|
-
entityName: 'type-policy-link',
|
|
211
|
-
id: currentLink['id'],
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
catch (err) {
|
|
216
|
-
logger_1.default.error(`Error Deleting rule set link: ${err}`);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function transformReducedLink(typePolicyLink, types, typePolicies) {
|
|
221
|
-
const foundType = types.find((type) => type.slug === typePolicyLink.typeSlug);
|
|
222
|
-
if (!foundType) {
|
|
223
|
-
logger_1.default.error(`Could not find type with slug ${typePolicyLink.typeSlug}`);
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
typePolicyLink.typeId = foundType.id;
|
|
227
|
-
const foundTypePolicy = typePolicies.find((tpp) => tpp.identifier === typePolicyLink.typePolicyIdentifier);
|
|
228
|
-
if (!foundTypePolicy) {
|
|
229
|
-
logger_1.default.error(`Could not find type policy with identifier ${typePolicyLink.typePolicyIdentifier}`);
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
typePolicyLink.typePolicyId = foundTypePolicy.id;
|
|
233
|
-
return true;
|
|
234
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.uploadTypePropertyPolicies = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const sdk_1 = require("@contrail/sdk");
|
|
6
6
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
@@ -8,12 +8,10 @@ const path = tslib_1.__importStar(require("path"));
|
|
|
8
8
|
const login_1 = require("../../auth/login");
|
|
9
9
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
10
10
|
const core_1 = require("@oclif/core");
|
|
11
|
-
const type_extractor_1 = require("../../helpers/types/type-extractor");
|
|
12
11
|
const users_1 = require("../../api/users");
|
|
13
12
|
const basecommand_1 = require("../../basecommand");
|
|
14
13
|
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
15
14
|
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
16
|
-
const _ = tslib_1.__importStar(require("lodash"));
|
|
17
15
|
class UploadTypePropertyPolicies extends basecommand_1.BaseCommand {
|
|
18
16
|
static description = 'Upload type property policies';
|
|
19
17
|
static examples = [
|
|
@@ -38,14 +36,12 @@ async function uploadTypePropertyPolicies(dir) {
|
|
|
38
36
|
try {
|
|
39
37
|
await (0, login_1.authUser)();
|
|
40
38
|
logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploading`);
|
|
41
|
-
const
|
|
39
|
+
const reducedTypePropertyPolicies = await loadTPPolicies(dir);
|
|
42
40
|
await uploadTPPolicyObjects(reducedTypePropertyPolicies);
|
|
43
|
-
await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
|
|
44
41
|
logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploaded`);
|
|
45
42
|
}
|
|
46
43
|
catch (e) {
|
|
47
44
|
logger_1.default.info(`${chalk_1.default.red.bold('FAIL')} Type Property Policy Upload Failed . ${e}`);
|
|
48
|
-
//TODO make this only print if a debug flag is set
|
|
49
45
|
console.trace(e);
|
|
50
46
|
return;
|
|
51
47
|
}
|
|
@@ -54,15 +50,13 @@ async function uploadTypePropertyPolicies(dir) {
|
|
|
54
50
|
exports.uploadTypePropertyPolicies = uploadTypePropertyPolicies;
|
|
55
51
|
function loadTPPolicies(fromDir) {
|
|
56
52
|
const tpps = [];
|
|
57
|
-
let tppLinks = [];
|
|
58
53
|
const dir = path.join(fromDir, 'type-property-policies');
|
|
59
54
|
try {
|
|
60
55
|
const files = fs_1.default.readdirSync(dir);
|
|
61
56
|
for (const file of files) {
|
|
62
57
|
tpps.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
|
|
63
58
|
}
|
|
64
|
-
|
|
65
|
-
return [tpps, tppLinks];
|
|
59
|
+
return tpps;
|
|
66
60
|
}
|
|
67
61
|
catch (e) {
|
|
68
62
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -155,133 +149,3 @@ async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
|
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
151
|
}
|
|
158
|
-
async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
|
|
159
|
-
const typesWithProperties = await (0, type_extractor_1.getTypes)();
|
|
160
|
-
const typeProperties = [];
|
|
161
|
-
typesWithProperties.forEach((type) => {
|
|
162
|
-
if (type.typeProperties) {
|
|
163
|
-
for (const tp of type.typeProperties) {
|
|
164
|
-
tp.typeId = type.id;
|
|
165
|
-
tp.typeSlug = type.slug;
|
|
166
|
-
typeProperties.push(tp);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
const currentTPPs = await new sdk_1.Entities().get({
|
|
171
|
-
entityName: 'type-property-policy',
|
|
172
|
-
});
|
|
173
|
-
const currentTPPLinks = await new sdk_1.Entities().get({
|
|
174
|
-
entityName: 'type-property-policy-link',
|
|
175
|
-
});
|
|
176
|
-
logger_1.default.info(`found ${currentTPPLinks.length} current type property policy links`);
|
|
177
|
-
logger_1.default.info(`found ${reducedTypePropertyPolicyLinks.length} type property policy links to load`);
|
|
178
|
-
const currentLinksHashes = {};
|
|
179
|
-
for (const currentLink of currentTPPLinks) {
|
|
180
|
-
const foundTPs = findAllOccurrences(typeProperties, (tp) => tp.id === currentLink.typePropertyId);
|
|
181
|
-
for (const foundTP of foundTPs) {
|
|
182
|
-
const foundTPP = currentTPPs.find((tpp) => tpp.id === currentLink.typePropertyPolicyId);
|
|
183
|
-
if (!foundTP || !foundTPP) {
|
|
184
|
-
logger_1.default.info(`skipping unhashable, invalid policy link: ${JSON.stringify(currentLink, null, 2)}`);
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
const hash = `${foundTP.typeSlug}|${foundTP.slug}|${foundTPP.identifier}`;
|
|
188
|
-
currentLinksHashes[hash] = currentLink;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
logger_1.default.debug(`current links hashes: ${JSON.stringify(currentLinksHashes, null, 2)}`);
|
|
192
|
-
const reducedLinksByHashes = {};
|
|
193
|
-
for (const loadedLink of reducedTypePropertyPolicyLinks) {
|
|
194
|
-
const hash = `${loadedLink.typeSlug}|${loadedLink.typePropertySlug}|${loadedLink.typePropertyPolicyIdentifier}`;
|
|
195
|
-
reducedLinksByHashes[hash] = loadedLink;
|
|
196
|
-
}
|
|
197
|
-
const toCreate = Object.keys(reducedLinksByHashes)
|
|
198
|
-
.filter((x) => !currentLinksHashes[x])
|
|
199
|
-
.map((x) => {
|
|
200
|
-
return {
|
|
201
|
-
[x]: reducedLinksByHashes[x],
|
|
202
|
-
};
|
|
203
|
-
})
|
|
204
|
-
.reduce((a, b) => Object.assign(a, b), {});
|
|
205
|
-
const toDelete = _.uniqBy(Object.keys(currentLinksHashes)
|
|
206
|
-
.filter((x) => !reducedLinksByHashes[x])
|
|
207
|
-
.map((x) => {
|
|
208
|
-
return {
|
|
209
|
-
[x]: currentLinksHashes[x],
|
|
210
|
-
};
|
|
211
|
-
}), 'id').reduce((a, b) => Object.assign(a, b), {});
|
|
212
|
-
logger_1.default.debug(`reduced links hashes: ${JSON.stringify(reducedLinksByHashes, null, 2)}`);
|
|
213
|
-
logger_1.default.info(`found ${Object.keys(toCreate).length} type property policy links to create`);
|
|
214
|
-
logger_1.default.info(`found ${Object.keys(toDelete).length} type property policy links to delete`);
|
|
215
|
-
logger_1.default.debug(`to create: ${JSON.stringify(toCreate, null, 2)}`);
|
|
216
|
-
logger_1.default.debug(`to delete: ${JSON.stringify(toDelete, null, 2)}`);
|
|
217
|
-
logger_1.default.debug(`current links hashes to delete: ${JSON.stringify(Object.keys(currentLinksHashes).filter((x) => !reducedLinksByHashes[x]), null, 2)}`);
|
|
218
|
-
// fs.writeFileSync('toCreate.json', JSON.stringify(toCreate, null, 2));
|
|
219
|
-
// fs.writeFileSync('toDelete.json', JSON.stringify(toDelete, null, 2));
|
|
220
|
-
// fs.writeFileSync('currentLinksHashes.json', JSON.stringify(currentLinksHashes, null, 2));
|
|
221
|
-
// fs.writeFileSync('reducedLinksByHashes.json', JSON.stringify(reducedLinksByHashes, null, 2));
|
|
222
|
-
// fs.writeFileSync(
|
|
223
|
-
// 'current_link_hashes_to_delete.json',
|
|
224
|
-
// JSON.stringify(
|
|
225
|
-
// Object.keys(currentLinksHashes).filter((x) => !reducedLinksByHashes[x]),
|
|
226
|
-
// null,
|
|
227
|
-
// 2,
|
|
228
|
-
// ),
|
|
229
|
-
// );
|
|
230
|
-
// return;
|
|
231
|
-
for (const [hash, link] of Object.entries(toCreate)) {
|
|
232
|
-
try {
|
|
233
|
-
if (!transformReducedLink(link, typeProperties, currentTPPs)) {
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
logger_1.default.info(`Creating: ${hash}: ${JSON.stringify(link, null, 2)}`);
|
|
237
|
-
await new sdk_1.Entities().create({
|
|
238
|
-
entityName: 'type-property-policy-link',
|
|
239
|
-
object: {
|
|
240
|
-
typePropertyPolicyId: link.typePropertyPolicyId,
|
|
241
|
-
typePropertyId: link.typePropertyId,
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
catch (err) {
|
|
246
|
-
logger_1.default.error(`Error Uploading type property policy links: ${err}`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
for (const [hash, link] of Object.entries(toDelete)) {
|
|
250
|
-
try {
|
|
251
|
-
logger_1.default.info(`Deleting: ${hash}`);
|
|
252
|
-
await new sdk_1.Entities().delete({
|
|
253
|
-
entityName: 'type-property-policy-link',
|
|
254
|
-
id: link['id'],
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
catch (err) {
|
|
258
|
-
logger_1.default.error(`Error Deleting type property policy link: ${err}`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function transformReducedLink(TPPLink, typeProperties, typePropertyPolicies) {
|
|
262
|
-
const foundTP = typeProperties.find((tp) => tp.slug === TPPLink.typePropertySlug && tp.typeSlug === TPPLink.typeSlug);
|
|
263
|
-
if (!foundTP) {
|
|
264
|
-
logger_1.default.error(`Could not find type property with slug ${TPPLink.typePropertySlug} `);
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
TPPLink.typePropertyId = foundTP.id;
|
|
268
|
-
const foundTPP = typePropertyPolicies.find((tpp) => tpp.identifier === TPPLink.typePropertyPolicyIdentifier);
|
|
269
|
-
if (!foundTPP) {
|
|
270
|
-
logger_1.default.error(`Could not find type property policy with identifier ${TPPLink.typePropertyPolicyIdentifier} `);
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
TPPLink.typePropertyPolicyId = foundTPP.id;
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function findAllOccurrences(array, evaluator) {
|
|
278
|
-
const found = [];
|
|
279
|
-
for (let i = 0; i < array.length; i++) {
|
|
280
|
-
const element = array[i];
|
|
281
|
-
if (evaluator(element)) {
|
|
282
|
-
found.push(element);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return found;
|
|
286
|
-
}
|
|
287
|
-
exports.findAllOccurrences = findAllOccurrences;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ProjectConfiguration } from '../../interfaces';
|
|
2
|
+
import { ProcessingOptions } from './post-processor';
|
|
2
3
|
export declare function getProjectFile(fileName: any): ProjectConfiguration;
|
|
3
|
-
export declare function exportProject(name:
|
|
4
|
+
export declare function exportProject(name: string, processingOptions?: ProcessingOptions | null): Promise<void>;
|
|
@@ -8,6 +8,7 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
|
8
8
|
const sdk_1 = require("@contrail/sdk");
|
|
9
9
|
const util_1 = require("@contrail/util");
|
|
10
10
|
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
11
|
+
const post_processor_1 = require("./post-processor");
|
|
11
12
|
function getProjectFile(fileName) {
|
|
12
13
|
const CURRENT_DIR = process.cwd();
|
|
13
14
|
try {
|
|
@@ -21,7 +22,7 @@ function getProjectFile(fileName) {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
exports.getProjectFile = getProjectFile;
|
|
24
|
-
async function exportProject(name) {
|
|
25
|
+
async function exportProject(name, processingOptions) {
|
|
25
26
|
const allWorkspaces = await new sdk_1.Entities().get({
|
|
26
27
|
entityName: 'workspace',
|
|
27
28
|
useSearch: false,
|
|
@@ -42,7 +43,41 @@ async function exportProject(name) {
|
|
|
42
43
|
const allAssortments = [];
|
|
43
44
|
await getAssortmentsAndSubFolders(workspace.id, projectConfiguration.assortments, projectConfiguration.subFolders, allAssortments);
|
|
44
45
|
await convertRelationshipsInFolders(projectConfiguration, allAssortments);
|
|
45
|
-
|
|
46
|
+
let finalData = { projectConfiguration: projectConfiguration };
|
|
47
|
+
// Apply post-processing if requested
|
|
48
|
+
if (processingOptions) {
|
|
49
|
+
logger_1.default.info('Starting post-processing...');
|
|
50
|
+
const processor = new post_processor_1.ProjectPostProcessor(processingOptions);
|
|
51
|
+
const { data, results } = processor.processProjectData(finalData);
|
|
52
|
+
finalData = data;
|
|
53
|
+
// Log analysis results
|
|
54
|
+
if (processingOptions.verbose || processingOptions.analyzeOnly) {
|
|
55
|
+
logger_1.default.info('========== ANALYSIS RESULTS ==========');
|
|
56
|
+
logger_1.default.info(`Total objects analyzed: ${results.stats.totalObjects}`);
|
|
57
|
+
logger_1.default.info(`- Assortments: ${results.stats.totalAssortments}`);
|
|
58
|
+
logger_1.default.info(`- Plans: ${results.stats.totalPlans}`);
|
|
59
|
+
logger_1.default.info(`- Backings: ${results.stats.totalBackings}`);
|
|
60
|
+
logger_1.default.info(`- Folders: ${results.stats.totalFolders}`);
|
|
61
|
+
logger_1.default.info('\nIDENTIFIER ANALYSIS:');
|
|
62
|
+
logger_1.default.info(`- Missing identifiers: ${results.stats.missingIdentifiers}`);
|
|
63
|
+
logger_1.default.info(`- Duplicate identifiers: ${results.stats.duplicateIdentifiers}`);
|
|
64
|
+
logger_1.default.info(`- Empty identifiers: ${results.stats.emptyIdentifiers}`);
|
|
65
|
+
if (Object.keys(results.duplicates).length > 0) {
|
|
66
|
+
logger_1.default.info('\n=== DUPLICATE IDENTIFIERS ===');
|
|
67
|
+
for (const [id, info] of Object.entries(results.duplicates)) {
|
|
68
|
+
logger_1.default.info(`\n"${id}" (${info.count} occurrences):`);
|
|
69
|
+
info.names.forEach((nameItem, i) => {
|
|
70
|
+
logger_1.default.info(` ${i + 1}. "${nameItem}"`);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (processingOptions.analyzeOnly) {
|
|
76
|
+
logger_1.default.info('Analysis complete. No file written (analyze-only mode).');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
saveData(finalData, name);
|
|
46
81
|
}
|
|
47
82
|
exports.exportProject = exportProject;
|
|
48
83
|
async function getAssortmentsAndSubFolders(parentId, assortments, subFolders, allAssortments) {
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration interface for processing options
|
|
3
|
+
*/
|
|
4
|
+
export interface ProcessingOptions {
|
|
5
|
+
removeBackings: boolean;
|
|
6
|
+
fixMissingIdentifiers: boolean;
|
|
7
|
+
cleanProperties: boolean;
|
|
8
|
+
analyzeOnly: boolean;
|
|
9
|
+
verbose: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Statistics tracking for all operations
|
|
13
|
+
*/
|
|
14
|
+
export interface ProcessingStats {
|
|
15
|
+
itemTypeConverted: number;
|
|
16
|
+
nbFXRatesRemoved: number;
|
|
17
|
+
createdByRemoved: number;
|
|
18
|
+
updatedByRemoved: number;
|
|
19
|
+
emptyAssortmentAttsRemoved: number;
|
|
20
|
+
itemTypeIdRemoved?: number;
|
|
21
|
+
identifiersCreated: number;
|
|
22
|
+
planIdentifiers: number;
|
|
23
|
+
backingIdentifiers: number;
|
|
24
|
+
folderIdentifiers: number;
|
|
25
|
+
viewsIdentifiers: number;
|
|
26
|
+
assortmentIdentifiers: number;
|
|
27
|
+
backingsRemoved: number;
|
|
28
|
+
removedBackingNames: string[];
|
|
29
|
+
totalObjects: number;
|
|
30
|
+
totalAssortments: number;
|
|
31
|
+
totalPlans: number;
|
|
32
|
+
totalBackings: number;
|
|
33
|
+
totalFolders: number;
|
|
34
|
+
duplicateIdentifiers: number;
|
|
35
|
+
emptyIdentifiers: number;
|
|
36
|
+
missingIdentifiers: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Duplicate identifier information
|
|
40
|
+
*/
|
|
41
|
+
export interface DuplicateInfo {
|
|
42
|
+
count: number;
|
|
43
|
+
names: string[];
|
|
44
|
+
paths: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Analysis results interface
|
|
48
|
+
*/
|
|
49
|
+
export interface AnalysisResults {
|
|
50
|
+
stats: ProcessingStats;
|
|
51
|
+
duplicates: Record<string, DuplicateInfo>;
|
|
52
|
+
emptyIdentifierObjects: Array<{
|
|
53
|
+
name: string;
|
|
54
|
+
path: string;
|
|
55
|
+
}>;
|
|
56
|
+
missingIdentifierObjects: {
|
|
57
|
+
assortments: Array<{
|
|
58
|
+
name: string;
|
|
59
|
+
path: string;
|
|
60
|
+
}>;
|
|
61
|
+
plans: Array<{
|
|
62
|
+
name: string;
|
|
63
|
+
path: string;
|
|
64
|
+
}>;
|
|
65
|
+
folders: Array<{
|
|
66
|
+
name: string;
|
|
67
|
+
path: string;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Main class for processing project YAML data
|
|
73
|
+
*/
|
|
74
|
+
export declare class ProjectPostProcessor {
|
|
75
|
+
private stats;
|
|
76
|
+
private options;
|
|
77
|
+
private projectId;
|
|
78
|
+
constructor(options?: Partial<ProcessingOptions>);
|
|
79
|
+
private initializeStats;
|
|
80
|
+
/**
|
|
81
|
+
* Main processing method for project data
|
|
82
|
+
*/
|
|
83
|
+
processProjectData(projectData: any): {
|
|
84
|
+
data: any;
|
|
85
|
+
results: AnalysisResults;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Extract project ID from project data
|
|
89
|
+
*/
|
|
90
|
+
private extractProjectId;
|
|
91
|
+
/**
|
|
92
|
+
* Analyze project data for identifiers, types, and structure
|
|
93
|
+
*/
|
|
94
|
+
private analyzeProjectData;
|
|
95
|
+
/**
|
|
96
|
+
* Clean properties from project data
|
|
97
|
+
*/
|
|
98
|
+
private cleanProperties;
|
|
99
|
+
/**
|
|
100
|
+
* Process assortmentAtts object
|
|
101
|
+
*/
|
|
102
|
+
private processAssortmentAtts;
|
|
103
|
+
/**
|
|
104
|
+
* Fix missing identifiers
|
|
105
|
+
*/
|
|
106
|
+
private fixMissingIdentifiers;
|
|
107
|
+
/**
|
|
108
|
+
* Remove backing assortments
|
|
109
|
+
*/
|
|
110
|
+
private removeBackings;
|
|
111
|
+
/**
|
|
112
|
+
* Generate identifier for an object
|
|
113
|
+
*/
|
|
114
|
+
private generateIdentifier;
|
|
115
|
+
/**
|
|
116
|
+
* Determine object type
|
|
117
|
+
*/
|
|
118
|
+
private getObjectType;
|
|
119
|
+
/**
|
|
120
|
+
* Check if object should have an identifier
|
|
121
|
+
*/
|
|
122
|
+
private shouldHaveIdentifier;
|
|
123
|
+
/**
|
|
124
|
+
* Log processing summary
|
|
125
|
+
*/
|
|
126
|
+
private logProcessingSummary;
|
|
127
|
+
/**
|
|
128
|
+
* Get processing statistics
|
|
129
|
+
*/
|
|
130
|
+
getStats(): ProcessingStats;
|
|
131
|
+
}
|