diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2024-02-13 21:13:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-13 21:13:57 +0000 |
commit | 1be73ee8d2206a7f1520257d81c8a5a4f3cc195e (patch) | |
tree | c18785b9eac4612277ab70be164476ebd95a7303 /src/lustre_add_ffi.erl | |
parent | 7960593c4feee21b65171afa220c2b32b43dd788 (diff) | |
download | lustre-1be73ee8d2206a7f1520257d81c8a5a4f3cc195e.tar.gz lustre-1be73ee8d2206a7f1520257d81c8a5a4f3cc195e.zip |
🚧 Begin working on CLI things. (#45)
* :recycle: Rename http ffi to lustre_try_ffi.
* :wrench: Add any files under lustre/cli as internal modules.
* :recyle: Move lustre/try command into cli subdirectory.
* :heavy_plus_sign: Add justin, simplifile, and tom as dependencies.
* :sparkles: Write a 'lustre add' command for downloading esbuild.
* :construction: Begin work on a 'lustre build' command for bundling apps and components.
* :sparkles: Add 'main' function as CLI entrypoint to lustre.
* :bug: Fix `no-styles` flag's name
* :bug: Use consistent path for error reporting in lustre add
* :construction: Project module
* :truck: Move esbuild functions to their own module
* :construction: Use a temporary file to bundle components
* :construction: Build app and update to glint rc
* :heavy_plus_sign: Add filepath dependency
* :bug: Fix wrong paths in esbuild code
---------
Co-authored-by: Giacomo Cavalieri <giacomo.cavalieri@icloud.com>
Diffstat (limited to 'src/lustre_add_ffi.erl')
-rw-r--r-- | src/lustre_add_ffi.erl | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lustre_add_ffi.erl b/src/lustre_add_ffi.erl new file mode 100644 index 0000000..d7c5030 --- /dev/null +++ b/src/lustre_add_ffi.erl @@ -0,0 +1,49 @@ +-module(lustre_add_ffi). +-export([ + get_cpu/0, + get_esbuild/1, + get_os/0, + unzip_esbuild/1 +]). + +get_os() -> + case os:type() of + {win32, _} -> <<"win32">>; + {unix, darwin} -> <<"darwin">>; + {unix, linux} -> <<"linux">>; + {_, Unknown} -> atom_to_binary(Unknown, utf8) + end. + +get_cpu() -> + case erlang:system_info(os_type) of + {unix, _} -> + [Arch, _] = string:split(erlang:system_info(system_architecture), "-"), + list_to_binary(Arch); + {win32, _} -> + case erlang:system_info(wordsize) of + 4 -> {ok, <<"ia32">>}; + 8 -> {ok, <<"x64">>} + end + end. + +get_esbuild(Url) -> + inets:start(), + ssl:start(), + + case httpc:request(get, {Url, []}, [], [{body_format, binary}]) of + {ok, {{_, 200, _}, _, Zip}} -> {ok, Zip}; + {ok, Res} -> {error, {network_error, Res}}; + {error, Err} -> {error, {network_error, Err}} + end. + +unzip_esbuild(Zip) -> + Result = + erl_tar:extract({binary, Zip}, [ + memory, compressed, {files, ["package/bin/esbuild"]} + ]), + + case Result of + {ok, [{_, Esbuild}]} -> {ok, Esbuild}; + {ok, Res} -> {error, {unzip_error, Res}}; + {error, Err} -> {error, {unzip_error, Err}} + end. |