diff --git a/.talismanrc b/.talismanrc index 72731f04a8..73a915ab0f 100644 --- a/.talismanrc +++ b/.talismanrc @@ -66,7 +66,7 @@ fileignoreconfig: - filename: packages/contentstack-bulk-publish/src/producer/publish-unpublished-env.js checksum: 44dbc966df086f835fdca11cb305d0a5f448ca0be811c14b894e0024f9491385 - filename: packages/contentstack-import/src/import/modules/entries.ts - checksum: 0fa92065747da2ea3b02c666da5a0c6d3e74552c804a15578d9da0bfeb082615 + checksum: 290730774c61220645ec211b85b9e218cdbd8addc2d8fd8f061dfa5ede5b5c75 - filename: packages/contentstack-utilities/src/logger/logger.ts checksum: 76429bc87e279624b386f00e7eb3f4ec25621ace7056289f812b9a076d6e184e - filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -109,8 +109,6 @@ fileignoreconfig: checksum: b0fa8088fcbb17510fa275bd0dde3f6f4246f2525741c30426f07dd62fe497b0 - filename: packages/contentstack-audit/src/modules/content-types.ts checksum: ddf7b08e6a80af09c6a7019a637c26089fb76572c7c3d079a8af244b02985f16 - - filename: packages/contentstack-import/test/unit/commands/cm/stacks/import.test.ts - checksum: b11e57f1b824d405f86438e9e7c59183f8c59b66b42d8d16dbeaf76195a30548 - filename: packages/contentstack-import/test/unit/utils/asset-helper.test.ts checksum: 8e83200ac8028f9289ff1bd3a50d191b35c8e28f1854141c90fa1b0134d6bf8a - filename: packages/contentstack-import/test/unit/import/modules/marketplace-apps.test.ts @@ -199,8 +197,6 @@ fileignoreconfig: checksum: 49dd8e754a0d3635585a74e943ab097593f061089a7cddc22683ec6caddbb3c5 - filename: packages/contentstack-export/test/unit/export/modules/personalize.test.ts checksum: 83cf034fabee00b42b4243a8c0b8ba280ab7c1e68ffd741c49c31aaee8ca0315 - - filename: packages/contentstack-utilities/test/unit/logger.test.ts - checksum: 11778d0252202c18a1ca6a38883d6e12fc324ff86ad0fe058bc2505f9cd66ba3 - filename: packages/contentstack-audit/test/unit/audit-base-command.test.ts checksum: 17a16b4457c820494442f335d94d0949961e68e8ca72ca0f1fa9d4d0eeb0c17a - filename: packages/contentstack-import/src/import/modules/taxonomies.ts @@ -269,4 +265,12 @@ fileignoreconfig: checksum: 9b83875b8d82086f13e0b7ab44ff7fe95486fced95b0c22d5c73fa69fbe35d4a - filename: packages/contentstack-bulk-publish/src/producer/add-fields.js checksum: 3e70b11978fc5f29a6a6c90b725c28c9df8d15bcc6fd74e2253fca23a3630160 + - filename: packages/contentstack-utilities/src/logger/session-path.ts + checksum: 4c66980a857bc12012a45e50790c0eaab06883db5e1476d84fb142a08b70b2e7 + - filename: packages/contentstack-import/test/unit/commands/cm/stacks/import.test.ts + checksum: ead3c34bad34f912d8663599273d26a95bb48220e16d9e9e3d33f5c064a487a5 + - filename: packages/contentstack-utilities/src/helpers.ts + checksum: 9d7df9d79cec75f238a0072bf79c4934b4724bf1466451ea6f923adfd5c0b75b + - filename: packages/contentstack-utilities/test/unit/logger.test.ts + checksum: a1939dea16166b1893a248179524a76f2ed20b04b99c83bd1a5a13fcf6f0dadc version: '1.0' diff --git a/package-lock.json b/package-lock.json index 1d31b5551a..978aec1717 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26616,21 +26616,21 @@ }, "packages/contentstack": { "name": "@contentstack/cli", - "version": "1.53.1", + "version": "1.54.0", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.16.2", "@contentstack/cli-auth": "~1.6.3", - "@contentstack/cli-cm-bootstrap": "~1.17.2", + "@contentstack/cli-cm-bootstrap": "~1.18.0", "@contentstack/cli-cm-branches": "~1.6.2", "@contentstack/cli-cm-bulk-publish": "~1.10.4", - "@contentstack/cli-cm-clone": "~1.18.1", + "@contentstack/cli-cm-clone": "~1.19.0", "@contentstack/cli-cm-export": "~1.22.2", "@contentstack/cli-cm-export-to-csv": "~1.10.2", - "@contentstack/cli-cm-import": "~1.30.2", + "@contentstack/cli-cm-import": "~1.31.0", "@contentstack/cli-cm-import-setup": "~1.7.2", "@contentstack/cli-cm-migrate-rte": "~1.6.3", - "@contentstack/cli-cm-seed": "~1.13.2", + "@contentstack/cli-cm-seed": "~1.14.0", "@contentstack/cli-command": "~1.7.1", "@contentstack/cli-config": "~1.16.2", "@contentstack/cli-launch": "^1.9.2", @@ -26913,10 +26913,10 @@ }, "packages/contentstack-bootstrap": { "name": "@contentstack/cli-cm-bootstrap", - "version": "1.17.2", + "version": "1.18.0", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-seed": "~1.13.2", + "@contentstack/cli-cm-seed": "~1.14.0", "@contentstack/cli-command": "~1.7.1", "@contentstack/cli-utilities": "~1.16.0", "@oclif/core": "^4.3.0", @@ -27046,12 +27046,12 @@ }, "packages/contentstack-clone": { "name": "@contentstack/cli-cm-clone", - "version": "1.18.1", + "version": "1.19.0", "license": "MIT", "dependencies": { "@colors/colors": "^1.6.0", "@contentstack/cli-cm-export": "~1.22.2", - "@contentstack/cli-cm-import": "~1.30.2", + "@contentstack/cli-cm-import": "~1.31.0", "@contentstack/cli-command": "~1.7.1", "@contentstack/cli-utilities": "~1.16.0", "@oclif/core": "^4.3.0", @@ -28001,7 +28001,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.30.2", + "version": "1.31.0", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.16.2", @@ -28156,10 +28156,10 @@ }, "packages/contentstack-seed": { "name": "@contentstack/cli-cm-seed", - "version": "1.13.2", + "version": "1.14.0", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "1.30.2", + "@contentstack/cli-cm-import": "~1.31.0", "@contentstack/cli-command": "~1.7.1", "@contentstack/cli-utilities": "~1.16.0", "@contentstack/management": "~1.22.0", diff --git a/packages/contentstack-bootstrap/package.json b/packages/contentstack-bootstrap/package.json index f1e7d0ddff..0d0ee4f8a2 100644 --- a/packages/contentstack-bootstrap/package.json +++ b/packages/contentstack-bootstrap/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-bootstrap", "description": "Bootstrap contentstack apps", - "version": "1.17.2", + "version": "1.18.0", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "scripts": { @@ -16,7 +16,7 @@ "test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\"" }, "dependencies": { - "@contentstack/cli-cm-seed": "~1.13.2", + "@contentstack/cli-cm-seed": "~1.14.0", "@contentstack/cli-command": "~1.7.1", "@contentstack/cli-utilities": "~1.16.0", "@oclif/core": "^4.3.0", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index a89f54e59b..bc3443d320 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -1,13 +1,13 @@ { "name": "@contentstack/cli-cm-clone", "description": "Contentstack stack clone plugin", - "version": "1.18.1", + "version": "1.19.0", "author": "Contentstack", "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { "@colors/colors": "^1.6.0", "@contentstack/cli-cm-export": "~1.22.2", - "@contentstack/cli-cm-import": "~1.30.2", + "@contentstack/cli-cm-import": "~1.31.0", "@contentstack/cli-command": "~1.7.1", "@contentstack/cli-utilities": "~1.16.0", "@oclif/core": "^4.3.0", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 1294bd1d70..96e6cdc73f 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-import", "description": "Contentstack CLI plugin to import content into stack", - "version": "1.30.2", + "version": "1.31.0", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-import/src/config/index.ts b/packages/contentstack-import/src/config/index.ts index 75f8d6bc8b..76b70e1121 100644 --- a/packages/contentstack-import/src/config/index.ts +++ b/packages/contentstack-import/src/config/index.ts @@ -33,6 +33,7 @@ const config: DefaultConfig = { 'stack', 'assets', 'taxonomies', + 'composable-studio', 'extensions', 'marketplace-apps', 'global-fields', @@ -44,7 +45,6 @@ const config: DefaultConfig = { 'variant-entries', 'labels', 'webhooks', - 'composable-studio', ], locales: { dirName: 'locales', diff --git a/packages/contentstack-import/src/import/modules/composable-studio.ts b/packages/contentstack-import/src/import/modules/composable-studio.ts index 521384692d..04cd04ef8d 100644 --- a/packages/contentstack-import/src/import/modules/composable-studio.ts +++ b/packages/contentstack-import/src/import/modules/composable-studio.ts @@ -20,6 +20,7 @@ export default class ImportComposableStudio { private apiClient: HttpClient; private envUidMapperPath: string; private envUidMapper: Record; + private projectMapperPath: string; constructor({ importConfig }: ModuleClassParams) { this.importConfig = importConfig; @@ -28,6 +29,7 @@ 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.composableStudioFilePath = join(this.composableStudioPath, this.composableStudioConfig.fileName); this.envUidMapperPath = join(this.importConfig.backupDir, 'mapper', 'environments', 'uid-mapping.json'); this.envUidMapper = {}; @@ -244,6 +246,14 @@ export default class ImportComposableStudio { if (response.status >= 200 && response.status < 300) { projectCreated = true; log.debug(`Project created successfully with UID: ${response.data?.uid}`, this.importConfig.context); + + // Create mapper directory if it doesn't exist + await fsUtil.makeDirectory(this.projectMapperPath); + + // write the project to file + const projectFileSuccessPath = join(this.projectMapperPath, this.composableStudioConfig.fileName); + fsUtil.writeFile(projectFileSuccessPath, response.data as unknown as Record); + log.debug(`Project written to: ${projectFileSuccessPath}`, this.importConfig.context); } else { throw new Error(`API call failed with status ${response.status}: ${JSON.stringify(response.data)}`); } diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index 19b7ca51ea..462c10a8f0 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -8,7 +8,7 @@ import * as path from 'path'; import { isEmpty, find, cloneDeep, map } from 'lodash'; import { sanitizePath, log, handleAndLogError } from '@contentstack/cli-utilities'; -import { fsUtil, schemaTemplate, lookupExtension, lookUpTaxonomy } from '../../utils'; +import { fsUtil, schemaTemplate, lookupExtension, lookUpTaxonomy, fileHelper } from '../../utils'; import { ImportConfig, ModuleClassParams } from '../../types'; import BaseClass, { ApiOptions } from './base-class'; import { updateFieldRules } from '../../utils/content-type-helper'; @@ -54,6 +54,8 @@ export default class ContentTypesImport extends BaseClass { public taxonomies: Record; private extPendingPath: string; private isExtensionsUpdate = false; + private composableStudioSuccessPath: string; + private composableStudioExportPath: string; constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); @@ -84,6 +86,19 @@ export default class ContentTypesImport extends BaseClass { ['schema.json', 'true'], ['.DS_Store', 'true'], ]); + + this.composableStudioSuccessPath = path.join( + sanitizePath(this.importConfig.data), + 'mapper', + this.importConfig.modules['composable-studio'].dirName, + this.importConfig.modules['composable-studio'].fileName, + ); + + this.composableStudioExportPath = path.join( + sanitizePath(this.importConfig.data), + this.importConfig.modules['composable-studio'].dirName, + this.importConfig.modules['composable-studio'].fileName, + ); this.cTs = []; this.createdCTs = []; this.titleToUIdMap = new Map(); @@ -110,6 +125,35 @@ export default class ContentTypesImport extends BaseClass { } log.debug(`Found ${this.cTs.length} content types to import`, this.importConfig.context); + // If success file doesn't exist but export file does, skip the composition content type + if ( + !fileHelper.fileExistsSync(this.composableStudioSuccessPath) && + fileHelper.fileExistsSync(this.composableStudioExportPath) + ) { + const exportedProject = fileHelper.readFileSync(this.composableStudioExportPath) as { + contentTypeUid: string; + }; + + if (exportedProject?.contentTypeUid) { + const originalCount = this.cTs.length; + this.cTs = this.cTs.filter((ct: Record) => { + const shouldSkip = ct.uid === exportedProject.contentTypeUid; + if (shouldSkip) { + log.info( + `Skipping content type '${ct.uid}' as Composable Studio project was not created successfully`, + this.importConfig.context, + ); + } + return !shouldSkip; + }); + + const skippedCount = originalCount - this.cTs.length; + if (skippedCount > 0) { + log.debug(`Filtered out ${skippedCount} composition content type(s) from import`, this.importConfig.context); + } + } + } + await fsUtil.makeDirectory(this.cTsMapperPath); log.debug('Created content types mapper directory.', this.importConfig.context); diff --git a/packages/contentstack-import/src/import/modules/entries.ts b/packages/contentstack-import/src/import/modules/entries.ts index 4cc7174c69..09e996c2f0 100644 --- a/packages/contentstack-import/src/import/modules/entries.ts +++ b/packages/contentstack-import/src/import/modules/entries.ts @@ -57,6 +57,8 @@ export default class EntriesImport extends BaseClass { public rteCTs: any; public rteCTsWithRef: any; public entriesForVariant: Array<{ content_type: string; locale: string; entry_uid: string }> = []; + private composableStudioSuccessPath: string; + private composableStudioExportPath: string; constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); @@ -92,6 +94,18 @@ export default class EntriesImport extends BaseClass { sanitizePath(importConfig.modules.locales.dirName), sanitizePath(importConfig.modules.locales.fileName), ); + this.composableStudioSuccessPath = path.join( + sanitizePath(this.importConfig.data), + 'mapper', + this.importConfig.modules['composable-studio'].dirName, + this.importConfig.modules['composable-studio'].fileName, + ); + + this.composableStudioExportPath = path.join( + sanitizePath(this.importConfig.data), + this.importConfig.modules['composable-studio'].dirName, + this.importConfig.modules['composable-studio'].fileName, + ); this.importConcurrency = this.entriesConfig.importConcurrency || importConfig.importConcurrency; this.entriesUidMapper = {}; this.modifiedCTs = []; @@ -116,6 +130,37 @@ export default class EntriesImport extends BaseClass { return; } log.debug(`Found ${this.cTs.length} content types for entry import`, this.importConfig.context); + // If success file doesn't exist but export file does, skip the composition entries + if ( + !fileHelper.fileExistsSync(this.composableStudioSuccessPath) && + fileHelper.fileExistsSync(this.composableStudioExportPath) + ) { + const exportedProject = fileHelper.readFileSync(this.composableStudioExportPath) as { + contentTypeUid: string; + }; + + if (exportedProject?.contentTypeUid) { + const originalCount = this.cTs.length; + this.cTs = this.cTs.filter((ct: Record) => { + const shouldSkip = ct.uid === exportedProject.contentTypeUid; + if (shouldSkip) { + log.info( + `Skipping entries for content type '${ct.uid}' as Composable Studio project was not created successfully`, + this.importConfig.context, + ); + } + return !shouldSkip; + }); + + const skippedCount = originalCount - this.cTs.length; + if (skippedCount > 0) { + log.debug( + `Filtered out ${skippedCount} composition content type(s) from entry import`, + this.importConfig.context, + ); + } + } + } this.installedExtensions = ( (fsUtil.readFile(this.marketplaceAppMapperPath) as any) || { extension_uid: {} } @@ -124,10 +169,7 @@ export default class EntriesImport extends BaseClass { this.assetUidMapper = (fsUtil.readFile(this.assetUidMapperPath) as Record) || {}; this.assetUrlMapper = (fsUtil.readFile(this.assetUrlMapperPath) as Record) || {}; - log.debug( - `Loaded asset mappings – UIDs: ${Object.keys(this.assetUidMapper).length}`, - this.importConfig.context, - ); + log.debug(`Loaded asset mappings – UIDs: ${Object.keys(this.assetUidMapper).length}`, this.importConfig.context); this.taxonomies = (fsUtil.readFile(this.taxonomiesPath) || {}) as Record; log.debug('Loaded taxonomy data for entry processing.', this.importConfig.context); diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index 49f221aef4..c5e5b472f3 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -1,11 +1,11 @@ { "name": "@contentstack/cli-cm-seed", "description": "create a Stack from existing content types, entries, assets, etc.", - "version": "1.13.2", + "version": "1.14.0", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-import": "1.30.2", + "@contentstack/cli-cm-import": "~1.31.0", "@contentstack/cli-command": "~1.7.1", "@contentstack/cli-utilities": "~1.16.0", "@contentstack/management": "~1.22.0", diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 96d490059d..e2718ed94c 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli", "description": "Command-line tool (CLI) to interact with Contentstack", - "version": "1.53.1", + "version": "1.54.0", "author": "Contentstack", "bin": { "csdx": "./bin/run.js" @@ -24,16 +24,16 @@ "dependencies": { "@contentstack/cli-audit": "~1.16.2", "@contentstack/cli-cm-export": "~1.22.2", - "@contentstack/cli-cm-import": "~1.30.2", + "@contentstack/cli-cm-import": "~1.31.0", "@contentstack/cli-auth": "~1.6.3", - "@contentstack/cli-cm-bootstrap": "~1.17.2", + "@contentstack/cli-cm-bootstrap": "~1.18.0", "@contentstack/cli-cm-branches": "~1.6.2", "@contentstack/cli-cm-bulk-publish": "~1.10.4", - "@contentstack/cli-cm-clone": "~1.18.1", + "@contentstack/cli-cm-clone": "~1.19.0", "@contentstack/cli-cm-export-to-csv": "~1.10.2", "@contentstack/cli-cm-import-setup": "~1.7.2", "@contentstack/cli-cm-migrate-rte": "~1.6.3", - "@contentstack/cli-cm-seed": "~1.13.2", + "@contentstack/cli-cm-seed": "~1.14.0", "@contentstack/cli-command": "~1.7.1", "@contentstack/cli-config": "~1.16.2", "@contentstack/cli-launch": "^1.9.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c83b19d375..99a8f71f5c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,16 +14,16 @@ importers: specifiers: '@contentstack/cli-audit': ~1.16.2 '@contentstack/cli-auth': ~1.6.3 - '@contentstack/cli-cm-bootstrap': ~1.17.2 + '@contentstack/cli-cm-bootstrap': ~1.18.0 '@contentstack/cli-cm-branches': ~1.6.2 '@contentstack/cli-cm-bulk-publish': ~1.10.4 - '@contentstack/cli-cm-clone': ~1.18.1 + '@contentstack/cli-cm-clone': ~1.19.0 '@contentstack/cli-cm-export': ~1.22.2 '@contentstack/cli-cm-export-to-csv': ~1.10.2 - '@contentstack/cli-cm-import': ~1.30.2 + '@contentstack/cli-cm-import': ~1.31.0 '@contentstack/cli-cm-import-setup': ~1.7.2 '@contentstack/cli-cm-migrate-rte': ~1.6.3 - '@contentstack/cli-cm-seed': ~1.13.2 + '@contentstack/cli-cm-seed': ~1.14.0 '@contentstack/cli-command': ~1.7.1 '@contentstack/cli-config': ~1.16.2 '@contentstack/cli-launch': ^1.9.2 @@ -243,7 +243,7 @@ importers: packages/contentstack-bootstrap: specifiers: - '@contentstack/cli-cm-seed': ~1.13.2 + '@contentstack/cli-cm-seed': ~1.14.0 '@contentstack/cli-command': ~1.7.1 '@contentstack/cli-utilities': ~1.16.0 '@oclif/core': ^4.3.0 @@ -380,7 +380,7 @@ importers: specifiers: '@colors/colors': ^1.6.0 '@contentstack/cli-cm-export': ~1.22.2 - '@contentstack/cli-cm-import': ~1.30.2 + '@contentstack/cli-cm-import': ~1.31.0 '@contentstack/cli-command': ~1.7.1 '@contentstack/cli-utilities': ~1.16.0 '@oclif/core': ^4.3.0 @@ -886,7 +886,7 @@ importers: packages/contentstack-seed: specifiers: - '@contentstack/cli-cm-import': 1.30.2 + '@contentstack/cli-cm-import': ~1.31.0 '@contentstack/cli-command': ~1.7.1 '@contentstack/cli-utilities': ~1.16.0 '@contentstack/management': ~1.22.0