Skip to content

Commit ffcc0bb

Browse files
Merge pull request #2122 from contentstack/fix/DX-3491
update logger to v2 and fix import path validation
2 parents d539ee5 + 5e67f6e commit ffcc0bb

File tree

13 files changed

+2188
-2134
lines changed

13 files changed

+2188
-2134
lines changed

.talismanrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: e99f717f726226d79c6d484b44fa3d8e758038fbaca671301377741e36802b6d
3+
checksum: 560538910aada20a4c770b19f977bbe62680ca86ec6f5c3eb4b5a61e4f3f1a49
44
- filename: pnpm-lock.yaml
5-
checksum: d26dfe4137bcd958a79beff8a2867fbbad531f81ef0c8c8a8786e8680b79b52e
5+
checksum: 713cd001a5929ee85ab17eb7ef96c32a2b23878685a3ed74604a6ba6fd579058
66
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
77
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
88
- filename: packages/contentstack-import-setup/test/config.json
@@ -86,5 +86,5 @@ fileignoreconfig:
8686
- filename: packages/contentstack-import-setup/src/utils/backup-handler.ts
8787
checksum: 7db02c6f2627400b28fc96d505bf074d477080a45ba13943709d4845b6ca0908
8888
- filename: packages/contentstack-import/src/utils/backup-handler.ts
89-
checksum: 4f7a8bea92ebffbc34a0979b3a63fef327562a899b773481d67a675140cfa4bf
89+
checksum: 0a9accdafce01837166223ed00cd801e2ebb39a4ef952231f67232859a5beea8
9090
version: "1.0"

package-lock.json

Lines changed: 596 additions & 565 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-clone/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@colors/colors": "^1.6.0",
99
"@contentstack/cli-cm-export": "~1.20.1",
10-
"@contentstack/cli-cm-import": "~1.28.0",
10+
"@contentstack/cli-cm-import": "~1.28.1",
1111
"@contentstack/cli-command": "~1.6.1",
1212
"@contentstack/cli-utilities": "~1.14.1",
1313
"@oclif/core": "^4.3.0",

packages/contentstack-import/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
4747
$ csdx COMMAND
4848
running command...
4949
$ csdx (--version)
50-
@contentstack/cli-cm-import/1.28.0 darwin-arm64 node-v22.14.0
50+
@contentstack/cli-cm-import/1.28.1 darwin-arm64 node-v22.14.0
5151
$ csdx --help [COMMAND]
5252
USAGE
5353
$ csdx COMMAND

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-cm-import",
33
"description": "Contentstack CLI plugin to import content into stack",
4-
"version": "1.28.0",
4+
"version": "1.28.1",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {

packages/contentstack-import/src/import/module-importer.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolve } from 'path';
22
import { AuditFix } from '@contentstack/cli-audit';
33
import messages, { $t } from '@contentstack/cli-audit/lib/messages';
4-
import { addLocale, cliux, ContentstackClient, Logger, log } from '@contentstack/cli-utilities';
4+
import { addLocale, cliux, ContentstackClient, log } from '@contentstack/cli-utilities';
55

66
import startModuleImport from './modules';
77
import startJSModuleImport from './modules-js';
@@ -10,7 +10,6 @@ import {
1010
backupHandler,
1111
masterLocalDetails,
1212
sanitizeStack,
13-
initLogger,
1413
setupBranchConfig,
1514
executeImportPathLogic,
1615
} from '../utils';
@@ -30,14 +29,15 @@ class ModuleImporter {
3029
}
3130

3231
async start(): Promise<any> {
32+
3333
if (!this.importConfig.management_token) {
3434
const stackDetails: Record<string, unknown> = await this.stackAPIClient.fetch();
3535
this.importConfig.stackName = stackDetails.name as string;
3636
this.importConfig.org_uid = stackDetails.org_uid as string;
3737
}
38-
38+
3939
await this.resolveImportPath();
40-
40+
4141
await setupBranchConfig(this.importConfig, this.stackAPIClient);
4242
if (this.importConfig.branchAlias && this.importConfig.branchName) {
4343
this.stackAPIClient = this.managementAPIClient.stack({
@@ -58,9 +58,6 @@ class ModuleImporter {
5858
this.importConfig.data = backupDir;
5959
}
6060

61-
// NOTE init log
62-
const logger = initLogger(this.importConfig);
63-
6461
// NOTE audit and fix the import content.
6562
if (
6663
!this.importConfig.skipAudit &&
@@ -69,7 +66,7 @@ class ModuleImporter {
6966
this.importConfig.moduleName,
7067
))
7168
) {
72-
if (!(await this.auditImportData(logger))) {
69+
if (!(await this.auditImportData())) {
7370
return { noSuccessMsg: true };
7471
}
7572
}
@@ -152,7 +149,7 @@ class ModuleImporter {
152149
* @returns The function `auditImportData()` returns a boolean value. It returns `true` if there is a
153150
* fix available and the user confirms to proceed with the fix, otherwise it returns `false`.
154151
*/
155-
async auditImportData(logger: Logger) {
152+
async auditImportData() {
156153
const basePath = resolve(this.importConfig.cliLogsPath || this.importConfig.backupDir, 'logs', 'audit');
157154
const auditConfig = this.importConfig.auditConfig;
158155
auditConfig.config.basePath = basePath;
@@ -189,7 +186,7 @@ class ModuleImporter {
189186
const { hasFix, config } = result;
190187

191188
if (hasFix) {
192-
logger.log($t(messages.FINAL_REPORT_PATH, { path: config.reportPath }), 'warn');
189+
log.warn($t(messages.FINAL_REPORT_PATH, { path: config.reportPath }), this.importConfig.context);
193190

194191
if (
195192
this.importConfig.forceStopMarketplaceAppsPrompt ||

packages/contentstack-import/src/utils/backup-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
5454

5555
if (backupDirPath) {
5656
log.debug(`Starting content copy to backup directory: ${backupDirPath}`);
57-
cliux.print('Copying content to the backup directory...');
57+
log.info('Copying content to the backup directory...', importConfig.context);
5858

5959
return new Promise((resolve, reject) => {
6060
return copy(sourceDir, backupDirPath, (error: any) => {

packages/contentstack-import/src/utils/import-config-handler.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
4343
config.contentDir = path.resolve(config.contentDir);
4444
//Note to support the old key
4545
config.data = config.contentDir;
46-
if (fileExistsSync(path.join(config.contentDir, 'export-info.json'))) {
47-
config.contentVersion =
48-
((await readFile(path.join(config.contentDir, 'export-info.json'))) || {}).contentVersion || 2;
49-
} else {
50-
config.contentVersion = 1;
51-
}
5246

5347
const managementTokenAlias = importCmdFlags['management-token-alias'] || importCmdFlags['alias'];
5448

packages/contentstack-import/src/utils/import-path-resolver.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export const resolveImportPath = async (importConfig: ImportConfig, stackAPIClie
123123
* @param importConfig - The import configuration object
124124
* @param resolvedPath - The resolved path
125125
*/
126-
export const updateImportConfigWithResolvedPath = (importConfig: ImportConfig, resolvedPath: string): void => {
126+
export const updateImportConfigWithResolvedPath = async (importConfig: ImportConfig, resolvedPath: string): Promise<void> => {
127127
log.debug(`Updating import config with resolved path: ${resolvedPath}`);
128128

129129
if (!fileExistsSync(resolvedPath)) {
@@ -137,8 +137,18 @@ export const updateImportConfigWithResolvedPath = (importConfig: ImportConfig, r
137137

138138
importConfig.data = resolvedPath;
139139

140+
const exportInfoPath = path.join(resolvedPath, 'export-info.json');
141+
if (fileExistsSync(exportInfoPath)) {
142+
const exportInfo = await readFile(exportInfoPath);
143+
importConfig.contentVersion = exportInfo?.contentVersion || 2;
144+
log.debug(`Content version set to ${importConfig.contentVersion} from ${exportInfoPath}`);
145+
} else {
146+
importConfig.contentVersion = 1;
147+
log.debug(`No export-info.json found at ${exportInfoPath}, setting content version to 1`);
148+
}
149+
140150
log.debug(
141-
`Import config updated - contentDir: ${importConfig.contentDir}, branchDir: ${importConfig.branchDir}, data: ${importConfig.data}`,
151+
`Import config updated - contentDir: ${importConfig.contentDir}, branchDir: ${importConfig.branchDir}, data: ${importConfig.data}, contentVersion: ${importConfig.contentVersion}`,
142152
);
143153
};
144154

@@ -153,7 +163,7 @@ export const executeImportPathLogic = async (importConfig: ImportConfig, stackAP
153163

154164
const resolvedPath = await resolveImportPath(importConfig, stackAPIClient);
155165

156-
updateImportConfigWithResolvedPath(importConfig, resolvedPath);
166+
await updateImportConfigWithResolvedPath(importConfig, resolvedPath);
157167

158168
return resolvedPath;
159169
};

packages/contentstack-seed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
8-
"@contentstack/cli-cm-import": "~1.28.0",
8+
"@contentstack/cli-cm-import": "~1.28.1",
99
"@contentstack/cli-command": "~1.6.1",
1010
"@contentstack/cli-utilities": "~1.14.1",
1111
"@contentstack/management": "~1.22.0",

0 commit comments

Comments
 (0)