Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@contentstack/cli-utilities": "~2.0.0-beta.2",
"@oclif/core": "^4.3.0",
"@oclif/plugin-help": "^6.2.28",
"chalk": "^4.1.2",
"chalk": "^5.6.2",
"fast-csv": "^4.3.6",
"fs-extra": "^11.3.0",
"lodash": "^4.17.23",
Expand Down
12 changes: 6 additions & 6 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import { getChalk } from '@contentstack/cli-utilities';
import * as csv from 'fast-csv';
import { copy } from 'fs-extra';
import { v4 as uuid } from 'uuid';
Expand Down Expand Up @@ -55,7 +55,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
minWidth: 7,
header: 'Fix Status',
get: (row: any) => {
return row.fixStatus === 'Fixed' ? chalk.greenBright(row.fixStatus) : chalk.redBright(row.fixStatus);
return row.fixStatus === 'Fixed' ? getChalk().greenBright(row.fixStatus) : getChalk().redBright(row.fixStatus);
},
},
};
Expand Down Expand Up @@ -548,7 +548,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
value: 'missingRefs',
alias: 'Missing references',
formatter: (cellValue: any) => {
return chalk.red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
return getChalk().red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
},
},
{
Expand Down Expand Up @@ -588,7 +588,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
value: key,
formatter: (cellValue: any) => {
if (key === 'fixStatus' || key === 'Fixable' || key === 'Fixed') {
return chalk.green(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
return getChalk().green(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
} else if (
key === 'content_types' ||
key === 'branches' ||
Expand All @@ -598,9 +598,9 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
key === 'Non-Fixable' ||
key === 'Not-Fixed'
) {
return chalk.red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
return getChalk().red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
} else {
return chalk.white(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
return getChalk().white(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
}
},
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-audit/src/types/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color } from "chalk";
import type { ForegroundColorName } from 'chalk';
import { PrintOptions } from "@contentstack/cli-utilities";

import config from "../config";
Expand Down Expand Up @@ -26,7 +26,7 @@ export type LoggerType = "info" | "warn" | "error" | "debug" | 'hidden';
export type PrintType = {
message: string;
bold?: boolean;
color?: typeof Color;
color?: ForegroundColorName;
};

export type JSONFlagOptions = {
Expand Down
9 changes: 5 additions & 4 deletions packages/contentstack-audit/src/util/log.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import map from 'lodash/map';
import winston from 'winston';
import chalk, { Chalk } from 'chalk';
import { getChalk, ChalkInstance } from '@contentstack/cli-utilities';
import replace from 'lodash/replace';
import isObject from 'lodash/isObject';
import { normalize, resolve } from 'path';
Expand Down Expand Up @@ -170,10 +170,11 @@ export default class Logger {
* @param printInput - An array of objects with the following properties:
*/
export function print(printInput: Array<PrintType>): void {
const chalk = getChalk();
const str = map(printInput, ({ message, bold, color }: PrintType) => {
let chalkFn: Chalk = chalk;
if (color) chalkFn = chalkFn[color];
if (bold) chalkFn = chalkFn.bold;
let chalkFn: ChalkInstance = chalk;
if (color) chalkFn = chalkFn[color] as ChalkInstance;
if (bold) chalkFn = chalkFn.bold as ChalkInstance;

return chalkFn(message);
}).join(' ');
Expand Down
12 changes: 6 additions & 6 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
"build": "pnpm compile && oclif manifest",
"clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo",
"build": "npm run clean && npm run compile",
"clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
"compile": "tsc -b tsconfig.json",
"postpack": "rm -f oclif.manifest.json",
"prepack": "pnpm compile && oclif manifest && oclif readme",
"version": "oclif readme && git add README.md",
"test": "npm run build && npm run test:e2e",
"test": "npm run compile && npm run test:e2e",
"test:e2e": "nyc mocha \"test/**/*.test.js\" || exit 0",
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
Expand All @@ -22,15 +22,15 @@
"@contentstack/cli-config": "~2.0.0-beta.3",
"@oclif/core": "^4.3.0",
"@oclif/plugin-help": "^6.2.37",
"inquirer": "8.2.7",
"inquirer": "12.11.1",
"mkdirp": "^1.0.4",
"tar": "^7.5.7"
},
"devDependencies": {
"@oclif/test": "^4.1.13",
"@types/inquirer": "^9.0.8",
"@types/mkdirp": "^1.0.2",
"@types/node": "^14.18.63",
"@types/node": "^18.11.9",
"@types/tar": "^6.1.13",
"chai": "^4.5.0",
"eslint": "^8.57.1",
Expand All @@ -41,7 +41,7 @@
"oclif": "^4.17.46",
"tmp": "^0.2.5",
"ts-node": "^8.10.2",
"typescript": "^4.9.5"
"typescript": "^5.9.3"
},
"engines": {
"node": ">=14.0.0"
Expand Down
9 changes: 4 additions & 5 deletions packages/contentstack-bootstrap/src/bootstrap/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const inquirer = require('inquirer');
import inquirer from 'inquirer';
import { cliux, pathValidator } from '@contentstack/cli-utilities';

import messageHandler from '../messages';
Expand Down Expand Up @@ -50,15 +50,14 @@ export async function inquireCloneDirectory(): Promise<string> {
}

// Ask for the custom path
let selectedCustomPath = await inquirer.prompt([
const selectedCustomPath = await inquirer.prompt([
{
type: 'string',
type: 'input',
name: 'path',
message: messageHandler.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY'),
},
]);
selectedCustomPath = pathValidator(selectedCustomPath.path);
return selectedCustomPath;
return pathValidator(selectedCustomPath.path);
}

export async function inquireGithubAccessToken(): Promise<any> {
Expand Down
23 changes: 16 additions & 7 deletions packages/contentstack-bootstrap/test/bootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Bootstrapping an app', () => {
configHandlerTokens = { 'test-alias': { token: aliasToken } },
} = options;

// configHandler stub
// configHandler stub (tokens only when hasAlias; do not stub get for auth - use configHandler.set('authorisationType', 'OAUTH') in tests instead)
if (hasAlias) {
sandbox.stub(configHandler, 'get').withArgs('tokens').returns(configHandlerTokens);
}
Expand Down Expand Up @@ -371,9 +371,8 @@ describe('Bootstrapping an app', () => {
},
});

// Mock region and cmaHost
command.region = mock.region;
command.cmaHost = mock.region.cma;
// Mock region and cmaHost (base class getter uses _region, then cmaHost uses region)
command._region = mock.region;

// Mock managementSDKClient
const managementAPIClientStub = {
Expand Down Expand Up @@ -408,6 +407,7 @@ describe('Bootstrapping an app', () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});
Expand All @@ -417,6 +417,8 @@ describe('Bootstrapping an app', () => {
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
sandbox.stub(interactive, 'inquireLivePreviewSupport');
sandbox.stub(interactive, 'inquireRunDevServer');

// Mock config
const config = require('../lib/config');
Expand Down Expand Up @@ -462,6 +464,7 @@ describe('Bootstrapping an app', () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});
Expand All @@ -471,6 +474,8 @@ describe('Bootstrapping an app', () => {
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
sandbox.stub(interactive, 'inquireLivePreviewSupport');
sandbox.stub(interactive, 'inquireRunDevServer');

// Mock config
const config = require('../lib/config');
Expand Down Expand Up @@ -516,6 +521,7 @@ describe('Bootstrapping an app', () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});
Expand Down Expand Up @@ -572,6 +578,7 @@ describe('Bootstrapping an app', () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});
Expand Down Expand Up @@ -619,21 +626,23 @@ describe('Bootstrapping an app', () => {
// Verify that appType is set correctly
expect(bootstrapOptions).to.not.be.null;
expect(bootstrapOptions.appType).to.equal('sampleapp');
// Verify that inquireApp was called with sampleApps
expect(interactive.inquireApp.calledWith(config.sampleApps)).to.be.true;
// Verify that inquireApp was called with sampleApps (config.default in compiled CJS)
expect(interactive.inquireApp.calledWith(config.default.sampleApps)).to.be.true;
});

it('should handle app-name flag correctly', async () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});

// Mock interactive functions
// Mock interactive functions (stub inquireApp so .called exists for assertion)
const interactive = require('../lib/bootstrap/interactive');
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
sandbox.stub(interactive, 'inquireLivePreviewSupport').resolves(false);
sandbox.stub(interactive, 'inquireRunDevServer').resolves(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { expect } = require('chai');
const sinon = require('sinon');
const inquirer = require('inquirer');
// Inquirer v12 CJS export is { default: { prompt, ... } }; use default so stubs apply to what lib uses
const inquirer = require('inquirer').default || require('inquirer');
const { inquireRunDevServer } = require('../lib/bootstrap/interactive');
const messages = require('../messages/index.json');

Expand Down
15 changes: 7 additions & 8 deletions packages/contentstack-bootstrap/test/interactive.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { expect } = require('chai');
const sinon = require('sinon');
const inquirer = require('inquirer');
// Inquirer v12 CJS export is { default: { prompt, ... } }; use default so stubs apply to what lib uses
const inquirer = require('inquirer').default || require('inquirer');
const {
inquireApp,
inquireCloneDirectory,
Expand All @@ -11,6 +14,7 @@ const {
continueBootstrapCommand,
} = require('../lib/bootstrap/interactive');
const messages = require('../messages/index.json');
const { pathValidator } = require('@contentstack/cli-utilities');

describe('Interactive Functions Tests', () => {
let sandbox;
Expand Down Expand Up @@ -101,30 +105,25 @@ describe('Interactive Functions Tests', () => {
.resolves({ path: 'Other' })
.onSecondCall()
.resolves({ path: customPath });
const pathValidatorStub = sandbox.stub(require('@contentstack/cli-utilities'), 'pathValidator').returns(customPath);

const result = await inquireCloneDirectory();

expect(result).to.equal(customPath);
expect(result).to.equal(pathValidator(customPath));
expect(inquirer.prompt.calledTwice).to.be.true;
expect(pathValidatorStub.calledOnce).to.be.true;
});

it('should validate custom path using pathValidator', async () => {
const rawPath = '/some/path';
const validatedPath = '/validated/path';
sandbox
.stub(inquirer, 'prompt')
.onFirstCall()
.resolves({ path: 'Other' })
.onSecondCall()
.resolves({ path: rawPath });
const pathValidatorStub = sandbox.stub(require('@contentstack/cli-utilities'), 'pathValidator').returns(validatedPath);

const result = await inquireCloneDirectory();

expect(pathValidatorStub.calledWith(rawPath)).to.be.true;
expect(result).to.equal(validatedPath);
expect(result).to.equal(pathValidator(rawPath));
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@oclif/core": "^4.3.0",
"@oclif/plugin-help": "^6.2.28",
"@contentstack/cli-utilities": "~2.0.0-beta.2",
"chalk": "^4.1.2",
"chalk": "^5.6.2",
"just-diff": "^6.0.2",
"lodash": "^4.17.23"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-branches/src/branch/merge-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import os from 'os';
import path from 'path';
import forEach from 'lodash/forEach';
import { cliux } from '@contentstack/cli-utilities';
import chalk from 'chalk';
import { getChalk } from '@contentstack/cli-utilities';
import { MergeInputOptions, MergeSummary } from '../interfaces';
import {
selectMergeStrategy,
Expand Down Expand Up @@ -140,15 +140,15 @@ export default class MergeHandler {
const strategyName = this.mergeSettings.strategy;

if (allEmpty) {
cliux.print(chalk.red(`No items selected according to the '${strategyName}' strategy.`));
cliux.print(getChalk().red(`No items selected according to the '${strategyName}' strategy.`));
process.exit(1);
}

for (const [type, { exists, empty }] of Object.entries(moduleStatus)) {
if (exists && empty) {
const readable = type === 'contentType' ? 'Content Types' : 'Global fields';
cliux.print('\n')
cliux.print(chalk.yellow(`Note: No ${readable} selected according to the '${strategyName}' strategy.`));
cliux.print(getChalk().yellow(`Note: No ${readable} selected according to the '${strategyName}' strategy.`));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TableHeader,
} from '@contentstack/cli-utilities';
import { getbranchesList, getbranchConfig, interactive, handleErrorMsg } from '../../../utils/index';
import chalk from 'chalk';
import { getChalk } from '@contentstack/cli-utilities';
export default class BranchListCommand extends Command {
static description: string = messageHandler.parse('List the branches'); // Note: Update the description

Expand Down Expand Up @@ -54,10 +54,10 @@ export default class BranchListCommand extends Command {

if (!verbose) {
currentBranch[0]?.Source
? cliux.print(`* ${chalk.bold(currentBranch[0].Branch)} (source: ${currentBranch[0].Source})`, {
? cliux.print(`* ${getChalk().bold(currentBranch[0].Branch)} (source: ${currentBranch[0].Source})`, {
color: 'blue',
})
: cliux.print(`* ${chalk.bold(currentBranch[0].Branch)}`, {
: cliux.print(`* ${getChalk().bold(currentBranch[0].Branch)}`, {
color: 'blue',
});

Expand Down
Loading