Skip to content

Commit 194d42f

Browse files
author
naman-contentstack
committed
fix: minor fixes in asset scanning flow
1 parent 8853d0e commit 194d42f

6 files changed

Lines changed: 16 additions & 50 deletions

File tree

.talismanrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fileignoreconfig:
2-
- filename: pnpm-lock.yaml
3-
checksum: 7ec6345eb15ed0be001753ee49733421a8a07096dc8a18465cdad1b82562fed8
2+
- filename: packages/contentstack-import/src/commands/cm/stacks/import.ts
3+
checksum: bbf5ebdec2350c3b6d8118a25046e4e11b68c56434ac6c89be6aaab047a6ac4b
4+
- filename: packages/contentstack-import/src/import/modules/assets.ts
5+
checksum: ce46c32788ea908075873b4dee475bae75975eb58771d0da06a3debb6817bf91
46
version: '1.0'

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +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 {
9-
$t,
10-
messages,
11-
fetchAssets,
12-
scanDataDirStats,
13-
BATCH_CONSTANTS,
14-
categorizeByScanStatus,
15-
fillMissingFlags,
16-
} from '../../../utils';
8+
import { $t, messages, fetchAssets, scanDataDirStats, BATCH_CONSTANTS, categorizeByScanStatus } from '../../../utils';
179
import type { DataDirScanStats } from '../../../utils';
1810
import { AssetService } from '../../../services';
1911

@@ -67,13 +59,6 @@ export default class BulkAssets extends BaseBulkCommand {
6759

6860
protected resourceType: ResourceType = ResourceType.ASSET;
6961

70-
protected async resolveFlagsInteractively(flags: any): Promise<any> {
71-
if (flags['data-dir']) {
72-
return flags;
73-
}
74-
return fillMissingFlags(flags, { promptDataDir: true });
75-
}
76-
7762
async run(): Promise<void> {
7863
try {
7964
if (this.bulkOperationConfig.sourceEnv) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,6 @@ 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-
387382
// Errors
388383
NO_DELIVERY_TOKENS_FOUND:
389384
'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: 9 additions & 25 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, options?: { promptDataDir?: boolean }): Promise<any> {
154+
export async function fillMissingFlags(flags: any): Promise<any> {
155155
const updatedFlags = { ...flags };
156156

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

165+
// The presence of --data-dir is what selects the import-backup publish flow:
166+
// environments and locales are then derived per-asset from the backup, so we
167+
// neither prompt for the data-dir path nor for environments/locales here.
168+
const hasDataDir = !!updatedFlags['data-dir'];
169+
165170
// Check if any required fields are missing
166171
const needsCredentials = !updatedFlags.alias && !updatedFlags['stack-api-key'];
167172
const needsOperation = !updatedFlags.operation;
168-
const needsEnvironments = !updatedFlags.environments || updatedFlags.environments.length === 0;
169173
// Check if non-localized filter is used
170174
const isNonLocalized = updatedFlags.filter === FilterType.NON_LOCALIZED;
171-
const needsLocales = !isNonLocalized && (!updatedFlags.locales || updatedFlags.locales.length === 0);
172-
const needsDataDir = options?.promptDataDir && !updatedFlags['data-dir'];
175+
const needsEnvironments = !hasDataDir && (!updatedFlags.environments || updatedFlags.environments.length === 0);
176+
const needsLocales = !hasDataDir && !isNonLocalized && (!updatedFlags.locales || updatedFlags.locales.length === 0);
173177

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

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-
215199
// 3. Check for cross-publish mode
216200
const isCrossPublish = updatedFlags['source-env'] || updatedFlags['source-alias'];
217201

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export default class ImportCommand extends Command {
162162
if (importConfig.assetScanningEnabled) {
163163
cliux.print('\nAsset Scanning is enabled — assets were not published.', { color: 'yellow' });
164164
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' });
165+
cliux.print(` csdx cm:stacks:bulk-assets --data-dir ${backupDir} --stack-api-key ${importConfig.apiKey} --operation publish`, { color: 'cyan' });
166166
}
167167
this.logSuccessAndBackupMessages(backupDir, importConfig);
168168
// Clear progress module setting now that import is complete

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default class ImportAssets extends BaseClass {
202202
log.info(' Asset Scanning is enabled for this stack.', this.importConfig.context);
203203
log.info(' Assets cannot be published immediately — scanning must complete first.', this.importConfig.context);
204204
log.info(' Once scanning is done, publish your assets using:', this.importConfig.context);
205-
log.info(' csdx cm:stacks:bulk-assets --data-dir ./content --stack-api-key <key>', this.importConfig.context);
205+
log.info(' csdx cm:stacks:bulk-assets --data-dir ./content --stack-api-key <key> --operation publish', this.importConfig.context);
206206
}
207207
} catch (error) {
208208
this.completeProgress(false, error?.message || 'Asset import failed');

0 commit comments

Comments
 (0)