Skip to content

Commit 2b38bee

Browse files
authored
Merge branch 'v2-dev' into enhc/DX-5171
2 parents a32b74d + 409cc07 commit 2b38bee

87 files changed

Lines changed: 4126 additions & 1461 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fileignoreconfig:
22
- filename: pnpm-lock.yaml
3-
checksum: 901fcf828dc9d8d85277c767cd468791388a4a3b0cb30525bcdcb86d009be6f4
3+
checksum: ac795ffbdc0f82463baf34715a30b76cf6a67b2d8893ec835a5861aa915b20bf
44
version: '1.0'

packages/contentstack-audit/.mocharc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"require": [
33
"test/helpers/init.js",
4-
"ts-node/register"
4+
"ts-node/register",
5+
"test/helpers/mocha-root-hooks.js"
56
],
67
"watch-extensions": [
78
"ts"

packages/contentstack-audit/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "2.0.0-beta.7",
3+
"version": "2.0.0-beta.8",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",
@@ -18,11 +18,11 @@
1818
"/oclif.manifest.json"
1919
],
2020
"dependencies": {
21-
"@contentstack/cli-command": "~2.0.0-beta.3",
22-
"@contentstack/cli-utilities": "~2.0.0-beta.3",
21+
"@contentstack/cli-command": "~2.0.0-beta.4",
22+
"@contentstack/cli-utilities": "~2.0.0-beta.4",
2323
"@oclif/core": "^4.3.0",
2424
"@oclif/plugin-help": "^6.2.28",
25-
"chalk": "^4.1.2",
25+
"chalk": "^5.6.2",
2626
"fast-csv": "^4.3.6",
2727
"fs-extra": "^11.3.0",
2828
"lodash": "^4.17.23",
@@ -73,8 +73,8 @@
7373
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
7474
"version": "oclif readme && git add README.md",
7575
"clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
76-
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"",
77-
"test:unit": "mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.ts\""
76+
"test:unit:report": "nyc --extension .ts mocha --forbid-only --file test/unit/logger-config.js \"test/unit/**/*.test.ts\"",
77+
"test:unit": "mocha --timeout 10000 --forbid-only --file test/unit/logger-config.js \"test/unit/**/*.test.ts\""
7878
},
7979
"engines": {
8080
"node": ">=16"

packages/contentstack-audit/src/audit-base-command.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import { getChalk } from '@contentstack/cli-utilities';
22
import * as csv from 'fast-csv';
33
import { copy } from 'fs-extra';
44
import { v4 as uuid } from 'uuid';
@@ -55,7 +55,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
5555
minWidth: 7,
5656
header: 'Fix Status',
5757
get: (row: any) => {
58-
return row.fixStatus === 'Fixed' ? chalk.greenBright(row.fixStatus) : chalk.redBright(row.fixStatus);
58+
return row.fixStatus === 'Fixed' ? getChalk().greenBright(row.fixStatus) : getChalk().redBright(row.fixStatus);
5959
},
6060
},
6161
};
@@ -548,7 +548,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
548548
value: 'missingRefs',
549549
alias: 'Missing references',
550550
formatter: (cellValue: any) => {
551-
return chalk.red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
551+
return getChalk().red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
552552
},
553553
},
554554
{
@@ -588,7 +588,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
588588
value: key,
589589
formatter: (cellValue: any) => {
590590
if (key === 'fixStatus' || key === 'Fixable' || key === 'Fixed') {
591-
return chalk.green(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
591+
return getChalk().green(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
592592
} else if (
593593
key === 'content_types' ||
594594
key === 'branches' ||
@@ -598,9 +598,9 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
598598
key === 'Non-Fixable' ||
599599
key === 'Not-Fixed'
600600
) {
601-
return chalk.red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
601+
return getChalk().red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
602602
} else {
603-
return chalk.white(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
603+
return getChalk().white(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
604604
}
605605
},
606606
}));

packages/contentstack-audit/src/modules/assets.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default class Assets extends BaseClass {
2727
protected schema: ContentTypeStruct[] = [];
2828
protected missingEnvLocales: Record<string, any> = {};
2929
public moduleName: keyof typeof auditConfig.moduleConfig;
30+
private fixOverwriteConfirmed: boolean | null = null;
3031

3132
constructor({ fix, config, moduleName }: ModuleConstructorParam & CtConstructorParam) {
3233
super({ config });
@@ -161,11 +162,17 @@ export default class Assets extends BaseClass {
161162

162163
if (this.fix) {
163164
log.debug('Fix mode enabled, checking write permissions', this.config.auditContext);
164-
if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) {
165-
log.debug(`Asking user for confirmation to write fix content (--yes flag: ${this.config.flags.yes})`, this.config.auditContext);
166-
canWrite = this.config.flags.yes || (await cliux.confirm(commonMsg.FIX_CONFIRMATION));
165+
if (this.config.flags['copy-dir'] || this.config.flags['external-config']?.skipConfirm || this.config.flags.yes) {
166+
this.fixOverwriteConfirmed = true;
167+
log.debug('Skipping confirmation due to copy-dir, external-config, or yes flags', this.config.auditContext);
168+
} else if (this.fixOverwriteConfirmed !== null) {
169+
canWrite = this.fixOverwriteConfirmed;
170+
log.debug(`Using cached overwrite confirmation: ${canWrite}`, this.config.auditContext);
167171
} else {
168-
log.debug('Skipping confirmation due to copy-dir or external-config flags', this.config.auditContext);
172+
log.debug(`Asking user for confirmation to write fix content (--yes flag: ${this.config.flags.yes})`, this.config.auditContext);
173+
this.completeProgress(true);
174+
canWrite = await cliux.confirm(commonMsg.FIX_CONFIRMATION);
175+
this.fixOverwriteConfirmed = canWrite;
169176
}
170177

171178
if (canWrite) {
@@ -248,13 +255,16 @@ export default class Assets extends BaseClass {
248255
if (this.progressManager) {
249256
this.progressManager.tick(true, `asset: ${assetUid}`, null);
250257
}
251-
258+
252259
if (this.fix) {
253260
log.debug(`Fixing asset ${assetUid}`, this.config.auditContext);
254261
log.info($t(auditFixMsg.ASSET_FIX, { uid: assetUid }), this.config.auditContext);
255-
await this.writeFixContent(`${basePath}/${indexer[fileIndex]}`, this.assets);
256262
}
257263
}
264+
265+
if (this.fix) {
266+
await this.writeFixContent(`${basePath}/${indexer[fileIndex]}`, this.assets);
267+
}
258268
}
259269

260270
log.debug(`Asset reference validation completed. Processed ${Object.keys(this.missingEnvLocales).length} assets with issues`, this.config.auditContext);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,15 @@ export default class ContentType extends BaseClass {
222222
let canWrite = true;
223223

224224
if (!this.inMemoryFix && this.fix) {
225+
if (Array.isArray(this.schema) && this.schema.length === 0) {
226+
log.debug('No schemas to write, skipping writeFixContent', this.config.auditContext);
227+
return;
228+
}
229+
225230
log.debug('Fix mode enabled, checking write permissions', this.config.auditContext);
226231
if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) {
227232
log.debug('Asking user for confirmation to write fix content', this.config.auditContext);
233+
this.completeProgress(true);
228234
canWrite = this.config.flags.yes ?? (await cliux.confirm(commonMsg.FIX_CONFIRMATION));
229235
} else {
230236
log.debug('Skipping confirmation due to copy-dir or external-config flags', this.config.auditContext);

packages/contentstack-audit/src/modules/custom-roles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export default class CustomRoles extends BaseClass {
249249
log.debug('Skipping confirmation due to copy-dir, external-config, or yes flags', this.config.auditContext);
250250
} else {
251251
log.debug('Asking user for confirmation to write fix content', this.config.auditContext);
252+
this.completeProgress(true);
252253
}
253254

254255
const canWrite = skipConfirm || (await cliux.confirm(commonMsg.FIX_CONFIRMATION));

packages/contentstack-audit/src/modules/entries.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default class Entries extends BaseClass {
6060
public environments: string[] = [];
6161
public entryMetaData: Record<string, any>[] = [];
6262
public moduleName: keyof typeof auditConfig.moduleConfig = 'entries';
63+
private fixOverwriteConfirmed: boolean | null = null;
6364

6465
constructor({ fix, config, moduleName, ctSchema, gfSchema }: ModuleConstructorParam & CtConstructorParam) {
6566
super({ config });
@@ -541,14 +542,21 @@ export default class Entries extends BaseClass {
541542

542543
const skipConfirm = this.config.flags['copy-dir'] || this.config.flags['external-config']?.skipConfirm;
543544

544-
if (skipConfirm) {
545-
log.debug('Skipping confirmation due to copy-dir or external-config flags', this.config.auditContext);
545+
let canWrite: boolean;
546+
if (skipConfirm || this.config.flags.yes) {
547+
canWrite = true;
548+
this.fixOverwriteConfirmed = true;
549+
log.debug('Skipping confirmation due to copy-dir, external-config, or yes flags', this.config.auditContext);
550+
} else if (this.fixOverwriteConfirmed !== null) {
551+
canWrite = this.fixOverwriteConfirmed;
552+
log.debug(`Using cached overwrite confirmation: ${canWrite}`, this.config.auditContext);
546553
} else {
547554
log.debug('Asking user for confirmation to write fix content', this.config.auditContext);
555+
this.completeProgress(true);
556+
canWrite = await cliux.confirm(commonMsg.FIX_CONFIRMATION);
557+
this.fixOverwriteConfirmed = canWrite;
548558
}
549559

550-
const canWrite = skipConfirm || this.config.flags.yes || (await cliux.confirm(commonMsg.FIX_CONFIRMATION));
551-
552560
if (canWrite) {
553561
log.debug(`Writing fixed entries to: ${filePath}`, this.config.auditContext);
554562
writeFileSync(filePath, JSON.stringify(schema));

packages/contentstack-audit/src/modules/extensions.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,19 @@ export default class Extensions extends BaseClass {
172172
? JSON.parse(readFileSync(this.extensionsPath, 'utf8'))
173173
: {};
174174
log.debug(`Loaded ${Object.keys(newExtensionSchema).length} existing extensions`, this.config.auditContext);
175-
175+
176+
let userConfirm: boolean;
177+
if (
178+
this.config.flags['copy-dir'] ||
179+
this.config.flags['external-config']?.skipConfirm ||
180+
this.config.flags.yes
181+
) {
182+
userConfirm = true;
183+
} else {
184+
this.completeProgress(true);
185+
userConfirm = await cliux.confirm(commonMsg.FIX_CONFIRMATION);
186+
}
187+
176188
for (const ext of missingCtInExtensions) {
177189
const { uid, title } = ext;
178190
log.debug(`Fixing extension: ${title} (${uid})`, this.config.auditContext);
@@ -187,8 +199,7 @@ export default class Extensions extends BaseClass {
187199
} else {
188200
log.debug(`Extension ${title} has no valid content types or scope not found`, this.config.auditContext);
189201
cliux.print($t(commonMsg.EXTENSION_FIX_WARN, { title: title, uid }), { color: 'yellow' });
190-
const shouldDelete = this.config.flags.yes || (await cliux.confirm(commonMsg.EXTENSION_FIX_CONFIRMATION));
191-
if (shouldDelete) {
202+
if (userConfirm) {
192203
log.debug(`Deleting extension: ${title} (${uid})`, this.config.auditContext);
193204
delete newExtensionSchema[uid];
194205
} else {
@@ -198,23 +209,33 @@ export default class Extensions extends BaseClass {
198209
}
199210

200211
log.debug(`Extensions scope fix completed, writing updated schema`, this.config.auditContext);
201-
await this.writeFixContent(newExtensionSchema);
212+
await this.writeFixContent(newExtensionSchema, userConfirm);
202213
}
203214

204-
async writeFixContent(fixedExtensions: Record<string, Extension>) {
215+
async writeFixContent(fixedExtensions: Record<string, Extension>, preConfirmed?: boolean) {
205216
log.debug(`Writing fix content for ${Object.keys(fixedExtensions).length} extensions`, this.config.auditContext);
206217
log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);
207218
log.debug(`Copy directory flag: ${this.config.flags['copy-dir']}`, this.config.auditContext);
208219
log.debug(`External config skip confirm: ${this.config.flags['external-config']?.skipConfirm}`, this.config.auditContext);
209220
log.debug(`Yes flag: ${this.config.flags.yes}`, this.config.auditContext);
210221

211-
if (
212-
this.fix &&
213-
(this.config.flags['copy-dir'] ||
214-
this.config.flags['external-config']?.skipConfirm ||
215-
this.config.flags.yes ||
216-
(await cliux.confirm(commonMsg.FIX_CONFIRMATION)))
222+
let shouldWrite: boolean;
223+
if (!this.fix) {
224+
shouldWrite = false;
225+
} else if (preConfirmed !== undefined) {
226+
shouldWrite = preConfirmed;
227+
} else if (
228+
this.config.flags['copy-dir'] ||
229+
this.config.flags['external-config']?.skipConfirm ||
230+
this.config.flags.yes
217231
) {
232+
shouldWrite = true;
233+
} else {
234+
this.completeProgress(true);
235+
shouldWrite = await cliux.confirm(commonMsg.FIX_CONFIRMATION);
236+
}
237+
238+
if (shouldWrite) {
218239
const outputPath = join(this.folderPath, this.config.moduleConfig[this.moduleName].fileName);
219240
log.debug(`Writing fixed extensions to: ${outputPath}`, this.config.auditContext);
220241
log.debug(`Extensions to write: ${Object.keys(fixedExtensions).join(', ')}`, this.config.auditContext);

packages/contentstack-audit/src/modules/field_rules.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ export default class FieldRule extends BaseClass {
474474
if (this.fix) {
475475
if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) {
476476
log.debug(`Asking user for confirmation to write fix content`, this.config.auditContext);
477+
this.completeProgress(true);
477478
canWrite = this.config.flags.yes ?? (await cliux.confirm(commonMsg.FIX_CONFIRMATION));
478479
log.debug(`User confirmation: ${canWrite}`, this.config.auditContext);
479480
} else {

0 commit comments

Comments
 (0)