@contentstack/cli-audit 1.2.0 → 1.2.1

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 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.2.0 linux-x64 node-v18.18.2
22
+ @contentstack/cli-audit/1.2.1 linux-x64 node-v18.18.2
23
23
  $ csdx --help [COMMAND]
24
24
  USAGE
25
25
  $ csdx COMMAND
@@ -147,8 +147,8 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
147
147
  this.log(this.$t(messages_1.auditMsg.NOT_VALID_PATH, { path: ctPath }), 'error');
148
148
  }
149
149
  }
150
- let gfSchema = (0, fs_1.existsSync)(gfPath) ? JSON.parse((0, fs_1.readFileSync)(gfPath, 'utf-8')) : [];
151
- let ctSchema = (0, fs_1.existsSync)(ctPath) ? JSON.parse((0, fs_1.readFileSync)(ctPath, 'utf-8')) : [];
150
+ const gfSchema = (0, fs_1.existsSync)(gfPath) ? JSON.parse((0, fs_1.readFileSync)(gfPath, 'utf8')) : [];
151
+ const ctSchema = (0, fs_1.existsSync)(ctPath) ? JSON.parse((0, fs_1.readFileSync)(ctPath, 'utf8')) : [];
152
152
  return { ctSchema, gfSchema };
153
153
  }
154
154
  /**
@@ -22,6 +22,15 @@ export default class Entries {
22
22
  * @returns the `missingRefs` object.
23
23
  */
24
24
  run(): Promise<Record<string, any>>;
25
+ /**
26
+ * The function removes any properties from the `missingRefs` object that have an empty array value.
27
+ */
28
+ removeEmptyVal(): void;
29
+ /**
30
+ * The function `fixPrerequisiteData` fixes the prerequisite data by updating the `ctSchema` and
31
+ * `gfSchema` properties using the `ContentType` class.
32
+ */
33
+ fixPrerequisiteData(): Promise<void>;
25
34
  /**
26
35
  * The function checks if it can write the fix content to a file and if so, it writes the content as
27
36
  * JSON to the specified file path.
@@ -212,7 +221,7 @@ export default class Entries {
212
221
  * block in the `tree` array.
213
222
  * @returns the `entryBlock` object.
214
223
  */
215
- modularBlockRefCheck(tree: Record<string, unknown>[], blocks: ModularBlockType[], entryBlock: EntryModularBlocksDataType, index: Number): EntryModularBlocksDataType;
224
+ modularBlockRefCheck(tree: Record<string, unknown>[], blocks: ModularBlockType[], entryBlock: EntryModularBlocksDataType, index: number): EntryModularBlocksDataType;
216
225
  /**
217
226
  * The `jsonRefCheck` function checks if a reference exists in a JSON tree and adds missing
218
227
  * references to a list if they are not found.
@@ -34,22 +34,7 @@ class Entries {
34
34
  throw new Error((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }));
35
35
  }
36
36
  await this.prepareEntryMetaData();
37
- this.ctSchema = (await new content_types_1.default({
38
- fix: true,
39
- log: () => { },
40
- config: this.config,
41
- moduleName: 'content-types',
42
- ctSchema: this.ctSchema,
43
- gfSchema: this.gfSchema,
44
- }).run(true));
45
- this.gfSchema = (await new content_types_1.default({
46
- fix: true,
47
- log: () => { },
48
- config: this.config,
49
- moduleName: 'entries',
50
- ctSchema: this.ctSchema,
51
- gfSchema: this.gfSchema,
52
- }).run(true));
37
+ await this.fixPrerequisiteData();
53
38
  for (const { code } of this.locales) {
54
39
  for (const ctSchema of this.ctSchema) {
55
40
  const basePath = (0, path_1.join)(this.folderPath, ctSchema.uid, code);
@@ -78,12 +63,40 @@ class Entries {
78
63
  }
79
64
  }
80
65
  this.log('', 'info'); // Adding empty line
66
+ this.removeEmptyVal();
67
+ return this.missingRefs;
68
+ }
69
+ /**
70
+ * The function removes any properties from the `missingRefs` object that have an empty array value.
71
+ */
72
+ removeEmptyVal() {
81
73
  for (let propName in this.missingRefs) {
82
74
  if (!this.missingRefs[propName].length) {
83
75
  delete this.missingRefs[propName];
84
76
  }
85
77
  }
86
- return this.missingRefs;
78
+ }
79
+ /**
80
+ * The function `fixPrerequisiteData` fixes the prerequisite data by updating the `ctSchema` and
81
+ * `gfSchema` properties using the `ContentType` class.
82
+ */
83
+ async fixPrerequisiteData() {
84
+ this.ctSchema = (await new content_types_1.default({
85
+ fix: true,
86
+ log: () => { },
87
+ config: this.config,
88
+ moduleName: 'content-types',
89
+ ctSchema: this.ctSchema,
90
+ gfSchema: this.gfSchema,
91
+ }).run(true));
92
+ this.gfSchema = (await new content_types_1.default({
93
+ fix: true,
94
+ log: () => { },
95
+ config: this.config,
96
+ moduleName: 'entries',
97
+ ctSchema: this.ctSchema,
98
+ gfSchema: this.gfSchema,
99
+ }).run(true));
87
100
  }
88
101
  /**
89
102
  * The function checks if it can write the fix content to a file and if so, it writes the content as
@@ -325,10 +338,11 @@ class Entries {
325
338
  if (data_type === 'json') {
326
339
  if (field.field_metadata.extension) {
327
340
  // NOTE Custom field type
328
- return field;
341
+ break;
329
342
  }
330
343
  else if (field.field_metadata.allow_json_rte) {
331
- return this.fixJsonRteMissingReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
344
+ this.fixJsonRteMissingReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
345
+ break;
332
346
  }
333
347
  }
334
348
  // NOTE Reference field
@@ -479,7 +493,7 @@ class Entries {
479
493
  data_type: field.data_type,
480
494
  display_name: field.display_name,
481
495
  treeStr: tree
482
- .map(({ name, index }) => (index || index === 0 ? `[${index}].${name}` : name))
496
+ .map(({ name, index }) => (index || index === 0 ? `[${+index}].${name}` : name))
483
497
  .filter((val) => val)
484
498
  .join(' ➜ '),
485
499
  missingRefs,
@@ -516,7 +530,7 @@ class Entries {
516
530
  fixStatus: this.fix ? 'Fixed' : undefined,
517
531
  tree: [...tree, { index, uid: key, name: key }],
518
532
  treeStr: [...tree, { index, uid: key, name: key }]
519
- .map(({ name, index }) => (index || index === 0 ? `[${index}].${name}` : name))
533
+ .map(({ name, index }) => (index || index === 0 ? `[${+index}].${name}` : name))
520
534
  .filter((val) => val)
521
535
  .join(' ➜ '),
522
536
  missingRefs: [key],
@@ -569,8 +583,8 @@ class Entries {
569
583
  const localesFolderPath = (0, path_1.resolve)(this.config.basePath, this.config.moduleConfig.locales.dirName);
570
584
  const localesPath = (0, path_1.join)(localesFolderPath, this.config.moduleConfig.locales.fileName);
571
585
  const masterLocalesPath = (0, path_1.join)(localesFolderPath, 'master-locale.json');
572
- this.locales = (0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(masterLocalesPath, 'utf-8')));
573
- this.locales.push(...(0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf-8'))));
586
+ this.locales = (0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(masterLocalesPath, 'utf8')));
587
+ this.locales.push(...(0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf8'))));
574
588
  for (const { code } of this.locales) {
575
589
  for (const { uid } of this.ctSchema) {
576
590
  let basePath = (0, path_1.join)(this.folderPath, uid, code);
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.0",
2
+ "version": "1.2.1",
3
3
  "commands": {
4
4
  "cm:stacks:audit:fix": {
5
5
  "id": "cm:stacks:audit:fix",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-audit",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Contentstack audit plugin",
5
5
  "author": "Contentstack CLI",
6
6
  "homepage": "https://github.com/contentstack/cli",
@@ -18,8 +18,8 @@
18
18
  "/oclif.manifest.json"
19
19
  ],
20
20
  "dependencies": {
21
- "@contentstack/cli-command": "~1.2.14",
22
- "@contentstack/cli-utilities": "~1.5.4",
21
+ "@contentstack/cli-command": "~1.2.15",
22
+ "@contentstack/cli-utilities": "~1.5.5",
23
23
  "@oclif/plugin-help": "^5",
24
24
  "@oclif/plugin-plugins": "^3.8.4",
25
25
  "chalk": "^4.1.2",