Skip to content

Commit d615f20

Browse files
Merge pull request #2307 from contentstack/feat/DX-3864
feat: add new logger in config
2 parents a8774c5 + e68f05d commit d615f20

File tree

28 files changed

+4821
-6554
lines changed

28 files changed

+4821
-6554
lines changed

.talismanrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: 0cac869eb2f174e45751388de3eb46d48fbc8f5dbc56faf06000dbad7b5e8466
3+
checksum: 26be769c9d3bcc7095237527dd0004c3981be0dc7bf5c01f650b05a0ea09ecb6
44
- filename: pnpm-lock.yaml
5-
checksum: cf7ddbd499ceb5d26ceb94381db0ecd576745b96b4deedd7442d3c8aa820ba92
5+
checksum: 44d84111971dd7c108417a3e6e35bb3c61347d3eff4ea113a636429085d8502b
66
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
77
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
88
- filename: packages/contentstack-import-setup/test/config.json
@@ -273,4 +273,8 @@ fileignoreconfig:
273273
checksum: 6912e5ea32b4456ad04d1645750c72bbb29ab1895368c3a242ab39e9350ec531
274274
- filename: packages/contentstack-audit/test/unit/mock/contents/composable_studio/invalid_composable_studio.json
275275
checksum: e6465aa0011d1565a2de848d9cca74395d11419e6ac840e7dfb52e1d255b1c4f
276+
- filename: packages/contentstack-audit/src/modules/modulesData.ts
277+
checksum: 1e6c1fba1172512401038d5454c8d218201ec62262449c5c878609592e0124c4
278+
- filename: packages/contentstack-audit/src/modules/composable-studio.ts
279+
checksum: 4fc97ff582d6dff9a54b3a50dfa3cbb5febd38a55aeb8737034b97188ad543ba
276280
version: '1.0'

package-lock.json

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

packages/contentstack-auth/src/base-command.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { Command } from '@contentstack/cli-command';
2-
import { configHandler, createLogContext, Flags, getAuthenticationMethod, Interfaces, log } from '@contentstack/cli-utilities';
2+
import {
3+
configHandler,
4+
createLogContext,
5+
Flags,
6+
getAuthenticationMethod,
7+
Interfaces,
8+
log,
9+
} from '@contentstack/cli-utilities';
310
import { Context } from './interfaces';
411

512
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
@@ -17,8 +24,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
1724
public async init(): Promise<void> {
1825
await super.init();
1926
// this.contextDetails = { ...this.createExportContext() };
20-
this.contextDetails = { ...createLogContext(this.context?.info?.command || 'auth', '',) };
21-
27+
this.contextDetails = {
28+
...createLogContext(this.context?.info?.command || 'auth', '', configHandler.get('authenticationMethod')),
29+
};
2230
}
2331

2432
/**
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { join, resolve } from "path";
2-
import { existsSync, readdirSync } from "fs";
3-
import config from "./config.json" with { type: "json" };
4-
import filter from "lodash/filter.js";
5-
import forEach from "lodash/forEach.js";
6-
import isEmpty from "lodash/isEmpty.js";
7-
import isArray from "lodash/isArray.js";
8-
import includes from "lodash/includes.js";
1+
import { join, resolve } from 'path';
2+
import { existsSync, readdirSync } from 'fs';
3+
import config from './config.json';
4+
import filter from 'lodash/filter.js';
5+
import forEach from 'lodash/forEach.js';
6+
import isEmpty from 'lodash/isEmpty.js';
7+
import isArray from 'lodash/isArray.js';
8+
import includes from 'lodash/includes.js';
99
import dotenv from 'dotenv';
1010

1111
// NOTE init env variables
1212
dotenv.config();
1313

1414
const { IS_TS, UNIT_EXECUTION_ORDER, INTEGRATION_EXECUTION_ORDER } = config;
1515

16-
const testFileExtension = IS_TS ? ".ts" : ".js";
17-
process.env.TS_NODE_PROJECT = resolve("test/tsconfig.json");
16+
const testFileExtension = IS_TS ? '.ts' : '.js';
17+
process.env.TS_NODE_PROJECT = resolve('test/tsconfig.json');
1818

1919
/**
2020
* @method getFileName
2121
* @param {string} file
2222
* @returns {string}
2323
*/
2424
const getFileName = (file: string): string => {
25-
if (includes(file, ".test") && includes(file, testFileExtension)) return file;
26-
else if (includes(file, ".test")) return `${file}${testFileExtension}`;
27-
else if (!includes(file, ".test")) return `${file}.test${testFileExtension}`;
25+
if (includes(file, '.test') && includes(file, testFileExtension)) return file;
26+
else if (includes(file, '.test')) return `${file}${testFileExtension}`;
27+
else if (!includes(file, '.test')) return `${file}.test${testFileExtension}`;
2828
else return `${file}.test${testFileExtension}`;
2929
};
3030

@@ -33,7 +33,7 @@ const getFileName = (file: string): string => {
3333
* @param {Array<string>} files
3434
* @param {string} basePath
3535
*/
36-
const includeTestFiles = (files: Array<string>, basePath = "integration") => {
36+
const includeTestFiles = (files: Array<string>, basePath = 'integration') => {
3737
forEach(files, (file) => {
3838
const filename = getFileName(file);
3939
const filePath = join(__dirname, basePath, filename);
@@ -52,27 +52,24 @@ const includeTestFiles = (files: Array<string>, basePath = "integration") => {
5252
* @param {Array<string> | undefined | null} executionOrder
5353
* @param {boolean} isIntegrationTest
5454
*/
55-
const run = (
56-
executionOrder: Array<string> | undefined | null,
57-
isIntegrationTest = true
58-
) => {
59-
const testFolder = isIntegrationTest ? "integration" : "unit";
55+
const run = (executionOrder: Array<string> | undefined | null, isIntegrationTest = true) => {
56+
const testFolder = isIntegrationTest ? 'integration' : 'unit';
6057

6158
if (executionOrder && isArray(executionOrder) && !isEmpty(executionOrder)) {
6259
includeTestFiles(executionOrder, testFolder);
6360
} else {
6461
const basePath = join(__dirname, testFolder);
6562
const allIntegrationTestFiles = filter(readdirSync(basePath), (file) =>
66-
includes(file, `.test${testFileExtension}`)
63+
includes(file, `.test${testFileExtension}`),
6764
);
6865
includeTestFiles(allIntegrationTestFiles);
6966
}
7067
};
7168

7269
const args = process.argv.slice(2);
7370

74-
if (includes(args, "--integration-test")) {
71+
if (includes(args, '--integration-test')) {
7572
run(INTEGRATION_EXECUTION_ORDER);
76-
} else if (includes(args, "--unit-test")) {
73+
} else if (includes(args, '--unit-test')) {
7774
// run(UNIT_EXECUTION_ORDER, false);
7875
}

packages/contentstack-bulk-publish/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-cm-bulk-publish/1.10.4 darwin-arm64 node-v22.14.0
21+
@contentstack/cli-cm-bulk-publish/1.10.5 darwin-arm64 node-v22.14.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-bulk-publish/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@contentstack/cli-cm-bulk-publish",
33
"description": "Contentstack CLI plugin for bulk publish actions",
4-
"version": "1.10.4",
4+
"version": "1.10.5",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
88
"@contentstack/cli-command": "~1.7.1",
9-
"@contentstack/cli-config": "~1.16.2",
9+
"@contentstack/cli-config": "~1.17.0",
1010
"@contentstack/cli-utilities": "~1.16.0",
1111
"@oclif/core": "^4.3.0",
1212
"@oclif/plugin-help": "^6.2.28",

packages/contentstack-config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-config/1.16.2 darwin-arm64 node-v22.14.0
21+
@contentstack/cli-config/1.17.0 darwin-arm64 node-v22.14.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-config/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-config",
33
"description": "Contentstack CLI plugin for configuration",
4-
"version": "1.16.2",
4+
"version": "1.17.0",
55
"author": "Contentstack",
66
"scripts": {
77
"build": "npm run clean && npm run compile",

packages/contentstack-config/src/base-command.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
import { Command } from '@contentstack/cli-command';
2-
import { ArgInput, FlagInput, Flags, Interfaces, LoggerService } from '@contentstack/cli-utilities';
2+
import { ArgInput, FlagInput, Flags, Interfaces, configHandler, createLogContext } from '@contentstack/cli-utilities';
33

44
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
55
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>;
66

77
export abstract class BaseCommand<T extends typeof Command> extends Command {
8-
public logger!: LoggerService;
8+
public contextDetails!: {
9+
command: string;
10+
module: string;
11+
userId: string;
12+
email: string;
13+
sessionId: string;
14+
apiKey: string;
15+
orgId: string;
16+
authenticationMethod: string;
17+
};
918
protected args!: Args<T>;
1019
protected flags!: Flags<T>;
1120

12-
static args: ArgInput<{ [arg: string]: any; }>;
21+
static args: ArgInput<{ [arg: string]: any }>;
1322
/**
1423
* The `init` function initializes the command by parsing arguments and flags, registering search
1524
* plugins, registering the configuration, and initializing the logger.
1625
*/
1726
public async init(): Promise<void> {
1827
await super.init();
1928

20-
// Init logger
21-
this.logger = new LoggerService(process.cwd(), 'cli-log');
29+
// Init logger context
30+
this.contextDetails = {
31+
...createLogContext(this.context?.info?.command || 'config', '', configHandler.get('authenticationMethod')),
32+
};
2233
}
2334

2435
/**
@@ -46,4 +57,4 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
4657
// called after run and catch regardless of whether or not the command errored
4758
return super.finally(_);
4859
}
49-
}
60+
}

packages/contentstack-config/src/commands/config/get/base-branch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command } from '@contentstack/cli-command';
2-
import { cliux, configHandler, messageHandler, TableHeader } from '@contentstack/cli-utilities';
2+
import { cliux, configHandler, messageHandler, TableHeader, handleAndLogError } from '@contentstack/cli-utilities';
33

44
export default class BranchGetCommand extends Command {
55
static description = 'Get current branch set for CLI';
@@ -25,7 +25,7 @@ export default class BranchGetCommand extends Command {
2525
cliux.print(`error: ${messageHandler.parse('CLI_CONFIG_BRANCH_LIST_NO_BRANCHES')}`, { color: 'red' });
2626
}
2727
} catch (error) {
28-
cliux.error('Error', error);
28+
handleAndLogError(error, { module: 'config-get-base-branch' });
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)