From b8ce61d17a2184377e5451c7d831ae679e941996 Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Wed, 17 Dec 2025 12:23:43 +0530 Subject: [PATCH 1/2] skip composition type and compositions if studio project failed to import --- .talismanrc | 2 +- .../contentstack-import/src/config/index.ts | 2 +- .../src/import/modules/composable-studio.ts | 10 ++++ .../src/import/modules/content-types.ts | 46 ++++++++++++++++- .../src/import/modules/entries.ts | 50 +++++++++++++++++-- 5 files changed, 103 insertions(+), 7 deletions(-) diff --git a/.talismanrc b/.talismanrc index 414acd491e..6918bbe888 100644 --- a/.talismanrc +++ b/.talismanrc @@ -66,7 +66,7 @@ fileignoreconfig: - filename: packages/contentstack-bulk-publish/src/producer/publish-unpublished-env.js checksum: 96fd15e027f38b156c69f10943ea1d5a70e580fa8a5efeb3286cd7132145c72d - filename: packages/contentstack-import/src/import/modules/entries.ts - checksum: 2fd4e8ecf75e077632a6408d09997f0921d2a3508f9f2cb8f47fe79a28592300 + checksum: 290730774c61220645ec211b85b9e218cdbd8addc2d8fd8f061dfa5ede5b5c75 - filename: packages/contentstack-utilities/src/logger/logger.ts checksum: 76429bc87e279624b386f00e7eb3f4ec25621ace7056289f812b9a076d6e184e - filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts 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); From f51a47b83ea079778c0d7bd011194355b761299f Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Wed, 17 Dec 2025 12:54:52 +0530 Subject: [PATCH 2/2] bumped version --- package-lock.json | 24 ++++++++++---------- packages/contentstack-bootstrap/package.json | 4 ++-- packages/contentstack-clone/package.json | 4 ++-- packages/contentstack-import/package.json | 2 +- packages/contentstack-seed/package.json | 4 ++-- packages/contentstack/package.json | 10 ++++---- pnpm-lock.yaml | 14 ++++++------ 7 files changed, 31 insertions(+), 31 deletions(-) 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-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