@@ -6,6 +6,9 @@ const yaml = require('js-yaml');
6
6
const {
7
7
prompt
8
8
} = require ( 'enquirer' ) ;
9
+ const {
10
+ type
11
+ } = require ( 'os' ) ;
9
12
10
13
require ( 'dotenv' ) . config ( ) ;
11
14
@@ -37,9 +40,15 @@ const getCatalog = async (url, page_token = "MA==") => {
37
40
}
38
41
}
39
42
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
+ }
40
49
const getDestinationData = async ( id ) => {
41
50
const res = await getCatalog ( `${ PAPI_URL } /catalog/destinations/${ id } ` )
42
- destination = res . data . destinationMetadata
51
+ let destination = res . data . destinationMetadata
43
52
let settings = destination . options
44
53
settings . sort ( ( a , b ) => {
45
54
if ( a . name . toLowerCase ( ) < b . name . toLowerCase ( ) ) {
@@ -101,30 +110,60 @@ const getDestinationData = async (id) => {
101
110
}
102
111
103
112
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 ( )
104
121
122
+ for ( i in existingIds ) {
123
+ let id = existingIds [ i ]
124
+ let destination = await checkDestinationStatus ( id )
125
+ let status = destination . status
105
126
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
+ }
106
136
const addPrivateDestination = async ( ) => {
137
+ let ids = await checkExistingStatus ( )
138
+ ids . sort ( ) ;
107
139
const DEST_ID = await prompt ( {
108
140
type : 'input' ,
109
141
name : 'id' ,
110
142
message : 'Enter the destination ID'
111
143
} )
112
144
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." )
121
151
} 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
+ }
128
167
}
129
168
130
169
}
0 commit comments