Skip to content

Commit fc472c8

Browse files
Merge pull request #282 from contentstack/fix/DX-9308
fix: Update flags in AssetsPublishCommand and add user reminder in ImportCommand for asset publishing
2 parents 2d575c1 + 1a2732c commit fc472c8

4 files changed

Lines changed: 38 additions & 21 deletions

File tree

packages/contentstack-bulk-publish/src/commands/cm/assets/publish.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class AssetsPublishCommand extends Command {
1515
assetsFlags.folderUid = assetsFlags['folder-uid'] || assetsFlags.folderUid;
1616
assetsFlags.bulkPublish = assetsFlags['bulk-publish'] || assetsFlags.bulkPublish;
1717
assetsFlags.apiVersion = assetsFlags['api-version'] || '3'; // setting default value for apiVersion
18-
assetsFlags.dataDir = assetsFlags['data-dir'] || assetsFlags.dataDir;
18+
assetsFlags.backupDir = assetsFlags['backup-dir'] || assetsFlags.backupDir;
1919
delete assetsFlags['api-version'];
2020
delete assetsFlags['retry-failed'];
2121
delete assetsFlags['folder-uid'];
2222
delete assetsFlags['bulk-publish'];
23-
delete assetsFlags['data-dir'];
23+
delete assetsFlags['backup-dir'];
2424

2525
let updatedFlags;
2626
try {
@@ -113,15 +113,15 @@ class AssetsPublishCommand extends Command {
113113
}
114114
}
115115

116-
validate({ environments, retryFailed, locales, dataDir, 'source-env': sourceEnv, 'delivery-token': deliveryToken }) {
116+
validate({ environments, retryFailed, locales, backupDir, 'source-env': sourceEnv, 'delivery-token': deliveryToken }) {
117117
let missing = [];
118118
if (retryFailed) {
119119
return true;
120120
}
121121

122-
// In data-dir mode, environments and locales are derived per-asset from the
122+
// In backup-dir mode, environments and locales are derived per-asset from the
123123
// backup publish_details, so they are not required on the command line.
124-
if (dataDir) {
124+
if (backupDir) {
125125
return true;
126126
}
127127

@@ -189,10 +189,10 @@ AssetsPublishCommand.flags = {
189189
'(optional) The UID of the Assets’ folder from which the assets need to be published. The default value is cs_root.',
190190
exclusive: ['source-env'],
191191
}),
192-
'data-dir': flags.string({
192+
'backup-dir': flags.string({
193193
description:
194194
'(optional) Path to the import backup directory. When set, each imported asset is published only to the environments and locales it was published to in the source stack (read from the backup’s publish details and asset UID mapping), with asset-scan gating applied. Intended for the post-import publish flow.',
195-
exclusive: ['source-env', 'folder-uid'],
195+
exclusive: ['source-env', 'folder-uid', 'environments', 'locales'],
196196
}),
197197
'bulk-publish': flags.string({
198198
description: 'Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by default.',
@@ -273,13 +273,13 @@ AssetsPublishCommand.examples = [
273273
'Using --stack-api-key flag',
274274
'csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY]',
275275
'',
276-
'Using --data-dir flag (publish imported assets to their original environments after asset scanning)',
277-
'csdx cm:assets:publish --data-dir [PATH TO IMPORT BACKUP DIR] --stack-api-key [STACK API KEY]',
276+
'Using --backup-dir flag (publish imported assets to their original environments after asset scanning)',
277+
'csdx cm:assets:publish --backup-dir [PATH TO IMPORT BACKUP DIR] --stack-api-key [STACK API KEY]',
278278
];
279279

280280
AssetsPublishCommand.aliases = ['cm:bulk-publish:assets'];
281281

282282
AssetsPublishCommand.usage =
283-
'cm:assets:publish [-a <value>] [--retry-failed <value>] [-e <value>] [--folder-uid <value>] [--data-dir <value>] [--bulk-publish <value>] [-c <value>] [-y] [--locales <value>] [--branch <value>] [--delivery-token <value>] [--source-env <value>]';
283+
'cm:assets:publish [-a <value>] [--retry-failed <value>] [-e <value>] [--folder-uid <value>] [--backup-dir <value>] [--bulk-publish <value>] [-c <value>] [-y] [--locales <value>] [--branch <value>] [--delivery-token <value>] [--source-env <value>]';
284284

285285
module.exports = AssetsPublishCommand;

packages/contentstack-bulk-publish/src/consumer/publish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ function displayEntriesDetails(sanitizedData, action, mapping = []) {
6161
function displayAssetsDetails(sanitizedData, action, mapping) {
6262
if (action === 'bulk_publish') {
6363
sanitizedData.forEach((asset) => {
64-
asset?.publish_details.forEach((pd) => {
64+
asset?.publish_details?.forEach((pd) => {
6565
if (Object.keys(mapping).includes(pd.environment)) {
6666
console.log(
6767
chalk.green(
6868
`Asset UID: '${asset.uid}'${pd.version ? `, Version: '${pd.version}'` : ''}${
69-
asset.locale ? `, Locale: '${asset.locale}'` : ''
69+
asset.locale ? `, Locale: '${asset.locale}'` : ''}
7070
}, Environment: ${pd.environment}`,
7171
),
7272
);

packages/contentstack-bulk-publish/src/producer/publish-assets.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,16 @@ async function processPendingAssets(pendingItems, stack, bulkPublish, environmen
256256
* subset). The single in-memory floor is the asset uid-mapping file itself (same
257257
* as import's publish()); for very large stacks raise Node's --max-old-space-size.
258258
*/
259-
async function getAssetsFromBackup(stack, dataDir, bulkPublish, apiVersion, bulkPublishLimit) {
260-
const assetsPath = path.join(dataDir, 'assets');
259+
async function getAssetsFromBackup(stack, backupDir, bulkPublish, apiVersion, bulkPublishLimit) {
260+
const assetsPath = path.join(backupDir, 'assets');
261261
const assetsIndexPath = path.join(assetsPath, 'assets.json');
262-
const assetUidMapperPath = path.join(dataDir, 'mapper', 'assets', 'uid-mapping.json');
263-
const envUidMapperPath = path.join(dataDir, 'mapper', 'environments', 'uid-mapping.json');
264-
const environmentsPath = path.join(dataDir, 'environments', 'environments.json');
262+
const assetUidMapperPath = path.join(backupDir, 'mapper', 'assets', 'uid-mapping.json');
263+
const envUidMapperPath = path.join(backupDir, 'mapper', 'environments', 'uid-mapping.json');
264+
const environmentsPath = path.join(backupDir, 'environments', 'environments.json');
265265

266266
// A backup with no assets is a legitimate outcome of a successful import that
267267
// had 0 assets (assets.json is never produced) — exit cleanly, not as a crash.
268-
// A genuinely wrong --data-dir surfaces via the uid-mapping/environments guards below.
268+
// A genuinely wrong --backup-dir surfaces via the uid-mapping/environments guards below.
269269
if (!existsSync(assetsPath) || !existsSync(assetsIndexPath)) {
270270
console.log(chalk.yellow('No assets found in backup — nothing to publish.'));
271271
return;
@@ -457,7 +457,7 @@ function setConfig(conf, bp) {
457457
scanSummary = { clean: 0, quarantined: 0, inQueue: 0, noStatus: 0 };
458458
}
459459

460-
async function start({ retryFailed, bulkPublish, environments, folderUid, locales, apiVersion, dataDir }, stack, config) {
460+
async function start({ retryFailed, bulkPublish, environments, folderUid, locales, apiVersion, backupDir }, stack, config) {
461461
process.on('beforeExit', async () => {
462462
// Print the scan summary here (not inline after enqueueing):
463463
printScanSummary(scanSummary);
@@ -498,12 +498,12 @@ async function start({ retryFailed, bulkPublish, environments, folderUid, locale
498498
} else {
499499
await retryFailedLogs(retryFailed, { assetQueue: queue }, 'publish');
500500
}
501-
} else if (dataDir) {
501+
} else if (backupDir) {
502502
// Post-import flow: publish each imported asset only to its original
503503
// environments/locales (from backup publish_details), scan-gated.
504504
setConfig(config, bulkPublish);
505505
const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid);
506-
await getAssetsFromBackup(stack, dataDir, bulkPublish, apiVersion, bulkPublishLimit);
506+
await getAssetsFromBackup(stack, backupDir, bulkPublish, apiVersion, bulkPublishLimit);
507507
} else if (folderUid) {
508508
setConfig(config, bulkPublish);
509509
const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ export default class ImportCommand extends Command {
187187

188188
log.success(`The log has been stored at: ${getLogPath()}`, importConfig.context);
189189
log.info(`The backup content has been stored at: ${backupDir}`, importConfig.context);
190+
191+
// Closing reminder: when assets were imported but not published inline
192+
// (asset scanning enabled, or --skip-assets-publish), point the user to
193+
// cm:assets:publish with the backup dir and stack pre-filled so the note
194+
// isn't lost in the per-module logs above.
195+
const assetsImported = importConfig.moduleName
196+
? importConfig.moduleName === 'assets'
197+
: importConfig.modules?.types?.includes('assets');
198+
// Mirror the publish gate in assets.ts (`!skipAssetsPublish`): assets are
199+
// left unpublished exactly when skipAssetsPublish is set — which also
200+
// covers the scanning case, since detecting scanning sets skipAssetsPublish.
201+
if (!result?.noSuccessMsg && assetsImported && importConfig.skipAssetsPublish) {
202+
log.info(
203+
`Note: assets were imported but not published asset scanning is enabled and must complete first. To publish them, run:\n csdx cm:assets:publish --backup-dir ${backupDir} --stack-api-key ${importConfig.apiKey}`,
204+
importConfig.context,
205+
);
206+
}
190207
} catch (error) {
191208
handleAndLogError(error);
192209
log.info(`The log has been stored at '${getLogPath()}'`);

0 commit comments

Comments
 (0)