File tree Expand file tree Collapse file tree 4 files changed +24
-4
lines changed
Expand file tree Collapse file tree 4 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 1818
1919open Node_shim
2020
21- let usage = " Usage: node-shim-install <program> <version>"
21+ let usage = " Usage: node-shim-install <program> [version]\n\n " ^
22+ " If version is not given will install latest stable version of program.\n "
2223
2324let () =
2425 let arg_spec = [] in
@@ -32,8 +33,8 @@ let () =
3233 in
3334 Arg. parse arg_spec parse_anon usage;
3435 match (! program, ! version) with
35- | None , _
36- | _ , None ->
36+ | None , _ ->
3737 Arg. usage arg_spec usage;
3838 exit 1
39+ | Some p , None -> Install. install_latest p
3940 | Some p , Some v -> Install. install p v
Original file line number Diff line number Diff line change @@ -69,5 +69,19 @@ let install' program version =
6969 extracted_dir_name program version >> = fun extracted_dir ->
7070 Lwt_unix. rename (File. join [program_dir; extracted_dir]) version_dir
7171
72+ let resolve_latest_version program =
73+ let program_name = Program. to_string program in
74+ let version_url = Printf. sprintf " https://semver.io/%s/stable" program_name in
75+ Lwt_io. printlf " Resolving latest stable version of %s" program_name >> = fun () ->
76+ Unix_utils. get_url version_url >> = fun version ->
77+ Lwt. return (Version. of_string (String. trim version))
78+
79+ let install_latest' program =
80+ resolve_latest_version program >> = fun version ->
81+ install' program version
82+
7283let install program version =
73- Lwt_main. run (install' program version);
84+ Lwt_main. run (install' program version)
85+
86+ let install_latest program =
87+ Lwt_main. run (install_latest' program)
Original file line number Diff line number Diff line change 1717*)
1818
1919val install : Program .t -> Version .t -> unit
20+
21+ val install_latest : Program .t -> unit
Original file line number Diff line number Diff line change @@ -38,5 +38,8 @@ let mkdirp path =
3838let download url target =
3939 exec [|" wget" ; " --quiet" ; " -O" ; target; url|]
4040
41+ let get_url url =
42+ Lwt_process. pread (" " , [|" wget" ; " -qO-" ; url|])
43+
4144let extract archive target_dir =
4245 exec [|" tar" ; " -xzf" ; archive; " -C" ; target_dir|]
You can’t perform that action at this time.
0 commit comments