Skip to content

Commit c09e718

Browse files
Merge pull request #1821 from contentstack/development
staging | 24-03-2025
2 parents 575bc0f + 3615ace commit c09e718

File tree

15 files changed

+1211
-1128
lines changed

15 files changed

+1211
-1128
lines changed

package-lock.json

+419-496
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
1919
$ csdx COMMAND
2020
running command...
2121
$ csdx (--version|-v)
22-
@contentstack/cli-audit/1.8.0 darwin-arm64 node-v23.6.0
22+
@contentstack/cli-audit/1.9.0 darwin-arm64 node-v23.6.0
2323
$ csdx --help [COMMAND]
2424
USAGE
2525
$ csdx COMMAND
@@ -269,7 +269,7 @@ EXAMPLES
269269
$ csdx plugins
270270
```
271271

272-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/index.ts)_
272+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/index.ts)_
273273

274274
## `csdx plugins:add PLUGIN`
275275

@@ -343,7 +343,7 @@ EXAMPLES
343343
$ csdx plugins:inspect myplugin
344344
```
345345

346-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/inspect.ts)_
346+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/inspect.ts)_
347347

348348
## `csdx plugins:install PLUGIN`
349349

@@ -392,7 +392,7 @@ EXAMPLES
392392
$ csdx plugins:install someuser/someplugin
393393
```
394394

395-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/install.ts)_
395+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/install.ts)_
396396

397397
## `csdx plugins:link PATH`
398398

@@ -423,7 +423,7 @@ EXAMPLES
423423
$ csdx plugins:link myplugin
424424
```
425425

426-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/link.ts)_
426+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/link.ts)_
427427

428428
## `csdx plugins:remove [PLUGIN]`
429429

@@ -464,7 +464,7 @@ FLAGS
464464
--reinstall Reinstall all plugins after uninstalling.
465465
```
466466

467-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/reset.ts)_
467+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/reset.ts)_
468468

469469
## `csdx plugins:uninstall [PLUGIN]`
470470

@@ -492,7 +492,7 @@ EXAMPLES
492492
$ csdx plugins:uninstall myplugin
493493
```
494494

495-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/uninstall.ts)_
495+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/uninstall.ts)_
496496

497497
## `csdx plugins:unlink [PLUGIN]`
498498

@@ -536,5 +536,5 @@ DESCRIPTION
536536
Update installed plugins.
537537
```
538538

539-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/update.ts)_
539+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/update.ts)_
540540
<!-- commandsstop -->

packages/contentstack-audit/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "1.8.0",
3+
"version": "1.9.0",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",

packages/contentstack-audit/src/config/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ const config = {
9393
'entry_uid',
9494
'publish_locale',
9595
'publish_environment',
96-
'asset_uid'
96+
'asset_uid',
97+
'selectedValue'
9798
],
9899
ReportTitleForEntries: {
99100
Entries_Select_feild: 'Entries_Select_feild',
@@ -103,6 +104,7 @@ const config = {
103104
Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details'
104105
},
105106
feild_level_modules: ['Entries_Title_feild', 'Entries_Mandatory_feild', 'Entries_Select_feild', 'Entry_Missing_Locale_and_Env_in_Publish_Details'],
107+
fixSelectField: false
106108
};
107109

108110
export default config;

packages/contentstack-audit/src/messages/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const auditMsg = {
4040
SCAN_ASSET_SUCCESS_MSG: `Successfully completed the scanning of Asset with UID '{uid}'.`,
4141
SCAN_ASSET_WARN_MSG: `The locale '{locale}' or environment '{environment}' are not present for asset with uid '{uid}'`,
4242
ENTRY_PUBLISH_DETAILS: `Removing the publish detials for entry '{uid}' of ct '{ctuid}' in locale '{locale}' as locale '{publocale}' or environment '{environment}' does not exist`,
43-
CT_REFERENCE_FIELD: `The mentioned Reference Field is not Array field name 'reference_to' having display name 'display_name'`,
43+
CT_REFERENCE_FIELD: `The mentioned Reference field is not Array field reference is '{reference_to}' having display name '{display_name}''`,
4444
ASSET_NOT_EXIST: `The publish_details either does not exist or is not an array for asset uid '{uid}'`,
4545
ENTRY_PUBLISH_DETAILS_NOT_EXIST: `The publish_details either does not exist or is not an array for entry uid '{uid}'`,
4646
};

packages/contentstack-audit/src/modules/content-types.ts

+81-48
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,20 @@ export default class ContentType {
5353
this.gfSchema = gfSchema;
5454
this.moduleName = this.validateModules(moduleName!, this.config.moduleConfig);
5555
this.fileName = config.moduleConfig[this.moduleName].fileName;
56-
this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig[this.moduleName].dirName));
56+
this.folderPath = resolve(
57+
sanitizePath(config.basePath),
58+
sanitizePath(config.moduleConfig[this.moduleName].dirName),
59+
);
5760
}
5861

59-
validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig {
62+
validateModules(
63+
moduleName: keyof typeof auditConfig.moduleConfig,
64+
moduleConfig: Record<string, unknown>,
65+
): keyof typeof auditConfig.moduleConfig {
6066
if (Object.keys(moduleConfig).includes(moduleName)) {
6167
return moduleName;
6268
}
63-
return 'content-types'
69+
return 'content-types';
6470
}
6571
/**
6672
* The `run` function checks if a folder path exists, sets the schema based on the module name,
@@ -121,7 +127,7 @@ export default class ContentType {
121127
if (existsSync(extensionPath)) {
122128
try {
123129
this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8')));
124-
} catch (error) { }
130+
} catch (error) {}
125131
}
126132

127133
if (existsSync(marketplacePath)) {
@@ -134,7 +140,7 @@ export default class ContentType {
134140
) as string[];
135141
this.extensions.push(...metaData);
136142
}
137-
} catch (error) { }
143+
} catch (error) {}
138144
}
139145
}
140146

@@ -270,19 +276,19 @@ export default class ContentType {
270276

271277
return missingRefs.length
272278
? [
273-
{
274-
tree,
275-
data_type,
276-
missingRefs,
277-
display_name,
278-
ct_uid: this.currentUid,
279-
name: this.currentTitle,
280-
treeStr: tree
281-
.map(({ name }) => name)
282-
.filter((val) => val)
283-
.join(' ➜ '),
284-
},
285-
]
279+
{
280+
tree,
281+
data_type,
282+
missingRefs,
283+
display_name,
284+
ct_uid: this.currentUid,
285+
name: this.currentTitle,
286+
treeStr: tree
287+
.map(({ name }) => name)
288+
.filter((val) => val)
289+
.join(' ➜ '),
290+
},
291+
]
286292
: [];
287293
}
288294

@@ -383,34 +389,46 @@ export default class ContentType {
383389
const missingRefs: string[] = [];
384390
let { reference_to, display_name, data_type } = field;
385391

386-
for (const reference of reference_to ?? []) {
387-
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
388-
if (this.config.skipRefs.includes(reference)) {
389-
continue;
392+
if (!Array.isArray(reference_to)) {
393+
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), 'error');
394+
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
395+
if (!this.config.skipRefs.includes(reference_to)) {
396+
const refExist = find(this.ctSchema, { uid: reference_to });
397+
398+
if (!refExist) {
399+
missingRefs.push(reference_to);
400+
}
390401
}
402+
} else {
403+
for (const reference of reference_to ?? []) {
404+
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
405+
if (this.config.skipRefs.includes(reference)) {
406+
continue;
407+
}
391408

392-
const refExist = find(this.ctSchema, { uid: reference });
409+
const refExist = find(this.ctSchema, { uid: reference });
393410

394-
if (!refExist) {
395-
missingRefs.push(reference);
411+
if (!refExist) {
412+
missingRefs.push(reference);
413+
}
396414
}
397415
}
398416

399417
return missingRefs.length
400418
? [
401-
{
402-
tree,
403-
data_type,
404-
missingRefs,
405-
display_name,
406-
ct_uid: this.currentUid,
407-
name: this.currentTitle,
408-
treeStr: tree
409-
.map(({ name }) => name)
410-
.filter((val) => val)
411-
.join(' ➜ '),
412-
},
413-
]
419+
{
420+
tree,
421+
data_type,
422+
missingRefs,
423+
display_name,
424+
ct_uid: this.currentUid,
425+
name: this.currentTitle,
426+
treeStr: tree
427+
.map(({ name }) => name)
428+
.filter((val) => val)
429+
.join(' ➜ '),
430+
},
431+
]
414432
: [];
415433
}
416434

@@ -635,19 +653,34 @@ export default class ContentType {
635653
let fixStatus;
636654
const missingRefs: string[] = [];
637655
const { reference_to, data_type, display_name } = field;
638-
if(!Array.isArray(reference_to)) {
639-
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), { color: 'green' });
640-
}
641-
for (const reference of reference_to ?? []) {
642-
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
643-
if (this.config.skipRefs.includes(reference)) {
644-
continue;
656+
if (!Array.isArray(reference_to)) {
657+
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'error');
658+
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
659+
if (!this.config.skipRefs.includes(reference_to)) {
660+
const refExist = find(this.ctSchema, { uid: reference_to });
661+
662+
if (!refExist) {
663+
missingRefs.push(reference_to);
664+
}
665+
}
666+
667+
field.reference_to = [reference_to];
668+
field.field_metadata = {
669+
...field.field_metadata,
670+
ref_multiple_content_types: true
645671
}
672+
} else {
673+
for (const reference of reference_to ?? []) {
674+
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
675+
if (this.config.skipRefs.includes(reference)) {
676+
continue;
677+
}
646678

647-
const refExist = find(this.ctSchema, { uid: reference });
679+
const refExist = find(this.ctSchema, { uid: reference });
648680

649-
if (!refExist) {
650-
missingRefs.push(reference);
681+
if (!refExist) {
682+
missingRefs.push(reference);
683+
}
651684
}
652685
}
653686

0 commit comments

Comments
 (0)