From 273c8f60afed40167ea7d5bf079c8c3ae1d2b2cc Mon Sep 17 00:00:00 2001 From: bwireman Date: Thu, 18 Jul 2024 19:26:38 -0500 Subject: [PATCH] pull in runtime --- .tool-versions | 2 +- README.md | 3 ++- gleam.toml | 4 ++-- manifest.toml | 2 +- src/cactus.gleam | 4 ++-- src/cactus/write.gleam | 22 ++++++++++++++++++++-- test/write_test.gleam | 2 +- 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.tool-versions b/.tool-versions index 950402f..beaf4ef 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ gleam 1.3.2 erlang 27.0 nodejs 20.15.1 -deno 1.44.4 +deno 1.45.2 diff --git a/README.md b/README.md index 68a3914..dc6743b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ Bun, Deno & Nodejs are _all_ supported! ```sh # initialize configured hooks -gleam run -m cactus +# specify the target depending on how you want the hooks to run +gleam run --target -m cactus ``` ### ⚙️ Config diff --git a/gleam.toml b/gleam.toml index ed34e4b..d20e7c0 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "cactus" -version = "1.0.0" +version = "1.1.0" licences = ["MIT"] repository = { type = "github", user = "bwireman", repo = "cactus" } description = "A tool for managing git lifecycle hooks with ✨ gleam! Pre commit, Pre push and more!" @@ -10,7 +10,7 @@ target = "javascript" [javascript] typescript_declarations = false -runtime = "bun" +runtime = "nodejs" [javascript.deno] allow_all = true diff --git a/manifest.toml b/manifest.toml index 88ce9ad..0d4ab65 100644 --- a/manifest.toml +++ b/manifest.toml @@ -14,7 +14,7 @@ packages = [ { name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" }, { name = "shellout", version = "1.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "E2FCD18957F0E9F67E1F497FC9FF57393392F8A9BAEAEA4779541DE7A68DD7E0" }, { name = "simplifile", version = "2.0.1", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "5FFEBD0CAB39BDD343C3E1CCA6438B2848847DC170BA2386DF9D7064F34DF000" }, - { name = "tom", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "A5364613E3DBF77F38EFF81DA9F99324086D029EC2B2D44348762FBE38602311" }, + { name = "tom", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "9EECB60150E834A07238BD5C7DF1FF07F7D4C5862BB8A773923D1981C7875FB0" }, { name = "yamerl", version = "0.10.0", build_tools = ["rebar3"], requirements = [], otp_app = "yamerl", source = "hex", outer_checksum = "346ADB2963F1051DC837A2364E4ACF6EB7D80097C0F53CBDC3046EC8EC4B4E6E" }, ] diff --git a/src/cactus.gleam b/src/cactus.gleam index 6dbf564..74da36e 100644 --- a/src/cactus.gleam +++ b/src/cactus.gleam @@ -37,7 +37,7 @@ pub fn main() -> Result(Nil, CactusErr) { "help" | "--help" | "-h" -> { Ok(print_info( " -🌵 Cactus (version: 1.0.0) +🌵 Cactus (version: 1.1.0) --------------------------------------- A tool for managing git lifecycle hooks with ✨ gleam! Pre commit, Pre push @@ -47,7 +47,7 @@ Usage: 1. Configure your desired hooks in your project's `gleam.toml` - More info: https://github.com/bwireman/cactus?tab=readme-ov-file#%EF%B8%8F-config -2. Run `gleam run -m cactus` +2. Run `gleam run --target -m cactus` 3. Celebrate! 🎉 ", )) diff --git a/src/cactus/write.gleam b/src/cactus/write.gleam index 512bd1d..ad6bdf4 100644 --- a/src/cactus/write.gleam +++ b/src/cactus/write.gleam @@ -16,7 +16,25 @@ const valid_hooks = [ "pre-push", "pre-rebase", "pre-receive", "push-to-checkout", "update", "test", ] -pub const tmpl = "gleam run -m cactus -- " +@target(javascript) +pub fn tmpl() -> String { + let runtime = + parse_gleam_toml("./gleam.toml") + |> try(fn(gleam_toml) { + as_invalid_field_err(tom.get_table(gleam_toml, ["javascript"])) + }) + |> try(fn(gleam_toml) { + as_invalid_field_err(tom.get_string(gleam_toml, ["runtime"])) + }) + |> result.unwrap("nodejs") + + "gleam run --target javascript --runtime " <> runtime <> " -m cactus -- " +} + +@target(erlang) +pub fn tmpl() -> String { + "gleam run --target erlang -m cactus -- " +} pub fn is_valid_hook_name(name: String) -> Bool { list.contains(valid_hooks, name) @@ -33,7 +51,7 @@ pub fn create_script( let _ = simplifile.create_directory(hooks_dir) let _ = simplifile.create_file(path) - use _ <- try(as_fs_err(simplifile.write(path, tmpl <> command), path)) + use _ <- try(as_fs_err(simplifile.write(path, tmpl() <> command), path)) simplifile.set_permissions( path, diff --git a/test/write_test.gleam b/test/write_test.gleam index 9229149..4711575 100644 --- a/test/write_test.gleam +++ b/test/write_test.gleam @@ -25,5 +25,5 @@ pub fn create_script_test() { simplifile.read("test/testdata/scripts/test") |> should.be_ok - |> should.equal(write.tmpl <> "test") + |> should.equal(write.tmpl() <> "test") }