Skip to content

Commit

Permalink
pull in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
bwireman committed Jul 19, 2024
1 parent 4ba7ba6 commit 273c8f6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gleam 1.3.2
erlang 27.0
nodejs 20.15.1
deno 1.44.4
deno 1.45.2
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <javascript|erlang> -m cactus
```

### ⚙️ Config
Expand Down
4 changes: 2 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -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!"
Expand All @@ -10,7 +10,7 @@ target = "javascript"

[javascript]
typescript_declarations = false
runtime = "bun"
runtime = "nodejs"

[javascript.deno]
allow_all = true
Expand Down
2 changes: 1 addition & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
]

Expand Down
4 changes: 2 additions & 2 deletions src/cactus.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <erlang|javascript> -m cactus`
3. Celebrate! 🎉
",
))
Expand Down
22 changes: 20 additions & 2 deletions src/cactus/write.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/write_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 273c8f6

Please sign in to comment.