@@ -6,7 +6,7 @@ import forEach from 'lodash/forEach';
66import indexOf from 'lodash/indexOf' ;
77import { join , resolve } from 'path' ;
88import { readFileSync , existsSync } from 'fs' ;
9- import { FsUtility , HttpResponse } from '@contentstack/cli-utilities' ;
9+ import { FsUtility , HttpResponse , sanitizePath } from '@contentstack/cli-utilities' ;
1010
1111import VariantAdapter , { VariantHttpClient } from '../utils/variant-api-adapter' ;
1212import {
@@ -53,12 +53,12 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
5353 organization_uid : config . org_uid ,
5454 'X-Project-Uid' : config . modules . personalization . project_id ,
5555 } ,
56- } ;
56+ } ;
5757 super ( Object . assign ( omit ( config , [ 'helpers' ] ) , conf ) ) ;
58- this . entriesMapperPath = resolve ( config . backupDir , config . branchName || '' , 'mapper' , 'entries' ) ;
58+ this . entriesMapperPath = resolve ( sanitizePath ( config . backupDir ) , config . branchName || '' , 'mapper' , 'entries' ) ;
5959 this . personalizationConfig = this . config . modules . personalization ;
60- this . entriesDirPath = resolve ( config . backupDir , config . branchName || '' , config . modules . entries . dirName ) ;
61- this . failedVariantPath = resolve ( this . entriesMapperPath , 'failed-entry-variants.json' ) ;
60+ this . entriesDirPath = resolve ( sanitizePath ( config . backupDir ) , config . branchName || '' , sanitizePath ( config . modules . entries . dirName ) ) ;
61+ this . failedVariantPath = resolve ( sanitizePath ( this . entriesMapperPath ) , 'failed-entry-variants.json' ) ;
6262 this . failedVariantEntries = new Map ( ) ;
6363 }
6464
@@ -71,12 +71,12 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
7171 * message indicating that no entries were found and return.
7272 */
7373 async import ( ) {
74- const filePath = resolve ( this . entriesMapperPath , 'data-for-variant-entry.json' ) ;
74+ const filePath = resolve ( sanitizePath ( this . entriesMapperPath ) , 'data-for-variant-entry.json' ) ;
7575 const variantIdPath = resolve (
76- this . config . backupDir ,
76+ sanitizePath ( this . config . backupDir ) ,
7777 'mapper' ,
78- this . personalizationConfig . dirName ,
79- this . personalizationConfig . experiences . dirName ,
78+ sanitizePath ( this . personalizationConfig . dirName ) ,
79+ sanitizePath ( this . personalizationConfig . experiences . dirName ) ,
8080 'variants-uid-mapping.json' ,
8181 ) ;
8282
@@ -97,18 +97,18 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
9797 return ;
9898 }
9999
100- const entriesUidMapperPath = join ( this . entriesMapperPath , 'uid-mapping.json' ) ;
101- const assetUidMapperPath = resolve ( this . config . backupDir , 'mapper' , 'assets' , 'uid-mapping.json' ) ;
102- const assetUrlMapperPath = resolve ( this . config . backupDir , 'mapper' , 'assets' , 'url-mapping.json' ) ;
100+ const entriesUidMapperPath = join ( sanitizePath ( this . entriesMapperPath ) , 'uid-mapping.json' ) ;
101+ const assetUidMapperPath = resolve ( sanitizePath ( this . config . backupDir ) , 'mapper' , 'assets' , 'uid-mapping.json' ) ;
102+ const assetUrlMapperPath = resolve ( sanitizePath ( this . config . backupDir ) , 'mapper' , 'assets' , 'url-mapping.json' ) ;
103103 const taxonomiesPath = resolve (
104- this . config . backupDir ,
104+ sanitizePath ( this . config . backupDir ) ,
105105 'mapper' ,
106- this . config . modules . taxonomies . dirName ,
106+ sanitizePath ( this . config . modules . taxonomies . dirName ) ,
107107 'terms' ,
108108 'success.json' ,
109109 ) ;
110- const marketplaceAppMapperPath = resolve ( this . config . backupDir , 'mapper' , 'marketplace_apps' , 'uid-mapping.json' ) ;
111- const envPath = resolve ( this . config . backupDir , 'environments' , 'environments.json' ) ;
110+ const marketplaceAppMapperPath = resolve ( sanitizePath ( this . config . backupDir ) , 'mapper' , 'marketplace_apps' , 'uid-mapping.json' ) ;
111+ const envPath = resolve ( sanitizePath ( this . config . backupDir ) , 'environments' , 'environments.json' ) ;
112112 // NOTE Read and store list of variant IDs
113113 this . variantIdList = ( fsUtil . readFile ( variantIdPath , true ) || { } ) as Record < string , unknown > ;
114114 if ( isEmpty ( this . variantIdList ) ) {
@@ -141,9 +141,9 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
141141 const { content_type, locale, entry_uid } = entriesForVariant ;
142142 const ctConfig = this . config . modules [ 'content-types' ] ;
143143 const contentType : ContentTypeStruct = JSON . parse (
144- readFileSync ( resolve ( this . config . backupDir , ctConfig . dirName , `${ content_type } .json` ) , 'utf8' ) ,
144+ readFileSync ( resolve ( sanitizePath ( this . config . backupDir ) , sanitizePath ( ctConfig . dirName ) , `${ content_type } .json` ) , 'utf8' ) ,
145145 ) ;
146- const variantEntryBasePath = join ( this . entriesDirPath , content_type , locale , variantEntry . dirName , entry_uid ) ;
146+ const variantEntryBasePath = join ( sanitizePath ( this . entriesDirPath ) , sanitizePath ( content_type ) , sanitizePath ( locale ) , sanitizePath ( variantEntry . dirName ) , sanitizePath ( entry_uid ) ) ;
147147 const fs = new FsUtility ( { basePath : variantEntryBasePath } ) ;
148148
149149 for ( const _ in fs . indexFileContent ) {
@@ -327,7 +327,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
327327 } ,
328328 this . assetUidMapper ,
329329 this . assetUrlMapper ,
330- join ( this . entriesDirPath , contentType . uid ) ,
330+ join ( sanitizePath ( this . entriesDirPath ) , sanitizePath ( contentType . uid ) ) ,
331331 this . installedExtensions ,
332332 ) ;
333333 }
0 commit comments