Skip to content
Draft
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
14 changes: 9 additions & 5 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const config: DefaultConfig = {
'stack',
'assets',
'taxonomies',
'composable-studio',
'extensions',
'marketplace-apps',
'global-fields',
Expand All @@ -44,7 +45,6 @@ const config: DefaultConfig = {
'variant-entries',
'labels',
'webhooks',
'composable-studio',
],
locales: {
dirName: 'locales',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class ImportComposableStudio {
private apiClient: HttpClient;
private envUidMapperPath: string;
private envUidMapper: Record<string, string>;
private projectMapperPath: string;

constructor({ importConfig }: ModuleClassParams) {
this.importConfig = importConfig;
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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<string, unknown>);
log.debug(`Project written to: ${projectFileSuccessPath}`, this.importConfig.context);
} else {
throw new Error(`API call failed with status ${response.status}: ${JSON.stringify(response.data)}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,6 +54,8 @@ export default class ContentTypesImport extends BaseClass {
public taxonomies: Record<string, unknown>;
private extPendingPath: string;
private isExtensionsUpdate = false;
private composableStudioSuccessPath: string;
private composableStudioExportPath: string;

constructor({ importConfig, stackAPIClient }: ModuleClassParams) {
super({ importConfig, stackAPIClient });
Expand Down Expand Up @@ -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();
Expand All @@ -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<string, unknown>) => {
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);

Expand Down
50 changes: 46 additions & 4 deletions packages/contentstack-import/src/import/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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<string, unknown>) => {
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: {} }
Expand All @@ -124,10 +169,7 @@ export default class EntriesImport extends BaseClass {

this.assetUidMapper = (fsUtil.readFile(this.assetUidMapperPath) as Record<string, any>) || {};
this.assetUrlMapper = (fsUtil.readFile(this.assetUrlMapperPath) as Record<string, any>) || {};
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<string, any>;
log.debug('Loaded taxonomy data for entry processing.', this.importConfig.context);
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading
Loading