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
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
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default class ExportTaxonomies extends BaseClass {
return;
}

const taxonomiesFilePath = pResolve(this.taxonomiesFolderPath, 'taxonomies.json');
const taxonomiesFilePath = pResolve(this.taxonomiesFolderPath, this.taxonomiesConfig.fileName);
log.debug(`Writing taxonomies metadata to: ${taxonomiesFilePath}`, this.exportConfig.context);
fsUtil.writeFile(taxonomiesFilePath, this.taxonomies);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('EntriesExport', () => {
},
content_types: {
dirName: 'content_types',
fileName: 'schema.json',
fileName: 'content_types.json',
},
personalize: {
baseURL: {
Expand Down
61 changes: 61 additions & 0 deletions packages/contentstack-import/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;
41 changes: 31 additions & 10 deletions packages/contentstack-import/src/import/modules/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { existsSync } from 'node:fs';
import includes from 'lodash/includes';
import { v4 as uuid } from 'uuid';
import { resolve as pResolve, join } from 'node:path';
import { FsUtility, log, handleAndLogError } from '@contentstack/cli-utilities';
import {
FsUtility,
log,
handleAndLogError,
} from '@contentstack/cli-utilities';
import { PATH_CONSTANTS } from '../../constants';

import config from '../../config';
import { ModuleClassParams } from '../../types';
Expand All @@ -36,15 +41,23 @@ export default class ImportAssets extends BaseClass {
this.importConfig.context.module = MODULE_CONTEXTS.ASSETS;
this.currentModuleName = MODULE_NAMES[MODULE_CONTEXTS.ASSETS];

this.assetsPath = join(this.importConfig.backupDir, 'assets');
this.mapperDirPath = join(this.importConfig.backupDir, 'mapper', 'assets');
this.assetUidMapperPath = join(this.mapperDirPath, 'uid-mapping.json');
this.assetUrlMapperPath = join(this.mapperDirPath, 'url-mapping.json');
this.assetFolderUidMapperPath = join(this.mapperDirPath, 'folder-mapping.json');
this.assetsPath = join(this.importConfig.backupDir, PATH_CONSTANTS.CONTENT_DIRS.ASSETS);
this.mapperDirPath = join(
this.importConfig.backupDir,
PATH_CONSTANTS.MAPPER,
PATH_CONSTANTS.MAPPER_MODULES.ASSETS,
);
this.assetUidMapperPath = join(this.mapperDirPath, PATH_CONSTANTS.FILES.UID_MAPPING);
this.assetUrlMapperPath = join(this.mapperDirPath, PATH_CONSTANTS.FILES.URL_MAPPING);
this.assetFolderUidMapperPath = join(this.mapperDirPath, PATH_CONSTANTS.FILES.FOLDER_MAPPING);
this.assetsRootPath = join(this.importConfig.backupDir, this.assetConfig.dirName);
this.fs = new FsUtility({ basePath: this.mapperDirPath });
this.environments = this.fs.readFile(
join(this.importConfig.backupDir, 'environments', 'environments.json'),
join(
this.importConfig.backupDir,
PATH_CONSTANTS.CONTENT_DIRS.ENVIRONMENTS,
PATH_CONSTANTS.FILES.ENVIRONMENTS,
),
true,
) as Record<string, unknown>;
}
Expand Down Expand Up @@ -208,7 +221,9 @@ export default class ImportAssets extends BaseClass {
*/
async importAssets(isVersion = false): Promise<void> {
const processName = isVersion ? 'import versioned assets' : 'import assets';
const indexFileName = isVersion ? 'versioned-assets.json' : 'assets.json';
const indexFileName = isVersion
? PATH_CONSTANTS.FILES.VERSIONED_ASSETS
: this.assetConfig.fileName;
const basePath = isVersion ? join(this.assetsPath, 'versions') : this.assetsPath;
const progressProcessName = isVersion ? PROCESS_NAMES.ASSET_VERSIONS : PROCESS_NAMES.ASSET_UPLOAD;

Expand Down Expand Up @@ -355,7 +370,10 @@ export default class ImportAssets extends BaseClass {
* @returns {Promise<void>} Promise<void>
*/
async publish() {
const fs = new FsUtility({ basePath: this.assetsPath, indexFileName: 'assets.json' });
const fs = new FsUtility({
basePath: this.assetsPath,
indexFileName: this.assetConfig.fileName,
});
if (isEmpty(this.assetsUidMap)) {
log.debug('Loading asset UID mappings from file', this.importConfig.context);
this.assetsUidMap = fs.readFile(this.assetUidMapperPath, true) as any;
Expand Down Expand Up @@ -563,7 +581,10 @@ export default class ImportAssets extends BaseClass {
}

private async countPublishableAssets(): Promise<number> {
const fsUtil = new FsUtility({ basePath: this.assetsPath, indexFileName: 'assets.json' });
const fsUtil = new FsUtility({
basePath: this.assetsPath,
indexFileName: this.assetConfig.fileName,
});
let count = 0;

for (const _ of values(fsUtil.indexFileContent)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
HttpClient,
authenticationHandler,
} from '@contentstack/cli-utilities';
import { PATH_CONSTANTS } from '../../constants';
import isEmpty from 'lodash/isEmpty';

import { fsUtil, fileHelper } from '../../utils';
Expand All @@ -29,9 +30,18 @@ export default class ImportComposableStudio {

// Setup paths
this.composableStudioPath = join(this.importConfig.backupDir, this.composableStudioConfig.dirName);
this.projectMapperPath = join(this.importConfig.backupDir, 'mapper', this.composableStudioConfig.dirName);
this.projectMapperPath = join(
this.importConfig.backupDir,
PATH_CONSTANTS.MAPPER,
this.composableStudioConfig.dirName,
);
this.composableStudioFilePath = join(this.composableStudioPath, this.composableStudioConfig.fileName);
this.envUidMapperPath = join(this.importConfig.backupDir, 'mapper', 'environments', 'uid-mapping.json');
this.envUidMapperPath = join(
this.importConfig.backupDir,
PATH_CONSTANTS.MAPPER,
PATH_CONSTANTS.MAPPER_MODULES.ENVIRONMENTS,
PATH_CONSTANTS.FILES.UID_MAPPING,
);
this.envUidMapper = {};

// Initialize HttpClient with Studio API base URL
Expand Down
Loading
Loading