Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
238 commits
Select commit Hold shift + click to select a range
41c83b5
update logger in audit command
Sep 16, 2025
22009bf
updated test cases
Sep 16, 2025
eedccf3
update test cases
Sep 17, 2025
ed3ea9b
update test cases
Sep 17, 2025
8e9bb52
Merge branch 'development' into enhancement/DX-3394
Sep 17, 2025
b74db1e
updated test cases
Sep 17, 2025
fdcca67
resolve comments
Sep 17, 2025
d669d07
update test cases
Sep 17, 2025
b19a3e7
Merge branch 'development' into enhancement/DX-3394
Sep 17, 2025
a89aaa1
added debug logs in audit
Sep 17, 2025
7898dc0
add logging for failing test cases
Sep 17, 2025
ba5c487
removed consoles
Sep 17, 2025
0652ebb
updated logs as per comments
Sep 23, 2025
9b9c570
updated log message
Sep 23, 2025
78af6cf
updated logger implementation
Sep 24, 2025
d929e28
updated test cases with v2 logger
Sep 24, 2025
fc01291
updated test cases
Sep 24, 2025
a9e9fca
added content in logging
Sep 25, 2025
be735c0
update audit context with dynamic module names
Sep 26, 2025
4aa9803
Merge branch 'development' into enhancement/DX-3394
Sep 27, 2025
5c61630
added info logs
Sep 27, 2025
f549024
added delay config
Sep 30, 2025
39947be
removed consoles
Sep 30, 2025
65de097
Merge branch 'development' into enhancement/DX_3542
Sep 30, 2025
7ce24b0
Merge branch 'development' into enhancement/DX-3394
Sep 30, 2025
09b4e49
updated logs
Sep 30, 2025
1569ac1
Merge branch 'development' into enhancement/DX-3394
Sep 30, 2025
8aafb98
updated talisman
Sep 30, 2025
f6d2487
version bump
Oct 1, 2025
dfe2a5c
resolved comments
Oct 3, 2025
2319fbb
Merge pull request #2148 from contentstack/main
harshithad0703 Oct 6, 2025
272b0b0
Feat: Test setup for the Import Unit Test cases and import command Test
cs-raj Oct 7, 2025
e94341b
removed env delay config
Oct 7, 2025
175a21b
updated SDK
Oct 7, 2025
a96a17b
Feat: Added Unit test cases for the base class
cs-raj Oct 7, 2025
a59f407
Talisman Update
cs-raj Oct 7, 2025
fbf5ca9
Merge branch 'development' into tests/DX-3589
cs-raj Oct 7, 2025
1d61afc
Merge branch 'development' into tests/DX-3587
cs-raj Oct 7, 2025
0fc0ff7
Merge pull request #2151 from contentstack/tests/DX-3587
cs-raj Oct 8, 2025
7c46332
Merge branch 'development' into tests/DX-3589
cs-raj Oct 8, 2025
2e6ae12
Merge pull request #2152 from contentstack/tests/DX-3589
cs-raj Oct 8, 2025
b2336ee
feat: Updated the test workflow to include the import command unit te…
cs-raj Oct 9, 2025
97c1daa
updated import statements
cs-raj Oct 9, 2025
02903d5
Merge pull request #2155 from contentstack/tests/feat-workflow-update
cs-raj Oct 9, 2025
ac45fb0
Fixed error in Nuxt kickstarter apps
sunil-lakshman Oct 9, 2025
72feff1
Merge branch 'development' into enhancement/DX-3394
Oct 9, 2025
0e5b9a3
Merge pull request #2123 from contentstack/enhancement/DX-3394
harshithad0703 Oct 9, 2025
15b05c3
Merge pull request #2157 from contentstack/development
harshithad0703 Oct 9, 2025
3bdc06f
Updated the Graphql Host for Kickstart Graphql app
sunil-lakshman Oct 10, 2025
88c3ce2
Merge branch 'development' into fix/dx-3622
sunil-lakshman Oct 10, 2025
40ab817
Updated package lock file
sunil-lakshman Oct 10, 2025
41643af
Merge pull request #2156 from contentstack/fix/dx-3622
sunil-lakshman Oct 10, 2025
91b7b38
Fix: Added Unit test cases for Assets module
cs-raj Oct 13, 2025
c0eea4e
Merge branch 'development' into tests/fix-assets
cs-raj Oct 13, 2025
3e15f53
Fix: Added Test cases for content-types
cs-raj Oct 13, 2025
27cff2e
Merge pull request #2159 from contentstack/tests/fix-assets
cs-raj Oct 13, 2025
3803931
Merge branch 'development' into tests/fix-content-types
cs-raj Oct 13, 2025
a87ef38
Merge pull request #2160 from contentstack/tests/fix-content-types
cs-raj Oct 13, 2025
51d7c2c
feat: taxonomy localization support in export
aman19K Oct 13, 2025
ce382a1
feat: taxonomy localization support in import
aman19K Oct 13, 2025
efe83b3
feat: taxonomy locale support in migration example & script
aman19K Oct 13, 2025
6552069
fix: corrupted config file issue
aman19K Oct 13, 2025
f71523d
Added Test cases for global-fields
cs-raj Oct 13, 2025
7e257d4
chore: update @contentstack/cli-cm-import to version 1.28.2 in multip…
harshithad0703 Oct 13, 2025
516e832
Merge pull request #2164 from contentstack/fix/version-bump-v1.50.0
harshithad0703 Oct 13, 2025
909369e
Merge pull request #2158 from contentstack/staging
harshithad0703 Oct 13, 2025
5b0f518
Merge pull request #2163 from contentstack/test/global-fields
cs-raj Oct 13, 2025
55869f1
Merge pull request #2161 from contentstack/feat/DX-3598
aman19K Oct 13, 2025
55fd7c0
update delay cases for bulk publish
Oct 13, 2025
3a9d972
Merge branch 'development' into enhancement/DX_3542
Oct 13, 2025
9f3550e
Fix: Added Unit test cases for workflow module
cs-raj Oct 14, 2025
c590236
Fixed the failing test
cs-raj Oct 14, 2025
a47be65
update package-lock
harshithad0703 Oct 14, 2025
b776036
Merge pull request #2165 from contentstack/tests/workflows
cs-raj Oct 14, 2025
503075d
Merge branch 'development' into fix/back-merge
harshithad0703 Oct 14, 2025
8f215d3
Merge pull request #2167 from contentstack/fix/back-merge
harshithad0703 Oct 14, 2025
c19de5c
Merge branch development into fix/back-merge4
harshithad0703 Oct 14, 2025
b27dc27
update package-lock
harshithad0703 Oct 14, 2025
5749676
Merge pull request #2169 from contentstack/fix/back-merge4
harshithad0703 Oct 14, 2025
4ada993
Fix: Added test cases for Custom roles
cs-raj Oct 14, 2025
2f63a00
Merge branch 'development' into tests/custom-roles
cs-raj Oct 14, 2025
4bde38d
Merge pull request #2170 from contentstack/tests/custom-roles
cs-raj Oct 14, 2025
28a1940
enhance: update error logging
Oct 14, 2025
50b8a90
fix: Added Test cases for asset-helpers
cs-raj Oct 14, 2025
7acc5c2
Merge pull request #2173 from contentstack/tests/DX-3588-a
cs-raj Oct 14, 2025
f20b019
Fix: Added Tests for Taxonomies and Setup-branch
cs-raj Oct 14, 2025
1a18cd0
Fix: Updated the package to use rewire
cs-raj Oct 15, 2025
59705e5
Lock File update
cs-raj Oct 15, 2025
a7cf210
Merge pull request #2174 from contentstack/tests/DX-3588
cs-raj Oct 15, 2025
337e2c8
fix: Added Tests cases for marketplace module
cs-raj Oct 16, 2025
4b676ee
Added Additional Test cases
cs-raj Oct 16, 2025
6710b66
Merge branch 'development' into enhancement/DX-3639
Oct 16, 2025
df7293e
enh: increased log file size threshold from 1 MB to 5 MB and number o…
aman19K Oct 16, 2025
bde8a4f
Merge pull request #2171 from contentstack/enhancement/DX-3639
naman-contentstack Oct 16, 2025
cf70c07
Fixed formatting
cs-raj Oct 16, 2025
a680ca7
fix: formatting
aman19K Oct 16, 2025
0be4487
Merge branch 'development' into tests/DX-3594
cs-raj Oct 16, 2025
bed6713
Merge branch 'development' into enh/DX-3647
aman19K Oct 16, 2025
410202e
Merge pull request #2176 from contentstack/tests/DX-3594
cs-raj Oct 16, 2025
43da37d
Merge branch 'development' into enh/DX-3647
aman19K Oct 16, 2025
857e323
Merge pull request #2177 from contentstack/enh/DX-3647
aman19K Oct 16, 2025
d364abf
feat: Added taxonomy localization support in export-to-csv
aman19K Oct 16, 2025
9d13906
fix: export to csv test cases
aman19K Oct 17, 2025
52d5a35
fix: Added Unit Test cases for Labels
cs-raj Oct 17, 2025
ed7524b
Merge pull request #2178 from contentstack/feat/DX-3638
aman19K Oct 17, 2025
56aba10
Merge pull request #2179 from contentstack/tests/DX-3594
cs-raj Oct 17, 2025
2fc71d8
fix: infinite retry loop on errors
aman19K Oct 18, 2025
3d57ef1
fix: Added Unit Test cases for entries and fixed marketplace test cases
cs-raj Oct 22, 2025
e6db2ce
fix: Fixed marketplace tests
cs-raj Oct 23, 2025
6e4409f
Version bump
cs-raj Oct 23, 2025
08b7d6e
Merge pull request #2181 from contentstack/tests/DX-3595
cs-raj Oct 23, 2025
93cfe12
Merge pull request #2180 from contentstack/development
harshithad0703 Oct 23, 2025
1dd44da
fix:Added unit test case for content-type-helper
cs-raj Oct 23, 2025
350abec
Merge pull request #2183 from contentstack/test/DX-3653-a
cs-raj Oct 23, 2025
25f1e1c
Fix: Added test cases for extension helper
cs-raj Oct 24, 2025
02baaea
Merge pull request #2184 from contentstack/test/DX-3653-b
cs-raj Oct 24, 2025
0b0500c
Merge branch 'development' into enhancement/DX_3542
Oct 24, 2025
2a75b6f
Merge branch 'development' into enhancement/DX_3542
naman-contentstack Oct 24, 2025
c20e1d7
Merge pull request #2140 from contentstack/enhancement/DX_3542
naman-contentstack Oct 24, 2025
8fc698e
Merge remote-tracking branch 'origin/staging' into fix/version-back-m…
harshithad0703 Oct 24, 2025
e6294dd
update: bump @contentstack/cli-variants version to 1.3.4 across multi…
harshithad0703 Oct 24, 2025
baa0096
Merge pull request #2188 from contentstack/fix/version-back-merge
harshithad0703 Oct 24, 2025
8a809c2
Merge pull request #2186 from contentstack/development
harshithad0703 Oct 24, 2025
09311d8
Fix: Added test cases for Entries helper
cs-raj Oct 24, 2025
3d6d13f
Merge branch 'development' into test/DX-3653-c
harshithad0703 Oct 24, 2025
f8f5358
Merge pull request #2189 from contentstack/test/DX-3653-c
cs-raj Oct 24, 2025
708cb92
Fix: Added Tests for Stack module
cs-raj Oct 27, 2025
7438c68
Merge pull request #2190 from contentstack/tests/DX-3591
cs-raj Oct 27, 2025
729ed39
Fix: Added Test cases for environments module
cs-raj Oct 27, 2025
c4325ee
feat: add test cases base-class and asssets for export module
Oct 27, 2025
f2a4f40
fix: add status code 422 in the retry logic, updated example config
Oct 27, 2025
9355c4e
Merge pull request #2193 from contentstack/fix/DX_3644
naman-contentstack Oct 27, 2025
745936c
Merge pull request #2191 from contentstack/tests/DX-3591-b
cs-raj Oct 27, 2025
e71c079
Fix: Added Tests for Locales module
cs-raj Oct 27, 2025
22ba8fc
Version bump
cs-raj Oct 27, 2025
90b5c51
Merge pull request #2185 from contentstack/staging
harshithad0703 Oct 27, 2025
a8a9dfd
Merge branch 'development' into enhancement/DX-3579
Oct 27, 2025
ac2cc75
Fixed bulk publish issue
sunil-lakshman Oct 27, 2025
e7eb21f
Merge pull request #2192 from contentstack/enhancement/DX-3579
naman-contentstack Oct 27, 2025
01f9cdb
Added log message and await for bulk publish
sunil-lakshman Oct 27, 2025
7b70e4d
Merge pull request #2196 from contentstack/main
harshithad0703 Oct 27, 2025
c05e08c
Merge branch 'staging' into hotfix/dx-3658-bulk-publish
sunil-lakshman Oct 27, 2025
35a600f
Added release version bump
sunil-lakshman Oct 27, 2025
1eaa179
Merge branch 'development' into tests/DX-3591-c
cs-raj Oct 28, 2025
a42eb01
Merge pull request #2194 from contentstack/tests/DX-3591-c
cs-raj Oct 28, 2025
c2d84d5
chore: add test cases for envs, extensions, locales,stacks, taxonomie…
Oct 28, 2025
ee7fb00
add test cases in stack.test
Oct 28, 2025
2ab7518
Fixed the Handling of Multiple Global Fields
cs-raj Oct 28, 2025
0d1ac6d
Merge pull request #2197 from contentstack/feat/DX-3583
naman-contentstack Oct 28, 2025
f8797e7
chore: add test cases for global-fields, custom roles, workflows, con…
Oct 28, 2025
02c34bb
Merge pull request #2199 from contentstack/feat/DX-3584
naman-contentstack Oct 28, 2025
de71b1a
Merge branch 'development' into fix/DX-3623
cs-raj Oct 28, 2025
d9b868c
Removed commented code
sunil-lakshman Oct 28, 2025
5ff3e46
Merge pull request #2195 from contentstack/hotfix/dx-3658-bulk-publish
sunil-lakshman Oct 29, 2025
4b80829
Merge branch staging into fix/merge-conflicts
harshithad0703 Oct 29, 2025
88dae10
Merge pull request #2204 from contentstack/fix/merge-conflicts
harshithad0703 Oct 29, 2025
cd598df
Merge branch 'development' into fix/DX-3623
cs-raj Oct 29, 2025
4850572
Tests: Added Unit Test cases for Extensions Webhooks Taxonomies and U…
cs-raj Oct 29, 2025
354814a
Merge branch 'development' into tests/DX-3665
cs-raj Oct 29, 2025
d925e90
Merge pull request #2205 from contentstack/tests/DX-3665
cs-raj Oct 29, 2025
7d724ab
Tests: Added unit test cases for personalize, variant-entries and index
cs-raj Oct 29, 2025
bbcac3b
Tests: Added Unit Test cases for Module importer
cs-raj Oct 29, 2025
c2b979a
chore: add test cases for utils
Oct 29, 2025
045631c
Merge branch 'development' into feat/DX-3580
Oct 29, 2025
2f7f9e9
Merge pull request #2207 from contentstack/tests/DX-3668
cs-raj Oct 29, 2025
f58d303
add fix for test cases
Oct 29, 2025
741fea5
update file helper test case
Oct 29, 2025
c8858eb
updated test cases
Oct 29, 2025
0f6f546
Merge branch 'development' into feat/DX-3580
Oct 29, 2025
70de1fe
Test: Added Unit Test cases for Backup Handler, Common Helper File He…
cs-raj Oct 29, 2025
e732839
Merge branch 'development' into tests/DX-3669
cs-raj Oct 30, 2025
98f63ce
Merge pull request #2208 from contentstack/feat/DX-3580
naman-contentstack Oct 30, 2025
5aeafed
Merge branch 'development' into tests/DX-3669
cs-raj Oct 30, 2025
ffd46e7
Merge pull request #2209 from contentstack/tests/DX-3669
cs-raj Oct 30, 2025
8df458c
Tests: Added test cases for Utilitites Modules
cs-raj Oct 30, 2025
8b21334
Merge branch 'development' into tests/DX-3670
cs-raj Oct 30, 2025
64620f7
Merge branch 'development' into tests/DX-3671
cs-raj Oct 30, 2025
4ec97f5
Merge pull request #2202 from contentstack/staging
harshithad0703 Oct 30, 2025
c97f5ed
Merge branch 'main' into fix/back-merge
harshithad0703 Oct 31, 2025
eaf6b2b
Merge pull request #2211 from contentstack/fix/back-merge
harshithad0703 Oct 31, 2025
4288b99
Merge branch 'development' into tests/DX-3670
cs-raj Oct 31, 2025
f11587d
Fixed the test cases
cs-raj Oct 31, 2025
13cc65b
Merge pull request #2213 from contentstack/tests/DX-3670
cs-raj Oct 31, 2025
ffe9909
Tests: Added Unit Test cases for Extensions Webhooks Taxonomies and U…
cs-raj Oct 29, 2025
bdd1590
Tests: Added Unit Test cases for Module importer
cs-raj Oct 29, 2025
b21556c
Tests: Added unit test cases for personalize, variant-entries and index
cs-raj Oct 29, 2025
9e8636d
chore: add test cases for utils
Oct 29, 2025
e28c741
add fix for test cases
Oct 29, 2025
5217749
update file helper test case
Oct 29, 2025
c8e3b1f
updated test cases
Oct 29, 2025
a611e36
Lock File Updatd
cs-raj Oct 31, 2025
9edf014
Test: Added Unit Test cases for Backup Handler, Common Helper File He…
cs-raj Oct 29, 2025
05c7323
Fixed the test cases
cs-raj Oct 31, 2025
98aacc0
Lock File update
cs-raj Oct 31, 2025
21b506b
Lock File udpate
cs-raj Oct 31, 2025
c7a2a22
Merge branch 'development' into fix/DX-3623
cs-raj Oct 31, 2025
47f19ac
Lock File Update
cs-raj Oct 31, 2025
2e61f23
Merge branch 'development' into tests/DX-3671
cs-raj Oct 31, 2025
1134f8c
Fixed unit test cases for logger and config handler
cs-raj Nov 3, 2025
faa3c28
Merge pull request #2214 from contentstack/tests/DX-3671
cs-raj Nov 3, 2025
0c04afa
Merge branch 'development' into fix/DX-3623
cs-raj Nov 4, 2025
700b94b
Merge pull request #2198 from contentstack/fix/DX-3623
cs-raj Nov 5, 2025
65ea0ff
Merge remote-tracking branch 'origin/development' into feat/DX-3572-t…
sunil-lakshman Nov 5, 2025
6fa709d
Added taxonomy localization unit testcases
sunil-lakshman Nov 6, 2025
c6a3733
Fixed unit testcases in export plugin
sunil-lakshman Nov 6, 2025
12a2b1f
Merge pull request #2217 from contentstack/fix/dx-3571-testcases
sunil-lakshman Nov 6, 2025
9b74159
Added version bump
sunil-lakshman Nov 6, 2025
88413bf
Added version bump
sunil-lakshman Nov 6, 2025
0776957
Merge pull request #2218 from contentstack/enh/version_bump
sunil-lakshman Nov 6, 2025
875b2b8
fix: export-to-csv fallback locale issue
aman19K Nov 6, 2025
ea0bc09
fix: export-to-csv fallback locale issue
aman19K Nov 6, 2025
73ca127
inquirer version bump
sunil-lakshman Nov 6, 2025
1016d9f
Merge pull request #2216 from contentstack/feat/DX-3571-taxonomy-loca…
sunil-lakshman Nov 7, 2025
eb5db3b
Merge pull request #2219 from contentstack/development
harshithad0703 Nov 7, 2025
ba7ceaf
Merge branch main into fix/version-bump
harshithad0703 Nov 7, 2025
578ddf8
Merge branch staging into fix/version-bump
harshithad0703 Nov 7, 2025
daa6987
version bump
harshithad0703 Nov 7, 2025
eccefd6
merge staging
harshithad0703 Nov 7, 2025
68d8dd8
merge staging
harshithad0703 Nov 7, 2025
d847adc
merge staging
harshithad0703 Nov 7, 2025
8d37e9b
merge staging
harshithad0703 Nov 7, 2025
cc55535
workflow update
harshithad0703 Nov 7, 2025
7338082
update workflow
harshithad0703 Nov 7, 2025
bd5005b
chore: update @contentstack/cli-utilities and @contentstack/cli-audit…
harshithad0703 Nov 7, 2025
a934abd
chore: update @contentstack/cli-cm-export-to-csv version to 1.10.0
harshithad0703 Nov 7, 2025
84d9f61
Merge pull request #2222 from contentstack/fix/version-bump
harshithad0703 Nov 7, 2025
1ba0471
taxonomy localisation change
shafeeqd959 Nov 10, 2025
b6a1bae
taxonomy locale changes
shafeeqd959 Nov 10, 2025
a627f4b
added taxonomy localization
shafeeqd959 Nov 11, 2025
6fa2b6e
updated talisman rc
shafeeqd959 Nov 11, 2025
8efe0ca
Merge pull request #2226 from contentstack/feat/taxonomy-localization…
shafeeqd959 Nov 11, 2025
e4471b6
bumped version
shafeeqd959 Nov 11, 2025
ed86244
Merge branch 'development' of github.com:contentstack/cli into feat/t…
shafeeqd959 Nov 11, 2025
5ef8c15
Merge pull request #2227 from contentstack/feat/taxonomy-localization…
harshithad0703 Nov 11, 2025
d10ca17
Merge pull request #2228 from contentstack/development
harshithad0703 Nov 11, 2025
cfc47de
Merge pull request #2221 from contentstack/staging
harshithad0703 Nov 12, 2025
b6834f0
Merge branch 'v2-beta-dev' into fix/update-version-12-11
harshithad0703 Nov 12, 2025
5613014
Merge pull request #2232 from contentstack/fix/update-version-12-11
harshithad0703 Nov 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ jobs:
working-directory: ./packages/contentstack-command
run: npm run test:unit

- name: Run tests for Contentstack Command
working-directory: ./packages/contentstack-command
run: npm run test:unit
# - name: Run tests for Contentstack Import Plugin
# working-directory: ./packages/contentstack-import
# run: npm run test:unit

# - name: Run tests for Contentstack Export Plugin
# working-directory: ./packages/contentstack-export
# run: npm run test:unit

- name: Run tests for Audit plugin
working-directory: ./packages/contentstack-audit
Expand Down
316 changes: 205 additions & 111 deletions .talismanrc

Large diffs are not rendered by default.

3,409 changes: 1,813 additions & 1,596 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ DESCRIPTION
Display help for csdx.
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.33/src/commands/help.ts)_
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.33/src/commands/help.ts)_

## `csdx plugins`
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.14.2",
"version": "1.16.0",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand Down
105 changes: 86 additions & 19 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { v4 as uuid } from 'uuid';
import isEmpty from 'lodash/isEmpty';
import { join, resolve } from 'path';
import cloneDeep from 'lodash/cloneDeep';
import { cliux, sanitizePath, TableFlags, TableHeader } from '@contentstack/cli-utilities';
import { cliux, sanitizePath, TableFlags, TableHeader, log, configHandler } from '@contentstack/cli-utilities';
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs';
import config from './config';
import { print } from './util/log';
Expand All @@ -31,11 +31,13 @@ import {
OutputColumn,
RefErrorReturnType,
WorkflowExtensionsRefErrorReturnType,
AuditContext,
} from './types';

export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseCommand> {
private currentCommand!: CommandNames;
private readonly summaryDataToPrint: Record<string, any> = [];
protected auditContext!: AuditContext;
get fixStatus() {
return {
fixStatus: {
Expand All @@ -48,6 +50,19 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
};
}

/**
* Create audit context object similar to export command
*/
private createAuditContext(moduleName?: string): AuditContext {
return {
command: this.context?.info?.command || 'cm:stacks:audit',
module: moduleName || 'audit',
email: configHandler.get('email') || '',
sessionId: this.context?.sessionId || '',
authenticationMethod: configHandler.get('authenticationMethod') || '',
};
}

/**
* The `start` function performs an audit on content types, global fields, entries, and workflows and displays
* any missing references.
Expand All @@ -56,9 +71,17 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
*/
async start(command: CommandNames): Promise<boolean> {
this.currentCommand = command;
// Initialize audit context
this.auditContext = this.createAuditContext();
log.debug(`Starting audit command: ${command}`, this.auditContext);
log.info(`Starting audit command: ${command}`, this.auditContext);


await this.promptQueue();
await this.createBackUp();
this.sharedConfig.reportPath = resolve(this.flags['report-path'] || process.cwd(), 'audit-report');
log.debug(`Data directory: ${this.flags['data-dir']}`, this.auditContext);
log.debug(`Report path: ${this.flags['report-path'] || process.cwd()}`, this.auditContext);

const {
missingCtRefs,
Expand Down Expand Up @@ -122,13 +145,13 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
!isEmpty(missingMultipleFields)
) {
if (this.currentCommand === 'cm:stacks:audit') {
this.log(this.$t(auditMsg.FINAL_REPORT_PATH, { path: this.sharedConfig.reportPath }), 'warn');
log.warn(this.$t(auditMsg.FINAL_REPORT_PATH, { path: this.sharedConfig.reportPath }), this.auditContext);
} else {
this.log(this.$t(this.messages.FIXED_CONTENT_PATH_MAG, { path: this.sharedConfig.basePath }), 'warn');
log.warn(this.$t(this.messages.FIXED_CONTENT_PATH_MAG, { path: this.sharedConfig.basePath }), this.auditContext);
}
} else {
this.log(this.messages.NO_MISSING_REF_FOUND, 'info');
this.log('');
log.info(this.messages.NO_MISSING_REF_FOUND, this.auditContext);
cliux.print('');

if (
this.flags['copy-dir'] &&
Expand Down Expand Up @@ -161,14 +184,24 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
* and `missingEntryRefs`.
*/
async scanAndFix() {
log.debug('Starting scan and fix process', this.auditContext);
let { ctSchema, gfSchema } = this.getCtAndGfSchema();
log.info(`Retrieved ${ctSchema?.length || 0} content types and ${gfSchema?.length || 0} global fields`, this.auditContext);

let missingCtRefs,
missingGfRefs,
missingEntryRefs,
missingCtRefsInExtensions,
missingCtRefsInWorkflow,
missingSelectFeild,
missingEntry,
missingEntry: {
missingEntryRefs?: Record<string, any>;
missingSelectFeild?: Record<string, any>;
missingMandatoryFields?: Record<string, any>;
missingTitleFields?: Record<string, any>;
missingEnvLocale?: Record<string, any>;
missingMultipleFields?: Record<string, any>;
} = {},
missingMandatoryFields,
missingTitleFields,
missingRefInCustomRoles,
Expand All @@ -180,13 +213,21 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
const constructorParam: ModuleConstructorParam & CtConstructorParam = {
ctSchema,
gfSchema,
log: this.log,
config: this.sharedConfig,
config: {
...this.sharedConfig,
auditContext: this.auditContext,
},
fix: this.currentCommand === 'cm:stacks:audit:fix',
};

let dataModuleWise: Record<string, any> = await new ModuleDataReader(cloneDeep(constructorParam)).run();
log.debug(`Data module wise: ${JSON.stringify(dataModuleWise)}`, this.auditContext);
for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
// Update audit context with current module
this.auditContext = this.createAuditContext(module);
log.debug(`Starting audit for module: ${module}`, this.auditContext);
log.info(`Starting audit for module: ${module}`, this.auditContext);

print([
{
bold: true,
Expand All @@ -199,21 +240,28 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma

switch (module) {
case 'assets':
log.info('Executing assets audit', this.auditContext);
missingEnvLocalesInAssets = await new Assets(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingEnvLocalesInAssets);
this.getAffectedData('assets', dataModuleWise['assets'], missingEnvLocalesInAssets);
log.success(`Assets audit completed. Found ${Object.keys(missingEnvLocalesInAssets || {}).length} issues`, this.auditContext);
break;
case 'content-types':
log.info('Executing content-types audit', this.auditContext);
missingCtRefs = await new ContentType(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingCtRefs);
this.getAffectedData('content-types', dataModuleWise['content-types'], missingCtRefs);
log.success(`Content-types audit completed. Found ${Object.keys(missingCtRefs || {}).length} issues`, this.auditContext);
break;
case 'global-fields':
log.info('Executing global-fields audit', this.auditContext);
missingGfRefs = await new GlobalField(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingGfRefs);
this.getAffectedData('global-fields', dataModuleWise['global-fields'], missingGfRefs);
log.success(`Global-fields audit completed. Found ${Object.keys(missingGfRefs || {}).length} issues`, this.auditContext);
break;
case 'entries':
log.info('Executing entries audit', this.auditContext);
missingEntry = await new Entries(cloneDeep(constructorParam)).run();
missingEntryRefs = missingEntry.missingEntryRefs ?? {};
missingSelectFeild = missingEntry.missingSelectFeild ?? {};
Expand All @@ -233,39 +281,47 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma

await this.prepareReport('Entry_Multiple_Fields', missingMultipleFields);
this.getAffectedData('entries', dataModuleWise['entries'], missingEntry);
log.success(`Entries audit completed. Found ${Object.keys(missingEntryRefs || {}).length} reference issues`, this.auditContext);

break;
case 'workflows':
log.info('Executing workflows audit', this.auditContext);
missingCtRefsInWorkflow = await new Workflows({
ctSchema,
log: this.log,
moduleName: module,
config: this.sharedConfig,
fix: this.currentCommand === 'cm:stacks:audit:fix',
}).run();
await this.prepareReport(module, missingCtRefsInWorkflow);
this.getAffectedData('workflows', dataModuleWise['workflows'], missingCtRefsInWorkflow);
log.success(`Workflows audit completed. Found ${Object.keys(missingCtRefsInWorkflow || {}).length} issues`, this.auditContext);

break;
case 'extensions':
log.info('Executing extensions audit', this.auditContext);
missingCtRefsInExtensions = await new Extensions(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingCtRefsInExtensions);
this.getAffectedData('extensions', dataModuleWise['extensions'], missingCtRefsInExtensions);
log.success(`Extensions audit completed. Found ${Object.keys(missingCtRefsInExtensions || {}).length} issues`, this.auditContext);
break;
case 'custom-roles':
log.info('Executing custom-roles audit', this.auditContext);
missingRefInCustomRoles = await new CustomRoles(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingRefInCustomRoles);
this.getAffectedData('custom-roles', dataModuleWise['custom-roles'], missingRefInCustomRoles);
log.success(`Custom-roles audit completed. Found ${Object.keys(missingRefInCustomRoles || {}).length} issues`, this.auditContext);

break;
case 'field-rules':
log.info('Executing field-rules audit', this.auditContext);
// NOTE: We are using the fixed content-type for validation of field rules
const data = this.getCtAndGfSchema();
constructorParam.ctSchema = data.ctSchema;
constructorParam.gfSchema = data.gfSchema;
missingFieldRules = await new FieldRule(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingFieldRules);
this.getAffectedData('field-rules', dataModuleWise['content-types'], missingFieldRules);
log.success(`Field-rules audit completed. Found ${Object.keys(missingFieldRules || {}).length} issues`, this.auditContext);
break;
}

Expand All @@ -283,6 +339,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
]);
}

log.debug('Scan and fix process completed', this.auditContext);
this.prepareReport('Summary', this.summaryDataToPrint);
this.prepareCSV('Summary', this.summaryDataToPrint);
return {
Expand Down Expand Up @@ -376,7 +433,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
*/
showOutputOnScreen(allMissingRefs: { module: string; missingRefs?: Record<string, any> }[]) {
if (this.sharedConfig.showTerminalOutput && !this.flags['external-config']?.noTerminalOutput) {
this.log(''); // NOTE adding new line
cliux.print(''); // NOTE adding new line
for (const { module, missingRefs } of allMissingRefs) {
if (!isEmpty(missingRefs)) {
print([
Expand Down Expand Up @@ -423,7 +480,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
];

cliux.table(tableHeaders, tableValues, { ...(this.flags as TableFlags) });
this.log(''); // NOTE adding new line
cliux.print(''); // NOTE adding new line
}
}
}
Expand All @@ -434,15 +491,15 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
if (!this.sharedConfig.showTerminalOutput || this.flags['external-config']?.noTerminalOutput) {
return;
}
this.log(''); // Adding a new line
cliux.print(''); // Adding a new line

for (let { module, missingRefs } of allMissingRefs) {
if (isEmpty(missingRefs)) {
continue;
}

print([{ bold: true, color: 'cyan', message: ` ${module}` }]);

const tableValues = Object.values(missingRefs).flat();
missingRefs = Object.values(missingRefs).flat();
const tableKeys = Object.keys(missingRefs[0]);
Expand Down Expand Up @@ -471,7 +528,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
}));

cliux.table(tableHeaders, tableValues, { ...(this.flags as TableFlags) });
this.log(''); // Adding a new line
cliux.print(''); // Adding a new line
}
}

Expand All @@ -493,19 +550,29 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
| 'Summary',
listOfMissingRefs: Record<string, any>,
): Promise<void> {
if (isEmpty(listOfMissingRefs)) return Promise.resolve(void 0);
log.debug(`Preparing report for module: ${moduleName}`, this.auditContext);
log.debug(`Report path: ${this.sharedConfig.reportPath}`, this.auditContext);
log.info(`Missing references count: ${Object.keys(listOfMissingRefs).length}`, this.auditContext);

if (isEmpty(listOfMissingRefs)) {
log.debug(`No missing references found for ${moduleName}, skipping report generation`, this.auditContext);
return Promise.resolve(void 0);
}

if (!existsSync(this.sharedConfig.reportPath)) {
log.debug(`Creating report directory: ${this.sharedConfig.reportPath}`, this.auditContext);
mkdirSync(this.sharedConfig.reportPath, { recursive: true });
} else {
log.debug(`Report directory already exists: ${this.sharedConfig.reportPath}`, this.auditContext);
}

// NOTE write int json
writeFileSync(
join(sanitizePath(this.sharedConfig.reportPath), `${sanitizePath(moduleName)}.json`),
JSON.stringify(listOfMissingRefs),
);
const jsonFilePath = join(sanitizePath(this.sharedConfig.reportPath), `${sanitizePath(moduleName)}.json`);
log.debug(`Writing JSON report to: ${jsonFilePath}`, this.auditContext);
writeFileSync(jsonFilePath, JSON.stringify(listOfMissingRefs));

// NOTE write into CSV
log.debug(`Preparing CSV report for: ${moduleName}`, this.auditContext);
return this.prepareCSV(moduleName, listOfMissingRefs);
}

Expand Down
15 changes: 3 additions & 12 deletions packages/contentstack-audit/src/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@ import merge from 'lodash/merge';
import isEmpty from 'lodash/isEmpty';
import { existsSync, readFileSync } from 'fs';
import { Command } from '@contentstack/cli-command';
import { Flags, FlagInput, Interfaces, cliux, ux, PrintOptions } from '@contentstack/cli-utilities';
import { Flags, FlagInput, Interfaces, cliux, ux, handleAndLogError } from '@contentstack/cli-utilities';

import config from './config';
import { Logger } from './util';
import { ConfigType, LogFn, LoggerType } from './types';
import { ConfigType } from './types';
import messages, { $t, commonMsg } from './messages';

export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>;

const noLog = (_message: string | any, _logType?: LoggerType | PrintOptions | undefined) => {};

export abstract class BaseCommand<T extends typeof Command> extends Command {
public log!: LogFn;
public logger!: Logger;
public readonly $t = $t;
protected sharedConfig: ConfigType = {
...config,
Expand Down Expand Up @@ -71,12 +66,8 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {

// Init logger
if (this.flags['external-config']?.noLog) {
this.log = noLog;
ux.action.start = () => {};
ux.action.stop = () => {};
} else {
const logger = new Logger(this.sharedConfig);
this.log = logger.log.bind(logger);
}
}

Expand Down Expand Up @@ -117,7 +108,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
JSON.parse(readFileSync(this.flags.config, { encoding: 'utf-8' })),
);
} catch (error) {
this.log(error, 'error');
handleAndLogError(error);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FlagInput, Flags, ux } from '@contentstack/cli-utilities';
import { FlagInput, Flags, ux, handleAndLogError } from '@contentstack/cli-utilities';

import config from '../../../../config';
import { ConfigType } from '../../../../types';
Expand Down Expand Up @@ -68,8 +68,7 @@ export default class AuditFix extends AuditBaseCommand {
return { config: this.sharedConfig, hasFix };
}
} catch (error) {
this.log(error instanceof Error ? error.message : error, 'error');
console.trace(error);
handleAndLogError(error);
ux.action.stop('Process failed.!');
this.exit(1);
}
Expand Down
Loading
Loading