@@ -17,6 +17,8 @@ require('dotenv').config();
1717const PAPI_URL = "https://api.segmentapis.com"
1818
1919const 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+
2022const privateDests = PRIVATE_DESTINATIONS . items
2123let private = [ ]
2224const getCatalog = async ( url , page_token = "MA==" ) => {
@@ -37,25 +39,65 @@ const getCatalog = async (url, page_token = "MA==") => {
3739 return res . data
3840 } catch ( err ) {
3941 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 ) ; // ***
4244 console . error ( err . response . headers ) ; // ***
4345 } finally {
44-
46+
4547 }
4648}
4749
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+ }
4870
4971const checkDestinationStatus = async ( id ) => {
5072 const res = await getCatalog ( `${ PAPI_URL } /catalog/destinations/${ id } ` )
5173 let destination = res . data . destinationMetadata
5274 return destination
5375}
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+ }
5496const getDestinationData = async ( id ) => {
5597 const res = await getCatalog ( `${ PAPI_URL } /catalog/destinations/${ id } ` )
5698 if ( res == null ) {
5799 return
58- }
100+ }
59101 let destination = res . data . destinationMetadata
60102 let settings = destination . options
61103 settings . sort ( ( a , b ) => {
@@ -69,11 +111,13 @@ const getDestinationData = async (id) => {
69111 } )
70112 let actions = destination . actions
71113 let presets = destination . presets
114+ let slug = slugify ( destination . name )
115+ let url = `connections/destinations/catalog/${ slug } `
72116
73117 // Force screen method into supportedMethods object
74118 destination . supportedMethods . screen = false
75119 // Set it true for LiveLike, per request
76- if ( destination . id == '63e42b47479274407b671071' ) {
120+ if ( destination . id == '63e42b47479274407b671071' ) {
77121 destination . supportedMethods . screen = true
78122 }
79123
@@ -93,8 +137,9 @@ const getDestinationData = async (id) => {
93137 id : destination . id ,
94138 display_name : destination . name ,
95139 name : destination . name ,
96- slug : destination . slug ,
140+ slug : slugify ( destination . name ) ,
97141 previous_names : destination . previousNames ,
142+ url,
98143 website : destination . website ,
99144 status : destination . status ,
100145 logo : {
@@ -119,6 +164,7 @@ const getDestinationData = async (id) => {
119164 private . push ( updatePrivateDest )
120165 } else {
121166 console . log ( `${ destination . name } is public and will be removed` )
167+ makeDestinationPublic ( url )
122168 }
123169
124170 const options = {
@@ -148,12 +194,18 @@ const checkExistingStatus = async () => {
148194 let id = existingIds [ i ]
149195 let destination = await checkDestinationStatus ( id )
150196 let status = destination . status
197+ let slug = slugify ( destination . name )
198+ let url = `connections/destinations/catalog/${ slug } `
199+
200+
201+
151202
152203 if ( status === "PRIVATE_BETA" ) {
153204 // console.log(`${destination.name} is private`)
154205 newIds . push ( id )
155206 } else {
156- // console.log(`${destination.name}is public`)
207+ console . log ( `src/connections/${ destination . name } is public` )
208+ makeDestinationPublic ( url )
157209 }
158210 }
159211 return newIds
0 commit comments