@@ -17,6 +17,8 @@ require('dotenv').config();
17
17
const PAPI_URL = "https://api.segmentapis.com"
18
18
19
19
const PRIVATE_DESTINATIONS = yaml . load ( fs . readFileSync ( path . resolve ( __dirname , `../src/_data/catalog/destinations_private.yml` ) ) )
20
+ const slugOverrides = yaml . load ( fs . readFileSync ( path . resolve ( __dirname , `../src/_data/catalog/slugs.yml` ) ) )
21
+
20
22
const privateDests = PRIVATE_DESTINATIONS . items
21
23
let private = [ ]
22
24
const getCatalog = async ( url , page_token = "MA==" ) => {
@@ -37,25 +39,65 @@ const getCatalog = async (url, page_token = "MA==") => {
37
39
return res . data
38
40
} catch ( err ) {
39
41
console . error ( "Error response:" ) ;
40
- console . error ( err . response . data ) ; // ***
41
- console . error ( err . response . status ) ; // ***
42
+ console . error ( err . response . data ) ; // ***
43
+ console . error ( err . response . status ) ; // ***
42
44
console . error ( err . response . headers ) ; // ***
43
45
} finally {
44
-
46
+
45
47
}
46
48
}
47
49
50
+ const slugify = ( displayName ) => {
51
+ let slug = displayName
52
+ . toLowerCase ( )
53
+ . replace ( / \s + / g, '-' )
54
+ . replace ( '-&-' , '-' )
55
+ . replace ( '/' , '-' )
56
+ . replace ( / [ \( \) ] / g, '' )
57
+ . replace ( '.' , '-' )
58
+
59
+ for ( key in slugOverrides ) {
60
+ let original = slugOverrides [ key ] . original
61
+ let override = slugOverrides [ key ] . override
62
+
63
+ if ( slug == original ) {
64
+ slug = override
65
+ }
66
+ }
67
+
68
+ return slug
69
+ }
48
70
49
71
const checkDestinationStatus = async ( id ) => {
50
72
const res = await getCatalog ( `${ PAPI_URL } /catalog/destinations/${ id } ` )
51
73
let destination = res . data . destinationMetadata
52
74
return destination
53
75
}
76
+
77
+ const makeDestinationPublic = async ( itemURL ) => {
78
+ const catalogPath = path . resolve ( 'src/' , itemURL , 'index.md' )
79
+ const f = fm ( fs . readFileSync ( catalogPath , 'utf8' ) ) ;
80
+ const fmatter = f . attributes
81
+ fmatter . private = false
82
+ fmatter . hidden = false
83
+ let new_fm = ""
84
+ for ( const property in fmatter ) {
85
+ if ( property == "versions" ) {
86
+ console . log ( `Need to fix versions on this one` )
87
+ }
88
+ //console.log(`${property}: ${fmatter[property]}`);
89
+ new_fm += `${ property } : ${ fmatter [ property ] } \n`
90
+ }
91
+ const attr = `---\n${ new_fm } \n---\n`
92
+ const body = f . body
93
+ const content = attr + body
94
+ fs . writeFileSync ( catalogPath , content )
95
+ }
54
96
const getDestinationData = async ( id ) => {
55
97
const res = await getCatalog ( `${ PAPI_URL } /catalog/destinations/${ id } ` )
56
98
if ( res == null ) {
57
99
return
58
- }
100
+ }
59
101
let destination = res . data . destinationMetadata
60
102
let settings = destination . options
61
103
settings . sort ( ( a , b ) => {
@@ -69,11 +111,13 @@ const getDestinationData = async (id) => {
69
111
} )
70
112
let actions = destination . actions
71
113
let presets = destination . presets
114
+ let slug = slugify ( destination . name )
115
+ let url = `connections/destinations/catalog/${ slug } `
72
116
73
117
// Force screen method into supportedMethods object
74
118
destination . supportedMethods . screen = false
75
119
// Set it true for LiveLike, per request
76
- if ( destination . id == '63e42b47479274407b671071' ) {
120
+ if ( destination . id == '63e42b47479274407b671071' ) {
77
121
destination . supportedMethods . screen = true
78
122
}
79
123
@@ -93,8 +137,9 @@ const getDestinationData = async (id) => {
93
137
id : destination . id ,
94
138
display_name : destination . name ,
95
139
name : destination . name ,
96
- slug : destination . slug ,
140
+ slug : slugify ( destination . name ) ,
97
141
previous_names : destination . previousNames ,
142
+ url,
98
143
website : destination . website ,
99
144
status : destination . status ,
100
145
logo : {
@@ -119,6 +164,7 @@ const getDestinationData = async (id) => {
119
164
private . push ( updatePrivateDest )
120
165
} else {
121
166
console . log ( `${ destination . name } is public and will be removed` )
167
+ makeDestinationPublic ( url )
122
168
}
123
169
124
170
const options = {
@@ -148,12 +194,18 @@ const checkExistingStatus = async () => {
148
194
let id = existingIds [ i ]
149
195
let destination = await checkDestinationStatus ( id )
150
196
let status = destination . status
197
+ let slug = slugify ( destination . name )
198
+ let url = `connections/destinations/catalog/${ slug } `
199
+
200
+
201
+
151
202
152
203
if ( status === "PRIVATE_BETA" ) {
153
204
// console.log(`${destination.name} is private`)
154
205
newIds . push ( id )
155
206
} else {
156
- // console.log(`${destination.name}is public`)
207
+ console . log ( `src/connections/${ destination . name } is public` )
208
+ makeDestinationPublic ( url )
157
209
}
158
210
}
159
211
return newIds
0 commit comments