diff --git a/package-lock.json b/package-lock.json index 83cfce9c34..0f7b414e2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1998,12 +1998,12 @@ } }, "node_modules/@oclif/plugin-plugins": { - "version": "5.0.11", - "resolved": "https://registry.npmjs.org/@oclif/plugin-plugins/-/plugin-plugins-5.0.11.tgz", - "integrity": "sha512-es+IMNI97Jw+EX25r9ejrOph9R/8FbNXmWrH/NnhUJ3lNDpeMPM8njP4ovHYJi2+ta2VTHDxhQFNRDlNnUiyOw==", + "version": "5.0.14", + "resolved": "https://registry.npmjs.org/@oclif/plugin-plugins/-/plugin-plugins-5.0.14.tgz", + "integrity": "sha512-5LM3w2PPfB6qMtgrAq+n8hG295i4vbnuPfQN4wPGLJq1tIiDpBEAX1XHnGhUdAeU0V8CU2AnjiucXFMTKvIdow==", "hasShrinkwrap": true, "dependencies": { - "@oclif/core": "^3.26.2", + "@oclif/core": "^3.26.4", "chalk": "^5.3.0", "debug": "^4.3.4", "npm": "10.5.0", @@ -2053,9 +2053,9 @@ } }, "node_modules/@oclif/plugin-plugins/node_modules/@oclif/core": { - "version": "3.26.2", - "resolved": "https://registry.npmjs.org/@oclif/core/-/core-3.26.2.tgz", - "integrity": "sha512-Gpn21jKjcOx0TecI1wLJrY/65jtgJx5f1GzTc81oKvEpKes1b3Li2SMZygRaWRpcQ3wjN0d7lTPi8WwLsmTBjA==", + "version": "3.26.4", + "resolved": "https://registry.npmjs.org/@oclif/core/-/core-3.26.4.tgz", + "integrity": "sha512-ntfo2ut7enNtAn/jB/dryMUPBM2Fh8Fydmi3k/Ybo6lCGU/hmsPFkBRjCEJAQMyNkK2yVZARaWogdOrcVgFz+w==", "license": "MIT", "dependencies": { "@types/cli-progress": "^3.11.5", @@ -2067,7 +2067,7 @@ "cli-progress": "^3.12.0", "color": "^4.2.3", "debug": "^4.3.4", - "ejs": "^3.1.9", + "ejs": "^3.1.10", "get-package-type": "^0.1.0", "globby": "^11.1.0", "hyperlinker": "^1.0.0", @@ -2461,9 +2461,9 @@ } }, "node_modules/@oclif/plugin-plugins/node_modules/ejs": { - "version": "3.1.9", - "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz", - "integrity": "sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ==", + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", "license": "Apache-2.0", "dependencies": { "jake": "^10.8.5" @@ -8018,9 +8018,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1601.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1601.0.tgz", - "integrity": "sha512-znwVdKs3g0j1cAFfi+PGPSmBxXjiekJXp1nnOUq4rxXYvN7av8gxptXaQz+vqB4uhNFsD+OXNQh+6bd9eQxZmw==", + "version": "2.1605.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1605.0.tgz", + "integrity": "sha512-/wtOuF7WgkbN6YL3xJ+FB54kvIAfnP/DQVDaE6rSYv6ft0xr01Si94NgQWhb5OcFkFfRAC4auZX8PiFNtOi9xQ==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -8764,9 +8764,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001611", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001611.tgz", - "integrity": "sha512-19NuN1/3PjA3QI8Eki55N8my4LzfkMCRLgCVfrl/slbSAchQfV0+GwjPrK3rq37As4UCLlM/DHajbKkAqbv92Q==", + "version": "1.0.30001612", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001612.tgz", + "integrity": "sha512-lFgnZ07UhaCcsSZgWW0K5j4e69dK1u/ltrL9lTUiFOwNHs12S3UMIEYgBV0Z6C6hRDev7iRnMzzYmKabYdXF9g==", "dev": true, "funding": [ { @@ -9427,9 +9427,9 @@ } }, "node_modules/commander": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", - "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", "engines": { "node": ">= 6" } @@ -10208,12 +10208,12 @@ } }, "node_modules/dot-object": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/dot-object/-/dot-object-2.1.4.tgz", - "integrity": "sha512-7FXnyyCLFawNYJ+NhkqyP9Wd2yzuo+7n9pGiYpkmXCTYa8Ci2U0eUNDVg5OuO5Pm6aFXI2SWN8/N/w7SJWu1WA==", + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/dot-object/-/dot-object-2.1.5.tgz", + "integrity": "sha512-xHF8EP4XH/Ba9fvAF2LDd5O3IITVolerVV6xvkxoM8zlGEiCUrggpAnHyOoKJKCrhvPcGATFAUwIujj7bRG5UA==", "dependencies": { - "commander": "^4.0.0", - "glob": "^7.1.5" + "commander": "^6.1.0", + "glob": "^7.1.6" }, "bin": { "dot-object": "bin/dot-object" @@ -10286,9 +10286,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.741", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.741.tgz", - "integrity": "sha512-AyTBZqDoS7/mvQK22gOQpjxbeV8iPeUBTvYlEh/1S9dKAHgQdxuF49g9rLbj0cRKtqH8PzLJzqT3nAdl+qoZTA==", + "version": "1.4.747", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.747.tgz", + "integrity": "sha512-+FnSWZIAvFHbsNVmUxhEqWiaOiPMcfum1GQzlWCg/wLigVtshOsjXHyEFfmt6cFK6+HkS3QOJBv6/3OPumbBfw==", "dev": true }, "node_modules/elegant-spinner": { @@ -10716,9 +10716,9 @@ } }, "node_modules/eslint-config-oclif-typescript": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/eslint-config-oclif-typescript/-/eslint-config-oclif-typescript-3.1.5.tgz", - "integrity": "sha512-bw6HYbv5UQcfK5knAPemViB+CpbxmAOsnaxtvFAEeOvQM61eVaNKtPyCj1DRgUOBUN7knJ0NBXOqUny+0nwSkQ==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/eslint-config-oclif-typescript/-/eslint-config-oclif-typescript-3.1.6.tgz", + "integrity": "sha512-K/Gv19vzTaeLQcs5syZ+Rup8RZfMclIuO2mV9YPG3GN64nSPA545+I7/uiaaxE4Ka+fKg2kZmMq3cFT0TOidpA==", "dev": true, "dependencies": { "@typescript-eslint/eslint-plugin": "^6.21.0", @@ -10726,7 +10726,7 @@ "eslint-config-xo-space": "^0.35.0", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.29.1", - "eslint-plugin-mocha": "^10.4.2", + "eslint-plugin-mocha": "^10.4.3", "eslint-plugin-n": "^15", "eslint-plugin-perfectionist": "^2.9.0" }, @@ -10976,9 +10976,9 @@ } }, "node_modules/eslint-config-oclif-typescript/node_modules/eslint-plugin-mocha": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.4.2.tgz", - "integrity": "sha512-cur4dVYnSEWTBwdqIBQFxa/9siAhesu0TX+lbJ4ClE9j0eNMNe6BSx3vkFFNz6tGoveyMyELFXa30f3fvuAVDg==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.4.3.tgz", + "integrity": "sha512-emc4TVjq5Ht0/upR+psftuz6IBG5q279p+1dSRDeHf+NS9aaerBi3lXKo1SEzwC29hFIW21gO89CEWSvRsi8IQ==", "dev": true, "dependencies": { "eslint-utils": "^3.0.0", @@ -18663,9 +18663,9 @@ } }, "node_modules/nwsapi": { - "version": "2.2.7", - "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz", - "integrity": "sha512-ub5E4+FBPKwAZx0UwIQOjYWGHTEq5sPqHQNRN8Z9e4A7u3Tj1weLJsL59yH9vmvqEtBHaOmT6cYQKIZOxp35FQ==" + "version": "2.2.9", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.9.tgz", + "integrity": "sha512-2f3F0SEEer8bBu0dsNCFF50N0cTThV1nWFYcEYFZttdW0lDAoybv9cQoK7X7/68Z89S7FoRrVjP1LPX4XRf9vg==" }, "node_modules/nyc": { "version": "15.1.0", @@ -24495,16 +24495,16 @@ } }, "node_modules/yeoman-generator/node_modules/@npmcli/installed-package-contents": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@npmcli/installed-package-contents/-/installed-package-contents-2.0.2.tgz", - "integrity": "sha512-xACzLPhnfD51GKvTOOuNX2/V4G4mz9/1I2MfDoye9kBM3RYe5g2YbscsaGoTlaWqkxeiapBWyseULVKpSVHtKQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@npmcli/installed-package-contents/-/installed-package-contents-2.1.0.tgz", + "integrity": "sha512-c8UuGLeZpm69BryRykLuKRyKFZYJsZSCT4aVY5ds4omyZqJ172ApzgfKJ5eV/r3HgLdUYgFVe54KSFVjKoe27w==", "dev": true, "dependencies": { "npm-bundled": "^3.0.0", "npm-normalize-package-bin": "^3.0.0" }, "bin": { - "installed-package-contents": "lib/index.js" + "installed-package-contents": "bin/index.js" }, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0" @@ -25400,7 +25400,7 @@ }, "packages/contentstack": { "name": "@contentstack/cli", - "version": "1.17.3", + "version": "1.17.4", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.5.4", @@ -25409,15 +25409,15 @@ "@contentstack/cli-cm-branches": "~1.0.24", "@contentstack/cli-cm-bulk-publish": "~1.4.5", "@contentstack/cli-cm-clone": "~1.10.3", - "@contentstack/cli-cm-export": "~1.11.1", + "@contentstack/cli-cm-export": "~1.11.2", "@contentstack/cli-cm-export-to-csv": "~1.7.0", - "@contentstack/cli-cm-import": "~1.15.1", + "@contentstack/cli-cm-import": "~1.15.2", "@contentstack/cli-cm-migrate-rte": "~1.4.15", "@contentstack/cli-cm-seed": "~1.7.3", "@contentstack/cli-command": "~1.2.17", "@contentstack/cli-config": "~1.6.3", "@contentstack/cli-launch": "~1.0.17", - "@contentstack/cli-migration": "~1.5.3", + "@contentstack/cli-migration": "~1.5.4", "@contentstack/cli-utilities": "~1.6.0", "@contentstack/management": "~1.15.3", "@oclif/core": "^2.9.3", @@ -25943,8 +25943,8 @@ "license": "MIT", "dependencies": { "@colors/colors": "^1.5.0", - "@contentstack/cli-cm-export": "~1.11.1", - "@contentstack/cli-cm-import": "~1.15.1", + "@contentstack/cli-cm-export": "~1.11.2", + "@contentstack/cli-cm-import": "~1.15.2", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.6.0", "async": "^3.2.4", @@ -26439,7 +26439,7 @@ }, "packages/contentstack-export": { "name": "@contentstack/cli-cm-export", - "version": "1.11.1", + "version": "1.11.2", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.16", @@ -26913,7 +26913,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.15.1", + "version": "1.15.2", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.5.4", @@ -27340,7 +27340,7 @@ }, "packages/contentstack-migration": { "name": "@contentstack/cli-migration", - "version": "1.5.3", + "version": "1.5.4", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.16", @@ -27376,7 +27376,7 @@ "version": "1.7.3", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "~1.15.1", + "@contentstack/cli-cm-import": "~1.15.2", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.6.0", "inquirer": "8.2.4", diff --git a/packages/contentstack-audit/src/modules/entries.ts b/packages/contentstack-audit/src/modules/entries.ts index dfce908806..75affa8be8 100644 --- a/packages/contentstack-audit/src/modules/entries.ts +++ b/packages/contentstack-audit/src/modules/entries.ts @@ -981,7 +981,14 @@ export default class Entries { const entries = (await fsUtility.readChunkFiles.next()) as Record; for (const entryUid in entries) { let { title } = entries[entryUid]; - if (!title) { + + if (entries[entryUid].hasOwnProperty('title') && !title) { + this.isEntryWithoutTitleField = true; + this.log( + `The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, + `error`, + ); + } else if (!title) { this.isEntryWithoutTitleField = true; this.log( `Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' does not have a 'title' field.`, @@ -993,8 +1000,8 @@ export default class Entries { } } } - if (this.isEntryWithoutTitleField) { - throw Error(`Entries found with missing 'title' field! Please make the data corrections and re-run the audit.`); - } + // if (this.isEntryWithoutTitleField) { + // throw Error(`Entries found with missing 'title' field! Please make the data corrections and re-run the audit.`); + // } } } diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 18b05ddded..185ae9c787 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -6,8 +6,8 @@ "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { "@colors/colors": "^1.5.0", - "@contentstack/cli-cm-export": "~1.11.1", - "@contentstack/cli-cm-import": "~1.15.1", + "@contentstack/cli-cm-export": "~1.11.2", + "@contentstack/cli-cm-import": "~1.15.2", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.6.0", "async": "^3.2.4", diff --git a/packages/contentstack-export-to-csv/package.json b/packages/contentstack-export-to-csv/package.json index 571b72317e..fa0e83a896 100644 --- a/packages/contentstack-export-to-csv/package.json +++ b/packages/contentstack-export-to-csv/package.json @@ -65,4 +65,4 @@ } }, "repository": "https://github.com/contentstack/cli" -} +} \ No newline at end of file diff --git a/packages/contentstack-export/package.json b/packages/contentstack-export/package.json index 9377e499df..0abcce9f0f 100644 --- a/packages/contentstack-export/package.json +++ b/packages/contentstack-export/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-export", "description": "Contentstack CLI plugin to export content from stack", - "version": "1.11.1", + "version": "1.11.2", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { @@ -98,4 +98,4 @@ } }, "repository": "https://github.com/contentstack/cli" -} +} \ No newline at end of file diff --git a/packages/contentstack-export/src/commands/cm/stacks/export.ts b/packages/contentstack-export/src/commands/cm/stacks/export.ts index 4e90b7e2ca..3b38c9e7b0 100644 --- a/packages/contentstack-export/src/commands/cm/stacks/export.ts +++ b/packages/contentstack-export/src/commands/cm/stacks/export.ts @@ -8,7 +8,7 @@ import { flags, ContentstackClient, FlagInput, - pathValidator + pathValidator, } from '@contentstack/cli-utilities'; import { ModuleExporter } from '../../../export'; import { setupExportConfig, log, formatError, writeExportMetaFile } from '../../../utils'; @@ -105,7 +105,7 @@ export default class ExportCommand extends Command { let exportConfig = await setupExportConfig(flags); // Note setting host to create cma client exportConfig.host = this.cmaHost; - exportDir = exportConfig.data || exportConfig.exportDir; + exportDir = exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir; const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig); const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig); await moduleExporter.start(); @@ -113,7 +113,11 @@ export default class ExportCommand extends Command { writeExportMetaFile(exportConfig); } log(exportConfig, `The content of the stack ${exportConfig.apiKey} has been exported successfully!`, 'success'); - log(exportConfig, `The log has been stored at '${pathValidator(path.join(exportDir, 'logs', 'export'))}'`, 'success'); + log( + exportConfig, + `The log has been stored at '${pathValidator(path.join(exportDir, 'logs', 'export'))}'`, + 'success', + ); } catch (error) { log({ data: exportDir } as ExportConfig, `Failed to export stack content - ${formatError(error)}`, 'error'); log({ data: exportDir } as ExportConfig, `The log has been stored at ${exportDir}`, 'info'); diff --git a/packages/contentstack-export/src/types/export-config.ts b/packages/contentstack-export/src/types/export-config.ts index a56db980e6..9da6a373f4 100644 --- a/packages/contentstack-export/src/types/export-config.ts +++ b/packages/contentstack-export/src/types/export-config.ts @@ -2,6 +2,7 @@ import { Modules } from '.'; import DefaultConfig from './default-config'; export default interface ExportConfig extends DefaultConfig { + cliLogsPath: string; exportDir: string; data: string; management_token?: string; @@ -27,7 +28,7 @@ export default interface ExportConfig extends DefaultConfig { access_token?: string; org_uid?: string; source_stack?: string; - sourceStackName?:string; + sourceStackName?: string; } type branch = { diff --git a/packages/contentstack-export/src/utils/logger.ts b/packages/contentstack-export/src/utils/logger.ts index b2b8302622..944a08e9bc 100644 --- a/packages/contentstack-export/src/utils/logger.ts +++ b/packages/contentstack-export/src/utils/logger.ts @@ -134,7 +134,7 @@ function init(_logPath: string) { } export const log = async (config: ExportConfig, message: any, type: string) => { - const logsPath = config.data; + const logsPath = config.cliLogsPath || config.data; // ignoring the type argument, as we are not using it to create a logfile anymore if (type !== 'error') { // removed type argument from init method diff --git a/packages/contentstack-import/example_config/auth_config.json b/packages/contentstack-import/example_config/auth_config.json index fb329ee1f2..e154879235 100644 --- a/packages/contentstack-import/example_config/auth_config.json +++ b/packages/contentstack-import/example_config/auth_config.json @@ -4,14 +4,15 @@ "code": "en-us" }, "data": "file path", - "target_stack":"bltXXXXXXXXXX", - "branchName":"example1", + "target_stack": "bltXXXXXXXXXX", + "branchName": "example1", "moduleName": "content-types", "concurrency": 1, "importConcurrency": 5, "fetchConcurrency": 5, "writeConcurrency": 5, - "securedAssets":false, + "securedAssets": false, "developerHubBaseUrl": "", - "createBackupDir": "./temp" -} + "createBackupDir": "./temp", + "cliLogsPath": "./tmp" +} \ No newline at end of file diff --git a/packages/contentstack-import/example_config/management_config.json b/packages/contentstack-import/example_config/management_config.json index 7d56aa34bd..b43edc20e9 100644 --- a/packages/contentstack-import/example_config/management_config.json +++ b/packages/contentstack-import/example_config/management_config.json @@ -4,12 +4,13 @@ "code": "en-us" }, "data": "file path", - "branchName":"example1", + "branchName": "example1", "moduleName": "content-types", "concurrency": 1, "importConcurrency": 5, "fetchConcurrency": 5, "writeConcurrency": 5, - "securedAssets":false, - "developerHubBaseUrl": "" -} + "securedAssets": false, + "developerHubBaseUrl": "", + "cliLogsPath": "./tmp" +} \ No newline at end of file diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 78b85fe616..1d426d3fc0 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.15.1", + "version": "1.15.2", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-import/src/commands/cm/stacks/import.ts b/packages/contentstack-import/src/commands/cm/stacks/import.ts index 5b7bf38e18..225edc5008 100644 --- a/packages/contentstack-import/src/commands/cm/stacks/import.ts +++ b/packages/contentstack-import/src/commands/cm/stacks/import.ts @@ -7,7 +7,7 @@ import { flags, FlagInput, ContentstackClient, - pathValidator + pathValidator, } from '@contentstack/cli-utilities'; import { ImportConfig } from '../../../types'; @@ -126,7 +126,7 @@ export default class ImportCommand extends Command { let importConfig = await setupImportConfig(flags); // Note setting host to create cma client importConfig.host = this.cmaHost; - backupDir = importConfig.backupDir; + backupDir = importConfig.cliLogsPath || importConfig.backupDir; const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig); const moduleImporter = new ModuleImporter(managementAPIClient, importConfig); @@ -144,7 +144,9 @@ export default class ImportCommand extends Command { log( importConfig, - `The log has been stored at '${pathValidator(path.join(importConfig.backupDir, 'logs', 'import'))}'`, + `The log has been stored at '${pathValidator( + path.join(importConfig.cliLogsPath || importConfig.backupDir, 'logs', 'import'), + )}'`, 'success', ); } catch (error) { @@ -156,7 +158,9 @@ export default class ImportCommand extends Command { log( { data: backupDir } as ImportConfig, `The log has been stored at ${ - { data: backupDir } ? pathValidator(path.join(backupDir || __dirname, 'logs', 'import')) : pathValidator(path.join(__dirname, 'logs')) + { data: backupDir } + ? pathValidator(path.join(backupDir || __dirname, 'logs', 'import')) + : pathValidator(path.join(__dirname, 'logs')) }`, 'info', ); diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index 6970d7d8dd..a22908ccaf 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -114,7 +114,7 @@ class ModuleImporter { * fix available and the user confirms to proceed with the fix, otherwise it returns `false`. */ async auditImportData(logger: Logger) { - const basePath = resolve(this.importConfig.backupDir, 'logs', 'audit'); + const basePath = resolve(this.importConfig.cliLogsPath || this.importConfig.backupDir, 'logs', 'audit'); const auditConfig = this.importConfig.auditConfig; auditConfig.config.basePath = basePath; auditConfig.config.branch = this.importConfig.branchName; diff --git a/packages/contentstack-import/src/types/import-config.ts b/packages/contentstack-import/src/types/import-config.ts index 69255e8391..60c21c2f95 100644 --- a/packages/contentstack-import/src/types/import-config.ts +++ b/packages/contentstack-import/src/types/import-config.ts @@ -11,6 +11,7 @@ export interface ExternalConfig { } export default interface ImportConfig extends DefaultConfig, ExternalConfig { + cliLogsPath: string; canCreatePrivateApp: boolean; contentDir: string; data: string; diff --git a/packages/contentstack-import/src/utils/log.ts b/packages/contentstack-import/src/utils/log.ts index 8e4f48b6e4..7c3923a3f8 100644 --- a/packages/contentstack-import/src/utils/log.ts +++ b/packages/contentstack-import/src/utils/log.ts @@ -26,7 +26,7 @@ export function log(entryOrMessage: MessageType, logType?: LogsType, hidden?: bo export function initLogger(config?: ImportConfig | undefined) { if (!logger) { - const basePath = pathValidator(join(config?.data ?? process.cwd(), 'logs', 'import')); + const basePath = pathValidator(join(config?.cliLogsPath ?? process.cwd(), 'logs', 'import')); logger = new Logger(Object.assign(config ?? {}, { basePath })); } diff --git a/packages/contentstack-import/src/utils/logger.ts b/packages/contentstack-import/src/utils/logger.ts index 207f89766d..d3542c11a1 100644 --- a/packages/contentstack-import/src/utils/logger.ts +++ b/packages/contentstack-import/src/utils/logger.ts @@ -136,14 +136,14 @@ function init(_logPath: string) { } export const log = async (config: ImportConfig, message: any, type: string) => { - config.data = config.data || path.join(__dirname, 'logs'); + config.cliLogsPath = config.cliLogsPath || config.data || path.join(__dirname, 'logs'); // ignoring the type argument, as we are not using it to create a logfile anymore if (type !== 'error') { // removed type argument from init method - if (type === 'warn') init(config.data).warn(message); //logged warning message in log file - else init(config.data).log(message); + if (type === 'warn') init(config.cliLogsPath).warn(message); //logged warning message in log file + else init(config.cliLogsPath).log(message); } else { - init(config.data).error(message); + init(config.cliLogsPath).error(message); } }; diff --git a/packages/contentstack-import/src/utils/marketplace-app-helper.ts b/packages/contentstack-import/src/utils/marketplace-app-helper.ts index e5cab282a8..b708bac4ad 100644 --- a/packages/contentstack-import/src/utils/marketplace-app-helper.ts +++ b/packages/contentstack-import/src/utils/marketplace-app-helper.ts @@ -103,6 +103,8 @@ export const getConfirmationToCreateApps = async (privateApps: any, config: Impo } } } + } else { + return Promise.resolve(true); } }; diff --git a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js new file mode 100644 index 0000000000..33d9c25229 --- /dev/null +++ b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js @@ -0,0 +1,157 @@ +const fs = require('fs'); +const chalk = require('chalk'); +const path = require('path'); +module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config }) => { + const modules = ['entries', 'assets', 'extensions', 'marketplace_apps']; + + const readAllModulesUids = (filePath) => { + let uidMapping = {}; + + modules.forEach((module) => { + const mappingFilePath = path.join(filePath, 'mapper', module, 'uid-mapping.json'); + if (fs.existsSync(mappingFilePath)) { + const mappedIds = JSON.parse(fs.readFileSync(mappingFilePath, 'utf-8')); + + if (module === 'marketplace_apps') { + Object.values(mappedIds).forEach((ids) => Object.assign(uidMapping, ids)); + } else { + Object.assign(uidMapping, mappedIds); + } + } + }); + + return uidMapping; + }; + + const getEntries = async (ct) => { + try { + let entries = []; + let skip = 0; + let limit = 100; + let count = 0; + while (skip <= count) { + const res = await stackSDKInstance.contentType(ct).entry().query({ include_count: true, skip, limit }).find(); + count = res.count; + skip += limit; + entries.push(...res.items); + } + return entries; + } catch (err) { + console.log(chalk.red(`Failed to fetch the entries...`)); + throw err; + } + }; + + const getContentTypeSchema = async (ct) => { + try { + return await stackSDKInstance.contentType(ct).fetch(); + } catch (err) { + console.log(chalk.red(`Failed to fetch the Content Type '${ct}' due to ${err.errorMessage}`)); + } + }; + + const findAllEntriesUid = (stringifiedEntry) => { + let pattern = /\bblt\w*/g; + let matches = stringifiedEntry.match(pattern); + return matches; + }; + + const replaceEntriesWithUpdatedUids = (matches, uidMapping, stringifiedEntry) => { + let isUpdated = false; + let oldUids = Object.keys(uidMapping); + matches.forEach((m) => { + if (oldUids.includes(m)) { + let regex = new RegExp(m, 'g'); + stringifiedEntry = stringifiedEntry.replace(regex, uidMapping[m]); + console.log(chalk.green(`Replacing the UID '${m}' with '${uidMapping[m]}'...`)); + isUpdated = true; + } + }); + return { stringifiedEntry, isUpdated }; + }; + + const updateEntryTask = () => { + return { + title: 'Update Reference Entries from Mapper', + successMessage: 'Reference Updated Successfully', + failedMessage: 'Failed to Update References in Entries', + task: async (params) => { + try { + const log = console.log; + + if ((!config.contentTypes && !Array.isArray(config.contentTypes)) || !config['mapper-path']) { + throw Error( + `Missing Content Type or mapper path in config! Please make sure to have the Content Type [in Array] and the mapper path in config.`, + ); + } + + for (let ct of config.contentTypes) { + let { schema: ctSchema } = (await getContentTypeSchema(ct)) ?? {}; + + if (!ctSchema) { + continue; + } + + let keys = ctSchema?.map((schema) => { + return schema.uid; + }); + + let entry = (await getEntries(ct)) ?? []; + + if (entry.length === 0) { + log(chalk.red(`No entry found for the CT Content-type '${ct}'`)); + continue; + } + let uidMapping = readAllModulesUids(config['mapper-path']); + + for (let e of entry) { + let isUpdated = false; + + let stringEntry = JSON.stringify(e); + + let matches = findAllEntriesUid(stringEntry); + + let res = replaceEntriesWithUpdatedUids(matches, uidMapping, stringEntry); + + stringEntry = res.stringifiedEntry; + isUpdated = res.isUpdated; + + stringEntry = JSON.parse(stringEntry); + + keys.forEach((k) => { + if (stringEntry[k]) { + e[k] = stringEntry[k]; + } + }); + + if (isUpdated) { + await e.update(e.locale); + + log( + chalk.green( + `Successfully updated the references in the entry with UID '${e.uid}' and title '${e.title}' of Content Type '${ct}' in Locale '${e.locale}'`, + ), + ); + } else { + log( + chalk.red( + `Failed to update the references in the entry with UID '${e.uid}' and title '${e.title}' of Content Type '${ct}' in Locale '${e.locale}'`, + ), + ); + } + } + log(chalk.green(`Successfully updated the references in the entries of Content Type '${ct}'`)); + } + } catch (err) { + if (err.request?.headers) { + delete err.request['headers']; + } + console.log(chalk.red(`Failed to update references...`)); + throw err; + } + }, + }; + }; + + migration.addTask(updateEntryTask()); +}; diff --git a/packages/contentstack-migration/package.json b/packages/contentstack-migration/package.json index ffc15d535c..200d631a6e 100644 --- a/packages/contentstack-migration/package.json +++ b/packages/contentstack-migration/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-migration", - "version": "1.5.3", + "version": "1.5.4", "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 3c1984da5f..97a419c1a7 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -5,7 +5,7 @@ "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-import": "~1.15.1", + "@contentstack/cli-cm-import": "~1.15.2", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.6.0", "inquirer": "8.2.4", diff --git a/packages/contentstack-utilities/src/helpers.ts b/packages/contentstack-utilities/src/helpers.ts index 6270ca906f..144770fe9a 100644 --- a/packages/contentstack-utilities/src/helpers.ts +++ b/packages/contentstack-utilities/src/helpers.ts @@ -37,7 +37,6 @@ export const createDeveloperHubUrl = (developerHubBaseUrl: string): string => { return developerHubBaseUrl.startsWith('http') ? developerHubBaseUrl : `https://${developerHubBaseUrl}`; }; - export const validatePath = (input: string) => { const pattern = /[*$%#<>{}!&?]/g; if (pattern.test(input)) { @@ -53,5 +52,4 @@ export const validatePath = (input: string) => { }; // To escape special characters in a string -export const escapeRegExp = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - +export const escapeRegExp = (str: string) => str?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 8cf64987d3..746b6c7369 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.17.3", + "version": "1.17.4", "author": "Contentstack", "bin": { "csdx": "./bin/run" @@ -27,16 +27,16 @@ "@contentstack/cli-cm-bootstrap": "~1.9.0", "@contentstack/cli-cm-branches": "~1.0.24", "@contentstack/cli-cm-bulk-publish": "~1.4.5", - "@contentstack/cli-cm-export": "~1.11.1", + "@contentstack/cli-cm-export": "~1.11.2", "@contentstack/cli-cm-clone": "~1.10.3", "@contentstack/cli-cm-export-to-csv": "~1.7.0", - "@contentstack/cli-cm-import": "~1.15.1", + "@contentstack/cli-cm-import": "~1.15.2", "@contentstack/cli-cm-migrate-rte": "~1.4.15", "@contentstack/cli-cm-seed": "~1.7.3", "@contentstack/cli-command": "~1.2.17", "@contentstack/cli-config": "~1.6.3", "@contentstack/cli-launch": "~1.0.17", - "@contentstack/cli-migration": "~1.5.3", + "@contentstack/cli-migration": "~1.5.4", "@contentstack/cli-utilities": "~1.6.0", "@contentstack/management": "~1.15.3", "@oclif/core": "^2.9.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8bd898e9ed..54c7f75d56 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,15 +16,15 @@ importers: '@contentstack/cli-cm-branches': ~1.0.24 '@contentstack/cli-cm-bulk-publish': ~1.4.5 '@contentstack/cli-cm-clone': ~1.10.3 - '@contentstack/cli-cm-export': ~1.11.1 + '@contentstack/cli-cm-export': ~1.11.2 '@contentstack/cli-cm-export-to-csv': ~1.7.0 - '@contentstack/cli-cm-import': ~1.15.1 + '@contentstack/cli-cm-import': ~1.15.2 '@contentstack/cli-cm-migrate-rte': ~1.4.15 '@contentstack/cli-cm-seed': ~1.7.3 '@contentstack/cli-command': ~1.2.17 '@contentstack/cli-config': ~1.6.3 '@contentstack/cli-launch': ~1.0.17 - '@contentstack/cli-migration': ~1.5.3 + '@contentstack/cli-migration': ~1.5.4 '@contentstack/cli-utilities': ~1.6.0 '@contentstack/management': ~1.15.3 '@oclif/core': ^2.9.3 @@ -423,8 +423,8 @@ importers: packages/contentstack-clone: specifiers: '@colors/colors': ^1.5.0 - '@contentstack/cli-cm-export': ~1.11.1 - '@contentstack/cli-cm-import': ~1.15.1 + '@contentstack/cli-cm-export': ~1.11.2 + '@contentstack/cli-cm-import': ~1.15.2 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.6.0 '@oclif/test': ^2.5.6 @@ -990,7 +990,7 @@ importers: packages/contentstack-seed: specifiers: - '@contentstack/cli-cm-import': ~1.15.1 + '@contentstack/cli-cm-import': ~1.15.2 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.6.0 '@oclif/plugin-help': ^5.1.19