Skip to content

dx | 3097 import stack settings #1979

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

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions packages/contentstack-import/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const config: DefaultConfig = {
types: [
'locales',
'environments',
'stack',
'assets',
'taxonomies',
'extensions',
Expand Down
47 changes: 47 additions & 0 deletions packages/contentstack-import/src/import/modules/stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { join } from 'node:path';
import { log, formatError, fileHelper, fsUtil } from '../../utils';
import BaseClass from './base-class';
import { ModuleClassParams } from '../../types';

export default class ImportStack extends BaseClass { // classname
private stackSettingsPath: string;
private envUidMapperPath: string;
private stackSettings: Record<string, any> | null = null;
private envUidMapper: Record<string, string> = {};

constructor({ importConfig, stackAPIClient }: ModuleClassParams) {
super({ importConfig, stackAPIClient });
this.stackSettingsPath = join(this.importConfig.backupDir, 'stack', 'settings.json');
this.envUidMapperPath = join(this.importConfig.backupDir, 'mapper', 'environments', 'uid-mapping.json');
}

async start(): Promise<void> {
log(this.importConfig, 'Migrating stack...', 'info');

if (fileHelper.fileExistsSync(this.envUidMapperPath)) {
this.envUidMapper = fsUtil.readFile(this.envUidMapperPath, true) as Record<string, string>;
} else {
throw new Error('Please run the environments migration first.');
}

if (fileHelper.fileExistsSync(this.stackSettingsPath)) {
this.stackSettings = fsUtil.readFile(this.stackSettingsPath, true) as Record<string, any>;
} else {
log(this.importConfig, 'No stack Found!', 'info');
return;
}

if (this.stackSettings.live_preview && this.stackSettings.live_preview['default-env']) {
const oldEnvUid = this.stackSettings.live_preview['default-env'];
const mappedEnvUid = this.envUidMapper[oldEnvUid];
this.stackSettings.live_preview['default-env'] = mappedEnvUid;
}

try {
await this.stack.addSettings(this.stackSettings);
log(this.importConfig, 'Successfully imported stack', 'success');
} catch (error) {
log(this.importConfig, `Stack failed to be imported! ${formatError(error)}`, 'error');
}
}
}
Loading