Skip to content

Commit

Permalink
Merge pull request #1331 from contentstack/main
Browse files Browse the repository at this point in the history
Hotfix back merge
  • Loading branch information
antonyagustine authored Mar 6, 2024
2 parents 5797b9b + 35e7b9a commit a9311de
Show file tree
Hide file tree
Showing 17 changed files with 1,233 additions and 1,013 deletions.
2,083 changes: 1,126 additions & 957 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.4.0",
"version": "1.4.1",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand Down
21 changes: 19 additions & 2 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
let { ctSchema, gfSchema } = this.getCtAndGfSchema();
let missingCtRefs, missingGfRefs, missingEntryRefs;
for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
ux.action.start(this.$t(this.messages.AUDIT_START_SPINNER, { module }));
print([
{
bold: true,
color: 'whiteBright',
message: this.$t(this.messages.AUDIT_START_SPINNER, { module }),
},
]);

const constructorParam = {
ctSchema,
Expand All @@ -109,7 +115,18 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
break;
}

ux.action.stop();
print([
{
bold: true,
color: 'whiteBright',
message: this.$t(this.messages.AUDIT_START_SPINNER, { module }),
},
{
bold: true,
message: ' done',
color: 'whiteBright',
},
]);
}

return { missingCtRefs, missingGfRefs, missingEntryRefs };
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {
showTerminalOutput: true,
skipRefs: ['sys_assets'],
skipFieldTypes: ['taxonomy'],
skipFieldTypes: ['taxonomy', 'group'],
modules: ['content-types', 'global-fields', 'entries'],
'fix-fields': ['reference', 'global_field', 'json:rte', 'json:extension', 'blocks', 'group'],
moduleConfig: {
Expand Down
18 changes: 12 additions & 6 deletions packages/contentstack-audit/src/messages/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import memoize from 'lodash/memoize';

const errors = {};

const tableColumnDescriptions = {
Expand Down Expand Up @@ -59,14 +61,18 @@ const messages: typeof errors &
* @returns a string.
*/
function $t(msg: string, args: Record<string, string>): string {
if (!msg) return '';
const transfer = memoize(function (msg: string, args: Record<string, string>) {
if (!msg) return '';

for (const key of Object.keys(args)) {
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
msg = msg.replace(new RegExp(`{${escapedKey}}`, 'g'), args[key] || escapedKey);
}

for (const key of Object.keys(args)) {
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
msg = msg.replace(new RegExp(`{${escapedKey}}`, 'g'), args[key]);
}
return msg;
});

return msg;
return transfer(msg, args);
}

export default messages;
Expand Down
18 changes: 9 additions & 9 deletions packages/contentstack-audit/src/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
ExtensionOrAppFieldDataType,
EntryExtensionOrAppFieldDataType,
} from '../types';
import { print } from '../util';
import GlobalField from './global-fields';
import { MarketplaceAppsInstallationData } from '../types/extension';

Expand Down Expand Up @@ -106,14 +107,13 @@ export default class Entries {
}

this.lookForReference([{ locale: code, uid, name: title }], ctSchema, this.entries[entryUid]);
this.log(
$t(auditMsg.SCAN_ENTRY_SUCCESS_MSG, {
title,
local: code,
module: this.config.moduleConfig.entries.name,
}),
'info',
);
const message = $t(auditMsg.SCAN_ENTRY_SUCCESS_MSG, {
title,
local: code,
module: this.config.moduleConfig.entries.name,
});
this.log(message, 'hidden');
print([{ message: `info: ${message}`, color: 'green' }]);
}

if (this.fix) {
Expand All @@ -122,7 +122,7 @@ export default class Entries {
}
}
}
this.log('', 'info'); // Adding empty line
// this.log('', 'info'); // Adding empty line

this.removeEmptyVal();

Expand Down
5 changes: 3 additions & 2 deletions packages/contentstack-audit/src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import config from "../config";

type LogFn = (
message: string | any,
logType?: LoggerType | PrintOptions | undefined
logType?: LoggerType | PrintOptions | undefined,
skipCredentialCheck?: boolean,
) => void;

type ExitFn = (code?: number | undefined) => void;
Expand All @@ -20,7 +21,7 @@ type ConfigType = {
Record<string, any>;

export { LogFn, ExitFn, Partial, ConfigType };
export type LoggerType = "info" | "warn" | "error" | "debug";
export type LoggerType = "info" | "warn" | "error" | "debug" | 'hidden';

export type PrintType = {
message: string;
Expand Down
43 changes: 29 additions & 14 deletions packages/contentstack-audit/src/util/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class Logger {
private infoLogger!: winston.Logger;
private errorLogger!: winston.Logger;
private config!: Record<string, any>;
private hiddenInfoLogger!: winston.Logger;

get loggerOptions(): winston.transports.FileTransportOptions {
return {
Expand All @@ -41,6 +42,7 @@ export default class Logger {
this.config = config;
this.infoLogger = this.getLoggerInstance('info');
this.errorLogger = this.getLoggerInstance('error');
this.hiddenInfoLogger = this.getLoggerInstance('hidden');
}

/**
Expand All @@ -55,24 +57,30 @@ export default class Logger {
const consoleOptions: winston.transports.ConsoleTransportOptions = {
format: winston.format.combine(winston.format.simple(), winston.format.colorize({ all: true })),
};
const isHidden = logType === 'hidden';
logType = logType === 'hidden' ? 'info' : logType;

if (logType === 'error') {
consoleOptions.level = logType;
}

const filename = normalize(resolve(this.config.basePath, 'logs', `${logType}.log`)).replace(
/^(\.\.(\/|\\|$))+/,
'',
);
const filename = normalize(
resolve(this.config.basePath, 'logs', `${logType}.log`),
).replace(/^(\.\.(\/|\\|$))+/, '');
const transports: winston.transport[] = [
new winston.transports.File({
...this.loggerOptions,
level: logType,
filename,
}),
];

if (!isHidden) {
transports.push(new winston.transports.Console(consoleOptions));
}

const loggerOptions: winston.LoggerOptions = {
transports: [
new winston.transports.File({
...this.loggerOptions,
level: logType,
filename,
}),
new winston.transports.Console(consoleOptions),
],
transports,
levels: customLevels.levels,
};

Expand All @@ -91,8 +99,12 @@ export default class Logger {
* @param {LoggerType | PrintOptions | undefined} [logType] - The `logType` parameter is an optional
* parameter that specifies the type of log. It can be one of the following values:
*/
log(message: string | any, logType?: LoggerType | PrintOptions | undefined): void {
const logString = this.returnString(message);
log(
message: string | any,
logType?: LoggerType | PrintOptions | undefined,
skipCredentialCheck: boolean = false,
): void {
const logString = skipCredentialCheck ? message : this.returnString(message);

switch (logType) {
case 'info':
Expand All @@ -103,6 +115,9 @@ export default class Logger {
case 'error':
this.errorLogger.error(logString);
break;
case 'hidden':
this.hiddenInfoLogger.log('info', logString);
break;
default:
ux.print(logString, logType || {});
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/test/unit/util/log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Log utility', () => {
const logSpy = sinon.spy(winston, 'createLogger');
const logger = new Logger({ basePath: resolve(__dirname, '..', 'mock') });

expect(logSpy.callCount).to.be.equals(2);
expect(logSpy.callCount).to.be.equals(3);
expect(Object.getPrototypeOf(logger)).has.ownProperty('log');
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.11.0",
"@contentstack/cli-cm-import": "~1.14.0",
"@contentstack/cli-cm-import": "~1.14.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"async": "^3.2.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.14.0",
"version": "1.14.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-audit": "~1.4.0",
"@contentstack/cli-audit": "~1.4.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/management": "~1.15.3",
Expand Down
9 changes: 8 additions & 1 deletion packages/contentstack-import/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const config: DefaultConfig = {
taxonomies: {
dirName: 'taxonomies',
fileName: 'taxonomies.json',
}
},
},
languagesCode: [
'af-za',
Expand Down Expand Up @@ -388,6 +388,13 @@ const config: DefaultConfig = {
// useBackedupDir: '',
// backupConcurrency: 10,
onlyTSModules: ['taxonomies'],
auditConfig: {
noLog: false, // Skip logs printing on terminal
skipConfirm: true, // Skip confirmation if any
returnResponse: true, // On process completion should return config used in the command
noTerminalOutput: false, // Skip final audit table output on terminal
config: { basePath: '' }, // To overwrite any build-in config. And this config is equal to --config flag.
}
};

export default config;
10 changes: 3 additions & 7 deletions packages/contentstack-import/src/import/module-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,9 @@ class ModuleImporter {
*/
async auditImportData(logger: Logger) {
const basePath = resolve(this.importConfig.backupDir, 'logs', 'audit');
const auditConfig = {
noLog: false, // Skip logs printing on terminal
skipConfirm: true, // Skip confirmation if any
returnResponse: true, // On process completion should return config used in the command
noTerminalOutput: false, // Skip final audit table output on terminal
config: { basePath }, // To overwrite any build-in config. This config is equal to --config flag.
};
const auditConfig = this.importConfig.auditConfig
auditConfig.config.basePath = basePath;

try {
const args = [
'--data-dir',
Expand Down
9 changes: 9 additions & 0 deletions packages/contentstack-import/src/types/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,13 @@ export default interface DefaultConfig {
createBackupDir?: string;
overwriteSupportedModules: string[];
onlyTSModules: string[];
auditConfig?: {
noLog?: boolean; // Skip logs printing on terminal
skipConfirm?: boolean; // Skip confirmation if any
returnResponse?: boolean; // On process completion should return config used in the command
noTerminalOutput?: boolean; // Skip final audit table output on terminal
config?: {
basePath?: string
} & Record<string, any>; // To overwrite any build-in config. And this config is equal to --config flag.
};
}
2 changes: 1 addition & 1 deletion packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-cm-import": "~1.14.0",
"@contentstack/cli-cm-import": "~1.14.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"inquirer": "8.2.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli",
"description": "Command-line tool (CLI) to interact with Contentstack",
"version": "1.15.0",
"version": "1.15.1",
"author": "Contentstack",
"bin": {
"csdx": "./bin/run"
Expand All @@ -22,15 +22,15 @@
"prepack": "pnpm compile && oclif manifest && oclif readme"
},
"dependencies": {
"@contentstack/cli-audit": "~1.4.0",
"@contentstack/cli-audit": "~1.4.1",
"@contentstack/cli-auth": "~1.3.17",
"@contentstack/cli-cm-bootstrap": "~1.9.0",
"@contentstack/cli-cm-branches": "~1.0.22",
"@contentstack/cli-cm-bulk-publish": "~1.4.2",
"@contentstack/cli-cm-export": "~1.11.0",
"@contentstack/cli-cm-clone": "~1.10.1",
"@contentstack/cli-cm-export-to-csv": "~1.7.0",
"@contentstack/cli-cm-import": "~1.14.0",
"@contentstack/cli-cm-import": "~1.14.1",
"@contentstack/cli-cm-migrate-rte": "~1.4.15",
"@contentstack/cli-cm-seed": "~1.7.1",
"@contentstack/cli-command": "~1.2.17",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

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

0 comments on commit a9311de

Please sign in to comment.