Skip to content

Commit fa5b7d7

Browse files
committed
fix: taxonomy import & entries publishing issue
1 parent f6085ac commit fa5b7d7

31 files changed

Lines changed: 763 additions & 271 deletions

packages/contentstack-audit/src/audit-base-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
237237

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

242242
for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
243243
// Update audit context with current module
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
export const PATH_CONSTANTS = {
2+
/** Root mapper directory (contains module-specific mapper subdirs) */
3+
MAPPER: 'mapper',
4+
5+
/** Common mapper file names */
6+
FILES: {
7+
SUCCESS: 'success.json',
8+
FAILS: 'fails.json',
9+
UID_MAPPING: 'uid-mapping.json',
10+
URL_MAPPING: 'url-mapping.json',
11+
UID_MAPPER: 'uid-mapper.json',
12+
SCHEMA: 'schema.json',
13+
SETTINGS: 'settings.json',
14+
MODIFIED_SCHEMAS: 'modified-schemas.json',
15+
UNIQUE_MAPPING: 'unique-mapping.json',
16+
TAXONOMIES: 'taxonomies.json',
17+
ENVIRONMENTS: 'environments.json',
18+
PENDING_EXTENSIONS: 'pending_extensions.js',
19+
PENDING_GLOBAL_FIELDS: 'pending_global_fields.js',
20+
INDEX: 'index.json',
21+
FOLDER_MAPPING: 'folder-mapping.json',
22+
VERSIONED_ASSETS: 'versioned-assets.json',
23+
},
24+
25+
/** Module subdirectory names within mapper */
26+
MAPPER_MODULES: {
27+
ASSETS: 'assets',
28+
ENTRIES: 'entries',
29+
CONTENT_TYPES: 'content_types',
30+
TAXONOMIES: 'taxonomies',
31+
TAXONOMY_TERMS: 'terms',
32+
GLOBAL_FIELDS: 'global_fields',
33+
EXTENSIONS: 'extensions',
34+
WORKFLOWS: 'workflows',
35+
WEBHOOKS: 'webhooks',
36+
LABELS: 'labels',
37+
ENVIRONMENTS: 'environments',
38+
MARKETPLACE_APPS: 'marketplace_apps',
39+
CUSTOM_ROLES: 'custom-roles',
40+
LANGUAGES: 'languages',
41+
},
42+
43+
/** Content directory names (used in both import and export) */
44+
CONTENT_DIRS: {
45+
ASSETS: 'assets',
46+
ENTRIES: 'entries',
47+
CONTENT_TYPES: 'content_types',
48+
TAXONOMIES: 'taxonomies',
49+
GLOBAL_FIELDS: 'global_fields',
50+
EXTENSIONS: 'extensions',
51+
WEBHOOKS: 'webhooks',
52+
WORKFLOWS: 'workflows',
53+
LABELS: 'labels',
54+
ENVIRONMENTS: 'environments',
55+
STACK: 'stack',
56+
LOCALES: 'locales',
57+
MARKETPLACE_APPS: 'marketplace_apps',
58+
},
59+
} as const;
60+
61+
export type PathConstants = typeof PATH_CONSTANTS;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
handleAndLogError,
2121
messageHandler,
2222
} from '@contentstack/cli-utilities';
23+
import { PATH_CONSTANTS } from '../../constants';
2324

2425
import config from '../../config';
2526
import { ModuleClassParams } from '../../types';
@@ -242,7 +243,7 @@ export default class ExportAssets extends BaseClass {
242243
fs = new FsUtility({
243244
metaHandler,
244245
moduleName: 'assets',
245-
indexFileName: 'assets.json',
246+
indexFileName: this.assetConfig.fileName,
246247
basePath: this.assetsRootPath,
247248
chunkFileSize: this.assetConfig.chunkFileSize,
248249
metaPickKeys: merge(['uid', 'url', 'filename', 'parent_uid'], this.assetConfig.assetsMetaKeys),
@@ -326,7 +327,7 @@ export default class ExportAssets extends BaseClass {
326327
if (!fs && !isEmpty(response)) {
327328
fs = new FsUtility({
328329
moduleName: 'assets',
329-
indexFileName: 'versioned-assets.json',
330+
indexFileName: PATH_CONSTANTS.FILES.VERSIONED_ASSETS,
330331
chunkFileSize: this.assetConfig.chunkFileSize,
331332
basePath: pResolve(this.assetsRootPath, 'versions'),
332333
metaPickKeys: merge(['uid', 'url', 'filename', '_version', 'parent_uid'], this.assetConfig.assetsMetaKeys),

packages/contentstack-export/src/export/modules/content-types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import * as path from 'path';
2-
import { ContentstackClient, handleAndLogError, messageHandler, log, sanitizePath } from '@contentstack/cli-utilities';
2+
import {
3+
ContentstackClient,
4+
handleAndLogError,
5+
messageHandler,
6+
log,
7+
sanitizePath,
8+
} from '@contentstack/cli-utilities';
9+
import { PATH_CONSTANTS } from '../../constants';
310

411
import BaseClass from './base-class';
512
import { ExportConfig, ModuleClassParams } from '../../types';
@@ -156,7 +163,7 @@ export default class ContentTypesExport extends BaseClass {
156163
concurrency: this.exportConfig.writeConcurrency,
157164
});
158165

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

162169
return fsUtil.writeFile(schemaFilePath, contentTypes);

packages/contentstack-export/src/export/modules/entries.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import * as path from 'path';
2-
import { ContentstackClient, FsUtility, handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
2+
import {
3+
ContentstackClient,
4+
FsUtility,
5+
handleAndLogError,
6+
messageHandler,
7+
log,
8+
sanitizePath,
9+
} from '@contentstack/cli-utilities';
10+
import { PATH_CONSTANTS } from '../../constants';
311
import { Export, ExportProjects } from '@contentstack/cli-variants';
4-
import { sanitizePath } from '@contentstack/cli-utilities';
512

613
import {
714
fsUtil,
@@ -55,7 +62,7 @@ export default class EntriesExport extends BaseClass {
5562
sanitizePath(exportConfig.exportDir),
5663
sanitizePath(exportConfig.branchName || ''),
5764
sanitizePath(exportConfig.modules.content_types.dirName),
58-
'schema.json',
65+
PATH_CONSTANTS.FILES.SCHEMA,
5966
);
6067
this.projectInstance = new ExportProjects(this.exportConfig);
6168
this.exportConfig.context.module = MODULE_CONTEXTS.ENTRIES;
@@ -313,7 +320,7 @@ export default class EntriesExport extends BaseClass {
313320
await fsUtil.makeDirectory(entryBasePath);
314321
this.entriesFileHelper = new FsUtility({
315322
moduleName: 'entries',
316-
indexFileName: 'index.json',
323+
indexFileName: PATH_CONSTANTS.FILES.INDEX,
317324
basePath: entryBasePath,
318325
chunkFileSize: this.entriesConfig.chunkFileSize,
319326
keepMetadata: false,

packages/contentstack-export/src/export/modules/stack.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import find from 'lodash/find';
22
import { resolve as pResolve } from 'node:path';
3-
import { handleAndLogError, isAuthenticated, managementSDKClient, log } from '@contentstack/cli-utilities';
3+
import {
4+
handleAndLogError,
5+
isAuthenticated,
6+
managementSDKClient,
7+
log,
8+
} from '@contentstack/cli-utilities';
9+
import { PATH_CONSTANTS } from '../../constants';
410

511
import BaseClass from './base-class';
612
import {
@@ -265,7 +271,7 @@ export default class ExportStack extends BaseClass {
265271
return this.stack
266272
.settings()
267273
.then((resp: any) => {
268-
fsUtil.writeFile(pResolve(this.stackFolderPath, 'settings.json'), resp);
274+
fsUtil.writeFile(pResolve(this.stackFolderPath, PATH_CONSTANTS.FILES.SETTINGS), resp);
269275

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

packages/contentstack-export/src/export/modules/taxonomies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export default class ExportTaxonomies extends BaseClass {
125125
return;
126126
}
127127

128-
const taxonomiesFilePath = pResolve(this.taxonomiesFolderPath, 'taxonomies.json');
128+
const taxonomiesFilePath = pResolve(this.taxonomiesFolderPath, this.taxonomiesConfig.fileName);
129129
log.debug(`Writing taxonomies metadata to: ${taxonomiesFilePath}`, this.exportConfig.context);
130130
fsUtil.writeFile(taxonomiesFilePath, this.taxonomies);
131131
}

packages/contentstack-export/test/unit/export/modules/entries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('EntriesExport', () => {
9292
},
9393
content_types: {
9494
dirName: 'content_types',
95-
fileName: 'schema.json',
95+
fileName: 'content_types.json',
9696
},
9797
personalize: {
9898
baseURL: {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
export const PATH_CONSTANTS = {
2+
/** Root mapper directory (contains module-specific mapper subdirs) */
3+
MAPPER: 'mapper',
4+
5+
/** Common mapper file names */
6+
FILES: {
7+
SUCCESS: 'success.json',
8+
FAILS: 'fails.json',
9+
UID_MAPPING: 'uid-mapping.json',
10+
URL_MAPPING: 'url-mapping.json',
11+
UID_MAPPER: 'uid-mapper.json',
12+
SCHEMA: 'schema.json',
13+
SETTINGS: 'settings.json',
14+
MODIFIED_SCHEMAS: 'modified-schemas.json',
15+
UNIQUE_MAPPING: 'unique-mapping.json',
16+
TAXONOMIES: 'taxonomies.json',
17+
ENVIRONMENTS: 'environments.json',
18+
PENDING_EXTENSIONS: 'pending_extensions.js',
19+
PENDING_GLOBAL_FIELDS: 'pending_global_fields.js',
20+
INDEX: 'index.json',
21+
FOLDER_MAPPING: 'folder-mapping.json',
22+
VERSIONED_ASSETS: 'versioned-assets.json',
23+
},
24+
25+
/** Module subdirectory names within mapper */
26+
MAPPER_MODULES: {
27+
ASSETS: 'assets',
28+
ENTRIES: 'entries',
29+
CONTENT_TYPES: 'content_types',
30+
TAXONOMIES: 'taxonomies',
31+
TAXONOMY_TERMS: 'terms',
32+
GLOBAL_FIELDS: 'global_fields',
33+
EXTENSIONS: 'extensions',
34+
WORKFLOWS: 'workflows',
35+
WEBHOOKS: 'webhooks',
36+
LABELS: 'labels',
37+
ENVIRONMENTS: 'environments',
38+
MARKETPLACE_APPS: 'marketplace_apps',
39+
CUSTOM_ROLES: 'custom-roles',
40+
LANGUAGES: 'languages',
41+
},
42+
43+
/** Content directory names (used in both import and export) */
44+
CONTENT_DIRS: {
45+
ASSETS: 'assets',
46+
ENTRIES: 'entries',
47+
CONTENT_TYPES: 'content_types',
48+
TAXONOMIES: 'taxonomies',
49+
GLOBAL_FIELDS: 'global_fields',
50+
EXTENSIONS: 'extensions',
51+
WEBHOOKS: 'webhooks',
52+
WORKFLOWS: 'workflows',
53+
LABELS: 'labels',
54+
ENVIRONMENTS: 'environments',
55+
STACK: 'stack',
56+
LOCALES: 'locales',
57+
MARKETPLACE_APPS: 'marketplace_apps',
58+
},
59+
} as const;
60+
61+
export type PathConstants = typeof PATH_CONSTANTS;

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { existsSync } from 'node:fs';
99
import includes from 'lodash/includes';
1010
import { v4 as uuid } from 'uuid';
1111
import { resolve as pResolve, join } from 'node:path';
12-
import { FsUtility, log, handleAndLogError } from '@contentstack/cli-utilities';
12+
import {
13+
FsUtility,
14+
log,
15+
handleAndLogError,
16+
} from '@contentstack/cli-utilities';
17+
import { PATH_CONSTANTS } from '../../constants';
1318

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

39-
this.assetsPath = join(this.importConfig.backupDir, 'assets');
40-
this.mapperDirPath = join(this.importConfig.backupDir, 'mapper', 'assets');
41-
this.assetUidMapperPath = join(this.mapperDirPath, 'uid-mapping.json');
42-
this.assetUrlMapperPath = join(this.mapperDirPath, 'url-mapping.json');
43-
this.assetFolderUidMapperPath = join(this.mapperDirPath, 'folder-mapping.json');
44+
this.assetsPath = join(this.importConfig.backupDir, PATH_CONSTANTS.CONTENT_DIRS.ASSETS);
45+
this.mapperDirPath = join(
46+
this.importConfig.backupDir,
47+
PATH_CONSTANTS.MAPPER,
48+
PATH_CONSTANTS.MAPPER_MODULES.ASSETS,
49+
);
50+
this.assetUidMapperPath = join(this.mapperDirPath, PATH_CONSTANTS.FILES.UID_MAPPING);
51+
this.assetUrlMapperPath = join(this.mapperDirPath, PATH_CONSTANTS.FILES.URL_MAPPING);
52+
this.assetFolderUidMapperPath = join(this.mapperDirPath, PATH_CONSTANTS.FILES.FOLDER_MAPPING);
4453
this.assetsRootPath = join(this.importConfig.backupDir, this.assetConfig.dirName);
4554
this.fs = new FsUtility({ basePath: this.mapperDirPath });
4655
this.environments = this.fs.readFile(
47-
join(this.importConfig.backupDir, 'environments', 'environments.json'),
56+
join(
57+
this.importConfig.backupDir,
58+
PATH_CONSTANTS.CONTENT_DIRS.ENVIRONMENTS,
59+
PATH_CONSTANTS.FILES.ENVIRONMENTS,
60+
),
4861
true,
4962
) as Record<string, unknown>;
5063
}
@@ -208,7 +221,9 @@ export default class ImportAssets extends BaseClass {
208221
*/
209222
async importAssets(isVersion = false): Promise<void> {
210223
const processName = isVersion ? 'import versioned assets' : 'import assets';
211-
const indexFileName = isVersion ? 'versioned-assets.json' : 'assets.json';
224+
const indexFileName = isVersion
225+
? PATH_CONSTANTS.FILES.VERSIONED_ASSETS
226+
: this.assetConfig.fileName;
212227
const basePath = isVersion ? join(this.assetsPath, 'versions') : this.assetsPath;
213228
const progressProcessName = isVersion ? PROCESS_NAMES.ASSET_VERSIONS : PROCESS_NAMES.ASSET_UPLOAD;
214229

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

565583
private async countPublishableAssets(): Promise<number> {
566-
const fsUtil = new FsUtility({ basePath: this.assetsPath, indexFileName: 'assets.json' });
584+
const fsUtil = new FsUtility({
585+
basePath: this.assetsPath,
586+
indexFileName: this.assetConfig.fileName,
587+
});
567588
let count = 0;
568589

569590
for (const _ of values(fsUtil.indexFileContent)) {

0 commit comments

Comments
 (0)