@@ -6,6 +6,9 @@ const yaml = require('js-yaml');
66const {
77 prompt
88} = require ( 'enquirer' ) ;
9+ const {
10+ type
11+ } = require ( 'os' ) ;
912
1013require ( 'dotenv' ) . config ( ) ;
1114
@@ -37,9 +40,15 @@ const getCatalog = async (url, page_token = "MA==") => {
3740 }
3841}
3942
43+
44+ const checkDestinationStatus = async ( id ) => {
45+ const res = await getCatalog ( `${ PAPI_URL } /catalog/destinations/${ id } ` )
46+ let destination = res . data . destinationMetadata
47+ return destination
48+ }
4049const getDestinationData = async ( id ) => {
4150 const res = await getCatalog ( `${ PAPI_URL } /catalog/destinations/${ id } ` )
42- destination = res . data . destinationMetadata
51+ let destination = res . data . destinationMetadata
4352 let settings = destination . options
4453 settings . sort ( ( a , b ) => {
4554 if ( a . name . toLowerCase ( ) < b . name . toLowerCase ( ) ) {
@@ -101,30 +110,60 @@ const getDestinationData = async (id) => {
101110}
102111
103112
113+ const checkExistingStatus = async ( ) => {
114+ let existingIds = [ ]
115+ let newIds = [ ]
116+ for ( let [ key ] of Object . entries ( privateDests ) ) {
117+ existingIds . push ( privateDests [ key ] . id )
118+ }
119+
120+ existingIds . sort ( )
104121
122+ for ( i in existingIds ) {
123+ let id = existingIds [ i ]
124+ let destination = await checkDestinationStatus ( id )
125+ let status = destination . status
105126
127+ if ( status === "PRIVATE_BETA" ) {
128+ // console.log(`${destination.name} is private`)
129+ newIds . push ( id )
130+ } else {
131+ // console.log(`${destination.name}is public`)
132+ }
133+ }
134+ return newIds
135+ }
106136const addPrivateDestination = async ( ) => {
137+ let ids = await checkExistingStatus ( )
138+ ids . sort ( ) ;
107139 const DEST_ID = await prompt ( {
108140 type : 'input' ,
109141 name : 'id' ,
110142 message : 'Enter the destination ID'
111143 } )
112144
113- const privateIds = [ ]
114- for ( let [ key ] of Object . entries ( privateDests ) ) {
115- privateIds . push ( privateDests [ key ] . id )
116- }
117-
118- if ( privateIds . includes ( DEST_ID . id ) ) {
119- console . log ( "This destination is already captured." )
120- return
145+ if ( DEST_ID . id = '0' ) {
146+ for ( const element in ids ) {
147+ let currentId = ids [ element ]
148+ await getDestinationData ( currentId )
149+ }
150+ console . log ( "Updating exsting Private Beta destinations." )
121151 } else {
122- privateIds . push ( DEST_ID . id )
123- }
124- privateIds . sort ( ) ;
125- for ( const element in privateIds ) {
126- let currentId = privateIds [ element ]
127- getDestinationData ( currentId )
152+ if ( ids . includes ( DEST_ID . id ) ) {
153+ console . log ( "This destination is already captured." )
154+ return
155+ } else {
156+ ids . push ( DEST_ID . id )
157+ fs . writeFileSync ( path . resolve ( __dirname , `../src/_data/catalog/destinations_private.yml` ) , '' ) ;
158+
159+ }
160+ ids . sort ( ) ;
161+
162+
163+ for ( const element in ids ) {
164+ let currentId = ids [ element ]
165+ await getDestinationData ( currentId )
166+ }
128167 }
129168
130169}
0 commit comments