From f941e6902ef528c5c0bb37c8ca3fec6e8bb14cbd Mon Sep 17 00:00:00 2001 From: noe Date: Tue, 29 Apr 2025 18:19:33 -0700 Subject: [PATCH] init gleam --- .github/workflows/test.yml | 23 ++++++++++++++ .gitignore | 8 +++-- README.md | 24 +++++++++++++++ flake.lock | 62 ++++++++++++++++++++++++-------------- flake.nix | 50 +++++++++++++++++++++--------- gleam.toml | 19 ++++++++++++ manifest.toml | 11 +++++++ shell.nix | 4 +-- src/switcheroo.gleam | 5 +++ test/switcheroo_test.gleam | 12 ++++++++ 10 files changed, 176 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 README.md create mode 100644 gleam.toml create mode 100644 manifest.toml create mode 100644 src/switcheroo.gleam create mode 100644 test/switcheroo_test.gleam diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6f6924a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: test + +on: + push: + branches: + - master + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: "27.1.2" + gleam-version: "1.10.0" + rebar3-version: "3" + # elixir-version: "1" + - run: gleam deps download + - run: gleam test + - run: gleam format --check src test diff --git a/.gitignore b/.gitignore index 61000c2..28b3f97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ -.direnv/ +*.beam +*.ez +/build +erl_crash.dump result -.env \ No newline at end of file +.env +.direnv \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..09d4f47 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# switcheroo + +[![Package Version](https://img.shields.io/hexpm/v/switcheroo)](https://hex.pm/packages/switcheroo) +[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/switcheroo/) + +```sh +gleam add switcheroo@1 +``` +```gleam +import switcheroo + +pub fn main() -> Nil { + // TODO: An example of the project in use +} +``` + +Further documentation can be found at . + +## Development + +```sh +gleam run # Run the project +gleam test # Run the tests +``` diff --git a/flake.lock b/flake.lock index 63fd3fc..b916aad 100644 --- a/flake.lock +++ b/flake.lock @@ -1,20 +1,35 @@ { "nodes": { - "flake-parts": { + "flake-utils": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "systems": "systems" }, "locked": { - "lastModified": 1743550720, - "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "c621e8422220273271f52058f618c94e405bb0f5", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { - "owner": "hercules-ci", - "repo": "flake-parts", + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nix-gleam": { + "locked": { + "lastModified": 1717670865, + "narHash": "sha256-+dAPiKAwCzlKWtx3aIHXfR6jydh1JyangewqZKJx500=", + "owner": "arnarg", + "repo": "nix-gleam", + "rev": "c69abe0e57a01991654d3de63dcd93a8b91b98ff", + "type": "github" + }, + "original": { + "owner": "arnarg", + "repo": "nix-gleam", "type": "github" } }, @@ -34,26 +49,27 @@ "type": "github" } }, - "nixpkgs-lib": { + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nix-gleam": "nix-gleam", + "nixpkgs": "nixpkgs" + } + }, + "systems": { "locked": { - "lastModified": 1743296961, - "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", + "owner": "nix-systems", + "repo": "default", "type": "github" } - }, - "root": { - "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index a78ce00..5df33ad 100644 --- a/flake.nix +++ b/flake.nix @@ -1,20 +1,42 @@ { - description = "plapkit"; + description = "My gleam application"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-parts.url = "github:hercules-ci/flake-parts"; - }; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nix-gleam.url = "github:arnarg/nix-gleam"; - outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ "x86_64-linux" "aarch64-linux" ]; - perSystem = { config, self', pkgs, lib, system, ... }: rec { - devShells.default = import ./shell.nix { inherit pkgs; }; + outputs = { + self, + nixpkgs, + flake-utils, + nix-gleam, + }: ( + flake-utils.lib.eachDefaultSystem + (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + nix-gleam.overlays.default + ]; + }; + in rec { + packages.default = pkgs.buildGleamApplication { + # The pname and version will be read from the `gleam.toml` + # file generated by gleam. + # But this can be overwritten here too: + # pname = "my-app"; + # version = "1.2.3"; + + # The target is read from the `gleam.toml` file too. + # Default is "erlang" if nothing is specified but + # this can also be overwritten here too: + # target = "javascript"; + + # Erlang package can be overridden but defaults to + # `pkgs.erlang`. + # erlangPackage = pkgs.erlang_nox; - packages.default = pkgs.buildGoModule { - name = "switcheroo"; src = ./.; - vendorHash = "sha256-YY7Hj7lSq7vEoMEIu/zmweWzd7p7KF+4YCUX2SJ7kwI="; }; packages.container = pkgs.dockerTools.buildImage { @@ -30,6 +52,6 @@ Cmd = [ "${packages.default}/bin/switcheroo" ]; }; }; - }; - }; + }) + ); } \ No newline at end of file diff --git a/gleam.toml b/gleam.toml new file mode 100644 index 0000000..3a1723b --- /dev/null +++ b/gleam.toml @@ -0,0 +1,19 @@ +name = "switcheroo" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "", repo = "" } +# links = [{ title = "Website", href = "" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_stdlib = ">= 0.44.0 and < 2.0.0" + +[dev-dependencies] +gleeunit = ">= 1.0.0 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..22f5a58 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.59.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "F8FEE9B35797301994B81AF75508CF87C328FE1585558B0FFD188DC2B32EAA95" }, + { name = "gleeunit", version = "1.3.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "A7DD6C07B7DA49A6E28796058AA89E651D233B357D5607006D70619CD89DAAAB" }, +] + +[requirements] +gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } +gleeunit = { version = ">= 1.0.0 and < 2.0.0" } diff --git a/shell.nix b/shell.nix index 7210e41..11899c7 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,5 @@ { pkgs ? import {} }: pkgs.mkShell { buildInputs = with pkgs; [ - go - just - sqlite + gleam ]; } diff --git a/src/switcheroo.gleam b/src/switcheroo.gleam new file mode 100644 index 0000000..2882b05 --- /dev/null +++ b/src/switcheroo.gleam @@ -0,0 +1,5 @@ +import gleam/io + +pub fn main() -> Nil { + io.println("Hello from switcheroo!") +} diff --git a/test/switcheroo_test.gleam b/test/switcheroo_test.gleam new file mode 100644 index 0000000..f8eb5bc --- /dev/null +++ b/test/switcheroo_test.gleam @@ -0,0 +1,12 @@ +import gleeunit +import gleeunit/should + +pub fn main() -> Nil { + gleeunit.main() +} + +// gleeunit test functions end in `_test` +pub fn hello_world_test() { + 1 + |> should.equal(1) +}