Skip to content

Commit

Permalink
Merge branch 'development' into feat/CS-43978
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-raj committed Mar 8, 2024
2 parents 37959b7 + 37b9e07 commit 4ffdda5
Show file tree
Hide file tree
Showing 70 changed files with 612 additions and 502 deletions.
446 changes: 179 additions & 267 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.4.0 darwin-arm64 node-v20.8.0
@contentstack/cli-audit/1.4.1 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -285,7 +285,7 @@ EXAMPLES
$ csdx plugins
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.1.17/src/commands/plugins/index.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.2.6/src/commands/plugins/index.ts)_

## `csdx plugins:install PLUGIN...`

Expand Down Expand Up @@ -354,7 +354,7 @@ EXAMPLES
$ csdx plugins:inspect myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.1.17/src/commands/plugins/inspect.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.2.6/src/commands/plugins/inspect.ts)_

## `csdx plugins:install PLUGIN...`

Expand Down Expand Up @@ -398,7 +398,7 @@ EXAMPLES
$ csdx plugins:install someuser/someplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.1.17/src/commands/plugins/install.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.2.6/src/commands/plugins/install.ts)_

## `csdx plugins:link PLUGIN`

Expand Down Expand Up @@ -428,7 +428,7 @@ EXAMPLES
$ csdx plugins:link myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.1.17/src/commands/plugins/link.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.2.6/src/commands/plugins/link.ts)_

## `csdx plugins:uninstall PLUGIN...`

Expand Down Expand Up @@ -462,10 +462,14 @@ Remove all user-installed and linked plugins.

```
USAGE
$ csdx plugins:reset
$ csdx plugins:reset [--hard] [--reinstall]
FLAGS
--hard Delete node_modules and package manager related files in addition to uninstalling plugins.
--reinstall Reinstall all plugins after uninstalling.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.1.17/src/commands/plugins/reset.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.2.6/src/commands/plugins/reset.ts)_

## `csdx plugins:uninstall PLUGIN...`

Expand Down Expand Up @@ -493,7 +497,7 @@ EXAMPLES
$ csdx plugins:uninstall myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.1.17/src/commands/plugins/uninstall.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.2.6/src/commands/plugins/uninstall.ts)_

## `csdx plugins:uninstall PLUGIN...`

Expand Down Expand Up @@ -537,5 +541,5 @@ DESCRIPTION
Update installed plugins.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.1.17/src/commands/plugins/update.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v4.2.6/src/commands/plugins/update.ts)_
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions 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 All @@ -19,7 +19,7 @@
],
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^4.1.9",
"chalk": "^4.1.2",
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 @@ -94,7 +94,13 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
let { ctSchema, gfSchema } = this.getCtAndGfSchema();
let missingCtRefs, missingGfRefs, missingEntryRefs, missingCtRefsInExtensions;
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 Down Expand Up @@ -124,7 +130,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, missingCtRefsInExtensions };
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', 'extensions'],
'fix-fields': ['reference', 'global_field', 'json:rte', 'json:extension', 'blocks', 'group'],
moduleConfig: {
Expand Down
19 changes: 13 additions & 6 deletions packages/contentstack-audit/src/messages/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import memoize from 'lodash/memoize';
import { escapeRegExp } from '@contentstack/cli-utilities';

const errors = {};

const tableColumnDescriptions = {
Expand Down Expand Up @@ -62,14 +65,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 = escapeRegExp(key);
msg = msg.replace(new RegExp(`{${escapedKey}}`, 'g'), escapeRegExp(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-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.9.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-bootstrap/1.9.1 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.9.0",
"version": "1.9.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -19,7 +19,7 @@
"dependencies": {
"@contentstack/cli-cm-seed": "~1.7.0",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"inquirer": "8.2.4",
"mkdirp": "^1.0.4",
"tar": "^6.1.13"
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-bootstrap/src/bootstrap/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
const inquirer = require('inquirer');
import { cliux } from '@contentstack/cli-utilities';
import { cliux, pathValidator } from '@contentstack/cli-utilities';

import messageHandler from '../messages';

Expand Down Expand Up @@ -58,7 +58,7 @@ export async function inquireCloneDirectory(): Promise<string> {
message: messageHandler.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY'),
},
]);
selectedCustomPath = path.resolve(selectedCustomPath.path);
selectedCustomPath = pathValidator(selectedCustomPath.path);
return selectedCustomPath;
}

Expand Down
Loading

0 comments on commit 4ffdda5

Please sign in to comment.