Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge development to staging #1232

Merged
merged 54 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0ffdbb5
Merge pull request #1218 from contentstack/staging
aman19K Dec 18, 2023
ef4d653
added early access support in http client
shafeeqd959 Dec 19, 2023
52342df
Fix: Audit fix command schema not found fixes
antonyagustine Dec 19, 2023
fb53ce6
Code clean script fix
antonyagustine Dec 19, 2023
56b8e10
Fix: Modular blocks issue fixed in content-type
antonyagustine Dec 19, 2023
82e6f09
Version bump
antonyagustine Dec 20, 2023
b303fe2
added early access header in unpublish and cross publish delivery api…
shafeeqd959 Dec 20, 2023
fa06b82
early access updates
shafeeqd959 Dec 20, 2023
91bbfa5
Merge pull request #1221 from contentstack/fix/CS-43193
antonyagustine Dec 20, 2023
92f3f25
Feat: New hidden flag introduced to accept json data to overwrite def…
antonyagustine Dec 21, 2023
360536c
Merge branch 'development' of https://github.com/contentstack/cli int…
antonyagustine Dec 21, 2023
07d2831
Merge branch 'development' into feat/CS-42772
shafeeqd959 Dec 21, 2023
e7fdcb1
Merge pull request #1219 from contentstack/feat/CS-42772
shafeeqd959 Dec 21, 2023
b9b3835
Merge branch 'development' into feat/CS-42773
shafeeqd959 Dec 21, 2023
bc51285
Merge branch 'development' of github.com:contentstack/cli into feat/C…
shafeeqd959 Dec 21, 2023
a4e8eff
updated lock files
shafeeqd959 Dec 21, 2023
70cd88a
Merge branch 'feat/CS-42773' of github.com:contentstack/cli into feat…
shafeeqd959 Dec 21, 2023
5b7edde
Type definition moved from script file to types file
antonyagustine Dec 21, 2023
d6a56dc
Merge branch 'development' into feat/CS-43198
antonyagustine Dec 21, 2023
0ef49dd
Merge pull request #1223 from contentstack/feat/CS-43198
antonyagustine Dec 21, 2023
35f5bff
Merge branch 'development' into feat/CS-42773
shafeeqd959 Dec 22, 2023
d6d4d97
Merge pull request #1222 from contentstack/feat/CS-42773
shafeeqd959 Dec 22, 2023
eee14f5
Feat: Audit fix command integration with Import
antonyagustine Dec 22, 2023
ea606fe
removed stray console.log
cs-raj Jan 2, 2024
e4b44c9
fix: set region command error with doc link
aman19K Jan 2, 2024
42df6d9
axios patch version bump
cs-raj Jan 2, 2024
133f23d
Merge pull request #1225 from contentstack/fix/CS-42684
cs-raj Jan 2, 2024
77be8e8
Merge branch 'development' into fix/region-error-msg
aman19K Jan 2, 2024
f6b0664
Merge pull request #1226 from contentstack/fix/region-error-msg
aman19K Jan 2, 2024
7055073
Version bum
antonyagustine Jan 3, 2024
7443ce2
Merge branch 'development' into feat/CS-43223
antonyagustine Jan 3, 2024
b4f00fa
Import minor version bump
antonyagustine Jan 3, 2024
c9c53eb
Skip audit-fix on seed command
antonyagustine Jan 3, 2024
ce32a52
Feat: Audit fix command integration with Import
antonyagustine Jan 3, 2024
5acd500
Merge branch 'feat/CS-43223' into feat/CS-43173
antonyagustine Jan 3, 2024
61176df
Fix: Missing return statement added
antonyagustine Jan 8, 2024
4c3de39
axios version bump
cs-raj Jan 8, 2024
5223355
Log correction
antonyagustine Jan 8, 2024
8903916
removed axios from import
cs-raj Jan 8, 2024
b32032c
Merge pull request #1230 from contentstack/fix/CS-43366
cs-raj Jan 8, 2024
c85c95f
Merge branch 'development' into feat/CS-43223
antonyagustine Jan 8, 2024
8929f71
fix: create, update , create-update entry migration script
aman19K Jan 8, 2024
2763ddf
fix: logger instance
aman19K Jan 8, 2024
97f39de
Merge branch 'development' into fix/CS-43247
aman19K Jan 8, 2024
4ff4518
UI text corrections
antonyagustine Jan 8, 2024
dc1dddb
Merge branch 'feat/CS-43223' of https://github.com/contentstack/cli i…
antonyagustine Jan 8, 2024
0a273ad
Merge branch 'feat/CS-43223' into feat/CS-43173
antonyagustine Jan 8, 2024
505254a
Merge pull request #1228 from contentstack/feat/CS-43173
antonyagustine Jan 9, 2024
c227748
Merge pull request #1227 from contentstack/feat/CS-43223
antonyagustine Jan 9, 2024
8c5a08f
fix: update entry migration doc url
aman19K Jan 9, 2024
d5f874a
version bump
aman19K Jan 9, 2024
dfb7480
Merge branch 'development' into fix/CS-43247
aman19K Jan 9, 2024
7afd151
fix: windows command path
aman19K Jan 9, 2024
f29b61f
Merge pull request #1231 from contentstack/fix/CS-43247
aman19K Jan 9, 2024
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
20,130 changes: 46 additions & 20,084 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.3.0 darwin-arm64 node-v20.8.0
@contentstack/cli-audit/1.3.2 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
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.3.1",
"version": "1.3.2",
"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.9",
"@contentstack/cli-utilities": "~1.5.10",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^4.1.9",
"chalk": "^4.1.2",
Expand Down
21 changes: 14 additions & 7 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
* @param {string} command - The `command` parameter is a string that represents the current command
* being executed.
*/
async start(command: CommandNames): Promise<void> {
async start(command: CommandNames): Promise<boolean> {
this.currentCommand = command;
await this.promptQueue();
await this.createBackUp();
Expand All @@ -60,11 +60,17 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
this.log(this.messages.NO_MISSING_REF_FOUND, 'info');
this.log('');

if (this.currentCommand === 'cm:stacks:audit:fix' && existsSync(this.sharedConfig.basePath)) {
if (
this.flags['copy-dir'] &&
this.currentCommand === 'cm:stacks:audit:fix' &&
existsSync(this.sharedConfig.basePath)
) {
// NOTE Clean up the backup dir if no issue found while audit the content
rmSync(this.sharedConfig.basePath, { recursive: true });
}
}

return !isEmpty(missingCtRefs) || !isEmpty(missingGfRefs) || !isEmpty(missingEntryRefs);
}

/**
Expand Down Expand Up @@ -135,10 +141,11 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
}

// NOTE create bkp directory
const backupDirPath = `${(this.flags['copy-path'] || this.flags['data-dir']).replace(
/\/+$/,
'',
)}_backup_${uuid()}`;
const backupDirPath = `${(
this.flags['copy-path'] ||
this.flags['data-dir'] ||
this.sharedConfig.basePath
).replace(/\/+$/, '')}_backup_${uuid()}`;

if (!existsSync(backupDirPath)) {
mkdirSync(backupDirPath, { recursive: true });
Expand Down Expand Up @@ -194,7 +201,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
* objects, where each object has two properties:
*/
showOutputOnScreen(allMissingRefs: { module: string; missingRefs?: Record<string, any> }[]) {
if (this.sharedConfig.showTerminalOutput) {
if (this.sharedConfig.showTerminalOutput && !this.flags['external-config']?.noTerminalOutput) {
this.log(''); // NOTE adding new line
for (const { module, missingRefs } of allMissingRefs) {
if (!isEmpty(missingRefs)) {
Expand Down
23 changes: 18 additions & 5 deletions packages/contentstack-audit/src/base-command.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import merge from 'lodash/merge';
import isEmpty from 'lodash/isEmpty';
import { existsSync, readFileSync } from 'fs';
import { Command } from '@contentstack/cli-command';
import { Flags, FlagInput, Interfaces, cliux as ux } from '@contentstack/cli-utilities';
import { Flags, FlagInput, Interfaces, cliux, ux, PrintOptions } from '@contentstack/cli-utilities';

import config from './config';
import { Logger } from './util';
import { ConfigType, LogFn } from './types';
import { ConfigType, LogFn, LoggerType } from './types';
import messages, { $t, commonMsg } from './messages';

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

const noLog = (_message: string | any, _logType?: LoggerType | PrintOptions | undefined) => {};

export abstract class BaseCommand<T extends typeof Command> extends Command {
public log!: LogFn;
public logger!: Logger;
Expand Down Expand Up @@ -55,12 +58,22 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {

this.sharedConfig = Object.assign(this.sharedConfig, { flags: this.flags });

ux.registerSearchPlugin();
if (!isEmpty(this.flags['external-config']?.config)) {
this.sharedConfig = Object.assign(this.sharedConfig, this.flags['external-config']?.config);
}

cliux.registerSearchPlugin();
this.registerConfig();

// Init logger
const logger = new Logger(this.sharedConfig);
this.log = logger.log.bind(logger);
if (this.flags['external-config']?.noLog) {
this.log = noLog;
ux.action.start = () => {};
ux.action.stop = () => {};
} else {
const logger = new Logger(this.sharedConfig);
this.log = logger.log.bind(logger);
}
}

/**
Expand Down
14 changes: 11 additions & 3 deletions packages/contentstack-audit/src/commands/cm/stacks/audit/fix.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { FlagInput, Flags, ux } from '@contentstack/cli-utilities';

import config from '../../../../config';
import { getTableFlags } from '../../../../util';
import { ConfigType } from '../../../../types';
import { auditFixMsg, auditMsg } from '../../../../messages';
import { AuditBaseCommand } from '../../../../audit-base-command';
import { getJsonInputFlags, getTableFlags } from '../../../../util';

const jsonFlag = getJsonInputFlags({ hidden: true });

export default class AuditFix extends AuditBaseCommand {
static aliases: string[] = ['audit:fix', 'cm:stacks:audit:fix'];
Expand Down Expand Up @@ -49,16 +52,21 @@ export default class AuditFix extends AuditBaseCommand {
hidden: true,
description: 'Use this flag to skip confirmation',
}),
'external-config': jsonFlag(),
...getTableFlags(),
};

/**
* The `run` function is an asynchronous function that performs an audit on different modules
* (content-types, global-fields, entries) and generates a report.
*/
async run(): Promise<void> {
async run(): Promise<void | { config: ConfigType; hasFix: boolean }> {
try {
await this.start('cm:stacks:audit:fix');
const hasFix = await this.start('cm:stacks:audit:fix');

if (this.flags['external-config']?.returnResponse) {
return { config: this.sharedConfig, hasFix };
}
} catch (error) {
this.log(error instanceof Error ? error.message : error, 'error');
console.trace(error);
Expand Down
5 changes: 4 additions & 1 deletion packages/contentstack-audit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default {};
import Audit from "./commands/cm/stacks/audit";
import AuditFix from "./commands/cm/stacks/audit/fix";

export { Audit, AuditFix };
6 changes: 3 additions & 3 deletions packages/contentstack-audit/src/modules/content-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default class ContentType {
let canWrite = true;

if (!this.inMemoryFix && this.fix) {
if (!this.config.flags['copy-dir']) {
if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) {
canWrite = this.config.flags.yes ?? (await ux.confirm(commonMsg.FIX_CONFIRMATION));
}

Expand Down Expand Up @@ -472,9 +472,9 @@ export default class ContentType {

if (!refExist) {
this.missingRefs[this.currentUid].push(refErrorObj);
}

return refExist;
return block;
}
}

block.schema = this.runFixOnSchema(tree, block.schema as ContentTypeSchemaType[]);
Expand Down
37 changes: 23 additions & 14 deletions packages/contentstack-audit/src/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ export default class Entries {
const { uid, title } = entry;
this.currentUid = uid;
this.currentTitle = title;
this.missingRefs[this.currentUid] = [];
this.lookForReference([{ uid, name: title }], ctSchema, this.entries[entryUid]);

if (!this.missingRefs[this.currentUid]) {
this.missingRefs[this.currentUid] = [];
}

this.lookForReference([{ locale: code, uid, name: title }], ctSchema, this.entries[entryUid]);
this.log(
$t(auditMsg.SCAN_ENTRY_SUCCESS_MSG, {
title,
Expand Down Expand Up @@ -156,7 +160,7 @@ export default class Entries {
let canWrite = true;

if (this.fix) {
if (!this.config.flags['copy-dir']) {
if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) {
canWrite = this.config.flags.yes || (await ux.confirm(commonMsg.FIX_CONFIRMATION));
}

Expand Down Expand Up @@ -451,6 +455,10 @@ export default class Entries {
schema.forEach((field) => {
const { uid, data_type } = field;

if (!Object(entry).hasOwnProperty(uid)) {
return;
}

switch (data_type) {
case 'global_field':
entry[uid] = this.fixGlobalFieldReferences(
Expand All @@ -474,7 +482,6 @@ export default class Entries {
break;
}
}

// NOTE Reference field
entry[uid] = this.fixMissingReferences(
[...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }],
Expand Down Expand Up @@ -623,19 +630,21 @@ export default class Entries {
return this.fixJsonRteMissingReferences([...tree, { index, type: child?.type, uid: child?.uid }], field, child);
}) as EntryJsonRTEFieldDataType[];
} else {
entry.children = entry.children
.map((child) => {
const refExist = this.jsonRefCheck(tree, field, child);
if (entry?.children) {
entry.children = entry.children
.map((child) => {
const refExist = this.jsonRefCheck(tree, field, child);

if (!refExist) return null;
if (!refExist) return null;

if (isEmpty(child.children)) {
child = this.fixJsonRteMissingReferences(tree, field, child) as EntryJsonRTEFieldDataType;
}
if (!isEmpty(child.children)) {
child = this.fixJsonRteMissingReferences(tree, field, child) as EntryJsonRTEFieldDataType;
}

return child;
})
.filter((val) => val) as EntryJsonRTEFieldDataType[];
return child;
})
.filter((val) => val) as EntryJsonRTEFieldDataType[];
}
}

return entry;
Expand Down
5 changes: 5 additions & 0 deletions packages/contentstack-audit/src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ export type PrintType = {
bold?: boolean;
color?: typeof Color;
};

export type JSONFlagOptions = {
hidden?: boolean;
description?: string;
};
32 changes: 29 additions & 3 deletions packages/contentstack-audit/src/util/flags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ux } from '@contentstack/cli-utilities';
import { FlagDefinition, Flags, ux } from '@contentstack/cli-utilities';

import { IFlags, IncludeFlags } from '../types';
import { IFlags, IncludeFlags, JSONFlagOptions } from '../types';
import { tableColumnDescriptions } from '../messages';

const defaultJSONOptions = { description: 'Provide JSON input' };

/**
* The function `getTableFlags` returns a set of table flags based on the specified columns, with
* updated descriptions and help groups.
Expand All @@ -28,4 +30,28 @@ function getTableFlags(
return flags;
}

export { getTableFlags };
/**
* The function `getJsonInputFlags` returns a flag definition for parsing JSON input.
* @param {JSONFlagOptions} options - The `options` parameter is an object that contains the following
* properties:
* @returns a `FlagDefinition` object.
*/
function getJsonInputFlags(
options: JSONFlagOptions = defaultJSONOptions,
): FlagDefinition<Record<string, unknown>, Record<string, unknown>> {
const { hidden, description = defaultJSONOptions.description } = options;

return Flags.custom<Record<string, unknown>, Record<string, unknown>>({
hidden,
description,
parse: async (input, _opts) => {
try {
return JSON.parse(input);
} catch (error) {
throw new Error('Invalid JSON');
}
},
});
}

export { getTableFlags, getJsonInputFlags };
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.9",
"@contentstack/cli-utilities": "~1.5.10",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@contentstack/cli-cm-seed": "~1.7.0",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.9",
"@contentstack/cli-utilities": "~1.5.10",
"inquirer": "8.2.4",
"mkdirp": "^1.0.4",
"tar": "^6.1.13"
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.19 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-branches/1.0.20 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.0.19",
"version": "1.0.20",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.9",
"@contentstack/cli-utilities": "~1.5.10",
"@oclif/core": "^2.9.3",
"async": "^3.2.4",
"big-json": "^3.2.0",
Expand Down
15 changes: 11 additions & 4 deletions packages/contentstack-branches/src/branch/merge-handler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os from 'os';
import path from 'path';
import forEach from 'lodash/forEach';
import { cliux } from '@contentstack/cli-utilities';
Expand Down Expand Up @@ -275,7 +276,7 @@ export default class MergeHandler {
deleted: [],
};

selectedMergeItems.forEach((item) => {
selectedMergeItems?.forEach((item) => {
mergeContent.content_types[item.status].push(item.value);
});
break;
Expand All @@ -290,10 +291,16 @@ export default class MergeHandler {
if (scriptFolderPath !== undefined) {
cliux.success(`\nSuccess! We have generated entry migration files in the folder ${scriptFolderPath}`);
cliux.print('\nWARNING!!! Migration is not intended to be run more than once. Migrated(entries/assets) will be duplicated if run more than once', {color: 'yellow'});

const migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config {compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath}} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`;

let migrationCommand: string;
if(os.platform() === 'win32'){
migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`;
}else{
migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config {compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath}} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`;
}

cliux.print(
`\nKindly follow the steps in the guide "https://www.contentstack.com/docs/developers/cli/migrate-branch-entries" to update the migration scripts, and then run the command:\n\n${migrationCommand}`,
`\nKindly follow the steps in the guide "https://www.contentstack.com/docs/developers/cli/entry-migration" to update the migration scripts, and then run the command:\n\n${migrationCommand}`,
{ color: 'blue' },
);
}
Expand Down
Loading
Loading