Skip to content

Commit ada59b6

Browse files
authored
Merge pull request #2380 from contentstack/fix/DX-4440
DX - 4440 - Fixed the import prompt for the Data directory
2 parents 9812606 + 4b79c0d commit ada59b6

5 files changed

Lines changed: 35 additions & 21 deletions

File tree

.talismanrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

22
fileignoreconfig:
33
- filename: package-lock.json
4-
checksum: 13b82bf3ada05a792580596fbedb02c988fd556b208a742da1ecb3f2678675b4
4+
checksum: fa2c81c72305bc19fa4f64457af1000aa2f0c179ecb7e46a5fc9d8b760c705a7
55
- filename: pnpm-lock.yaml
6-
checksum: 24ffee6d868d77669d32ac036c4abc2ab5f4c2d7f45f74c62f38a07e91240c26
6+
checksum: faaef9e003c5ba45e56ab1ca24a4fc285f53a2b9ecc6d3dbd11e7130a31db4a2
7+
- filename: packages/contentstack-clone/src/core/util/clone-handler.ts
8+
checksum: 0a7ed55e96aa5a94084538b4a480608593b04c316bf02cf54cdd3a647e9b714c
79
version: '1.0'

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-clone/src/core/util/clone-handler.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,14 @@ export class CloneHandler {
568568
delete exportConfig.import;
569569
delete exportConfig.export;
570570

571+
if (exportConfig.source_stack) {
572+
exportConfig.apiKey = exportConfig.source_stack;
573+
}
571574
// Resolve path to package root - go up 3 levels from __dirname (core/util -> package root)
572575
const packageRoot = path.resolve(__dirname, '../../..');
573576
const exportDir = path.join(packageRoot, 'contents');
574577
log.debug(`Export directory: ${exportDir}`, this.config.cloneContext);
575-
const cmd: string[] = ['-k', exportConfig.source_stack, '-d', exportDir];
578+
const cmd: string[] = ['-k', exportConfig.apiKey || exportConfig.source_stack, '-d', exportDir];
576579

577580
if (exportConfig.cloneType === 'a') {
578581
exportConfig.filteredModules = ['stack'].concat(STRUCTURE_LIST);
@@ -604,7 +607,7 @@ export class CloneHandler {
604607
...this.config.cloneContext,
605608
cmd: cmd.join(' '),
606609
exportDir,
607-
sourceStack: exportConfig.source_stack,
610+
sourceStack: exportConfig.apiKey || exportConfig.source_stack,
608611
branch: exportConfig.sourceStackBranch
609612
});
610613
log.debug('Running export command', { ...this.config.cloneContext, cmd });
@@ -634,7 +637,15 @@ export class CloneHandler {
634637
cmd.push('-a', importConfig.destination_alias);
635638
log.debug(`Using destination alias: ${importConfig.destination_alias}`, this.config.cloneContext);
636639
}
637-
if (!importConfig.data && importConfig.sourceStackBranch && importConfig.pathDir) {
640+
if (importConfig.target_stack) {
641+
importConfig.apiKey = importConfig.target_stack;
642+
log.debug(`Using target stack api key for import: ${importConfig.target_stack}`, this.config.cloneContext);
643+
}
644+
if (importConfig.data) {
645+
importConfig.contentDir = importConfig.data;
646+
}
647+
648+
if (!importConfig.contentDir && importConfig.sourceStackBranch && importConfig.pathDir) {
638649
const dataPath = path.join(importConfig.pathDir, importConfig.sourceStackBranch);
639650
cmd.push('-d', dataPath);
640651
log.debug(`Import data path: ${dataPath}`, this.config.cloneContext);
@@ -660,12 +671,12 @@ export class CloneHandler {
660671

661672
log.debug(`Writing import config to: ${configFilePath}`, this.config.cloneContext);
662673
fs.writeFileSync(configFilePath, JSON.stringify(importConfig));
663-
log.debug('Import command prepared', {
674+
log.debug('Import command prepared', {
664675
...this.config.cloneContext,
665676
cmd: cmd.join(' '),
666-
targetStack: importConfig.target_stack,
677+
targetStack: importConfig.apiKey || importConfig.target_stack,
667678
targetBranch: importConfig.targetStackBranch,
668-
dataPath: importConfig.data || (importConfig.pathDir && importConfig.sourceStackBranch ? path.join(importConfig.pathDir, importConfig.sourceStackBranch) : undefined)
679+
dataPath: importConfig.contentDir || (importConfig.pathDir && importConfig.sourceStackBranch ? path.join(importConfig.pathDir, importConfig.sourceStackBranch) : undefined)
669680
});
670681
log.debug('Running import command', { ...this.config.cloneContext, cmd });
671682
const importData = importCmd.run(cmd);
@@ -796,8 +807,8 @@ export class CloneHandler {
796807
let selectedValue: any = {};
797808
// Resolve path to package root - go up 3 levels from __dirname (core/util -> package root)
798809
const cloneTypePackageRoot = path.resolve(__dirname, '../../..');
799-
this.config.data = path.join(cloneTypePackageRoot, 'contents', this.config.sourceStackBranch || '');
800-
log.debug(`Clone data directory: ${this.config.data}`, this.config.cloneContext);
810+
this.config.contentDir = path.join(cloneTypePackageRoot, 'contents', this.config.sourceStackBranch || '');
811+
log.debug(`Clone content directory: ${this.config.contentDir}`, this.config.cloneContext);
801812

802813
if (!this.config.cloneType) {
803814
log.debug('Clone type not specified, prompting user for selection', this.config.cloneContext);

packages/contentstack-clone/src/types/clone-config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export interface CloneConfig {
3131
forceStopMarketplaceAppsPrompt?: boolean;
3232

3333
// Data and modules
34-
data?: string;
34+
/** Path to exported content for import (aligns with import plugin's contentDir) */
35+
contentDir?: string;
3536
modules?: string[];
3637
filteredModules?: string[];
3738

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)