@@ -552,7 +552,7 @@ const saveAsset = async (
552552*
553553* @throws Will log errors encountered during file reading, writing, or asset processing.
554554*/
555- const createAssets = async ( packagePath : any , destination_stack_id : string , projectId : string , ) => {
555+ const createAssets = async ( packagePath : any , destination_stack_id : string , projectId : string , isTest = false ) => {
556556 const srcFunc = 'createAssets' ;
557557 try {
558558 const assetsSave = path ?. join ?.( DATA , destination_stack_id , ASSETS_DIR_NAME ) ;
@@ -561,9 +561,12 @@ const createAssets = async (packagePath: any, destination_stack_id: string, proj
561561 const assetData : any = { } ;
562562 const metadata : AssetMetaData [ ] = [ ] ;
563563 const fileMeta = { "1" : ASSETS_SCHEMA_FILE } ;
564- const assets = JSON . parse ( data ) ?. assets ;
564+ let assets = JSON . parse ( data ) ?. assets ;
565565
566566 if ( assets && assets . length > 0 ) {
567+ if ( isTest ) {
568+ assets = assets ?. slice ( 0 , 10 ) ;
569+ }
567570 const limit = pLimit ( 10 ) ; // Limit concurrent operations to 10
568571 const tasks = assets . map ( ( asset : any ) =>
569572 limit ( ( ) => saveAsset ( asset , failedJSON , assetData , metadata , projectId , destination_stack_id , 0 ) )
@@ -708,7 +711,7 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string,
708711 *
709712 * @throws Will log errors encountered during file reading, processing, or writing of entries.
710713 */
711- const createEntry = async ( packagePath : any , destination_stack_id : string , projectId : string , contentTypes : any ) : Promise < void > => {
714+ const createEntry = async ( packagePath : any , destination_stack_id : string , projectId : string , contentTypes : any , mapperKeys : any ) : Promise < void > => {
712715 const srcFunc = 'createEntry' ;
713716 try {
714717 const entriesSave = path . join ( DATA , destination_stack_id , ENTRIES_DIR_NAME ) ;
@@ -721,7 +724,6 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
721724 if ( entries && entries . length > 0 ) {
722725 const assetId = await readFile ( assetsSave , ASSETS_SCHEMA_FILE ) ?? [ ] ;
723726 const entryId = await readFile ( path . join ( DATA , destination_stack_id , REFERENCES_DIR_NAME ) , REFERENCES_FILE_NAME ) ;
724- console . info ( "🚀 ~ createEntry ~ entryId:" , destination_stack_id )
725727 const environmentsId = await readFile ( environmentSave , ENVIRONMENTS_FILE_NAME ) ;
726728 const displayField : { [ key : string ] : any } = { }
727729 content . map ( ( item : any ) => {
@@ -768,7 +770,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
768770 } ) ;
769771 const pathName = getDisplayName ( name , displayField ) ;
770772 locales . forEach ( ( locale ) => {
771- const publishDetails = Object . values ( environmentsId )
773+ const publishDetails = Object ? .values ?. ( environmentsId )
772774 . filter ( ( env : any ) => env ?. name === environment_id )
773775 ?. map ( ( env : any ) => ( {
774776 environment : env ?. uid ,
@@ -778,15 +780,15 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
778780
779781 const title = entryData [ name ] [ locale ] [ id ] [ pathName ] || "" ;
780782 const urlTitle = title
781- . replace ( / [ ^ a - z A - Z 0 - 9 ] + / g, "-" )
782- . toLowerCase ( ) ;
783+ ? .replace ?. ( / [ ^ a - z A - Z 0 - 9 ] + / g, "-" )
784+ ? .toLowerCase ?. ( ) ;
783785 entryData [ name ] [ locale ] [ id ] = {
784- title : title . trim ( ) === "" ? urlTitle || id : title ,
786+ ...entryData [ name ] [ locale ] [ id ] ,
787+ title : title ?. trim ?.( ) === "" ? ( urlTitle || id ) : title ,
785788 uid : id ,
786- url : `/${ name . toLowerCase ( ) } /${ urlTitle } ` ,
787- locale : locale . toLowerCase ( ) ,
789+ url : `/${ name ? .toLowerCase ?. ( ) } /${ urlTitle } ` ,
790+ locale : locale ? .toLowerCase ?. ( ) ,
788791 publish_details : publishDetails ,
789- ...entryData [ name ] [ locale ] [ id ] ,
790792 } ;
791793 // Format object keys to snake_case
792794 Object . entries ( entryData [ name ] [ locale ] [ id ] ) . forEach (
@@ -808,15 +810,18 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
808810 ) ;
809811 const writePromises = [ ] ;
810812
811- for ( const [ key , values ] of Object . entries ( result ) ) {
813+ for ( const [ newKey , values ] of Object . entries ( result ) ) {
814+ const currentCT = contentTypes ?. find ( ( ct : any ) => ct ?. otherCmsUid === newKey ) ;
815+ const ctName = currentCT ?. contentstackUid in mapperKeys ?
816+ mapperKeys ?. [ currentCT ?. contentstackUid ] : ( currentCT ?. contentstackUid ?? newKey . replace ( / ( [ A - Z ] ) / g, "_$1" ) . toLowerCase ( ) ) ;
812817 for ( const [ localeKey , localeValues ] of Object . entries (
813818 values as { [ key : string ] : any }
814819 ) ) {
815820 const chunks = await makeChunks ( localeValues ) ;
816821 for ( const [ entryKey , entryValue ] of Object . entries ( localeValues ) ) {
817822 const message = getLogMessage (
818823 srcFunc ,
819- `Entry title "${ ( entryValue as { title : string } ) ?. title } "(${ key } ) in the ${ localeKey } locale has been successfully transformed.` ,
824+ `Entry title "${ ( entryValue as { title : string } ) ?. title } "(${ ctName } ) in the ${ localeKey } locale has been successfully transformed.` ,
820825 { }
821826 ) ;
822827 await customLogger ( projectId , destination_stack_id , "info" , message ) ;
@@ -825,7 +830,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
825830 let chunkIndex = 1 ;
826831 const filePath = path . join (
827832 entriesSave ,
828- key . replace ( / ( [ A - Z ] ) / g , "_$1" ) . toLowerCase ( ) , localeKey . toLowerCase ( )
833+ ctName , localeKey . toLowerCase ( )
829834 ) ;
830835 for ( const [ chunkId , chunkData ] of Object . entries ( chunks ) ) {
831836 refs [ chunkIndex ++ ] = `${ chunkId } -entries.json` ;
0 commit comments