@@ -88,39 +88,44 @@ function makeChunks(assetData: any) {
8888
8989const transformCloudinaryObject = ( input : any ) => {
9090 const result : any = [ ] ;
91+ if ( ! Array . isArray ( input ) ) {
92+ return result ;
93+ }
9194 for ( const metaData of input ?? [ ] ) {
92- result ?. push ( {
93- public_id : metaData . public_id ,
94- resource_type : metaData . resource_type ,
95- type : metaData . type ,
96- format : metaData . format ,
97- version : metaData . version ,
98- url : metaData . original_url ,
99- secure_url : metaData . original_secure_url ,
100- width : metaData . width ,
101- height : metaData . height ,
102- bytes : metaData . bytes ,
103- duration : metaData . duration ,
104- tags : metaData . tags ,
105- metadata : metaData . metadata ,
106- created_at : metaData . created_at ,
107- access_mode : "public" ,
108- access_control : [ ] ,
109- created_by : {
110- type : "" ,
111- id : ""
112- } ,
113- uploaded_by : {
114- type : "" ,
115- id : ""
116- } ,
117- folder_id : "" ,
118- id : "" ,
119- folder : "" ,
120- cs_metadata : {
121- config_label : "config"
122- }
123- } ) ;
95+ if ( metaData ?. public_id ) {
96+ result ?. push ( {
97+ public_id : metaData . public_id ,
98+ resource_type : metaData . resource_type ,
99+ type : metaData . type ,
100+ format : metaData . format ,
101+ version : metaData . version ,
102+ url : metaData . original_url ,
103+ secure_url : metaData . original_secure_url ,
104+ width : metaData . width ,
105+ height : metaData . height ,
106+ bytes : metaData . bytes ,
107+ duration : metaData . duration ,
108+ tags : metaData . tags ,
109+ metadata : metaData . metadata ,
110+ created_at : metaData . created_at ,
111+ access_mode : "public" ,
112+ access_control : [ ] ,
113+ created_by : {
114+ type : "" ,
115+ id : ""
116+ } ,
117+ uploaded_by : {
118+ type : "" ,
119+ id : ""
120+ } ,
121+ folder_id : uuidv4 ( ) ,
122+ id : uuidv4 ( ) ,
123+ folder : "" ,
124+ cs_metadata : {
125+ config_label : "config"
126+ }
127+ } ) ;
128+ }
124129 }
125130 return result ;
126131}
@@ -185,7 +190,7 @@ function convertToArray(data: any) {
185190 if ( typeof data === 'object' && data !== null && ! Array . isArray ( data ) ) {
186191 return [ data ] // Converts object values into an array
187192 }
188- return data ; // Return as is if it's already an array or not an object
193+ return data ?? [ ] ; // Return as is if it's already an array or not an object
189194}
190195
191196const mktApp = ( type : string , data : any ) => {
@@ -735,7 +740,6 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
735740 * @throws Will log errors encountered during file reading, processing, or writing of entries.
736741 */
737742const createEntry = async ( packagePath : any , destination_stack_id : string , projectId : string , contentTypes : any , mapperKeys : any , master_locale : string ) : Promise < void > => {
738- console . info ( "🚀 ~ createEntry ~ master_locale:" , master_locale )
739743 const srcFunc = 'createEntry' ;
740744 try {
741745 const entriesSave = path . join ( DATA , destination_stack_id , ENTRIES_DIR_NAME ) ;
@@ -782,7 +786,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
782786 entryData [ name ] [ lang ] [ id ] ??= { } ;
783787 locales . push ( lang ) ;
784788 const fieldData = currentCT ?. fieldMapping ?. find ( ( item : any ) => key === item ?. uid ) ;
785- const newId = fieldData ?. contentstackFieldUid ?? `${ key } ` . replace ( / [ ^ a - z A - Z 0 - 9 ] + / g, "_" ) ;
789+ const newId = fieldData ?. contentstackFieldUid ?? `${ key } ` ? .replace ?. ( / [ ^ a - z A - Z 0 - 9 ] + / g, "_" ) ;
786790 entryData [ name ] [ lang ] [ id ] [ newId ] = processField (
787791 langValue ,
788792 entryId ,
@@ -795,16 +799,14 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
795799 const pathName = getDisplayName ( name , displayField ) ;
796800 locales . forEach ( ( locale ) => {
797801 const localeCode = mapLocales ( { masterLocale : master_locale , locale, locales : LOCALE_MAPPER } ) ;
798- console . info ( "🚀 ~ locales.forEach ~ localeCode:" , localeCode ) ;
799802 const publishDetails = Object ?. values ?.( environmentsId ) ?. length ? Object ?. values ?.( environmentsId )
800803 . filter ( ( env : any ) => env ?. name === environment_id )
801804 ?. map ( ( env : any ) => ( {
802805 environment : env ?. uid ,
803806 version : 1 ,
804- locale : locale ?. toLowerCase ( ) ,
807+ locale : locale ?. toLowerCase ?. ( ) ,
805808 } ) ) : [ ] ;
806-
807- const title = entryData [ name ] [ locale ] [ id ] [ pathName ] || "" ;
809+ const title = fields ?. [ pathName ] ?. [ locale ] || "" ;
808810 const urlTitle = title
809811 ?. replace ?.( / [ ^ a - z A - Z 0 - 9 ] + / g, "-" )
810812 ?. toLowerCase ?.( ) ;
@@ -857,7 +859,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
857859 ) ;
858860 for await ( const [ chunkId , chunkData ] of Object . entries ( chunks ) ) {
859861 refs [ chunkIndex ++ ] = `${ chunkId } -entries.json` ;
860- await writeFile ( filePath , `${ chunkId } -entries.json` , chunkData )
862+ await writeFile ( filePath , `${ chunkId } -entries.json` , chunkData ) ;
861863 }
862864 await writeFile ( filePath , ENTRIES_MASTER_FILE , refs ) ;
863865 }
0 commit comments