Skip to content

Commit 33bd17a

Browse files
author
naman-contentstack
committed
feat: enhance bulk asset operations with data-dir support and user prompts
1 parent fbe694a commit 33bd17a

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

packages/contentstack-bulk-operations/src/commands/cm/stacks/bulk-assets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { flags, handleAndLogError, log } from '@contentstack/cli-utilities';
55

66
import { AssetPublishData, BulkOperationResult, OperationType, ResourceType } from '../../../interfaces';
77
import { BaseBulkCommand } from '../../../base-bulk-command';
8-
import { $t, messages, fetchAssets, scanDataDirStats, BATCH_CONSTANTS, categorizeByScanStatus } from '../../../utils';
8+
import { $t, messages, fetchAssets, scanDataDirStats, BATCH_CONSTANTS, categorizeByScanStatus, fillMissingFlags } from '../../../utils';
99
import type { DataDirScanStats } from '../../../utils';
1010
import { AssetService } from '../../../services';
1111

@@ -63,7 +63,7 @@ export default class BulkAssets extends BaseBulkCommand {
6363
if (flags['data-dir']) {
6464
return flags;
6565
}
66-
return super.resolveFlagsInteractively(flags);
66+
return fillMissingFlags(flags, { promptDataDir: true });
6767
}
6868

6969
async run(): Promise<void> {

packages/contentstack-bulk-operations/src/messages/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ const interactiveMsg = {
379379
TAXONOMY_UNSUPPORTED_RETRY: 'Retry and revert are not supported for bulk-taxonomies.',
380380
TAXONOMY_UNSUPPORTED_CROSS_PUBLISH: 'Cross-publish is not supported for bulk-taxonomies.',
381381

382+
// Data-dir (backup folder) prompt
383+
USE_DATA_DIR_PROMPT: 'Do you want to publish assets using publish details from an import backup folder (data-dir)?',
384+
ENTER_DATA_DIR: 'Enter the path to the import backup folder (data-dir):',
385+
DATA_DIR_REQUIRED: 'Backup folder path is required',
386+
382387
// Errors
383388
NO_DELIVERY_TOKENS_FOUND:
384389
'No delivery token aliases found. Add one using: csdx auth:tokens:add -a <alias> --delivery-token <token> --api-key <api-key> --environment <source-env> --type delivery',

packages/contentstack-bulk-operations/src/utils/interactive.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async function promptForSourceAlias(): Promise<string> {
151151
/**
152152
* Fills in missing required flags by prompting the user
153153
*/
154-
export async function fillMissingFlags(flags: any): Promise<any> {
154+
export async function fillMissingFlags(flags: any, options?: { promptDataDir?: boolean }): Promise<any> {
155155
const updatedFlags = { ...flags };
156156

157157
// Skip interactive mode for retry/revert operations
@@ -169,9 +169,10 @@ export async function fillMissingFlags(flags: any): Promise<any> {
169169
// Check if non-localized filter is used
170170
const isNonLocalized = updatedFlags.filter === FilterType.NON_LOCALIZED;
171171
const needsLocales = !isNonLocalized && (!updatedFlags.locales || updatedFlags.locales.length === 0);
172+
const needsDataDir = options?.promptDataDir && !updatedFlags['data-dir'];
172173

173174
// Only show interactive mode header if we need to prompt
174-
if (needsCredentials || needsOperation || needsEnvironments || needsLocales) {
175+
if (needsCredentials || needsOperation || needsEnvironments || needsLocales || needsDataDir) {
175176
cliux.print(messages.INTERACTIVE_MODE_START, { color: 'cyan' });
176177
didPrompt = true;
177178
}
@@ -191,6 +192,26 @@ export async function fillMissingFlags(flags: any): Promise<any> {
191192
updatedFlags.operation = await promptForOperation();
192193
}
193194

195+
// 2.5. Data-dir (import backup folder) — alternative to environments/locales for asset publish
196+
if (needsDataDir) {
197+
const useDataDir = await cliux.inquire<boolean>({
198+
type: 'confirm',
199+
name: 'useDataDir',
200+
message: messages.USE_DATA_DIR_PROMPT,
201+
default: false,
202+
});
203+
if (useDataDir) {
204+
updatedFlags['data-dir'] = await cliux.inquire<string>({
205+
type: 'input',
206+
name: 'dataDir',
207+
message: messages.ENTER_DATA_DIR,
208+
validate: (v: string) => (!v?.trim() ? messages.DATA_DIR_REQUIRED : true),
209+
});
210+
cliux.print(messages.INTERACTIVE_MODE_COMPLETE, { color: 'green' });
211+
return updatedFlags;
212+
}
213+
}
214+
194215
// 3. Check for cross-publish mode
195216
const isCrossPublish = updatedFlags['source-env'] || updatedFlags['source-alias'];
196217

packages/contentstack-import/src/commands/cm/stacks/import.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ export default class ImportCommand extends Command {
159159
backupDir = importConfig.backupDir;
160160
//Note: Final summary is now handled by summary manager
161161
CLIProgressManager.printGlobalSummary();
162+
if (importConfig.assetScanningEnabled) {
163+
cliux.print('\nAsset Scanning is enabled — assets were not published.', { color: 'yellow' });
164+
cliux.print(' Once scanning completes, publish your assets using:', { color: 'yellow' });
165+
cliux.print(` csdx cm:stacks:bulk-assets --data-dir ${backupDir} --stack-api-key ${importConfig.apiKey}`, { color: 'cyan' });
166+
}
162167
this.logSuccessAndBackupMessages(backupDir, importConfig);
163168
// Clear progress module setting now that import is complete
164169
clearProgressModuleSetting();

0 commit comments

Comments
 (0)