@@ -15,6 +15,7 @@ const PAPI_URL = "https://api.segmentapis.com"
1515
1616const  PRIVATE_DESTINATIONS  =  yaml . load ( fs . readFileSync ( path . resolve ( __dirname ,  `../src/_data/catalog/destinations_private.yml` ) ) ) 
1717const  privateDests  =  PRIVATE_DESTINATIONS . items 
18+ let  private  =  [ ] 
1819const  getCatalog  =  async  ( url ,  page_token  =  "MA==" )  =>  { 
1920  try  { 
2021    const  res  =  await  axios . get ( url ,  { 
@@ -36,6 +37,72 @@ const getCatalog = async (url, page_token = "MA==") => {
3637  } 
3738} 
3839
40+ const  getDestinationData  =  async  ( id )  =>  { 
41+   const  res  =  await  getCatalog ( `${ PAPI_URL } ${ id }  ) 
42+   destination  =  res . data . destinationMetadata 
43+   let  settings  =  destination . options 
44+   settings . sort ( ( a ,  b )  =>  { 
45+     if  ( a . name . toLowerCase ( )  <  b . name . toLowerCase ( ) )  { 
46+       return  - 1 ; 
47+     } 
48+     if  ( a . name . toLowerCase ( )  >  b . name . toLowerCase ( ) )  { 
49+       return  1 ; 
50+     } 
51+     return  0 ; 
52+   } ) 
53+   let  actions  =  destination . actions 
54+   let  presets  =  destination . presets 
55+ 
56+ 
57+ 
58+   let  updatePrivateDest  =  { 
59+     id : destination . id , 
60+     display_name : destination . name , 
61+     name : destination . name , 
62+     slug : destination . slug , 
63+     previous_names : destination . previousNames , 
64+     website : destination . website , 
65+     status : destination . status , 
66+     logo : { 
67+       url : destination . logos . default 
68+     } , 
69+     mark : { 
70+       url : destination . logos . mark 
71+     } , 
72+     methods : destination . supportedMethods , 
73+     platforms : destination . supportedPlatforms , 
74+     components : destination . components , 
75+     browserUnbundlingSupported : destination . supportedFeatures . browserUnbundling , 
76+     browserUnbundlingPublic : destination . supportedFeatures . browserUnbundlingPublic , 
77+     replay : destination . supportedFeatures . replay , 
78+     settings, 
79+     actions, 
80+     presets
81+   } 
82+ 
83+ 
84+   if  ( destination . status  ===  "PRIVATE_BETA"  ||  destination . status  ===  "PRIVATE_BUILDING" )  { 
85+     private . push ( updatePrivateDest ) 
86+   }  else  { 
87+     console . log ( `${ destination . name }  ) 
88+   } 
89+ 
90+   const  options  =  { 
91+     noArrayIndent : false 
92+   } 
93+ 
94+   output  =  "# AUTOGENERATED FROM PUBLIC API. DO NOT EDIT\n" 
95+   var  todayDate  =  new  Date ( ) . toISOString ( ) . slice ( 0 ,  10 ) ; 
96+   output  +=  "# destination data last updated "  +  todayDate  +  " \n" ; 
97+   output  +=  yaml . dump ( { 
98+     items : private 
99+   } ,  options ) 
100+   fs . writeFileSync ( path . resolve ( __dirname ,  `../src/_data/catalog/destinations_private.yml` ) ,  output ) ; 
101+ } 
102+ 
103+ 
104+ 
105+ 
39106const  addPrivateDestination  =  async  ( )  =>  { 
40107  const  DEST_ID  =  await  prompt ( { 
41108    type : 'input' , 
@@ -52,65 +119,12 @@ const addPrivateDestination = async () => {
52119    console . log ( "This destination is already captured." ) 
53120    return 
54121  }  else  { 
55-     const  res  =  await  getCatalog ( `${ PAPI_URL } ${ DEST_ID . id }  ) 
56-     destination  =  res . data . destinationMetadata 
57-     let  settings  =  destination . options 
58- 
59-     settings . sort ( ( a ,  b )  =>  { 
60-       if  ( a . name . toLowerCase ( )  <  b . name . toLowerCase ( ) )  { 
61-         return  - 1 ; 
62-       } 
63-       if  ( a . name . toLowerCase ( )  >  b . name . toLowerCase ( ) )  { 
64-         return  1 ; 
65-       } 
66-       return  0 ; 
67-     } ) 
68-     let  actions  =  destination . actions 
69-     let  presets  =  destination . presets 
70- 
71-     if  ( destination . status  ==  "PRIVATE_BETA"  ||  destination . status  ==  "PRIVATE_BUILDING" )  { 
72- 
73-       let  updatePrivateDest  =  { 
74-         id : destination . id , 
75-         display_name : destination . name , 
76-         name : destination . name , 
77-         slug : destination . slug , 
78-         previous_names : destination . previousNames , 
79-         website : destination . website , 
80-         status : destination . status , 
81-         logo : { 
82-           url : destination . logos . default 
83-         } , 
84-         mark : { 
85-           url : destination . logos . mark 
86-         } , 
87-         methods : destination . supportedMethods , 
88-         platforms : destination . supportedPlatforms , 
89-         components : destination . components , 
90-         browserUnbundlingSupported : destination . supportedFeatures . browserUnbundling , 
91-         browserUnbundlingPublic : destination . supportedFeatures . browserUnbundlingPublic , 
92-         replay : destination . supportedFeatures . replay , 
93-         settings, 
94-         actions, 
95-         presets
96-       } 
97- 
98-       privateDests . push ( updatePrivateDest ) 
99-       const  options  =  { 
100-         noArrayIndent : false 
101-       } 
122+     privateIds . push ( DEST_ID . id ) 
123+   } 
102124
103-       output  =  "# AUTOGENERATED FROM PUBLIC API. DO NOT EDIT\n" 
104-       var  todayDate  =  new  Date ( ) . toISOString ( ) . slice ( 0 ,  10 ) ; 
105-       output  +=  "# destination data last updated "  +  todayDate  +  " with "  +  destination . name  +  " \n" ; 
106-       output  +=  yaml . dump ( { 
107-         items : privateDests 
108-       } ,  options ) 
109-       //console.log(output) 
110-       fs . writeFileSync ( path . resolve ( __dirname ,  `../src/_data/catalog/destinations_private.yml` ) ,  output ) ; 
111-     }  else  { 
112-       console . log ( "This destination is already public" ) 
113-     } 
125+   for  ( const  element  in  privateIds )  { 
126+     let  currentId  =  privateIds [ element ] 
127+     getDestinationData ( currentId ) 
114128  } 
115129
116130} 
0 commit comments