Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 .talismanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: ce5abaaafcfa33bb71e4af691eb1f5786b7851bfb7f936712374251cbffe2a32
checksum: 48a1b9aca69c8decfed0f5333c8f4a8fa4689f1cb9c00a91dd18532418ea910f
version: '1.0'
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.19.1",
"version": "1.19.2",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -16,7 +16,7 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "~1.15.1",
"@contentstack/cli-cm-seed": "~1.15.2",
"@contentstack/cli-command": "~1.8.1",
"@contentstack/cli-config": "~1.20.2",
"@contentstack/cli-utilities": "~1.18.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.21.2",
"version": "1.21.3",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@colors/colors": "^1.6.0",
"@contentstack/cli-cm-export": "~1.24.2",
"@contentstack/cli-cm-import": "~1.32.2",
"@contentstack/cli-cm-export": "~1.25.0",
"@contentstack/cli-cm-import": "~1.33.0",
"@contentstack/cli-command": "~1.8.1",
"@contentstack/cli-utilities": "~1.18.2",
"@oclif/core": "^4.10.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-export",
"description": "Contentstack CLI plugin to export content from stack",
"version": "1.24.2",
"version": "1.25.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
11 changes: 4 additions & 7 deletions packages/contentstack-export/src/commands/cm/stacks/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ export default class ExportCommand extends Command {
try {
const { flags } = await this.parse(ExportCommand);
const exportConfig = await setupExportConfig(flags);

// Store apiKey in configHandler for session.json (return value not needed)
createLogContext(
this.context?.info?.command || 'cm:stacks:export',
exportConfig.apiKey,
exportConfig.authenticationMethod
exportConfig.authenticationMethod,
);

// For log entries, only pass module (other fields are in session.json)
exportConfig.context = { module: '' };
//log.info(`Using Cli Version: ${this.context?.cliVersion}`, exportConfig.context);
Expand All @@ -143,9 +143,7 @@ export default class ExportCommand extends Command {
if (!exportConfig.branches?.length) {
writeExportMetaFile(exportConfig);
}
log.success(
`The content of the stack ${exportConfig.apiKey} has been exported successfully!`,
);
log.success(`The content of the stack ${exportConfig.apiKey} has been exported successfully!`);
log.info(`The exported content has been stored at '${exportDir}'.`, exportConfig.context);
log.success(`The log has been stored at '${getLogPath()}'.`, exportConfig.context);
} catch (error) {
Expand All @@ -154,7 +152,6 @@ export default class ExportCommand extends Command {
}
}


// Assign values to exportConfig
private assignExportConfig(exportConfig: ExportConfig): void {
// Note setting host to create cma client
Expand Down
6 changes: 6 additions & 0 deletions packages/contentstack-export/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const config: DefaultConfig = {
'content-types',
'custom-roles',
'workflows',
'publishing-rules',
'personalize',
'entries',
'labels',
Expand Down Expand Up @@ -86,6 +87,11 @@ const config: DefaultConfig = {
fileName: 'workflows.json',
invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
},
'publishing-rules': {
dirName: 'workflows',
fileName: 'publishing-rules.json',
invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
},
globalfields: {
dirName: 'global_fields',
fileName: 'globalfields.json',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import * as path from 'path';
import {
ContentstackClient,
handleAndLogError,
messageHandler,
log,
sanitizePath,
} from '@contentstack/cli-utilities';
import { ContentstackClient, handleAndLogError, messageHandler, log, sanitizePath } from '@contentstack/cli-utilities';

import BaseClass from './base-class';
import { fsUtil, executeTask } from '../../utils';
Expand Down Expand Up @@ -86,7 +80,9 @@ export default class ContentTypesExport extends BaseClass {
const contentTypeSearchResponse = await this.stackAPIClient.contentType().query(this.qs).find();

log.debug(
`Fetched ${contentTypeSearchResponse.items?.length || 0} content types out of total ${contentTypeSearchResponse.count}`,
`Fetched ${contentTypeSearchResponse.items?.length || 0} content types out of total ${
contentTypeSearchResponse.count
}`,
this.exportConfig.context,
);

Expand Down
43 changes: 26 additions & 17 deletions packages/contentstack-export/src/export/modules/custom-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,26 @@ export default class ExportCustomRoles extends BaseClass {
this.customRolesConfig.dirName,
);
log.debug(`Custom roles folder path is: ${this.rolesFolderPath}`, this.exportConfig.context);

await fsUtil.makeDirectory(this.rolesFolderPath);
log.debug('Custom roles directory created.', this.exportConfig.context);

this.customRolesLocalesFilepath = pResolve(this.rolesFolderPath, this.customRolesConfig.customRolesLocalesFileName);
log.debug(`Custom roles locales file path is: ${this.customRolesLocalesFilepath}`, this.exportConfig.context);

await this.getCustomRoles();
await this.getLocales();
await this.getCustomRolesLocales();

log.debug(`Custom roles export completed. Total custom roles: ${Object.keys(this.customRoles).length}`, this.exportConfig.context);

log.debug(
`Custom roles export completed. Total custom roles: ${Object.keys(this.customRoles).length}`,
this.exportConfig.context,
);
}

async getCustomRoles(): Promise<void> {
log.debug('Fetching all roles from the stack...', this.exportConfig.context);

const roles = await this.stack
.role()
.fetchAll({ include_rules: true, include_permissions: true })
Expand All @@ -65,9 +68,12 @@ export default class ExportCustomRoles extends BaseClass {
log.debug('An error occurred while fetching roles.', this.exportConfig.context);
return handleAndLogError(err, { ...this.exportConfig.context });
});

const customRoles = roles.items.filter((role: any) => !this.existingRoles[role.name]);
log.debug(`Found ${customRoles.length} custom roles from ${roles.items?.length || 0} total roles.`, this.exportConfig.context);
log.debug(
`Found ${customRoles.length} custom roles from ${roles.items?.length || 0} total roles.`,
this.exportConfig.context,
);

if (!customRoles.length) {
log.info(messageHandler.parse('ROLES_NO_CUSTOM_ROLES'), this.exportConfig.context);
Expand All @@ -79,15 +85,15 @@ export default class ExportCustomRoles extends BaseClass {
log.info(messageHandler.parse('ROLES_EXPORTING_ROLE', role?.name), this.exportConfig.context);
this.customRoles[role.uid] = role;
});

const customRolesFilePath = pResolve(this.rolesFolderPath, this.customRolesConfig.fileName);
log.debug(`Writing custom roles to: ${customRolesFilePath}.`, this.exportConfig.context);
fsUtil.writeFile(customRolesFilePath, this.customRoles);
}

async getLocales() {
log.debug('Fetching locales for custom roles mapping...', this.exportConfig.context);

const locales = await this.stack
.locale()
.query({})
Expand All @@ -100,25 +106,28 @@ export default class ExportCustomRoles extends BaseClass {
log.debug('An error occurred while fetching locales.', this.exportConfig.context);
return handleAndLogError(err, { ...this.exportConfig.context });
});

for (const locale of locales.items) {
log.debug(`Mapping locale: ${locale?.name} (${locale?.uid})`, this.exportConfig.context);
this.sourceLocalesMap[locale.uid] = locale;
}

log.debug(`Mapped ${Object.keys(this.sourceLocalesMap).length} source locales.`, this.exportConfig.context);
}

async getCustomRolesLocales() {
log.debug('Processing custom roles locales mapping...', this.exportConfig.context);

for (const role of values(this.customRoles)) {
const customRole = role as Record<string, any>;
log.debug(`Processing locales for custom role: ${customRole?.name}`, this.exportConfig.context);

const rulesLocales = find(customRole.rules, (rule: any) => rule.module === 'locale');
if (rulesLocales?.locales?.length) {
log.debug(`Found ${rulesLocales.locales.length} locales for the role: ${customRole?.name}.`, this.exportConfig.context);
log.debug(
`Found ${rulesLocales.locales.length} locales for the role: ${customRole?.name}.`,
this.exportConfig.context,
);
forEach(rulesLocales.locales, (locale: any) => {
log.debug(`Adding locale ${locale} to the custom roles mapping.`, this.exportConfig.context);
this.localesMap[locale] = 1;
Expand All @@ -128,7 +137,7 @@ export default class ExportCustomRoles extends BaseClass {

if (keys(this.localesMap)?.length) {
log.debug(`Processing ${Object.keys(this.localesMap).length} mapped locales.`, this.exportConfig.context);

for (const locale in this.localesMap) {
if (this.sourceLocalesMap[locale] !== undefined) {
const sourceLocale = this.sourceLocalesMap[locale] as Record<string, any>;
Expand All @@ -137,7 +146,7 @@ export default class ExportCustomRoles extends BaseClass {
}
this.localesMap[locale] = this.sourceLocalesMap[locale];
}

log.debug(`Writing custom roles locales to: ${this.customRolesLocalesFilepath}.`, this.exportConfig.context);
fsUtil.writeFile(this.customRolesLocalesFilepath, this.localesMap);
} else {
Expand Down
21 changes: 12 additions & 9 deletions packages/contentstack-export/src/export/modules/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class ExportEnvironments extends BaseClass {

await fsUtil.makeDirectory(this.environmentsFolderPath);
log.debug('Environments directory created.', this.exportConfig.context);

await this.getEnvironments();
log.debug(`Retrieved ${Object.keys(this.environments).length} environments.`, this.exportConfig.context);

Expand All @@ -59,17 +59,17 @@ export default class ExportEnvironments extends BaseClass {
} else {
log.debug('Fetching environments with initial query...', this.exportConfig.context);
}

log.debug(`Query parameters: ${JSON.stringify(this.qs)}`, this.exportConfig.context);

await this.stack
.environment()
.query(this.qs)
.find()
.then(async (data: any) => {
const { items, count } = data;
log.debug(`Fetched ${items?.length || 0} environments out of ${count} total.`, this.exportConfig.context);

if (items?.length) {
log.debug(`Processing ${items.length} environments.`, this.exportConfig.context);
this.sanitizeAttribs(items);
Expand All @@ -92,16 +92,19 @@ export default class ExportEnvironments extends BaseClass {

sanitizeAttribs(environments: Record<string, string>[]) {
log.debug(`Sanitizing ${environments.length} environments...`, this.exportConfig.context);

for (let index = 0; index < environments?.length; index++) {
const extUid = environments[index].uid;
const envName = environments[index]?.name;
log.debug(`Processing environment: ${envName} (${extUid})`, this.exportConfig.context);

this.environments[extUid] = omit(environments[index], ['ACL']);
log.success(messageHandler.parse('ENVIRONMENT_EXPORT_SUCCESS', envName ), this.exportConfig.context);
log.success(messageHandler.parse('ENVIRONMENT_EXPORT_SUCCESS', envName), this.exportConfig.context);
}

log.debug(`Sanitization complete. Total environments processed: ${Object.keys(this.environments).length}`, this.exportConfig.context);

log.debug(
`Sanitization complete. Total environments processed: ${Object.keys(this.environments).length}`,
this.exportConfig.context,
);
}
}
23 changes: 13 additions & 10 deletions packages/contentstack-export/src/export/modules/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class ExportExtensions extends BaseClass {

async start(): Promise<void> {
log.debug('Starting extensions export process...', this.exportConfig.context);

this.extensionsFolderPath = pResolve(
this.exportConfig.data,
this.exportConfig.branchName || '',
Expand All @@ -37,7 +37,7 @@ export default class ExportExtensions extends BaseClass {

await fsUtil.makeDirectory(this.extensionsFolderPath);
log.debug('Extensions directory created.', this.exportConfig.context);

await this.getExtensions();
log.debug(`Retrieved ${Object.keys(this.extensions).length} extensions.`, this.exportConfig.context);

Expand All @@ -48,7 +48,7 @@ export default class ExportExtensions extends BaseClass {
log.debug(`Writing extensions to: ${extensionsFilePath}.`, this.exportConfig.context);
fsUtil.writeFile(extensionsFilePath, this.extensions);
log.success(
messageHandler.parse('EXTENSION_EXPORT_COMPLETE', Object.keys(this.extensions).length ),
messageHandler.parse('EXTENSION_EXPORT_COMPLETE', Object.keys(this.extensions).length),
this.exportConfig.context,
);
}
Expand All @@ -61,17 +61,17 @@ export default class ExportExtensions extends BaseClass {
} else {
log.debug('Fetching extensions with initial query...', this.exportConfig.context);
}

log.debug(`Query parameters: ${JSON.stringify(this.qs)}.`, this.exportConfig.context);

await this.stack
.extension()
.query(this.qs)
.find()
.then(async (data: any) => {
const { items, count } = data;
log.debug(`Fetched ${items?.length || 0} extensions out of ${count}.`, this.exportConfig.context);

if (items?.length) {
log.debug(`Processing ${items.length} extensions...`, this.exportConfig.context);
this.sanitizeAttribs(items);
Expand All @@ -94,16 +94,19 @@ export default class ExportExtensions extends BaseClass {

sanitizeAttribs(extensions: Record<string, string>[]) {
log.debug(`Sanitizing ${extensions.length} extensions...`, this.exportConfig.context);

for (let index = 0; index < extensions?.length; index++) {
const extUid = extensions[index].uid;
const extTitle = extensions[index]?.title;
log.debug(`Processing extension: '${extTitle}' (UID: ${extUid})...`, this.exportConfig.context);

this.extensions[extUid] = omit(extensions[index], ['SYS_ACL']);
log.info(messageHandler.parse('EXTENSION_EXPORT_SUCCESS', extTitle), this.exportConfig.context);
}

log.debug(`Sanitization complete. Total extensions processed: ${Object.keys(this.extensions).length}.`, this.exportConfig.context);

log.debug(
`Sanitization complete. Total extensions processed: ${Object.keys(this.extensions).length}.`,
this.exportConfig.context,
);
}
}
Loading
Loading