@@ -5,7 +5,7 @@ require Logger
55# define packages structure
66packages =
77 [
8- { :md , "### General" } ,
8+ { :section , "General" } ,
99 "membrane_sdk" ,
1010 "membrane_core" ,
1111 "membrane_rtc_engine" ,
@@ -14,8 +14,8 @@ packages =
1414 "membrane_demo" ,
1515 "membrane_tutorials" ,
1616 "boombox" ,
17- { :md , "### Plugins" } ,
18- { :md , "#### General purpose" } ,
17+ { :section , "Plugins" } ,
18+ { :subsection , "General purpose" } ,
1919 "membrane_file_plugin" ,
2020 "membrane_hackney_plugin" ,
2121 "membrane_scissors_plugin" ,
@@ -29,7 +29,7 @@ packages =
2929 "membrane_generator_plugin" ,
3030 "kim-company/membrane_live_framerate_converter_plugin" ,
3131 "membrane_template_plugin" ,
32- { :md , "#### Streaming protocols" } ,
32+ { :subsection , "Streaming protocols" } ,
3333 "membrane_webrtc_plugin" ,
3434 "membrane_rtmp_plugin" ,
3535 "membrane_http_adaptive_stream_plugin" ,
@@ -47,13 +47,13 @@ packages =
4747 "gBillal/membrane_rtsp_plugin" ,
4848 "kim-company/membrane_mpeg_ts_plugin" ,
4949 "kim-company/membrane_hls_plugin" ,
50- { :md , "#### Containers" } ,
50+ { :subsection , "Containers" } ,
5151 "membrane_mp4_plugin" ,
5252 "membrane_matroska_plugin" ,
5353 "membrane_flv_plugin" ,
5454 "membrane_ivf_plugin" ,
5555 "membrane_ogg_plugin" ,
56- { :md , "#### Audio codecs" } ,
56+ { :subsection , "Audio codecs" } ,
5757 "membrane_aac_plugin" ,
5858 "membrane_aac_fdk_plugin" ,
5959 "membrane_flac_plugin" ,
@@ -63,22 +63,22 @@ packages =
6363 "membrane_wav_plugin" ,
6464 "membrane_g711_plugin" ,
6565 "membrane_g711_ffmpeg_plugin" ,
66- { :md , "#### Video codecs" } ,
66+ { :subsection , "Video codecs" } ,
6767 "membrane_h26x_plugin" ,
6868 "membrane_h264_ffmpeg_plugin" ,
6969 "membrane_vpx_plugin" ,
7070 "membrane_abr_transcoder_plugin" ,
7171 "gBillal/membrane_h265_ffmpeg_plugin" ,
7272 "binarynoggin/elixir-turbojpeg" ,
7373 "kim-company/membrane_subtitle_mixer_plugin" ,
74- { :md , "#### Raw audio" } ,
74+ { :subsection , "Raw audio" } ,
7575 "membrane_raw_audio_parser_plugin" ,
7676 "membrane_portaudio_plugin" ,
7777 "membrane_audio_mix_plugin" ,
7878 "membrane_audio_filler_plugin" ,
7979 "membrane_ffmpeg_swresample_plugin" ,
8080 "membrane_audiometer_plugin" ,
81- { :md , "#### Raw video" } ,
81+ { :subsection , "Raw video" } ,
8282 "membrane_raw_video_parser_plugin" ,
8383 "membrane_video_merger_plugin" ,
8484 "membrane_smelter_plugin" ,
@@ -90,15 +90,15 @@ packages =
9090 "membrane_ffmpeg_swscale_plugin" ,
9191 "membrane_ffmpeg_video_filter_plugin" ,
9292 "kim-company/membrane_video_mixer_plugin" ,
93- { :md , "#### External APIs" } ,
93+ { :subsection , "External APIs" } ,
9494 "membrane_aws_plugin" ,
9595 "membrane_agora_plugin" ,
9696 "membrane_webrtc_live" ,
9797 "membrane_element_gcloud_speech_to_text" ,
9898 "membrane_element_ibm_speech_to_text" ,
9999 "YuzuTen/membrane_s3_plugin" ,
100100 "lawik/membrane_transcription" ,
101- { :md , "### Formats" } ,
101+ { :section , "Formats" } ,
102102 "membrane_rtp_format" ,
103103 "membrane_cmaf_format" ,
104104 "membrane_matroska_format" ,
@@ -114,7 +114,7 @@ packages =
114114 "membrane_vp9_format" ,
115115 "membrane_g711_format" ,
116116 "gBillal/membrane_h265_format" ,
117- { :md , "### Standalone media libs" } ,
117+ { :section , "Standalone media libs" } ,
118118 "elixir-webrtc/ex_webrtc" ,
119119 "ex_sdp" ,
120120 "ex_libnice" ,
@@ -124,7 +124,7 @@ packages =
124124 "ex_libsrt" ,
125125 "membrane_rtsp" ,
126126 "membrane_ffmpeg_generator" ,
127- { :md , "### Utils" } ,
127+ { :section , "Utils" } ,
128128 "unifex" ,
129129 "bundlex" ,
130130 "beamchmark" ,
@@ -138,8 +138,8 @@ packages =
138138 "membrane_precompiled_dependency_provider"
139139 ]
140140 |> Enum . map ( fn
141- { :md , markdown } ->
142- % { type: :markdown , content: markdown }
141+ { type , markdown } ->
142+ % { type: type , content: markdown }
143143
144144 package when is_binary ( package ) ->
145145 case String . split ( package , "/" , parts: 2 ) do
@@ -155,7 +155,7 @@ gh_req_timeout = 500
155155gh_req_mock = false
156156
157157# gh token for larger request rate
158- gh_token_header =
158+ gh_auth_header =
159159 case System . get_env ( "GITHUB_TOKEN" ) do
160160 nil -> [ ]
161161 token -> [ Authorization: "Bearer #{ token } " ]
@@ -167,15 +167,12 @@ repos =
167167 |> Enum . flat_map ( fn org ->
168168 Stream . from_index ( )
169169 |> Stream . map ( fn page ->
170- if gh_token_header == [ ] , do: Process . sleep ( gh_req_timeout )
170+ if gh_auth_header == [ ] , do: Process . sleep ( gh_req_timeout )
171171 url = "https://api.github.com/orgs/#{ org } /repos?per_page=100&page=#{ page } "
172172 Logger . debug ( "Fetching #{ url } " )
173173
174174 resp =
175- Req . get! ( url ,
176- headers: gh_token_header ,
177- decode_json: [ keys: :atoms ]
178- ) . body
175+ Req . get! ( url , headers: gh_auth_header , decode_json: [ keys: :atoms ] ) . body
179176
180177 unless is_list ( resp ) do
181178 raise "Received invalid response: #{ inspect ( resp ) } "
@@ -234,15 +231,11 @@ packages =
234231 % { owner: % { login: :mock } , html_url: :mock , description: :mock }
235232
236233 owner != nil ->
237- if gh_token_header == [ ] , do: if ( gh_token_header == [ ] )
238- Process . sleep ( gh_req_timeout )
234+ if gh_auth_header == [ ] , do: Process . sleep ( gh_req_timeout )
239235 url = "https://api.github.com/repos/#{ owner } /#{ name } "
240236 Logger . debug ( "Fetching #{ url } " )
241237
242- Req . get! ( url ,
243- headers: gh_token_header ,
244- decode_json: [ keys: :atoms ]
245- ) . body
238+ Req . get! ( url , headers: gh_auth_header , decode_json: [ keys: :atoms ] ) . body
246239
247240 Map . has_key? ( repos , name ) ->
248241 Map . fetch! ( repos , name )
@@ -263,6 +256,9 @@ packages =
263256 "[](#{ hex . body . docs_html_url } )"
264257 end
265258
259+ github_badge =
260+ "[](#{ repo . html_url } )"
261+
266262 owner_prefix =
267263 case repo . owner . login do
268264 "membraneframework-labs" -> "[Labs] "
@@ -276,7 +272,8 @@ packages =
276272 description: repo . description ,
277273 owner_prefix: owner_prefix ,
278274 hex_badge: hex_badge ,
279- hexdocs_badge: hexdocs_badge
275+ hexdocs_badge: hexdocs_badge ,
276+ github_badge: github_badge
280277 } )
281278
282279 other ->
@@ -291,21 +288,27 @@ header = """
291288| --- | --- | --- |
292289"""
293290
291+ generated_code_comment =
292+ "<!-- Generated code, do not edit. See `scripts/elixir/update_packages_list.exs`. -->"
293+
294294packages_md =
295295 packages
296296 |> Enum . map_reduce (
297297 % { is_header_present: false } ,
298298 fn
299- % { type: :markdown , content: content } , acc ->
300- { "\n " <> content , % { acc | is_header_present: false } }
299+ % { type: :section , content: content } , acc ->
300+ { "\n ### " <> content , % { acc | is_header_present: false } }
301+
302+ % { type: :subsection , content: content } , acc ->
303+ { "\n #### " <> content , % { acc | is_header_present: false } }
301304
302305 % { type: :package } = package , acc ->
303- readme_result = """
306+ package_info = """
304307 #{ if acc . is_header_present , do: "" , else: header } \
305308 | [#{ package . name } ](#{ package . url } ) | #{ package . owner_prefix } #{ package . description } | #{ package . hex_badge } #{ package . hexdocs_badge } |\
306309 """
307310
308- { readme_result , % { acc | is_header_present: true } }
311+ { package_info , % { acc | is_header_present: true } }
309312 end
310313 )
311314 |> elem ( 0 )
@@ -314,7 +317,7 @@ packages_md =
314317packages_md =
315318 """
316319 <!-- packages-list-start -->
317- <!-- Generated code, do not edit. See `scripts/elixir/update_packages_list.exs`. -->
320+ #{ generated_code_comment }
318321
319322 #{ packages_md }
320323
@@ -340,45 +343,51 @@ File.mkdir_p(packages_docs_path)
340343
341344packages
342345|> Enum . reduce (
343- % { file_path: nil , file_number: 0 , section: nil } ,
346+ % { file_path: nil , file_number: 0 , section: nil , files: [ ] } ,
344347 fn
345- % { type: :markdown , content: content } , acc ->
348+ % { type: :package } = package , acc ->
349+ package_info = """
350+ ## #{ package . name }
351+ #{ package . owner_prefix } #{ package . description }
352+
353+ #{ package . hex_badge } #{ package . hexdocs_badge } #{ package . github_badge }
354+
355+ """
356+
357+ files =
358+ List . update_at ( acc . files , 0 , fn { file_path , file_content } ->
359+ { file_path , file_content <> package_info }
360+ end )
361+
362+ % { acc | files: files }
363+
364+ % { type: type , content: content } , acc ->
346365 # So that the files have correct order
347366 prefix = "#{ acc . file_number } _" |> String . pad_leading ( 3 , "0" )
348367
349368 { filename , section } =
350- case content do
351- "### " <> section -> { section , section }
352- "#### " <> subsection -> { "#{ acc . section } | #{ subsection } " , acc . section }
369+ case type do
370+ : section -> { content , content }
371+ : subsection -> { "#{ acc . section } | #{ content } " , acc . section }
353372 end
354373
355374 file_path =
356375 Path . join ( packages_docs_path , prefix <> filename <> ".md" ) |> String . replace ( " " , "_" )
357376
358- if filename != "Plugins" do
359- File . write! (
360- file_path ,
361- "<!-- Generated code, do not edit. See `scripts/elixir/update_packages_list.exs`. -->\n "
362- )
363- end
364-
365- % { acc | file_path: file_path , section: section , file_number: acc . file_number + 1 }
366-
367- % { type: :package } = package , acc ->
368- github_badge =
369- "[](#{ package . url } )"
370-
371- docs_result = """
372- ## #{ package . name }
373- #{ package . owner_prefix } #{ package . description }
374-
375- #{ package . hex_badge } #{ package . hexdocs_badge } #{ github_badge }
376-
377- """
377+ files = [ { file_path , "" } | acc . files ]
378378
379- File . write ( acc . file_path , docs_result , [ :append ] )
380- acc
379+ % {
380+ acc
381+ | file_path: file_path ,
382+ section: section ,
383+ file_number: acc . file_number + 1 ,
384+ files: files
385+ }
381386 end
382387)
388+ |> Map . get ( :files )
389+ |> Enum . each ( fn { file_path , file_content } ->
390+ if file_content != "" , do: File . write! ( file_path , "#{ generated_code_comment } \n #{ file_content } " )
391+ end )
383392
384393IO . puts ( "Packages updated successfully." )
0 commit comments