Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: 7ec6345eb15ed0be001753ee49733421a8a07096dc8a18465cdad1b82562fed8
- filename: packages/contentstack-import/src/commands/cm/stacks/import.ts
checksum: bbf5ebdec2350c3b6d8118a25046e4e11b68c56434ac6c89be6aaab047a6ac4b
- filename: packages/contentstack-import/src/import/modules/assets.ts
checksum: ce46c32788ea908075873b4dee475bae75975eb58771d0da06a3debb6817bf91
version: '1.0'
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ import { flags, handleAndLogError, log } from '@contentstack/cli-utilities';

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

Expand Down Expand Up @@ -67,13 +59,6 @@ export default class BulkAssets extends BaseBulkCommand {

protected resourceType: ResourceType = ResourceType.ASSET;

protected async resolveFlagsInteractively(flags: any): Promise<any> {
if (flags['data-dir']) {
return flags;
}
return fillMissingFlags(flags, { promptDataDir: true });
}

async run(): Promise<void> {
try {
if (this.bulkOperationConfig.sourceEnv) {
Expand Down
5 changes: 0 additions & 5 deletions packages/contentstack-bulk-operations/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,6 @@ const interactiveMsg = {
TAXONOMY_UNSUPPORTED_RETRY: 'Retry and revert are not supported for bulk-taxonomies.',
TAXONOMY_UNSUPPORTED_CROSS_PUBLISH: 'Cross-publish is not supported for bulk-taxonomies.',

// Data-dir (backup folder) prompt
USE_DATA_DIR_PROMPT: 'Do you want to publish assets using publish details from an import backup folder (data-dir)?',
ENTER_DATA_DIR: 'Enter the path to the import backup folder (data-dir):',
DATA_DIR_REQUIRED: 'Backup folder path is required',

// Errors
NO_DELIVERY_TOKENS_FOUND:
'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',
Expand Down
34 changes: 9 additions & 25 deletions packages/contentstack-bulk-operations/src/utils/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function promptForSourceAlias(): Promise<string> {
/**
* Fills in missing required flags by prompting the user
*/
export async function fillMissingFlags(flags: any, options?: { promptDataDir?: boolean }): Promise<any> {
export async function fillMissingFlags(flags: any): Promise<any> {
const updatedFlags = { ...flags };

// Skip interactive mode for retry/revert operations
Expand All @@ -162,17 +162,21 @@ export async function fillMissingFlags(flags: any, options?: { promptDataDir?: b
// Track if we prompted for anything
let didPrompt = false;

// The presence of --data-dir is what selects the import-backup publish flow:
// environments and locales are then derived per-asset from the backup, so we
// neither prompt for the data-dir path nor for environments/locales here.
const hasDataDir = !!updatedFlags['data-dir'];

// Check if any required fields are missing
const needsCredentials = !updatedFlags.alias && !updatedFlags['stack-api-key'];
const needsOperation = !updatedFlags.operation;
const needsEnvironments = !updatedFlags.environments || updatedFlags.environments.length === 0;
// Check if non-localized filter is used
const isNonLocalized = updatedFlags.filter === FilterType.NON_LOCALIZED;
const needsLocales = !isNonLocalized && (!updatedFlags.locales || updatedFlags.locales.length === 0);
const needsDataDir = options?.promptDataDir && !updatedFlags['data-dir'];
const needsEnvironments = !hasDataDir && (!updatedFlags.environments || updatedFlags.environments.length === 0);
const needsLocales = !hasDataDir && !isNonLocalized && (!updatedFlags.locales || updatedFlags.locales.length === 0);

// Only show interactive mode header if we need to prompt
if (needsCredentials || needsOperation || needsEnvironments || needsLocales || needsDataDir) {
if (needsCredentials || needsOperation || needsEnvironments || needsLocales) {
cliux.print(messages.INTERACTIVE_MODE_START, { color: 'cyan' });
didPrompt = true;
}
Expand All @@ -192,26 +196,6 @@ export async function fillMissingFlags(flags: any, options?: { promptDataDir?: b
updatedFlags.operation = await promptForOperation();
}

// 2.5. Data-dir (import backup folder) — alternative to environments/locales for asset publish
if (needsDataDir) {
const useDataDir = await cliux.inquire<boolean>({
type: 'confirm',
name: 'useDataDir',
message: messages.USE_DATA_DIR_PROMPT,
default: false,
});
if (useDataDir) {
updatedFlags['data-dir'] = await cliux.inquire<string>({
type: 'input',
name: 'dataDir',
message: messages.ENTER_DATA_DIR,
validate: (v: string) => (!v?.trim() ? messages.DATA_DIR_REQUIRED : true),
});
cliux.print(messages.INTERACTIVE_MODE_COMPLETE, { color: 'green' });
return updatedFlags;
}
}

// 3. Check for cross-publish mode
const isCrossPublish = updatedFlags['source-env'] || updatedFlags['source-alias'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class ImportCommand extends Command {
if (importConfig.assetScanningEnabled) {
cliux.print('\nAsset Scanning is enabled — assets were not published.', { color: 'yellow' });
cliux.print(' Once scanning completes, publish your assets using:', { color: 'yellow' });
cliux.print(` csdx cm:stacks:bulk-assets --data-dir ${backupDir} --stack-api-key ${importConfig.apiKey}`, { color: 'cyan' });
cliux.print(` csdx cm:stacks:bulk-assets --data-dir ${backupDir} --stack-api-key ${importConfig.apiKey} --operation publish`, { color: 'cyan' });
}
this.logSuccessAndBackupMessages(backupDir, importConfig);
// Clear progress module setting now that import is complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class ImportAssets extends BaseClass {
log.info(' Asset Scanning is enabled for this stack.', this.importConfig.context);
log.info(' Assets cannot be published immediately — scanning must complete first.', this.importConfig.context);
log.info(' Once scanning is done, publish your assets using:', this.importConfig.context);
log.info(' csdx cm:stacks:bulk-assets --data-dir ./content --stack-api-key <key>', this.importConfig.context);
log.info(' csdx cm:stacks:bulk-assets --data-dir ./content --stack-api-key <key> --operation publish', this.importConfig.context);
}
} catch (error) {
this.completeProgress(false, error?.message || 'Asset import failed');
Expand Down
Loading