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
2 changes: 1 addition & 1 deletion packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma

// Extract logConfig and showConsoleLogs once before the loop to reuse throughout
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? true;
const showConsoleLogs = logConfig.showConsoleLogs ?? false;

for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
// Update audit context with current module
Expand Down
10 changes: 6 additions & 4 deletions packages/contentstack-export/src/commands/cm/stacks/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
configHandler,
log,
handleAndLogError,
getLogPath,
getSessionLogPath,
CLIProgressManager,
clearProgressModuleSetting,
} from '@contentstack/cli-utilities';
Expand Down Expand Up @@ -102,26 +102,28 @@ export default class ExportCommand extends Command {
const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig);
const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig);
await moduleExporter.start();
const sessionLogPath = getSessionLogPath();
log.success(
`The content of the stack ${exportConfig.apiKey} has been exported successfully!`,
);
log.info(`The exported content has been stored at '${exportDir}'`, exportConfig.context);
log.success(`The log has been stored at '${getLogPath()}'`, exportConfig.context);
log.success(`The log has been stored at '${sessionLogPath}'`, exportConfig.context);

// Print comprehensive summary at the end
if (!exportConfig.branches) CLIProgressManager.printGlobalSummary();
if (!configHandler.get('log')?.showConsoleLogs) {
cliux.print(`The log has been stored at '${getLogPath()}'`, { color: 'green' });
cliux.print(`The log has been stored at '${sessionLogPath}'`, { color: 'green' });
}
// Clear progress module setting now that export is complete
clearProgressModuleSetting();
} catch (error) {
// Clear progress module setting even on error
clearProgressModuleSetting();
handleAndLogError(error);
const sessionLogPath = getSessionLogPath();
if (!configHandler.get('log')?.showConsoleLogs) {
cliux.print(`Error: ${error}`, { color: 'red' });
cliux.print(`The log has been stored at '${getLogPath()}'`, { color: 'green' });
cliux.print(`The log has been stored at '${sessionLogPath}'`, { color: 'green' });
}
}
}
Expand Down
61 changes: 61 additions & 0 deletions packages/contentstack-export/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export const PATH_CONSTANTS = {
/** Root mapper directory (contains module-specific mapper subdirs) */
MAPPER: 'mapper',

/** Common mapper file names */
FILES: {
SUCCESS: 'success.json',
FAILS: 'fails.json',
UID_MAPPING: 'uid-mapping.json',
URL_MAPPING: 'url-mapping.json',
UID_MAPPER: 'uid-mapper.json',
SCHEMA: 'schema.json',
SETTINGS: 'settings.json',
MODIFIED_SCHEMAS: 'modified-schemas.json',
UNIQUE_MAPPING: 'unique-mapping.json',
TAXONOMIES: 'taxonomies.json',
ENVIRONMENTS: 'environments.json',
PENDING_EXTENSIONS: 'pending_extensions.js',
PENDING_GLOBAL_FIELDS: 'pending_global_fields.js',
INDEX: 'index.json',
FOLDER_MAPPING: 'folder-mapping.json',
VERSIONED_ASSETS: 'versioned-assets.json',
},

/** Module subdirectory names within mapper */
MAPPER_MODULES: {
ASSETS: 'assets',
ENTRIES: 'entries',
CONTENT_TYPES: 'content_types',
TAXONOMIES: 'taxonomies',
TAXONOMY_TERMS: 'terms',
GLOBAL_FIELDS: 'global_fields',
EXTENSIONS: 'extensions',
WORKFLOWS: 'workflows',
WEBHOOKS: 'webhooks',
LABELS: 'labels',
ENVIRONMENTS: 'environments',
MARKETPLACE_APPS: 'marketplace_apps',
CUSTOM_ROLES: 'custom-roles',
LANGUAGES: 'languages',
},

/** Content directory names (used in both import and export) */
CONTENT_DIRS: {
ASSETS: 'assets',
ENTRIES: 'entries',
CONTENT_TYPES: 'content_types',
TAXONOMIES: 'taxonomies',
GLOBAL_FIELDS: 'global_fields',
EXTENSIONS: 'extensions',
WEBHOOKS: 'webhooks',
WORKFLOWS: 'workflows',
LABELS: 'labels',
ENVIRONMENTS: 'environments',
STACK: 'stack',
LOCALES: 'locales',
MARKETPLACE_APPS: 'marketplace_apps',
},
} as const;

export type PathConstants = typeof PATH_CONSTANTS;
5 changes: 3 additions & 2 deletions packages/contentstack-export/src/export/modules/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
handleAndLogError,
messageHandler,
} from '@contentstack/cli-utilities';
import { PATH_CONSTANTS } from '../../constants';

import config from '../../config';
import { ModuleClassParams } from '../../types';
Expand Down Expand Up @@ -242,7 +243,7 @@ export default class ExportAssets extends BaseClass {
fs = new FsUtility({
metaHandler,
moduleName: 'assets',
indexFileName: 'assets.json',
indexFileName: this.assetConfig.fileName,
basePath: this.assetsRootPath,
chunkFileSize: this.assetConfig.chunkFileSize,
metaPickKeys: merge(['uid', 'url', 'filename', 'parent_uid'], this.assetConfig.assetsMetaKeys),
Expand Down Expand Up @@ -326,7 +327,7 @@ export default class ExportAssets extends BaseClass {
if (!fs && !isEmpty(response)) {
fs = new FsUtility({
moduleName: 'assets',
indexFileName: 'versioned-assets.json',
indexFileName: PATH_CONSTANTS.FILES.VERSIONED_ASSETS,
chunkFileSize: this.assetConfig.chunkFileSize,
basePath: pResolve(this.assetsRootPath, 'versions'),
metaPickKeys: merge(['uid', 'url', 'filename', '_version', 'parent_uid'], this.assetConfig.assetsMetaKeys),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chunk from 'lodash/chunk';
import isEmpty from 'lodash/isEmpty';
import entries from 'lodash/entries';
import isEqual from 'lodash/isEqual';
import { log, CLIProgressManager, configHandler } from '@contentstack/cli-utilities';
import { log, CLIProgressManager, configHandler, getSessionLogPath } from '@contentstack/cli-utilities';

import { ExportConfig, ModuleClassParams } from '../../types';

Expand Down Expand Up @@ -109,7 +109,7 @@ export default abstract class BaseClass {
* - moduleName: The module name to generate the message (e.g., 'Assets', 'Entries')
* If not provided, uses this.currentModuleName
* - customSuccessMessage: Optional custom success message. If not provided, generates: "{moduleName} have been exported successfully!"
* - customWarningMessage: Optional custom warning message. If not provided, generates: "{moduleName} have been exported with some errors. Please check the logs for details."
* - customWarningMessage: Optional custom warning message. If not provided, generates: "{moduleName} have been exported with some errors. Please check the logs at: {sessionLogPath}"
* - context: Optional context for logging
*/
protected completeProgressWithMessage(options?: CompleteProgressOptions): void {
Expand All @@ -120,7 +120,8 @@ export default abstract class BaseClass {

// Generate default messages if not provided
const successMessage = options?.customSuccessMessage || `${name} have been exported successfully!`;
const warningMessage = options?.customWarningMessage || `${name} have been exported with some errors. Please check the logs for details.`;
const sessionLogPath = getSessionLogPath();
const warningMessage = options?.customWarningMessage || `${name} have been exported with some errors. Please check the logs at: ${sessionLogPath}`;

this.completeProgress(true);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as path from 'path';
import { ContentstackClient, handleAndLogError, messageHandler, log, sanitizePath } from '@contentstack/cli-utilities';
import {
ContentstackClient,
handleAndLogError,
messageHandler,
log,
sanitizePath,
} from '@contentstack/cli-utilities';
import { PATH_CONSTANTS } from '../../constants';

import BaseClass from './base-class';
import { ExportConfig, ModuleClassParams } from '../../types';
Expand Down Expand Up @@ -156,7 +163,7 @@ export default class ContentTypesExport extends BaseClass {
concurrency: this.exportConfig.writeConcurrency,
});

const schemaFilePath = path.join(this.contentTypesDirPath, 'schema.json');
const schemaFilePath = path.join(this.contentTypesDirPath, PATH_CONSTANTS.FILES.SCHEMA);
log.debug(`Writing aggregate schema to: ${schemaFilePath}`, this.exportConfig.context);

return fsUtil.writeFile(schemaFilePath, contentTypes);
Expand Down
15 changes: 11 additions & 4 deletions packages/contentstack-export/src/export/modules/entries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import * as path from 'path';
import { ContentstackClient, FsUtility, handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
import {
ContentstackClient,
FsUtility,
handleAndLogError,
messageHandler,
log,
sanitizePath,
} from '@contentstack/cli-utilities';
import { PATH_CONSTANTS } from '../../constants';
import { Export, ExportProjects } from '@contentstack/cli-variants';
import { sanitizePath } from '@contentstack/cli-utilities';

import {
fsUtil,
Expand Down Expand Up @@ -55,7 +62,7 @@ export default class EntriesExport extends BaseClass {
sanitizePath(exportConfig.exportDir),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(exportConfig.modules.content_types.dirName),
'schema.json',
PATH_CONSTANTS.FILES.SCHEMA,
);
this.projectInstance = new ExportProjects(this.exportConfig);
this.exportConfig.context.module = MODULE_CONTEXTS.ENTRIES;
Expand Down Expand Up @@ -313,7 +320,7 @@ export default class EntriesExport extends BaseClass {
await fsUtil.makeDirectory(entryBasePath);
this.entriesFileHelper = new FsUtility({
moduleName: 'entries',
indexFileName: 'index.json',
indexFileName: PATH_CONSTANTS.FILES.INDEX,
basePath: entryBasePath,
chunkFileSize: this.entriesConfig.chunkFileSize,
keepMetadata: false,
Expand Down
10 changes: 8 additions & 2 deletions packages/contentstack-export/src/export/modules/stack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import find from 'lodash/find';
import { resolve as pResolve } from 'node:path';
import { handleAndLogError, isAuthenticated, managementSDKClient, log } from '@contentstack/cli-utilities';
import {
handleAndLogError,
isAuthenticated,
managementSDKClient,
log,
} from '@contentstack/cli-utilities';
import { PATH_CONSTANTS } from '../../constants';

import BaseClass from './base-class';
import {
Expand Down Expand Up @@ -265,7 +271,7 @@ export default class ExportStack extends BaseClass {
return this.stack
.settings()
.then((resp: any) => {
fsUtil.writeFile(pResolve(this.stackFolderPath, 'settings.json'), resp);
fsUtil.writeFile(pResolve(this.stackFolderPath, PATH_CONSTANTS.FILES.SETTINGS), resp);

// Track progress for stack settings completion
this.progressManager?.tick(true, 'stack settings', null, PROCESS_NAMES.STACK_SETTINGS);
Expand Down
Loading
Loading