Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@
"cm:stack-clone": "O-CLN"
}
}
}
}
4 changes: 2 additions & 2 deletions packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.32.0-beta.0",
"version": "1.32.0-beta.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down Expand Up @@ -94,4 +94,4 @@
}
},
"repository": "https://github.com/contentstack/cli"
}
}
33 changes: 33 additions & 0 deletions packages/contentstack-import/src/import/modules/custom-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class ImportCustomRoles extends BaseClass {
private customRolesUidMapperPath: string;
private envUidMapperFolderPath: string;
private entriesUidMapperFolderPath: string;
private assetsUidMapperFolderPath: string;
private createdCustomRolesPath: string;
private customRolesFailsPath: string;
private customRolesConfig: CustomRoleConfig;
Expand All @@ -25,6 +26,8 @@ export default class ImportCustomRoles extends BaseClass {
private environmentsUidMap: Record<string, unknown>;
private entriesUidMap: Record<string, unknown>;
private localesUidMap: Record<string, unknown>;
private assetsUidMap: Record<string, unknown>;
private assetsFolderUidMap: Record<string, unknown>;
public targetLocalesMap: Record<string, unknown>;
public sourceLocalesMap: Record<string, unknown>;

Expand All @@ -37,6 +40,7 @@ export default class ImportCustomRoles extends BaseClass {
this.customRolesUidMapperPath = join(this.customRolesMapperPath, 'uid-mapping.json');
this.envUidMapperFolderPath = join(this.importConfig.backupDir, 'mapper', 'environments');
this.entriesUidMapperFolderPath = join(this.importConfig.backupDir, 'mapper', 'entries');
this.assetsUidMapperFolderPath = join(this.importConfig.backupDir, 'mapper', 'assets');
this.createdCustomRolesPath = join(this.customRolesMapperPath, 'success.json');
this.customRolesFailsPath = join(this.customRolesMapperPath, 'fails.json');
this.customRoles = {};
Expand All @@ -47,6 +51,8 @@ export default class ImportCustomRoles extends BaseClass {
this.environmentsUidMap = {};
this.entriesUidMap = {};
this.localesUidMap = {};
this.assetsUidMap = {};
this.assetsFolderUidMap = {};
}

/**
Expand Down Expand Up @@ -86,6 +92,16 @@ export default class ImportCustomRoles extends BaseClass {
? (fsUtil.readFile(join(this.entriesUidMapperFolderPath, 'uid-mapping.json'), true) as Record<string, unknown>) || {}
: {};

log.debug('Loading assets UID data...', this.importConfig.context);
this.assetsUidMap = fileHelper.fileExistsSync(this.assetsUidMapperFolderPath)
? (fsUtil.readFile(join(this.assetsUidMapperFolderPath, 'uid-mapping.json'), true) as Record<string, unknown>) || {}
: {};

log.debug('Loading asset folders UID data...', this.importConfig.context);
this.assetsFolderUidMap = fileHelper.fileExistsSync(this.assetsUidMapperFolderPath)
? (fsUtil.readFile(join(this.assetsUidMapperFolderPath, 'folder-mapping.json'), true) as Record<string, unknown>) || {}
: {};

if (this.customRolesUidMapper && Object.keys(this.customRolesUidMapper || {}).length > 0) {
const customRolesUidCount = Object.keys(this.customRolesUidMapper || {}).length;
log.debug(`Loaded existing custom roles UID data: ${customRolesUidCount} items`, this.importConfig.context);
Expand Down Expand Up @@ -290,6 +306,23 @@ export default class ImportCustomRoles extends BaseClass {
} else {
log.debug('No entry UID mappings available for transformation.', this.importConfig.context);
}
} else if (rule.module === 'asset') {
if (!isEmpty(this.assetsUidMap)) {
const originalAssets = rule.assets?.length || 0;
rule.assets = map(rule.assets, (uid: string) => (this.assetsUidMap[uid] as string) ?? uid);
log.debug(`Transformed ${originalAssets} asset UIDs for rule`, this.importConfig.context);
} else {
log.debug('No asset UID mappings available for transformation.', this.importConfig.context);
}
} else if (rule.module === 'folder') {
if (!isEmpty(this.assetsFolderUidMap)) {
const originalFolders = rule.folders?.length || 0;
rule.folders = map(rule.folders, (uid: string) => (this.assetsFolderUidMap[uid] as string) ?? uid);
rule.heirarchy = map(rule.heirarchy, (uid: string) => (this.assetsFolderUidMap[uid] as string) ?? uid);
log.debug(`Transformed ${originalFolders} folder UIDs for rule`, this.importConfig.context);
} else {
log.debug('No asset folder UID mappings available for transformation.', this.importConfig.context);
}
}
return rule;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@
"compile": "tsc -b tsconfig.json",
"build": "pnpm compile && oclif manifest && oclif readme"
}
}
}
Loading