@contentstack/cli-audit 2.0.0-beta → 2.0.0-beta.2
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/LICENSE +1 -1
- package/README.md +13 -428
- package/lib/audit-base-command.d.ts +1 -4
- package/lib/audit-base-command.js +16 -22
- package/lib/commands/cm/stacks/audit/fix.d.ts +0 -1
- package/lib/commands/cm/stacks/audit/fix.js +0 -1
- package/lib/commands/cm/stacks/audit/index.d.ts +0 -1
- package/lib/commands/cm/stacks/audit/index.js +0 -1
- package/lib/config/index.d.ts +5 -0
- package/lib/config/index.js +16 -9
- package/lib/messages/index.d.ts +1 -0
- package/lib/messages/index.js +2 -1
- package/lib/modules/composable-studio.d.ts +40 -0
- package/lib/modules/composable-studio.js +307 -0
- package/lib/modules/index.d.ts +2 -1
- package/lib/modules/index.js +3 -1
- package/lib/modules/modulesData.js +17 -8
- package/lib/types/composable-studio.d.ts +25 -0
- package/lib/types/composable-studio.js +2 -0
- package/lib/types/content-types.d.ts +2 -1
- package/lib/types/content-types.js +1 -0
- package/lib/types/context.d.ts +0 -5
- package/oclif.manifest.json +7 -11
- package/package.json +5 -7
package/lib/config/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const config = {
|
|
|
13
13
|
'custom-roles',
|
|
14
14
|
'assets',
|
|
15
15
|
'field-rules',
|
|
16
|
+
'composable-studio',
|
|
16
17
|
],
|
|
17
18
|
'fix-fields': ['reference', 'global_field', 'json:rte', 'json:extension', 'blocks', 'group', 'content_types'],
|
|
18
19
|
'schema-fields-data-type': ['blocks', 'group', 'global_field'],
|
|
@@ -62,6 +63,11 @@ const config = {
|
|
|
62
63
|
dirName: 'environments',
|
|
63
64
|
fileName: 'environments.json',
|
|
64
65
|
},
|
|
66
|
+
'composable-studio': {
|
|
67
|
+
name: 'composable-studio',
|
|
68
|
+
dirName: 'composable_studio',
|
|
69
|
+
fileName: 'composable_studio.json',
|
|
70
|
+
},
|
|
65
71
|
},
|
|
66
72
|
entries: {
|
|
67
73
|
systemKeys: [
|
|
@@ -109,13 +115,14 @@ const config = {
|
|
|
109
115
|
'selectedValue',
|
|
110
116
|
'ct_uid',
|
|
111
117
|
'action',
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
'Module',
|
|
119
|
+
'Total',
|
|
120
|
+
'Fixable',
|
|
121
|
+
'Non-Fixable',
|
|
122
|
+
'Fixed',
|
|
123
|
+
'Not-Fixed',
|
|
124
|
+
'Passed',
|
|
125
|
+
'issues',
|
|
119
126
|
],
|
|
120
127
|
ReportTitleForEntries: {
|
|
121
128
|
Entries_Select_field: 'Entries_Select_field',
|
|
@@ -123,7 +130,7 @@ const config = {
|
|
|
123
130
|
Entries_Title_field: 'Entries_Title_field',
|
|
124
131
|
Entry_Missing_Locale_and_Env: 'Entry_Missing_Locale_and_Env',
|
|
125
132
|
Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details',
|
|
126
|
-
Entry_Multiple_Fields:
|
|
133
|
+
Entry_Multiple_Fields: 'Entry_Multiple_Fields',
|
|
127
134
|
},
|
|
128
135
|
feild_level_modules: [
|
|
129
136
|
'Entries_Title_field',
|
|
@@ -132,7 +139,7 @@ const config = {
|
|
|
132
139
|
'Entry_Missing_Locale_and_Env_in_Publish_Details',
|
|
133
140
|
'field-rules',
|
|
134
141
|
'Entry_Multiple_Fields',
|
|
135
|
-
'Summary'
|
|
142
|
+
'Summary',
|
|
136
143
|
],
|
|
137
144
|
fixSelectField: false,
|
|
138
145
|
};
|
package/lib/messages/index.d.ts
CHANGED
package/lib/messages/index.js
CHANGED
|
@@ -42,6 +42,7 @@ const auditMsg = {
|
|
|
42
42
|
AUDIT_CMD_DESCRIPTION: 'Perform audits and find possible errors in the exported Contentstack data',
|
|
43
43
|
SCAN_WF_SUCCESS_MSG: 'Successfully completed the scanning of workflow with UID {uid} and name {name}.',
|
|
44
44
|
SCAN_CR_SUCCESS_MSG: 'Successfully completed the scanning of custom role with UID {uid} and name {name}.',
|
|
45
|
+
SCAN_CS_SUCCESS_MSG: 'Successfully completed the scanning of studio project with UID {uid} and name {name}.',
|
|
45
46
|
SCAN_ASSET_SUCCESS_MSG: `Successfully completed the scanning of Asset with UID '{uid}'.`,
|
|
46
47
|
SCAN_ASSET_WARN_MSG: `The locale '{locale}' or environment '{environment}' are not present for asset with uid '{uid}'`,
|
|
47
48
|
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`,
|
|
@@ -51,7 +52,7 @@ const auditMsg = {
|
|
|
51
52
|
FIELD_RULE_CONDITION_ABSENT: `The operand field '{condition_field}' is not present in the schema of the content-type {ctUid}`,
|
|
52
53
|
FIELD_RULE_TARGET_ABSENT: `The target field '{target_field}' is not present in the schema of the content-type {ctUid}`,
|
|
53
54
|
FIELD_RULE_CONDITION_SCAN_MESSAGE: `Completed Scanning of Field Rule '{num}' condition of Content-type '{ctUid}'`,
|
|
54
|
-
FIELD_RULE_TARGET_SCAN_MESSAGE: `Completed Scanning of Field Rule '{num}' target of Content-type '{ctUid}'
|
|
55
|
+
FIELD_RULE_TARGET_SCAN_MESSAGE: `Completed Scanning of Field Rule '{num}' target of Content-type '{ctUid}'`,
|
|
55
56
|
};
|
|
56
57
|
exports.auditMsg = auditMsg;
|
|
57
58
|
const auditFixMsg = {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ConfigType, ContentTypeStruct, CtConstructorParam, ModuleConstructorParam } from '../types';
|
|
2
|
+
import auditConfig from '../config';
|
|
3
|
+
import { ComposableStudioProject } from '../types/composable-studio';
|
|
4
|
+
export default class ComposableStudio {
|
|
5
|
+
protected fix: boolean;
|
|
6
|
+
fileName: string;
|
|
7
|
+
config: ConfigType;
|
|
8
|
+
folderPath: string;
|
|
9
|
+
composableStudioProjects: ComposableStudioProject[];
|
|
10
|
+
ctSchema: ContentTypeStruct[];
|
|
11
|
+
moduleName: keyof typeof auditConfig.moduleConfig;
|
|
12
|
+
ctUidSet: Set<string>;
|
|
13
|
+
environmentUidSet: Set<string>;
|
|
14
|
+
localeCodeSet: Set<string>;
|
|
15
|
+
projectsWithIssues: any[];
|
|
16
|
+
composableStudioPath: string;
|
|
17
|
+
private projectsWithIssuesMap;
|
|
18
|
+
constructor({ fix, config, moduleName, ctSchema }: ModuleConstructorParam & Pick<CtConstructorParam, 'ctSchema'>);
|
|
19
|
+
validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Load environments from the environments.json file
|
|
22
|
+
*/
|
|
23
|
+
loadEnvironments(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Load locales from the locales.json and master-locale.json files
|
|
26
|
+
*/
|
|
27
|
+
loadLocales(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Main run method to audit composable studio projects
|
|
30
|
+
*/
|
|
31
|
+
run(): Promise<{}>;
|
|
32
|
+
/**
|
|
33
|
+
* Fix composable studio projects by removing invalid references
|
|
34
|
+
*/
|
|
35
|
+
fixComposableStudioProjects(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Write fixed composable studio projects back to file
|
|
38
|
+
*/
|
|
39
|
+
writeFixContent(fixedProjects: any): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
|
+
const messages_1 = require("../messages");
|
|
7
|
+
class ComposableStudio {
|
|
8
|
+
constructor({ fix, config, moduleName, ctSchema }) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.fix = fix !== null && fix !== void 0 ? fix : false;
|
|
11
|
+
this.ctSchema = ctSchema;
|
|
12
|
+
this.composableStudioProjects = [];
|
|
13
|
+
cli_utilities_1.log.debug(`Initializing ComposableStudio module`, this.config.auditContext);
|
|
14
|
+
cli_utilities_1.log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);
|
|
15
|
+
cli_utilities_1.log.debug(`Content types count: ${ctSchema.length}`, this.config.auditContext);
|
|
16
|
+
cli_utilities_1.log.debug(`Module name: ${moduleName}`, this.config.auditContext);
|
|
17
|
+
this.moduleName = this.validateModules(moduleName, this.config.moduleConfig);
|
|
18
|
+
this.fileName = config.moduleConfig[this.moduleName].fileName;
|
|
19
|
+
cli_utilities_1.log.debug(`File name: ${this.fileName}`, this.config.auditContext);
|
|
20
|
+
this.folderPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.basePath), (0, cli_utilities_1.sanitizePath)(config.moduleConfig[this.moduleName].dirName));
|
|
21
|
+
cli_utilities_1.log.debug(`Folder path: ${this.folderPath}`, this.config.auditContext);
|
|
22
|
+
this.ctUidSet = new Set();
|
|
23
|
+
this.environmentUidSet = new Set();
|
|
24
|
+
this.localeCodeSet = new Set();
|
|
25
|
+
this.projectsWithIssues = [];
|
|
26
|
+
this.projectsWithIssuesMap = new Map();
|
|
27
|
+
this.composableStudioPath = '';
|
|
28
|
+
cli_utilities_1.log.debug(`ComposableStudio module initialization completed`, this.config.auditContext);
|
|
29
|
+
}
|
|
30
|
+
validateModules(moduleName, moduleConfig) {
|
|
31
|
+
cli_utilities_1.log.debug(`Validating module: ${moduleName}`, this.config.auditContext);
|
|
32
|
+
cli_utilities_1.log.debug(`Available modules: ${Object.keys(moduleConfig).join(', ')}`, this.config.auditContext);
|
|
33
|
+
if (Object.keys(moduleConfig).includes(moduleName)) {
|
|
34
|
+
cli_utilities_1.log.debug(`Module ${moduleName} is valid`, this.config.auditContext);
|
|
35
|
+
return moduleName;
|
|
36
|
+
}
|
|
37
|
+
cli_utilities_1.log.debug(`Module ${moduleName} not found, defaulting to 'composable-studio'`, this.config.auditContext);
|
|
38
|
+
return 'composable-studio';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Load environments from the environments.json file
|
|
42
|
+
*/
|
|
43
|
+
async loadEnvironments() {
|
|
44
|
+
cli_utilities_1.log.debug(`Loading environments`, this.config.auditContext);
|
|
45
|
+
const environmentsPath = (0, path_1.resolve)(this.config.basePath, 'environments', 'environments.json');
|
|
46
|
+
if ((0, fs_1.existsSync)(environmentsPath)) {
|
|
47
|
+
cli_utilities_1.log.debug(`Environments file path: ${environmentsPath}`, this.config.auditContext);
|
|
48
|
+
try {
|
|
49
|
+
const environments = JSON.parse((0, fs_1.readFileSync)(environmentsPath, 'utf-8'));
|
|
50
|
+
const envArray = Array.isArray(environments) ? environments : Object.values(environments);
|
|
51
|
+
envArray.forEach((env) => {
|
|
52
|
+
if (env.uid) {
|
|
53
|
+
this.environmentUidSet.add(env.uid);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
cli_utilities_1.log.debug(`Loaded ${this.environmentUidSet.size} environments: ${Array.from(this.environmentUidSet).join(', ')}`, this.config.auditContext);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
(0, cli_utilities_1.handleAndLogError)(error, this.config.auditContext, 'Failed to load environments');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
cli_utilities_1.log.debug(`Environments file not found at: ${environmentsPath}`, this.config.auditContext);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Load locales from the locales.json and master-locale.json files
|
|
68
|
+
*/
|
|
69
|
+
async loadLocales() {
|
|
70
|
+
cli_utilities_1.log.debug(`Loading locales`, this.config.auditContext);
|
|
71
|
+
const localesPath = (0, path_1.resolve)(this.config.basePath, 'locales', 'locales.json');
|
|
72
|
+
const masterLocalePath = (0, path_1.resolve)(this.config.basePath, 'locales', 'master-locale.json');
|
|
73
|
+
// Load master locale
|
|
74
|
+
if ((0, fs_1.existsSync)(masterLocalePath)) {
|
|
75
|
+
cli_utilities_1.log.debug(`Master locale file path: ${masterLocalePath}`, this.config.auditContext);
|
|
76
|
+
try {
|
|
77
|
+
const masterLocales = JSON.parse((0, fs_1.readFileSync)(masterLocalePath, 'utf-8'));
|
|
78
|
+
const localeArray = Array.isArray(masterLocales) ? masterLocales : Object.values(masterLocales);
|
|
79
|
+
localeArray.forEach((locale) => {
|
|
80
|
+
if (locale.code) {
|
|
81
|
+
this.localeCodeSet.add(locale.code);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
cli_utilities_1.log.debug(`Loaded ${this.localeCodeSet.size} master locales`, this.config.auditContext);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
(0, cli_utilities_1.handleAndLogError)(error, this.config.auditContext, 'Failed to load master locales');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
cli_utilities_1.log.debug(`Master locale file not found at: ${masterLocalePath}`, this.config.auditContext);
|
|
92
|
+
}
|
|
93
|
+
// Load additional locales
|
|
94
|
+
if ((0, fs_1.existsSync)(localesPath)) {
|
|
95
|
+
cli_utilities_1.log.debug(`Locales file path: ${localesPath}`, this.config.auditContext);
|
|
96
|
+
try {
|
|
97
|
+
const locales = JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf-8'));
|
|
98
|
+
const localeArray = Array.isArray(locales) ? locales : Object.values(locales);
|
|
99
|
+
localeArray.forEach((locale) => {
|
|
100
|
+
if (locale.code) {
|
|
101
|
+
this.localeCodeSet.add(locale.code);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
cli_utilities_1.log.debug(`Total locales after loading additional locales: ${this.localeCodeSet.size}`, this.config.auditContext);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
(0, cli_utilities_1.handleAndLogError)(error, this.config.auditContext, 'Failed to load additional locales');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
cli_utilities_1.log.debug(`Locales file not found at: ${localesPath}`, this.config.auditContext);
|
|
112
|
+
}
|
|
113
|
+
cli_utilities_1.log.debug(`Locale codes loaded: ${Array.from(this.localeCodeSet).join(', ')}`, this.config.auditContext);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Main run method to audit composable studio projects
|
|
117
|
+
*/
|
|
118
|
+
async run() {
|
|
119
|
+
var _a, _b, _c, _d;
|
|
120
|
+
cli_utilities_1.log.debug(`Starting ${this.moduleName} audit process`, this.config.auditContext);
|
|
121
|
+
cli_utilities_1.log.debug(`Composable Studio folder path: ${this.folderPath}`, this.config.auditContext);
|
|
122
|
+
cli_utilities_1.log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);
|
|
123
|
+
if (!(0, fs_1.existsSync)(this.folderPath)) {
|
|
124
|
+
cli_utilities_1.log.debug(`Skipping ${this.moduleName} audit - path does not exist`, this.config.auditContext);
|
|
125
|
+
cli_utilities_1.log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
|
|
126
|
+
cli_utilities_1.cliux.print((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
|
|
127
|
+
return {};
|
|
128
|
+
}
|
|
129
|
+
this.composableStudioPath = (0, path_1.join)(this.folderPath, this.fileName);
|
|
130
|
+
cli_utilities_1.log.debug(`Composable Studio file path: ${this.composableStudioPath}`, this.config.auditContext);
|
|
131
|
+
// Load composable studio projects
|
|
132
|
+
cli_utilities_1.log.debug(`Loading composable studio projects from file`, this.config.auditContext);
|
|
133
|
+
if ((0, fs_1.existsSync)(this.composableStudioPath)) {
|
|
134
|
+
try {
|
|
135
|
+
const projectsData = JSON.parse((0, fs_1.readFileSync)(this.composableStudioPath, 'utf-8'));
|
|
136
|
+
this.composableStudioProjects = Array.isArray(projectsData) ? projectsData : [projectsData];
|
|
137
|
+
cli_utilities_1.log.debug(`Loaded ${this.composableStudioProjects.length} composable studio projects`, this.config.auditContext);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
(0, cli_utilities_1.handleAndLogError)(error, this.config.auditContext, 'Failed to load composable studio projects');
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
cli_utilities_1.log.debug(`Composable studio file not found`, this.config.auditContext);
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
148
|
+
// Build content type UID set
|
|
149
|
+
cli_utilities_1.log.debug(`Building content type UID set from ${this.ctSchema.length} content types`, this.config.auditContext);
|
|
150
|
+
this.ctSchema.forEach((ct) => this.ctUidSet.add(ct.uid));
|
|
151
|
+
cli_utilities_1.log.debug(`Content type UID set contains: ${Array.from(this.ctUidSet).join(', ')}`, this.config.auditContext);
|
|
152
|
+
// Load environments and locales
|
|
153
|
+
await this.loadEnvironments();
|
|
154
|
+
await this.loadLocales();
|
|
155
|
+
// Process each project
|
|
156
|
+
cli_utilities_1.log.debug(`Processing ${this.composableStudioProjects.length} composable studio projects`, this.config.auditContext);
|
|
157
|
+
for (const project of this.composableStudioProjects) {
|
|
158
|
+
const { name, uid, contentTypeUid, settings } = project;
|
|
159
|
+
cli_utilities_1.log.debug(`Processing composable studio project: ${name} (${uid})`, this.config.auditContext);
|
|
160
|
+
cli_utilities_1.log.debug(`Content type UID: ${contentTypeUid}`, this.config.auditContext);
|
|
161
|
+
cli_utilities_1.log.debug(`Environment: ${(_a = settings === null || settings === void 0 ? void 0 : settings.configuration) === null || _a === void 0 ? void 0 : _a.environment}`, this.config.auditContext);
|
|
162
|
+
cli_utilities_1.log.debug(`Locale: ${(_b = settings === null || settings === void 0 ? void 0 : settings.configuration) === null || _b === void 0 ? void 0 : _b.locale}`, this.config.auditContext);
|
|
163
|
+
let hasIssues = false;
|
|
164
|
+
const issuesList = [];
|
|
165
|
+
const invalidContentTypes = [];
|
|
166
|
+
const invalidEnvironments = [];
|
|
167
|
+
const invalidLocales = [];
|
|
168
|
+
// Check content type
|
|
169
|
+
if (contentTypeUid && !this.ctUidSet.has(contentTypeUid)) {
|
|
170
|
+
cli_utilities_1.log.debug(`Content type ${contentTypeUid} not found in project ${name}`, this.config.auditContext);
|
|
171
|
+
invalidContentTypes.push(contentTypeUid);
|
|
172
|
+
issuesList.push(`Invalid contentTypeUid: ${contentTypeUid}`);
|
|
173
|
+
hasIssues = true;
|
|
174
|
+
}
|
|
175
|
+
// Check environment
|
|
176
|
+
if (((_c = settings === null || settings === void 0 ? void 0 : settings.configuration) === null || _c === void 0 ? void 0 : _c.environment) && !this.environmentUidSet.has(settings.configuration.environment)) {
|
|
177
|
+
cli_utilities_1.log.debug(`Environment ${settings.configuration.environment} not found in project ${name}`, this.config.auditContext);
|
|
178
|
+
invalidEnvironments.push(settings.configuration.environment);
|
|
179
|
+
issuesList.push(`Invalid environment: ${settings.configuration.environment}`);
|
|
180
|
+
hasIssues = true;
|
|
181
|
+
}
|
|
182
|
+
// Check locale
|
|
183
|
+
if (((_d = settings === null || settings === void 0 ? void 0 : settings.configuration) === null || _d === void 0 ? void 0 : _d.locale) && !this.localeCodeSet.has(settings.configuration.locale)) {
|
|
184
|
+
cli_utilities_1.log.debug(`Locale ${settings.configuration.locale} not found in project ${name}`, this.config.auditContext);
|
|
185
|
+
invalidLocales.push(settings.configuration.locale);
|
|
186
|
+
issuesList.push(`Invalid locale: ${settings.configuration.locale}`);
|
|
187
|
+
hasIssues = true;
|
|
188
|
+
}
|
|
189
|
+
if (hasIssues) {
|
|
190
|
+
cli_utilities_1.log.debug(`Project ${name} has validation issues`, this.config.auditContext);
|
|
191
|
+
// Store the original project for fixing
|
|
192
|
+
this.projectsWithIssuesMap.set(uid, project);
|
|
193
|
+
// Create a report-friendly object
|
|
194
|
+
const reportEntry = {
|
|
195
|
+
title: name,
|
|
196
|
+
name: name,
|
|
197
|
+
uid: uid,
|
|
198
|
+
content_types: invalidContentTypes.length > 0 ? invalidContentTypes : undefined,
|
|
199
|
+
environment: invalidEnvironments.length > 0 ? invalidEnvironments : undefined,
|
|
200
|
+
locale: invalidLocales.length > 0 ? invalidLocales : undefined,
|
|
201
|
+
issues: issuesList.join(', '),
|
|
202
|
+
};
|
|
203
|
+
this.projectsWithIssues.push(reportEntry);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
cli_utilities_1.log.debug(`Project ${name} has no validation issues`, this.config.auditContext);
|
|
207
|
+
}
|
|
208
|
+
cli_utilities_1.log.info((0, messages_1.$t)(messages_1.auditMsg.SCAN_CS_SUCCESS_MSG, {
|
|
209
|
+
name,
|
|
210
|
+
uid,
|
|
211
|
+
}), this.config.auditContext);
|
|
212
|
+
}
|
|
213
|
+
cli_utilities_1.log.debug(`Composable Studio audit completed. Found ${this.projectsWithIssues.length} projects with issues`, this.config.auditContext);
|
|
214
|
+
if (this.fix && this.projectsWithIssues.length) {
|
|
215
|
+
cli_utilities_1.log.debug(`Fix mode enabled, fixing ${this.projectsWithIssues.length} projects`, this.config.auditContext);
|
|
216
|
+
await this.fixComposableStudioProjects();
|
|
217
|
+
this.projectsWithIssues.forEach((project) => {
|
|
218
|
+
cli_utilities_1.log.debug(`Marking project ${project.name} as fixed`, this.config.auditContext);
|
|
219
|
+
project.fixStatus = 'Fixed';
|
|
220
|
+
});
|
|
221
|
+
cli_utilities_1.log.debug(`Composable Studio fix completed`, this.config.auditContext);
|
|
222
|
+
return this.projectsWithIssues;
|
|
223
|
+
}
|
|
224
|
+
cli_utilities_1.log.debug(`Composable Studio audit completed without fixes`, this.config.auditContext);
|
|
225
|
+
return this.projectsWithIssues;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Fix composable studio projects by removing invalid references
|
|
229
|
+
*/
|
|
230
|
+
async fixComposableStudioProjects() {
|
|
231
|
+
var _a, _b, _c, _d;
|
|
232
|
+
cli_utilities_1.log.debug(`Starting composable studio projects fix`, this.config.auditContext);
|
|
233
|
+
cli_utilities_1.log.debug(`Loading current composable studio projects from: ${this.composableStudioPath}`, this.config.auditContext);
|
|
234
|
+
let projectsData;
|
|
235
|
+
try {
|
|
236
|
+
projectsData = JSON.parse((0, fs_1.readFileSync)(this.composableStudioPath, 'utf-8'));
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
cli_utilities_1.log.debug(`Failed to load composable studio projects for fixing: ${error}`, this.config.auditContext);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const isArray = Array.isArray(projectsData);
|
|
243
|
+
const projects = isArray ? projectsData : [projectsData];
|
|
244
|
+
cli_utilities_1.log.debug(`Loaded ${projects.length} projects for fixing`, this.config.auditContext);
|
|
245
|
+
for (let i = 0; i < projects.length; i++) {
|
|
246
|
+
const project = projects[i];
|
|
247
|
+
const { uid, name } = project;
|
|
248
|
+
cli_utilities_1.log.debug(`Fixing project: ${name} (${uid})`, this.config.auditContext);
|
|
249
|
+
let needsFix = false;
|
|
250
|
+
// Check and fix content type
|
|
251
|
+
if (project.contentTypeUid && !this.ctUidSet.has(project.contentTypeUid)) {
|
|
252
|
+
cli_utilities_1.log.debug(`Removing invalid content type ${project.contentTypeUid} from project ${name}`, this.config.auditContext);
|
|
253
|
+
cli_utilities_1.cliux.print(`Warning: Project "${name}" has invalid content type "${project.contentTypeUid}". It will be removed.`, { color: 'yellow' });
|
|
254
|
+
project.contentTypeUid = undefined;
|
|
255
|
+
needsFix = true;
|
|
256
|
+
}
|
|
257
|
+
// Check and fix environment
|
|
258
|
+
if (((_b = (_a = project.settings) === null || _a === void 0 ? void 0 : _a.configuration) === null || _b === void 0 ? void 0 : _b.environment) &&
|
|
259
|
+
!this.environmentUidSet.has(project.settings.configuration.environment)) {
|
|
260
|
+
cli_utilities_1.log.debug(`Removing invalid environment ${project.settings.configuration.environment} from project ${name}`, this.config.auditContext);
|
|
261
|
+
cli_utilities_1.cliux.print(`Warning: Project "${name}" has invalid environment "${project.settings.configuration.environment}". It will be removed.`, { color: 'yellow' });
|
|
262
|
+
project.settings.configuration.environment = undefined;
|
|
263
|
+
needsFix = true;
|
|
264
|
+
}
|
|
265
|
+
// Check and fix locale
|
|
266
|
+
if (((_d = (_c = project.settings) === null || _c === void 0 ? void 0 : _c.configuration) === null || _d === void 0 ? void 0 : _d.locale) && !this.localeCodeSet.has(project.settings.configuration.locale)) {
|
|
267
|
+
cli_utilities_1.log.debug(`Removing invalid locale ${project.settings.configuration.locale} from project ${name}`, this.config.auditContext);
|
|
268
|
+
cli_utilities_1.cliux.print(`Warning: Project "${name}" has invalid locale "${project.settings.configuration.locale}". It will be removed.`, { color: 'yellow' });
|
|
269
|
+
project.settings.configuration.locale = undefined;
|
|
270
|
+
needsFix = true;
|
|
271
|
+
}
|
|
272
|
+
if (needsFix) {
|
|
273
|
+
cli_utilities_1.log.debug(`Project ${name} was fixed`, this.config.auditContext);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
cli_utilities_1.log.debug(`Project ${name} did not need fixing`, this.config.auditContext);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
cli_utilities_1.log.debug(`Composable studio projects fix completed, writing updated file`, this.config.auditContext);
|
|
280
|
+
await this.writeFixContent(isArray ? projects : projects[0]);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Write fixed composable studio projects back to file
|
|
284
|
+
*/
|
|
285
|
+
async writeFixContent(fixedProjects) {
|
|
286
|
+
var _a, _b;
|
|
287
|
+
cli_utilities_1.log.debug(`Writing fix content`, this.config.auditContext);
|
|
288
|
+
cli_utilities_1.log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);
|
|
289
|
+
cli_utilities_1.log.debug(`Copy directory flag: ${this.config.flags['copy-dir']}`, this.config.auditContext);
|
|
290
|
+
cli_utilities_1.log.debug(`External config skip confirm: ${(_a = this.config.flags['external-config']) === null || _a === void 0 ? void 0 : _a.skipConfirm}`, this.config.auditContext);
|
|
291
|
+
cli_utilities_1.log.debug(`Yes flag: ${this.config.flags.yes}`, this.config.auditContext);
|
|
292
|
+
if (this.fix &&
|
|
293
|
+
(this.config.flags['copy-dir'] ||
|
|
294
|
+
((_b = this.config.flags['external-config']) === null || _b === void 0 ? void 0 : _b.skipConfirm) ||
|
|
295
|
+
this.config.flags.yes ||
|
|
296
|
+
(await cli_utilities_1.cliux.confirm(messages_1.commonMsg.FIX_CONFIRMATION)))) {
|
|
297
|
+
const outputPath = (0, path_1.join)(this.folderPath, this.config.moduleConfig[this.moduleName].fileName);
|
|
298
|
+
cli_utilities_1.log.debug(`Writing fixed composable studio projects to: ${outputPath}`, this.config.auditContext);
|
|
299
|
+
(0, fs_1.writeFileSync)(outputPath, JSON.stringify(fixedProjects, null, 2));
|
|
300
|
+
cli_utilities_1.log.debug(`Successfully wrote fixed composable studio projects to file`, this.config.auditContext);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
cli_utilities_1.log.debug(`Skipping file write - fix mode disabled or user declined confirmation`, this.config.auditContext);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
exports.default = ComposableStudio;
|
package/lib/modules/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ import CustomRoles from './custom-roles';
|
|
|
7
7
|
import Assets from './assets';
|
|
8
8
|
import FieldRule from './field_rules';
|
|
9
9
|
import ModuleDataReader from './modulesData';
|
|
10
|
+
import ComposableStudio from './composable-studio';
|
|
10
11
|
import BaseClass from './base-class';
|
|
11
|
-
export { Entries, GlobalField, ContentType, Workflows, Extensions, Assets, CustomRoles, FieldRule, ModuleDataReader, BaseClass };
|
|
12
|
+
export { Entries, GlobalField, ContentType, Workflows, Extensions, Assets, CustomRoles, FieldRule, ModuleDataReader, BaseClass, ComposableStudio };
|
package/lib/modules/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseClass = exports.ModuleDataReader = exports.FieldRule = exports.CustomRoles = exports.Assets = exports.Extensions = exports.Workflows = exports.ContentType = exports.GlobalField = exports.Entries = void 0;
|
|
3
|
+
exports.ComposableStudio = exports.BaseClass = exports.ModuleDataReader = exports.FieldRule = exports.CustomRoles = exports.Assets = exports.Extensions = exports.Workflows = exports.ContentType = exports.GlobalField = exports.Entries = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const entries_1 = tslib_1.__importDefault(require("./entries"));
|
|
6
6
|
exports.Entries = entries_1.default;
|
|
@@ -20,5 +20,7 @@ const field_rules_1 = tslib_1.__importDefault(require("./field_rules"));
|
|
|
20
20
|
exports.FieldRule = field_rules_1.default;
|
|
21
21
|
const modulesData_1 = tslib_1.__importDefault(require("./modulesData"));
|
|
22
22
|
exports.ModuleDataReader = modulesData_1.default;
|
|
23
|
+
const composable_studio_1 = tslib_1.__importDefault(require("./composable-studio"));
|
|
24
|
+
exports.ComposableStudio = composable_studio_1.default;
|
|
23
25
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
24
26
|
exports.BaseClass = base_class_1.default;
|
|
@@ -24,7 +24,7 @@ class ModuleDataReader {
|
|
|
24
24
|
cli_utilities_1.log.debug(`Getting item count for module: ${moduleName}`, this.config.auditContext);
|
|
25
25
|
let count = 0;
|
|
26
26
|
switch (moduleName) {
|
|
27
|
-
case
|
|
27
|
+
case 'content-types':
|
|
28
28
|
cli_utilities_1.log.debug(`Counting content types`, this.config.auditContext);
|
|
29
29
|
count = this.ctSchema.length;
|
|
30
30
|
cli_utilities_1.log.debug(`Content types count: ${count}`, this.config.auditContext);
|
|
@@ -38,7 +38,7 @@ class ModuleDataReader {
|
|
|
38
38
|
cli_utilities_1.log.debug(`Counting assets`, this.config.auditContext);
|
|
39
39
|
const assetsPath = (0, path_1.join)(this.folderPath, 'assets');
|
|
40
40
|
cli_utilities_1.log.debug(`Assets path: ${assetsPath}`, this.config.auditContext);
|
|
41
|
-
count = await this.readEntryAssetsModule(assetsPath, 'assets') || 0;
|
|
41
|
+
count = (await this.readEntryAssetsModule(assetsPath, 'assets')) || 0;
|
|
42
42
|
cli_utilities_1.log.debug(`Assets count: ${count}`, this.config.auditContext);
|
|
43
43
|
break;
|
|
44
44
|
}
|
|
@@ -53,11 +53,13 @@ class ModuleDataReader {
|
|
|
53
53
|
cli_utilities_1.log.debug(`Master locales path: ${masterLocalesPath}`, this.config.auditContext);
|
|
54
54
|
cli_utilities_1.log.debug(`Loading master locales`, this.config.auditContext);
|
|
55
55
|
this.locales = (0, lodash_1.values)(await this.readUsingFsModule(masterLocalesPath));
|
|
56
|
-
cli_utilities_1.log.debug(`Loaded ${this.locales.length} master locales: ${this.locales.map(locale => locale.code).join(', ')}`, this.config.auditContext);
|
|
56
|
+
cli_utilities_1.log.debug(`Loaded ${this.locales.length} master locales: ${this.locales.map((locale) => locale.code).join(', ')}`, this.config.auditContext);
|
|
57
57
|
if ((0, fs_1.existsSync)(localesPath)) {
|
|
58
58
|
cli_utilities_1.log.debug(`Loading additional locales from file`, this.config.auditContext);
|
|
59
59
|
this.locales.push(...(0, lodash_1.values)(JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf8'))));
|
|
60
|
-
cli_utilities_1.log.debug(`Total locales after loading: ${this.locales.length} - ${this.locales
|
|
60
|
+
cli_utilities_1.log.debug(`Total locales after loading: ${this.locales.length} - ${this.locales
|
|
61
|
+
.map((locale) => locale.code)
|
|
62
|
+
.join(', ')}`, this.config.auditContext);
|
|
61
63
|
}
|
|
62
64
|
else {
|
|
63
65
|
cli_utilities_1.log.debug(`Additional locales file not found`, this.config.auditContext);
|
|
@@ -69,7 +71,7 @@ class ModuleDataReader {
|
|
|
69
71
|
cli_utilities_1.log.debug(`Processing content type: ${ctSchema.uid}`, this.config.auditContext);
|
|
70
72
|
const basePath = (0, path_1.join)(this.folderPath, 'entries', ctSchema.uid, code);
|
|
71
73
|
cli_utilities_1.log.debug(`Base path: ${basePath}`, this.config.auditContext);
|
|
72
|
-
const entryCount = await this.readEntryAssetsModule(basePath, 'index') || 0;
|
|
74
|
+
const entryCount = (await this.readEntryAssetsModule(basePath, 'index')) || 0;
|
|
73
75
|
cli_utilities_1.log.debug(`Found ${entryCount} entries for ${ctSchema.uid} in ${code}`, this.config.auditContext);
|
|
74
76
|
count = count + entryCount;
|
|
75
77
|
}
|
|
@@ -79,12 +81,19 @@ class ModuleDataReader {
|
|
|
79
81
|
break;
|
|
80
82
|
case 'custom-roles':
|
|
81
83
|
case 'extensions':
|
|
82
|
-
case 'workflows':
|
|
84
|
+
case 'workflows':
|
|
85
|
+
case 'composable-studio': {
|
|
83
86
|
cli_utilities_1.log.debug(`Counting ${moduleName}`, this.config.auditContext);
|
|
84
87
|
const modulePath = (0, path_1.resolve)(this.folderPath, (0, cli_utilities_1.sanitizePath)(this.config.moduleConfig[moduleName].dirName), (0, cli_utilities_1.sanitizePath)(this.config.moduleConfig[moduleName].fileName));
|
|
85
88
|
cli_utilities_1.log.debug(`Reading module: ${moduleName} from file: ${modulePath}`, this.config.auditContext);
|
|
86
89
|
const moduleData = await this.readUsingFsModule(modulePath);
|
|
87
|
-
|
|
90
|
+
// For composable-studio, it could be a single object or an array
|
|
91
|
+
if (moduleName === 'composable-studio') {
|
|
92
|
+
count = Array.isArray(moduleData) ? moduleData.length : Object.keys(moduleData).length > 0 ? 1 : 0;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
count = (0, lodash_1.keys)(moduleData).length;
|
|
96
|
+
}
|
|
88
97
|
cli_utilities_1.log.debug(`module:${moduleName} count: ${count}`, this.config.auditContext);
|
|
89
98
|
break;
|
|
90
99
|
}
|
|
@@ -94,7 +103,7 @@ class ModuleDataReader {
|
|
|
94
103
|
}
|
|
95
104
|
async readUsingFsModule(path) {
|
|
96
105
|
cli_utilities_1.log.debug(`Reading file: ${path}`, this.config.auditContext);
|
|
97
|
-
const data = (0, fs_1.existsSync)(path) ?
|
|
106
|
+
const data = (0, fs_1.existsSync)(path) ? JSON.parse((0, fs_1.readFileSync)(path, 'utf-8')) : [];
|
|
98
107
|
cli_utilities_1.log.debug(`File ${(0, fs_1.existsSync)(path) ? 'exists' : 'not found'}, data type: ${Array.isArray(data) ? 'array' : 'object'}`, this.config.auditContext);
|
|
99
108
|
if ((0, fs_1.existsSync)(path)) {
|
|
100
109
|
const dataSize = Array.isArray(data) ? data.length : Object.keys(data).length;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface ComposableStudioProject {
|
|
2
|
+
name: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
canvasUrl?: string;
|
|
5
|
+
connectedStackApiKey?: string;
|
|
6
|
+
contentTypeUid: string;
|
|
7
|
+
organizationUid?: string;
|
|
8
|
+
settings: {
|
|
9
|
+
configuration: {
|
|
10
|
+
environment: string;
|
|
11
|
+
locale: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
createdBy?: string;
|
|
15
|
+
updatedBy?: string;
|
|
16
|
+
deletedAt?: boolean;
|
|
17
|
+
createdAt?: string;
|
|
18
|
+
updatedAt?: string;
|
|
19
|
+
uid: string;
|
|
20
|
+
missingContentType?: boolean;
|
|
21
|
+
missingEnvironment?: boolean;
|
|
22
|
+
missingLocale?: boolean;
|
|
23
|
+
fixStatus?: string;
|
|
24
|
+
}
|
|
25
|
+
export { ComposableStudioProject };
|
|
@@ -127,7 +127,8 @@ declare enum OutputColumn {
|
|
|
127
127
|
"Fixable" = "Fixable",
|
|
128
128
|
"Non-Fixable" = "Non-Fixable",
|
|
129
129
|
"Fixed" = "Fixed",
|
|
130
|
-
"Not-Fixed" = "Not-Fixed"
|
|
130
|
+
"Not-Fixed" = "Not-Fixed",
|
|
131
|
+
"Issues" = "issues"
|
|
131
132
|
}
|
|
132
133
|
export { CtConstructorParam, ContentTypeStruct, ModuleConstructorParam, ReferenceFieldDataType, GlobalFieldDataType, ExtensionOrAppFieldDataType, JsonRTEFieldDataType, GroupFieldDataType, ModularBlocksDataType, RefErrorReturnType, ModularBlocksSchemaTypes, ModularBlockType, OutputColumn, ContentTypeSchemaType, GlobalFieldSchemaTypes, WorkflowExtensionsRefErrorReturnType, SelectFeildStruct, FieldRuleStruct, };
|
|
133
134
|
type FieldRuleStruct = {
|
package/lib/types/context.d.ts
CHANGED
package/oclif.manifest.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"commands": {
|
|
3
3
|
"cm:stacks:audit:fix": {
|
|
4
|
-
"aliases": [
|
|
5
|
-
"audit:fix",
|
|
6
|
-
"cm:stacks:audit:fix"
|
|
7
|
-
],
|
|
4
|
+
"aliases": [],
|
|
8
5
|
"args": {},
|
|
9
6
|
"description": "Perform audits and fix possible errors in the exported Contentstack data.",
|
|
10
7
|
"examples": [
|
|
@@ -68,7 +65,8 @@
|
|
|
68
65
|
"workflows",
|
|
69
66
|
"custom-roles",
|
|
70
67
|
"assets",
|
|
71
|
-
"field-rules"
|
|
68
|
+
"field-rules",
|
|
69
|
+
"composable-studio"
|
|
72
70
|
],
|
|
73
71
|
"type": "option"
|
|
74
72
|
},
|
|
@@ -197,10 +195,7 @@
|
|
|
197
195
|
]
|
|
198
196
|
},
|
|
199
197
|
"cm:stacks:audit": {
|
|
200
|
-
"aliases": [
|
|
201
|
-
"audit",
|
|
202
|
-
"cm:stacks:audit"
|
|
203
|
-
],
|
|
198
|
+
"aliases": [],
|
|
204
199
|
"args": {},
|
|
205
200
|
"description": "Perform audits and find possible errors in the exported Contentstack data",
|
|
206
201
|
"examples": [
|
|
@@ -263,7 +258,8 @@
|
|
|
263
258
|
"workflows",
|
|
264
259
|
"custom-roles",
|
|
265
260
|
"assets",
|
|
266
|
-
"field-rules"
|
|
261
|
+
"field-rules",
|
|
262
|
+
"composable-studio"
|
|
267
263
|
],
|
|
268
264
|
"type": "option"
|
|
269
265
|
},
|
|
@@ -344,5 +340,5 @@
|
|
|
344
340
|
]
|
|
345
341
|
}
|
|
346
342
|
},
|
|
347
|
-
"version": "2.0.0-beta"
|
|
343
|
+
"version": "2.0.0-beta.2"
|
|
348
344
|
}
|