@@ -20,11 +20,12 @@ import {
2020 handleAndLogError ,
2121 messageHandler ,
2222 CLIProgressManager ,
23+ FEATURE ,
2324} from '@contentstack/cli-utilities' ;
2425import { PATH_CONSTANTS } from '../../constants' ;
2526
2627import config from '../../config' ;
27- import { ModuleClassParams } from '../../types' ;
28+ import { ModuleClassParams , GlobalSummary } from '../../types' ;
2829import BaseClass , { CustomPromiseHandler , CustomPromiseHandlerInput } from './base-class' ;
2930import { ExportSpaces , type AssetExportCounts } from '@contentstack/cli-asset-management' ;
3031import {
@@ -57,31 +58,31 @@ export default class ExportAssets extends BaseClass {
5758 } ;
5859 }
5960
60- /**
61- * Bug 3 — push real CS Assets entity counts into the final EXPORT summary: override the ASSETS
62- * module to count downloaded binaries only, and add dedicated ASSET TYPES / FIELDS / FOLDERS rows.
63- * Drives the global summary directly (no cli-utilities change); the live multibar is unaffected.
64- * The ASSETS strategy is set to Default so applyStrategyCorrections does not overwrite these.
65- */
66- private applyAssetSummaryCounts ( counts : AssetExportCounts ) : void {
67- type SummaryModule = { successCount : number ; failureCount : number } ;
68- type GlobalSummary = {
69- getModules ( ) : Map < string , SummaryModule > ;
70- registerModule ( name : string , totalItems ?: number ) : void ;
71- startModule ( name : string ) : void ;
72- completeModule ( name : string , success ?: boolean ) : void ;
73- } ;
74- // globalSummary is runtime-accessible but typed private; reach it via a structural cast.
61+ // globalSummary is runtime-accessible but typed private; feature-detect the shape and return null
62+ // so callers degrade instead of throwing if a future cli-utilities version changes it.
63+ private getGlobalSummary ( ) : GlobalSummary | null {
7564 const gs = ( CLIProgressManager as unknown as { globalSummary ?: GlobalSummary | null } ) . globalSummary ;
76- // We reach into cli-utilities' summary internals, so feature-detect the shape and DEGRADE
77- // (skip the count overrides) instead of throwing if a future version changes it.
7865 if (
7966 ! gs ||
8067 typeof gs . getModules !== 'function' ||
8168 typeof gs . registerModule !== 'function' ||
8269 typeof gs . startModule !== 'function' ||
8370 typeof gs . completeModule !== 'function'
8471 ) {
72+ return null ;
73+ }
74+ return gs ;
75+ }
76+
77+ /**
78+ * Bug 3 — push real CS Assets entity counts into the final EXPORT summary: override the ASSETS
79+ * module to count downloaded binaries only, and add dedicated ASSET TYPES / FIELDS / FOLDERS rows.
80+ * Drives the global summary directly (no cli-utilities change); the live multibar is unaffected.
81+ * The ASSETS strategy is set to Default so applyStrategyCorrections does not overwrite these.
82+ */
83+ private applyAssetSummaryCounts ( counts : AssetExportCounts ) : void {
84+ const gs = this . getGlobalSummary ( ) ;
85+ if ( ! gs ) {
8586 log . debug ( 'Global summary shape unavailable; skipping CS Assets summary count overrides' , this . exportConfig . context ) ;
8687 return ;
8788 }
@@ -116,7 +117,42 @@ export default class ExportAssets extends BaseClass {
116117 }
117118 }
118119
120+ // Records the skip in the final summary via the failure channel, which is the only per-module
121+ // slot carrying a message. createNestedProgress is intentionally not used: it would render an
122+ // empty "ASSETS:" live section.
123+ private markAssetsSkippedInSummary ( reason : string ) : void {
124+ const gs = this . getGlobalSummary ( ) ;
125+ if ( ! gs ) {
126+ log . debug ( 'Global summary shape unavailable; skipping ASSETS skip row' , this . exportConfig . context ) ;
127+ return ;
128+ }
129+
130+ try {
131+ const name = this . currentModuleName . toUpperCase ( ) ;
132+ gs . registerModule ( name ) ;
133+ gs . startModule ( name ) ;
134+ const module = gs . getModules ( ) . get ( name ) ;
135+ if ( module ) {
136+ module . failures . push ( { item : reason , error : reason } ) ;
137+ module . status = 'failed' ;
138+ module . endTime = Date . now ( ) ;
139+ }
140+ } catch ( e ) {
141+ log . debug ( `Failed to mark ASSETS as skipped in summary: ${ e } ` , this . exportConfig . context ) ;
142+ }
143+ }
144+
119145 async start ( ) : Promise < void > {
146+ const csAssetsInPlan = this . exportConfig . planStatus ?. [ FEATURE . ASSET_MANAGEMENT ] ?. is_part_of_plan ;
147+ if ( csAssetsInPlan && this . exportConfig . management_token ) {
148+ const warning =
149+ 'Skipping Contentstack Assets export: management token authentication is not supported by the Assets APIs. ' +
150+ 'Entry-to-asset references will NOT resolve in the exported content. ' +
151+ 'Re-run the export with a logged-in session (auth token or OAuth) to export Contentstack Assets.' ;
152+ this . markAssetsSkippedInSummary ( warning ) ;
153+ return ;
154+ }
155+
120156 const linkedWorkspaces = this . exportConfig . linkedWorkspaces ?? [ ] ;
121157
122158 if ( linkedWorkspaces . length > 0 ) {
0 commit comments