Skip to content

Commit a47c201

Browse files
committed
refactor: exported v2Logger as log to improve clarity
1 parent c4781ff commit a47c201

26 files changed

Lines changed: 101 additions & 101 deletions

packages/contentstack-export/src/commands/cm/stacks/export.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
pathValidator,
1111
sanitizePath,
1212
configHandler,
13-
v2Logger,
13+
log,
1414
handleAndLogError,
1515
getLogPath
1616
} from '@contentstack/cli-utilities';
@@ -126,8 +126,8 @@ export default class ExportCommand extends Command {
126126
if (!exportConfig.branches?.length) {
127127
writeExportMetaFile(exportConfig);
128128
}
129-
v2Logger.success(`The content of the stack ${exportConfig.apiKey} has been exported successfully!`,exportConfig.context)
130-
v2Logger.info(`The log has been stored at '${getLogPath()}'`, exportConfig.context)
129+
log.success(`The content of the stack ${exportConfig.apiKey} has been exported successfully!`,exportConfig.context)
130+
log.success(`The log has been stored at '${getLogPath()}'`, exportConfig.context)
131131
} catch (error) {
132132
handleAndLogError(error, { ...exportConfig.context });
133133
}

packages/contentstack-export/src/export/module-exporter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path';
2-
import { ContentstackClient, handleAndLogError, messageHandler, v2Logger } from '@contentstack/cli-utilities';
3-
import { setupBranches, setupExportDir, log, formatError, writeExportMetaFile } from '../utils';
2+
import { ContentstackClient, handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
3+
import { setupBranches, setupExportDir, writeExportMetaFile } from '../utils';
44
import startModuleExport from './modules';
55
import startJSModuleExport from './modules-js';
66
import { ExportConfig, Modules } from '../types';
@@ -38,10 +38,10 @@ class ModuleExporter {
3838
this.exportConfig.branchName = branch.uid;
3939
this.stackAPIClient.stackHeaders.branch = branch.uid;
4040
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, branch.uid);
41-
v2Logger.info(`Exporting content from branch ${branch.uid}`, this.exportConfig.context);
41+
log.info(`Exporting content from branch ${branch.uid}`, this.exportConfig.context);
4242
writeExportMetaFile(this.exportConfig, this.exportConfig.branchDir);
4343
await this.export();
44-
v2Logger.success(
44+
log.success(
4545
`The content of branch ${branch.uid} has been exported successfully!`,
4646
this.exportConfig.context,
4747
);
@@ -57,7 +57,7 @@ class ModuleExporter {
5757
}
5858

5959
async export() {
60-
v2Logger.info(
60+
log.info(
6161
`Started to export content, version is ${this.exportConfig.contentVersion}`,
6262
this.exportConfig.context,
6363
);
@@ -69,7 +69,7 @@ class ModuleExporter {
6969
}
7070

7171
async exportByModuleByName(moduleName: Modules) {
72-
v2Logger.info(`Exporting module: ${moduleName}`, this.exportConfig.context);
72+
log.info(`Exporting module: ${moduleName}`, this.exportConfig.context);
7373
// export the modules by name
7474
// calls the module runner which inturn calls the module itself
7575
let exportedModuleResponse;

packages/contentstack-export/src/export/modules/assets.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
FsUtility,
1616
getDirectories,
1717
configHandler,
18-
v2Logger,
18+
log,
1919
handleAndLogError,
2020
messageHandler,
2121
} from '@contentstack/cli-utilities';
@@ -63,7 +63,7 @@ export default class ExportAssets extends BaseClass {
6363

6464
// NOTE step 4: Download all assets
6565
await this.downloadAssets();
66-
v2Logger.success(messageHandler.parse('ASSET_EXPORT_COMPLETE'), this.exportConfig.context);
66+
log.success(messageHandler.parse('ASSET_EXPORT_COMPLETE'), this.exportConfig.context);
6767
}
6868

6969
/**
@@ -103,7 +103,7 @@ export default class ExportAssets extends BaseClass {
103103
this.assetsFolder,
104104
);
105105
}
106-
v2Logger.info(
106+
log.info(
107107
messageHandler.parse('ASSET_FOLDERS_EXPORT_COMPLETE', this.assetsFolder.length),
108108
this.exportConfig.context,
109109
);
@@ -170,7 +170,7 @@ export default class ExportAssets extends BaseClass {
170170
concurrencyLimit: this.assetConfig.fetchConcurrency,
171171
}).then(() => {
172172
fs?.completeFile(true);
173-
v2Logger.info(messageHandler.parse('ASSET_METADATA_EXPORT_COMPLETE'), this.exportConfig.context);
173+
log.info(messageHandler.parse('ASSET_METADATA_EXPORT_COMPLETE'), this.exportConfig.context);
174174
});
175175
}
176176

@@ -247,7 +247,7 @@ export default class ExportAssets extends BaseClass {
247247
promisifyHandler,
248248
).then(() => {
249249
fs?.completeFile(true);
250-
v2Logger.info(messageHandler.parse('ASSET_VERSIONED_METADATA_EXPORT_COMPLETE'), this.exportConfig.context);
250+
log.info(messageHandler.parse('ASSET_VERSIONED_METADATA_EXPORT_COMPLETE'), this.exportConfig.context);
251251
});
252252
}
253253

@@ -338,7 +338,7 @@ export default class ExportAssets extends BaseClass {
338338
data.pipe(assetWriterStream);
339339
}
340340

341-
v2Logger.success(
341+
log.success(
342342
messageHandler.parse('ASSET_DOWNLOAD_SUCCESS', asset.filename, asset.uid),
343343
this.exportConfig.context,
344344
);
@@ -378,7 +378,7 @@ export default class ExportAssets extends BaseClass {
378378
},
379379
promisifyHandler,
380380
).then(() => {
381-
v2Logger.success(messageHandler.parse('ASSET_DOWNLOAD_COMPLETE'), this.exportConfig.context);
381+
log.success(messageHandler.parse('ASSET_DOWNLOAD_COMPLETE'), this.exportConfig.context);
382382
});
383383
}
384384
}

packages/contentstack-export/src/export/modules/base-class.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import chunk from 'lodash/chunk';
55
import isEmpty from 'lodash/isEmpty';
66
import entries from 'lodash/entries';
77
import isEqual from 'lodash/isEqual';
8-
import { v2Logger } from '@contentstack/cli-utilities';
8+
import { log } from '@contentstack/cli-utilities';
99

1010
import { ExportConfig, ModuleClassParams } from '../../types';
1111

@@ -134,7 +134,7 @@ export default abstract class BaseClass {
134134
async logMsgAndWaitIfRequired(module: string, start: number, batchNo: number): Promise<void> {
135135
const end = Date.now();
136136
const exeTime = end - start;
137-
v2Logger.success(
137+
log.success(
138138
`Batch No. ${batchNo} of ${module} is complete. Time taken: ${exeTime} milliseconds`,
139139
this.exportConfig.context,
140140
);

packages/contentstack-export/src/export/modules/content-types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ContentstackClient,
44
handleAndLogError,
55
messageHandler,
6-
v2Logger,
6+
log,
77
sanitizePath,
88
} from '@contentstack/cli-utilities';
99

@@ -63,7 +63,7 @@ export default class ContentTypesExport extends BaseClass {
6363
await fsUtil.makeDirectory(this.contentTypesDirPath);
6464
await this.getContentTypes();
6565
await this.writeContentTypes(this.contentTypes);
66-
v2Logger.success(messageHandler.parse('CONTENT_TYPE_EXPORT_COMPLETE'), this.exportConfig.context);
66+
log.success(messageHandler.parse('CONTENT_TYPE_EXPORT_COMPLETE'), this.exportConfig.context);
6767
} catch (error) {
6868
handleAndLogError(error, { ...this.exportConfig.context });
6969
throw new Error(messageHandler.parse('CONTENT_TYPE_EXPORT_FAILED'));
@@ -85,7 +85,7 @@ export default class ContentTypesExport extends BaseClass {
8585
}
8686
return await this.getContentTypes(skip);
8787
} else {
88-
v2Logger.info(messageHandler.parse('CONTENT_TYPE_NO_TYPES'), this.exportConfig.context);
88+
log.info(messageHandler.parse('CONTENT_TYPE_NO_TYPES'), this.exportConfig.context);
8989
}
9090
}
9191

packages/contentstack-export/src/export/modules/custom-roles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import find from 'lodash/find';
33
import forEach from 'lodash/forEach';
44
import values from 'lodash/values';
55
import { resolve as pResolve } from 'node:path';
6-
import { handleAndLogError, messageHandler, v2Logger } from '@contentstack/cli-utilities';
6+
import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
77

88
import BaseClass from './base-class';
99
import { fsUtil } from '../../utils';
@@ -51,12 +51,12 @@ export default class ExportCustomRoles extends BaseClass {
5151
const customRoles = roles.items.filter((role: any) => !this.existingRoles[role.name]);
5252

5353
if (!customRoles.length) {
54-
v2Logger.info(messageHandler.parse('ROLES_NO_CUSTOM_ROLES'), this.exportConfig.context);
54+
log.info(messageHandler.parse('ROLES_NO_CUSTOM_ROLES'), this.exportConfig.context);
5555
return;
5656
}
5757

5858
customRoles.forEach((role: any) => {
59-
v2Logger.info(messageHandler.parse('ROLES_EXPORTING_ROLE', role.name), this.exportConfig.context);
59+
log.info(messageHandler.parse('ROLES_EXPORTING_ROLE', role.name), this.exportConfig.context);
6060
this.customRoles[role.uid] = role;
6161
});
6262
fsUtil.writeFile(pResolve(this.rolesFolderPath, this.customRolesConfig.fileName), this.customRoles);

packages/contentstack-export/src/export/modules/entries.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
FsUtility,
55
handleAndLogError,
66
messageHandler,
7-
v2Logger,
7+
log,
88
} from '@contentstack/cli-utilities';
99
import { Export, ExportProjects } from '@contentstack/cli-variants';
1010
import { sanitizePath } from '@contentstack/cli-utilities';
@@ -66,7 +66,7 @@ export default class EntriesExport extends BaseClass {
6666
const locales = fsUtil.readFile(this.localesFilePath) as Array<Record<string, unknown>>;
6767
const contentTypes = fsUtil.readFile(this.schemaFilePath) as Array<Record<string, unknown>>;
6868
if (contentTypes.length === 0) {
69-
v2Logger.info(messageHandler.parse('CONTENT_TYPE_NO_TYPES'), this.exportConfig.context);
69+
log.info(messageHandler.parse('CONTENT_TYPE_NO_TYPES'), this.exportConfig.context);
7070
return;
7171
}
7272

@@ -91,7 +91,7 @@ export default class EntriesExport extends BaseClass {
9191
for (let entryRequestOption of entryRequestOptions) {
9292
await this.getEntries(entryRequestOption);
9393
this.entriesFileHelper?.completeFile(true);
94-
v2Logger.success(
94+
log.success(
9595
messageHandler.parse(
9696
'ENTRIES_EXPORT_COMPLETE',
9797
entryRequestOption.contentType,
@@ -100,7 +100,7 @@ export default class EntriesExport extends BaseClass {
100100
this.exportConfig.context,
101101
);
102102
}
103-
v2Logger.success(messageHandler.parse('ENTRIES_EXPORT_SUCCESS'), this.exportConfig.context);
103+
log.success(messageHandler.parse('ENTRIES_EXPORT_SUCCESS'), this.exportConfig.context);
104104
} catch (error) {
105105
handleAndLogError(error, { ...this.exportConfig.context });
106106
}
@@ -216,7 +216,7 @@ export default class EntriesExport extends BaseClass {
216216
path.join(sanitizePath(options.versionedEntryPath), sanitizePath(`${entry.uid}.json`)),
217217
response,
218218
);
219-
v2Logger.success(
219+
log.success(
220220
messageHandler.parse('ENTRIES_VERSIONED_EXPORT_SUCCESS', options.contentType, entry.uid, options.locale),
221221
this.exportConfig.context,
222222
);

packages/contentstack-export/src/export/modules/environments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolve as pResolve } from 'node:path';
22
import omit from 'lodash/omit';
33
import isEmpty from 'lodash/isEmpty';
4-
import { handleAndLogError, messageHandler, v2Logger } from '@contentstack/cli-utilities';
4+
import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
55

66
import BaseClass from './base-class';
77
import { fsUtil } from '../../utils';
@@ -35,10 +35,10 @@ export default class ExportEnvironments extends BaseClass {
3535
await this.getEnvironments();
3636

3737
if (this.environments === undefined || isEmpty(this.environments)) {
38-
v2Logger.info(messageHandler.parse('ENVIRONMENT_NOT_FOUND'), this.exportConfig.context);
38+
log.info(messageHandler.parse('ENVIRONMENT_NOT_FOUND'), this.exportConfig.context);
3939
} else {
4040
fsUtil.writeFile(pResolve(this.environmentsFolderPath, this.environmentConfig.fileName), this.environments);
41-
v2Logger.success(
41+
log.success(
4242
messageHandler.parse('ENVIRONMENT_EXPORT_COMPLETE', Object.keys(this.environments).length),
4343
this.exportConfig.context,
4444
);
@@ -74,7 +74,7 @@ export default class ExportEnvironments extends BaseClass {
7474
const extUid = environments[index].uid;
7575
const envName = environments[index]?.name;
7676
this.environments[extUid] = omit(environments[index], ['ACL']);
77-
v2Logger.success(messageHandler.parse('ENVIRONMENT_EXPORT_SUCCESS', envName ), this.exportConfig.context);
77+
log.success(messageHandler.parse('ENVIRONMENT_EXPORT_SUCCESS', envName ), this.exportConfig.context);
7878
}
7979
}
8080
}

packages/contentstack-export/src/export/modules/extensions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import omit from 'lodash/omit';
22
import isEmpty from 'lodash/isEmpty';
33
import { resolve as pResolve } from 'node:path';
4-
import { handleAndLogError, messageHandler, v2Logger } from '@contentstack/cli-utilities';
4+
import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
55

66
import BaseClass from './base-class';
77
import { fsUtil } from '../../utils';
@@ -35,10 +35,10 @@ export default class ExportExtensions extends BaseClass {
3535
await this.getExtensions();
3636

3737
if (this.extensions === undefined || isEmpty(this.extensions)) {
38-
v2Logger.info(messageHandler.parse('EXTENSION_NOT_FOUND'), this.exportConfig.context);
38+
log.info(messageHandler.parse('EXTENSION_NOT_FOUND'), this.exportConfig.context);
3939
} else {
4040
fsUtil.writeFile(pResolve(this.extensionsFolderPath, this.extensionConfig.fileName), this.extensions);
41-
v2Logger.success(
41+
log.success(
4242
messageHandler.parse('EXTENSION_EXPORT_COMPLETE', Object.keys(this.extensions).length ),
4343
this.exportConfig.context,
4444
);
@@ -74,7 +74,7 @@ export default class ExportExtensions extends BaseClass {
7474
const extUid = extensions[index].uid;
7575
const extTitle = extensions[index]?.title;
7676
this.extensions[extUid] = omit(extensions[index], ['SYS_ACL']);
77-
v2Logger.info(messageHandler.parse('EXTENSION_EXPORT_SUCCESS', extTitle), this.exportConfig.context);
77+
log.info(messageHandler.parse('EXTENSION_EXPORT_SUCCESS', extTitle), this.exportConfig.context);
7878
}
7979
}
8080
}

packages/contentstack-export/src/export/modules/global-fields.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ContentstackClient,
44
handleAndLogError,
55
messageHandler,
6-
v2Logger,
6+
log,
77
sanitizePath,
88
} from '@contentstack/cli-utilities';
99

@@ -57,7 +57,7 @@ export default class GlobalFieldsExport extends BaseClass {
5757
await fsUtil.makeDirectory(this.globalFieldsDirPath);
5858
await this.getGlobalFields();
5959
fsUtil.writeFile(path.join(this.globalFieldsDirPath, this.globalFieldsConfig.fileName), this.globalFields);
60-
v2Logger.success(
60+
log.success(
6161
messageHandler.parse('GLOBAL_FIELDS_EXPORT_COMPLETE', this.globalFields.length),
6262
this.exportConfig.context,
6363
);

0 commit comments

Comments
 (0)