File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ defmodule Mix.Tasks.FetchCdpProtocol do
2+ @ moduledoc """
3+ Fetches up-to-date versions of all the Chrome Debugger Protocol files.
4+
5+ These protocol files are stored in the private storage of this library.
6+ """
7+
8+ use Mix.Task
9+
10+ @ shortdoc "Fetches up-to-date versions of all the Chrome Debugger Protocol files."
11+
12+ @ protocol_sources % {
13+ "1-2" => % {
14+ url:
15+ "https://raw.githubusercontent.com/ChromeDevTools/debugger-protocol-viewer/master/_data/1-2/protocol.json" ,
16+ output: "priv/1-2/protocol.json"
17+ } ,
18+ "1-3" => % {
19+ url:
20+ "https://github.com/ChromeDevTools/debugger-protocol-viewer/blob/master/_data/1-3/protocol.json" ,
21+ output: "priv/1-3/protocol.json"
22+ } ,
23+ "tot" => % {
24+ url:
25+ "https://raw.githubusercontent.com/ChromeDevTools/debugger-protocol-viewer/master/_data/tot/protocol.json" ,
26+ output: "priv/tot/protocol.json"
27+ }
28+ }
29+
30+ @ temporary_file "protocol.json"
31+
32+ @ impl true
33+ def run ( _ ) do
34+ Map . keys ( @ protocol_sources )
35+ |> Enum . each ( & fetch_protocol / 1 )
36+ end
37+
38+ def fetch_protocol ( version ) do
39+ protocol_source = Map . fetch! ( @ protocol_sources , version )
40+
41+ cmd! ( "wget #{ protocol_source . url } " )
42+ File . rename ( @ temporary_file , protocol_source . output )
43+ end
44+
45+ defp cmd! ( cmd ) do
46+ Mix . shell ( ) . info ( [ :magenta , "Running: #{ cmd } " ] )
47+
48+ exit_status = Mix . shell ( ) . cmd ( cmd )
49+
50+ if exit_status != 0 do
51+ Mix . raise ( "Non-zero result (#{ exit_status } ) from command: #{ cmd } " )
52+ end
53+ end
54+ end
You can’t perform that action at this time.
0 commit comments