1- import { resolve as pResolve , join } from 'node:path' ;
1+ import { join , resolve as pResolve } from 'node:path' ;
22import { mkdirSync , readdirSync , statSync } from 'node:fs' ;
33import { writeFile } from 'node:fs/promises' ;
44import { log , CLIProgressManager , configHandler } from '@contentstack/cli-utilities' ;
55
66import type {
77 AssetManagementAPIConfig ,
8- AssetManagementImportOptions ,
98 ImportContext ,
109 ImportResult ,
10+ ImportSpacesOptions ,
1111 SpaceMapping ,
1212} from '../types/asset-management-api' ;
1313import { AM_MAIN_PROCESS_NAME } from '../constants/index' ;
@@ -22,11 +22,11 @@ import ImportWorkspace from './workspaces';
2222 * Returns combined uidMap, urlMap, and spaceMappings for the bridge module.
2323 */
2424export class ImportSpaces {
25- private readonly options : AssetManagementImportOptions ;
25+ private readonly options : ImportSpacesOptions ;
2626 private parentProgressManager : CLIProgressManager | null = null ;
2727 private progressManager : CLIProgressManager | null = null ;
2828
29- constructor ( options : AssetManagementImportOptions ) {
29+ constructor ( options : ImportSpacesOptions ) {
3030 this . options = options ;
3131 }
3232
@@ -35,63 +35,37 @@ export class ImportSpaces {
3535 }
3636
3737 async start ( ) : Promise < ImportResult > {
38- const {
39- contentDir,
40- assetManagementUrl,
41- org_uid,
42- apiKey,
43- host,
44- sourceApiKey,
45- context,
46- apiConcurrency,
47- uploadAssetsConcurrency,
48- importFoldersConcurrency,
49- spacesDirName,
50- fieldsDir,
51- assetTypesDir,
52- fieldsFileName,
53- assetTypesFileName,
54- foldersFileName,
55- assetsFileName,
56- fieldsImportInvalidKeys,
57- assetTypesImportInvalidKeys,
58- mapperRootDir,
59- mapperAssetsModuleDir,
60- mapperUidFileName,
61- mapperUrlFileName,
62- mapperSpaceUidFileName,
63- } = this . options ;
64-
65- const spacesRootPath = pResolve ( contentDir , spacesDirName ?? 'spaces' ) ;
66-
38+ const configOptions = this . options ;
39+ const spacesRootPath = pResolve ( configOptions . contentDir , 'spaces' ) ;
40+ const org_uid = configOptions . org_uid ;
41+ const context = configOptions . context ;
6742 const importContext : ImportContext = {
6843 spacesRootPath,
69- sourceApiKey,
70- apiKey,
71- host,
44+ sourceApiKey : configOptions . sourceApiKey ,
45+ apiKey : configOptions . apiKey ,
46+ host : configOptions . host ,
7247 org_uid,
7348 context,
74- apiConcurrency,
75- uploadAssetsConcurrency,
76- importFoldersConcurrency,
77- spacesDirName,
78- fieldsDir,
79- assetTypesDir,
80- fieldsFileName,
81- assetTypesFileName,
82- foldersFileName,
83- assetsFileName,
84- fieldsImportInvalidKeys,
85- assetTypesImportInvalidKeys,
86- mapperRootDir,
87- mapperAssetsModuleDir,
88- mapperUidFileName,
89- mapperUrlFileName,
90- mapperSpaceUidFileName,
49+ apiConcurrency : configOptions . apiConcurrency ,
50+ uploadAssetsConcurrency : configOptions . uploadAssetsConcurrency ,
51+ importFoldersConcurrency : configOptions . importFoldersConcurrency ,
52+ spacesDirName : configOptions . spacesDirName ,
53+ fieldsDir : configOptions . fieldsDir ,
54+ assetTypesDir : configOptions . assetTypesDir ,
55+ fieldsFileName : configOptions . fieldsFileName ,
56+ assetTypesFileName : configOptions . assetTypesFileName ,
57+ foldersFileName : configOptions . foldersFileName ,
58+ assetsFileName : configOptions . assetsFileName ,
59+ fieldsImportInvalidKeys : configOptions . fieldsImportInvalidKeys ,
60+ assetTypesImportInvalidKeys : configOptions . assetTypesImportInvalidKeys ,
61+ mapperRootDir : configOptions . mapperRootDir ,
62+ mapperAssetsModuleDir : configOptions . mapperAssetsModuleDir ,
63+ mapperUidFileName : configOptions . mapperUidFileName ,
64+ mapperUrlFileName : configOptions . mapperUrlFileName ,
65+ mapperSpaceUidFileName : configOptions . mapperSpaceUidFileName ,
9166 } ;
92-
9367 const apiConfig : AssetManagementAPIConfig = {
94- baseURL : assetManagementUrl ,
68+ baseURL : configOptions . assetManagementUrl ,
9569 headers : { organization_uid : org_uid } ,
9670 context,
9771 } ;
@@ -186,13 +160,13 @@ export class ImportSpaces {
186160 }
187161
188162 if ( this . options . backupDir ) {
189- const mapperRoot = this . options . mapperRootDir ?? 'mapper' ;
190- const mapperAssetsMod = this . options . mapperAssetsModuleDir ?? 'assets' ;
163+ const mapperRoot = importContext . mapperRootDir ?? 'mapper' ;
164+ const mapperAssetsMod = importContext . mapperAssetsModuleDir ?? 'assets' ;
191165 const mapperDir = join ( this . options . backupDir , mapperRoot , mapperAssetsMod ) ;
192166 mkdirSync ( mapperDir , { recursive : true } ) ;
193- const uidFile = this . options . mapperUidFileName ?? 'uid-mapping.json' ;
194- const urlFile = this . options . mapperUrlFileName ?? 'url-mapping.json' ;
195- const spaceUidFile = this . options . mapperSpaceUidFileName ?? 'space-uid-mapping.json' ;
167+ const uidFile = importContext . mapperUidFileName ?? 'uid-mapping.json' ;
168+ const urlFile = importContext . mapperUrlFileName ?? 'url-mapping.json' ;
169+ const spaceUidFile = importContext . mapperSpaceUidFileName ?? 'space-uid-mapping.json' ;
196170 await writeFile ( join ( mapperDir , uidFile ) , JSON . stringify ( allUidMap ) , 'utf8' ) ;
197171 await writeFile ( join ( mapperDir , urlFile ) , JSON . stringify ( allUrlMap ) , 'utf8' ) ;
198172 await writeFile ( join ( mapperDir , spaceUidFile ) , JSON . stringify ( allSpaceUidMap ) , 'utf8' ) ;
0 commit comments