@@ -250,6 +250,8 @@ const updateSources = async () => {
250
250
let sources = [ ]
251
251
let sourcesUpdated = [ ]
252
252
let nextPageToken = "MA=="
253
+ let categories = new Set ( )
254
+ let sourceCategories = [ ]
253
255
254
256
while ( nextPageToken !== null ) {
255
257
const res = await getCatalog ( `${ PAPI_URL } /catalog/sources/` , nextPageToken )
@@ -263,15 +265,33 @@ const updateSources = async () => {
263
265
return 0 ;
264
266
} )
265
267
268
+ const libraryCategories = [
269
+ 'server' ,
270
+ 'mobile' ,
271
+ 'ott' ,
272
+ 'roku' ,
273
+ 'website'
274
+ ]
275
+
266
276
sources . forEach ( source => {
267
277
let slug = slugify ( source . name )
268
278
let settings = source . options
279
+ let mainCategory = source . categories [ 0 ] ? source . categories [ 0 ] . toLowerCase : ''
280
+
269
281
settings . sort ( ( a , b ) => {
270
282
if ( a . name < b . name ) { return - 1 ; }
271
283
if ( a . name > b . name ) { return 1 ; }
272
284
return 0 ;
273
285
} )
274
286
287
+
288
+ if ( libraryCategories . includes ( mainCategory ) ) {
289
+ url = `connections/sources/catalog/libraries/${ mainCategory } /${ slug } `
290
+ } else {
291
+ url = `connections/sources/catalog/cloud-apps/${ slug } `
292
+ }
293
+
294
+
275
295
let updatedSource = {
276
296
display_name : source . name ,
277
297
slug,
@@ -281,20 +301,40 @@ const updateSources = async () => {
281
301
} ,
282
302
// mark: {
283
303
// url: source.logos.mark
284
- // }
304
+ // },
305
+ categories : source . categories ,
285
306
}
286
307
sourcesUpdated . push ( updatedSource )
287
308
doesCatalogItemExist ( updatedSource )
309
+ source . categories . reduce ( ( s , e ) => s . add ( e ) , categories ) ;
288
310
289
311
290
- const options = { noArrayIndent : true } ;
291
- output = "# AUTOGENERATED FROM PUBLIC API. DO NOT EDIT\n"
292
- var todayDate = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ;
293
- output += "# source data last updated " + todayDate + " \n" ;
294
- output += yaml . safeDump ( { items : sourcesUpdated } , options ) ;
295
- fs . writeFileSync ( path . resolve ( __dirname , `../src/_data/catalog/sources_papi.yml` ) , output ) ;
296
312
} )
297
313
314
+ const sourceArray = Array . from ( categories )
315
+ sourceArray . forEach ( category => {
316
+ sourceCategories . push ( {
317
+ display_name : category ,
318
+ slug : slugify ( category )
319
+ } )
320
+ } )
321
+
322
+
323
+ // Create source catalog yaml file
324
+ const options = { noArrayIndent : false } ;
325
+ var todayDate = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ;
326
+ output = "# AUTOGENERATED FROM PLATFORM API. DO NOT EDIT\n"
327
+ output += "# sources last updated " + todayDate + " \n" ;
328
+ output += yaml . safeDump ( { items : sourcesUpdated } , options ) ;
329
+ fs . writeFileSync ( path . resolve ( __dirname , `../src/_data/catalog/sources.yml` ) , output ) ;
330
+
331
+ // Create source-category mapping yaml file
332
+ var todayDate = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ;
333
+ output = "# AUTOGENERATED FROM PLATFORM API. DO NOT EDIT\n"
334
+ output += "# source cateogries last updated " + todayDate + " \n" ;
335
+ output += yaml . safeDump ( { items : sourceCategories } , options ) ;
336
+ fs . writeFileSync ( path . resolve ( __dirname , `../src/_data/catalog/source_categories.yml` ) , output ) ;
337
+
298
338
299
339
300
340
}
@@ -455,6 +495,6 @@ const updateWarehouses = async () => {
455
495
456
496
}
457
497
458
- updateDestinations ( )
459
- // updateSources()
460
- updateWarehouses ( )
498
+ // updateDestinations()
499
+ updateSources ( )
500
+ // updateWarehouses()
0 commit comments