@@ -10,7 +10,9 @@ const {
1010 ASSETS_SCHEMA_FILE ,
1111 CONTENT_TYPES_DIR_NAME ,
1212 CONTENT_TYPES_SCHEMA_FILE ,
13- ENTRIES_MASTER_FILE
13+ ENTRIES_MASTER_FILE ,
14+ GLOBAL_FIELDS_DIR_NAME ,
15+ GLOBAL_FIELDS_FILE_NAME
1416} = MIGRATION_DATA_CONFIG ;
1517
1618
@@ -201,10 +203,41 @@ const sortAssets = async (baseDir: string) => {
201203 await fs . promises . writeFile ( path . join ( assetsPath , ASSETS_SCHEMA_FILE ) , JSON ?. stringify ?.( assetsMeta ) ) ;
202204}
203205
206+ const writeGlobalField = async ( schema : any , globalSave : string , filePath : string ) => {
207+ try {
208+ await fs . promises . access ( globalSave ) ;
209+ } catch ( err ) {
210+ try {
211+ await fs . promises . mkdir ( globalSave , { recursive : true } ) ;
212+ } catch ( mkdirErr ) {
213+ console . error ( "🚀 ~ fs.mkdir ~ err:" , mkdirErr ) ;
214+ return ;
215+ }
216+ }
217+ try {
218+ await fs . promises . writeFile ( filePath , JSON . stringify ( schema , null , 2 ) ) ;
219+ } catch ( writeErr ) {
220+ console . error ( "🚀 ~ fs.writeFile ~ err:" , writeErr ) ;
221+ }
222+ } ;
223+
224+ const sortGlobalField = async ( baseDir : string , finalData : any ) => {
225+ const globalSave = path . join ( process . cwd ( ) , baseDir , GLOBAL_FIELDS_DIR_NAME ) ;
226+ const globalPath = path . join ( globalSave , GLOBAL_FIELDS_FILE_NAME ) ;
227+ const globalData = await JSON . parse ( await fs . promises . readFile ( globalPath , 'utf8' ) ) ;
228+ const globalResult = [ ] ;
229+ for await ( const ct of globalData ) {
230+ await lookForReference ( ct , finalData ) ;
231+ globalResult ?. push ( ct ) ;
232+ }
233+ await writeGlobalField ( globalResult , globalPath , globalPath ) ;
234+ }
235+
204236const sortContentType = async ( baseDir : string , finalData : any ) => {
205237 const contentTypePath : string = path . join ( process . cwd ( ) , baseDir , CONTENT_TYPES_DIR_NAME ) ;
206238 const contentSave = path . join ( baseDir , CONTENT_TYPES_DIR_NAME ) ;
207239 const ctData = await JSON . parse ( await fs . promises . readFile ( path . join ( contentTypePath , CONTENT_TYPES_SCHEMA_FILE ) , 'utf8' ) ) ;
240+ await sortGlobalField ( baseDir , finalData ) ;
208241 const contentTypes : any = [ ] ;
209242 for await ( const ct of finalData ) {
210243 const findCtData = ctData ?. find ( ( ele : any ) => ele ?. uid === ct ?. contentType ) ;
@@ -218,6 +251,7 @@ const sortContentType = async (baseDir: string, finalData: any) => {
218251}
219252
220253
254+
221255export const testFolderCreator = async ( { destinationStackId } : any ) => {
222256 const sanitizedStackId = path . basename ( destinationStackId ) ;
223257 const baseDir = path . join ( MIGRATION_DATA_CONFIG . DATA , sanitizedStackId ) ;
0 commit comments