@contentstack/cli-audit 1.12.1 → 1.14.0
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 +9 -9
- package/lib/audit-base-command.js +4 -0
- package/lib/modules/content-types.js +64 -23
- package/lib/modules/entries.js +7 -5
- package/oclif.manifest.json +1 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
|
|
|
19
19
|
$ csdx COMMAND
|
|
20
20
|
running command...
|
|
21
21
|
$ csdx (--version|-v)
|
|
22
|
-
@contentstack/cli-audit/1.
|
|
22
|
+
@contentstack/cli-audit/1.14.0 linux-x64 node-v22.17.1
|
|
23
23
|
$ csdx --help [COMMAND]
|
|
24
24
|
USAGE
|
|
25
25
|
$ csdx COMMAND
|
|
@@ -282,7 +282,7 @@ DESCRIPTION
|
|
|
282
282
|
Display help for csdx.
|
|
283
283
|
```
|
|
284
284
|
|
|
285
|
-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.
|
|
285
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.31/src/commands/help.ts)_
|
|
286
286
|
|
|
287
287
|
## `csdx plugins`
|
|
288
288
|
|
|
@@ -305,7 +305,7 @@ EXAMPLES
|
|
|
305
305
|
$ csdx plugins
|
|
306
306
|
```
|
|
307
307
|
|
|
308
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
308
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.45/src/commands/plugins/index.ts)_
|
|
309
309
|
|
|
310
310
|
## `csdx plugins:add PLUGIN`
|
|
311
311
|
|
|
@@ -379,7 +379,7 @@ EXAMPLES
|
|
|
379
379
|
$ csdx plugins:inspect myplugin
|
|
380
380
|
```
|
|
381
381
|
|
|
382
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
382
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.45/src/commands/plugins/inspect.ts)_
|
|
383
383
|
|
|
384
384
|
## `csdx plugins:install PLUGIN`
|
|
385
385
|
|
|
@@ -428,7 +428,7 @@ EXAMPLES
|
|
|
428
428
|
$ csdx plugins:install someuser/someplugin
|
|
429
429
|
```
|
|
430
430
|
|
|
431
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
431
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.45/src/commands/plugins/install.ts)_
|
|
432
432
|
|
|
433
433
|
## `csdx plugins:link PATH`
|
|
434
434
|
|
|
@@ -459,7 +459,7 @@ EXAMPLES
|
|
|
459
459
|
$ csdx plugins:link myplugin
|
|
460
460
|
```
|
|
461
461
|
|
|
462
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
462
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.45/src/commands/plugins/link.ts)_
|
|
463
463
|
|
|
464
464
|
## `csdx plugins:remove [PLUGIN]`
|
|
465
465
|
|
|
@@ -500,7 +500,7 @@ FLAGS
|
|
|
500
500
|
--reinstall Reinstall all plugins after uninstalling.
|
|
501
501
|
```
|
|
502
502
|
|
|
503
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
503
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.45/src/commands/plugins/reset.ts)_
|
|
504
504
|
|
|
505
505
|
## `csdx plugins:uninstall [PLUGIN]`
|
|
506
506
|
|
|
@@ -528,7 +528,7 @@ EXAMPLES
|
|
|
528
528
|
$ csdx plugins:uninstall myplugin
|
|
529
529
|
```
|
|
530
530
|
|
|
531
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
531
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.45/src/commands/plugins/uninstall.ts)_
|
|
532
532
|
|
|
533
533
|
## `csdx plugins:unlink [PLUGIN]`
|
|
534
534
|
|
|
@@ -572,5 +572,5 @@ DESCRIPTION
|
|
|
572
572
|
Update installed plugins.
|
|
573
573
|
```
|
|
574
574
|
|
|
575
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
575
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.45/src/commands/plugins/update.ts)_
|
|
576
576
|
<!-- commandsstop -->
|
|
@@ -194,6 +194,10 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
|
|
|
194
194
|
this.getAffectedData('custom-roles', dataModuleWise['custom-roles'], missingRefInCustomRoles);
|
|
195
195
|
break;
|
|
196
196
|
case 'field-rules':
|
|
197
|
+
// NOTE: We are using the fixed content-type for validation of field rules
|
|
198
|
+
const data = this.getCtAndGfSchema();
|
|
199
|
+
constructorParam.ctSchema = data.ctSchema;
|
|
200
|
+
constructorParam.gfSchema = data.gfSchema;
|
|
197
201
|
missingFieldRules = await new modules_1.FieldRule((0, cloneDeep_1.default)(constructorParam)).run();
|
|
198
202
|
await this.prepareReport(module, missingFieldRules);
|
|
199
203
|
this.getAffectedData('field-rules', dataModuleWise['content-types'], missingFieldRules);
|
|
@@ -214,17 +214,35 @@ class ContentType {
|
|
|
214
214
|
*/
|
|
215
215
|
async validateGlobalField(tree, field) {
|
|
216
216
|
// NOTE Any GlobalField related logic can be added here
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
217
|
+
if (this.moduleName === 'global-fields') {
|
|
218
|
+
let { reference_to } = field;
|
|
219
|
+
const refExist = (0, find_1.default)(this.schema, { uid: reference_to });
|
|
220
|
+
if (!refExist) {
|
|
221
|
+
this.missingRefs[this.currentUid].push({
|
|
222
|
+
tree,
|
|
223
|
+
ct: this.currentUid,
|
|
224
|
+
name: this.currentTitle,
|
|
225
|
+
data_type: field.data_type,
|
|
226
|
+
display_name: field.display_name,
|
|
227
|
+
missingRefs: 'Referred Global Field Does not Exist',
|
|
228
|
+
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
229
|
+
});
|
|
230
|
+
return void 0;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else if (this.moduleName === 'content-types') {
|
|
234
|
+
if (!field.schema && !this.fix) {
|
|
235
|
+
this.missingRefs[this.currentUid].push({
|
|
236
|
+
tree,
|
|
237
|
+
ct_uid: this.currentUid,
|
|
238
|
+
name: this.currentTitle,
|
|
239
|
+
data_type: field.data_type,
|
|
240
|
+
display_name: field.display_name,
|
|
241
|
+
missingRefs: 'Empty schema found',
|
|
242
|
+
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
243
|
+
});
|
|
244
|
+
return void 0;
|
|
245
|
+
}
|
|
228
246
|
}
|
|
229
247
|
await this.lookForReference(tree, field);
|
|
230
248
|
}
|
|
@@ -339,8 +357,7 @@ class ContentType {
|
|
|
339
357
|
*/
|
|
340
358
|
runFixOnSchema(tree, schema) {
|
|
341
359
|
// NOTE Global field Fix
|
|
342
|
-
return schema
|
|
343
|
-
.map((field) => {
|
|
360
|
+
return schema === null || schema === void 0 ? void 0 : schema.map((field) => {
|
|
344
361
|
var _a;
|
|
345
362
|
const { data_type } = field;
|
|
346
363
|
const fixTypes = (_a = this.config.flags['fix-only']) !== null && _a !== void 0 ? _a : this.config['fix-fields'];
|
|
@@ -377,8 +394,7 @@ class ContentType {
|
|
|
377
394
|
default:
|
|
378
395
|
return field;
|
|
379
396
|
}
|
|
380
|
-
})
|
|
381
|
-
.filter((val) => {
|
|
397
|
+
}).filter((val) => {
|
|
382
398
|
if (this.config.skipFieldTypes.includes(val === null || val === void 0 ? void 0 : val.data_type))
|
|
383
399
|
return true;
|
|
384
400
|
if ((val === null || val === void 0 ? void 0 : val.schema) &&
|
|
@@ -400,7 +416,7 @@ class ContentType {
|
|
|
400
416
|
* doesn't.
|
|
401
417
|
*/
|
|
402
418
|
fixGlobalFieldReferences(tree, field) {
|
|
403
|
-
var _a;
|
|
419
|
+
var _a, _b;
|
|
404
420
|
const { reference_to, display_name, data_type } = field;
|
|
405
421
|
if (reference_to && data_type === 'global_field') {
|
|
406
422
|
tree = [...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }];
|
|
@@ -417,10 +433,12 @@ class ContentType {
|
|
|
417
433
|
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
418
434
|
});
|
|
419
435
|
}
|
|
420
|
-
else if (!field.schema) {
|
|
436
|
+
else if (!field.schema && this.moduleName === 'content-types') {
|
|
421
437
|
const gfSchema = (_a = (0, find_1.default)(this.gfSchema, { uid: field.reference_to })) === null || _a === void 0 ? void 0 : _a.schema;
|
|
422
438
|
if (gfSchema) {
|
|
423
439
|
field.schema = gfSchema;
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
424
442
|
this.missingRefs[this.currentUid].push({
|
|
425
443
|
tree,
|
|
426
444
|
data_type,
|
|
@@ -433,6 +451,27 @@ class ContentType {
|
|
|
433
451
|
});
|
|
434
452
|
}
|
|
435
453
|
}
|
|
454
|
+
else if (!field.schema && this.moduleName === 'global-fields') {
|
|
455
|
+
const gfSchema = (_b = (0, find_1.default)(this.gfSchema, { uid: field.reference_to })) === null || _b === void 0 ? void 0 : _b.schema;
|
|
456
|
+
if (gfSchema) {
|
|
457
|
+
field.schema = gfSchema;
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
this.missingRefs[this.currentUid].push({
|
|
461
|
+
tree,
|
|
462
|
+
data_type,
|
|
463
|
+
display_name,
|
|
464
|
+
fixStatus: 'Fixed',
|
|
465
|
+
ct_uid: this.currentUid,
|
|
466
|
+
name: this.currentTitle,
|
|
467
|
+
missingRefs: 'Referred Global Field Does not exist',
|
|
468
|
+
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (field.schema && !(0, isEmpty_1.default)(field.schema)) {
|
|
473
|
+
field.schema = this.runFixOnSchema(tree, field.schema);
|
|
474
|
+
}
|
|
436
475
|
return refExist ? field : null;
|
|
437
476
|
}
|
|
438
477
|
return field;
|
|
@@ -446,8 +485,7 @@ class ContentType {
|
|
|
446
485
|
* @returns an array of `ModularBlockType` objects.
|
|
447
486
|
*/
|
|
448
487
|
fixModularBlocksReferences(tree, blocks) {
|
|
449
|
-
return blocks
|
|
450
|
-
.map((block) => {
|
|
488
|
+
return blocks === null || blocks === void 0 ? void 0 : blocks.map((block) => {
|
|
451
489
|
const { reference_to, schema, title: display_name } = block;
|
|
452
490
|
tree = [...tree, { uid: block.uid, name: block.title }];
|
|
453
491
|
const refErrorObj = {
|
|
@@ -459,27 +497,30 @@ class ContentType {
|
|
|
459
497
|
fixStatus: this.fix ? 'Fixed' : undefined,
|
|
460
498
|
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
461
499
|
};
|
|
462
|
-
if (!schema) {
|
|
500
|
+
if (!schema && this.moduleName === 'content-types') {
|
|
463
501
|
this.missingRefs[this.currentUid].push(refErrorObj);
|
|
464
502
|
return false;
|
|
465
503
|
}
|
|
466
504
|
// NOTE Global field section
|
|
467
505
|
if (reference_to) {
|
|
468
506
|
const refExist = (0, find_1.default)(this.gfSchema, { uid: reference_to });
|
|
507
|
+
if (!refExist) {
|
|
508
|
+
this.missingRefs[this.currentUid].push(refErrorObj);
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
469
511
|
if (!refExist) {
|
|
470
512
|
this.missingRefs[this.currentUid].push(refErrorObj);
|
|
471
513
|
return block;
|
|
472
514
|
}
|
|
473
515
|
}
|
|
474
516
|
block.schema = this.runFixOnSchema(tree, block.schema);
|
|
475
|
-
if ((0, isEmpty_1.default)(block.schema)) {
|
|
517
|
+
if ((0, isEmpty_1.default)(block.schema) && this.moduleName === 'content-types') {
|
|
476
518
|
this.missingRefs[this.currentUid].push(Object.assign(Object.assign({}, refErrorObj), { missingRefs: 'Empty schema found', treeStr: tree.map(({ name }) => name).join(' ➜ ') }));
|
|
477
519
|
this.log((0, messages_1.$t)(messages_1.auditFixMsg.EMPTY_FIX_MSG, { path: tree.map(({ name }) => name).join(' ➜ ') }), 'info');
|
|
478
520
|
return null;
|
|
479
521
|
}
|
|
480
522
|
return block;
|
|
481
|
-
})
|
|
482
|
-
.filter((val) => val);
|
|
523
|
+
}).filter((val) => val);
|
|
483
524
|
}
|
|
484
525
|
/**
|
|
485
526
|
* The function checks for missing extension or app references in a given tree and fixes them if the
|
package/lib/modules/entries.js
CHANGED
|
@@ -67,7 +67,9 @@ class Entries {
|
|
|
67
67
|
const { uid, title } = entry;
|
|
68
68
|
this.currentUid = uid;
|
|
69
69
|
this.currentTitle = title;
|
|
70
|
-
|
|
70
|
+
if (this.currentTitle) {
|
|
71
|
+
this.currentTitle = this.removeEmojiAndImages(this.currentTitle);
|
|
72
|
+
}
|
|
71
73
|
if (!this.missingRefs[this.currentUid]) {
|
|
72
74
|
this.missingRefs[this.currentUid] = [];
|
|
73
75
|
}
|
|
@@ -80,7 +82,7 @@ class Entries {
|
|
|
80
82
|
if (this.fix) {
|
|
81
83
|
this.removeMissingKeysOnEntry(ctSchema.schema, this.entries[entryUid]);
|
|
82
84
|
}
|
|
83
|
-
this.lookForReference([{ locale: code, uid, name: this.removeEmojiAndImages(
|
|
85
|
+
this.lookForReference([{ locale: code, uid, name: this.removeEmojiAndImages(this.currentTitle) }], ctSchema, this.entries[entryUid]);
|
|
84
86
|
if ((_a = this.missingRefs[this.currentUid]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
85
87
|
this.missingRefs[this.currentUid].forEach((entry) => {
|
|
86
88
|
entry.ct = ctSchema.uid;
|
|
@@ -179,7 +181,7 @@ class Entries {
|
|
|
179
181
|
missingMandatoryFields: this.missingMandatoryFields,
|
|
180
182
|
missingTitleFields: this.missingTitleFields,
|
|
181
183
|
missingEnvLocale: this.missingEnvLocale,
|
|
182
|
-
missingMultipleFields: this.missingMultipleField
|
|
184
|
+
missingMultipleFields: this.missingMultipleField,
|
|
183
185
|
};
|
|
184
186
|
}
|
|
185
187
|
/**
|
|
@@ -590,7 +592,7 @@ class Entries {
|
|
|
590
592
|
.map(({ name }) => name)
|
|
591
593
|
.filter(Boolean)
|
|
592
594
|
.join(' ➜ '),
|
|
593
|
-
|
|
595
|
+
fixStatus: 'Fixed',
|
|
594
596
|
});
|
|
595
597
|
entry[uid] = [entry[uid]];
|
|
596
598
|
}
|
|
@@ -643,7 +645,7 @@ class Entries {
|
|
|
643
645
|
* Else empty array
|
|
644
646
|
*/
|
|
645
647
|
removeEmojiAndImages(str) {
|
|
646
|
-
return str.replace(/[\p{Emoji}\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Emoji_Modifier_Base}\p{Emoji_Component}]+/gu, '');
|
|
648
|
+
return str === null || str === void 0 ? void 0 : str.replace(/[\p{Emoji}\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Emoji_Modifier_Base}\p{Emoji_Component}]+/gu, '');
|
|
647
649
|
}
|
|
648
650
|
validateSelectField(tree, fieldStructure, field) {
|
|
649
651
|
const { display_name, enum: selectOptions, multiple, min_instance, display_type, data_type } = fieldStructure;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-audit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Contentstack audit plugin",
|
|
5
5
|
"author": "Contentstack CLI",
|
|
6
6
|
"homepage": "https://github.com/contentstack/cli",
|
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
"/oclif.manifest.json"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@contentstack/cli-command": "~1.
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
-
"@oclif/plugin-
|
|
21
|
+
"@contentstack/cli-command": "~1.6.0",
|
|
22
|
+
"@contentstack/cli-utilities": "~1.13.0",
|
|
23
|
+
"@oclif/core": "^4.3.0",
|
|
24
|
+
"@oclif/plugin-help": "^6.2.28",
|
|
25
|
+
"@oclif/plugin-plugins": "^5.4.38",
|
|
25
26
|
"chalk": "^4.1.2",
|
|
26
27
|
"fast-csv": "^4.3.6",
|
|
27
28
|
"fs-extra": "^11.3.0",
|
|
@@ -30,19 +31,19 @@
|
|
|
30
31
|
"winston": "^3.17.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@oclif/test": "^4.1.
|
|
34
|
+
"@oclif/test": "^4.1.13",
|
|
34
35
|
"@types/chai": "^4.3.20",
|
|
35
36
|
"@types/fs-extra": "^11.0.4",
|
|
36
37
|
"@types/mocha": "^10.0.10",
|
|
37
|
-
"@types/node": "^20.17.
|
|
38
|
+
"@types/node": "^20.17.50",
|
|
38
39
|
"@types/uuid": "^9.0.8",
|
|
39
40
|
"chai": "^4.5.0",
|
|
40
41
|
"eslint": "^8.57.1",
|
|
41
|
-
"eslint-config-oclif": "^6.0.
|
|
42
|
+
"eslint-config-oclif": "^6.0.62",
|
|
42
43
|
"eslint-config-oclif-typescript": "^3.1.14",
|
|
43
44
|
"mocha": "^10.8.2",
|
|
44
45
|
"nyc": "^15.1.0",
|
|
45
|
-
"oclif": "^4.17.
|
|
46
|
+
"oclif": "^4.17.46",
|
|
46
47
|
"shx": "^0.4.0",
|
|
47
48
|
"sinon": "^19.0.5",
|
|
48
49
|
"ts-node": "^10.9.2",
|