Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed Feb 29, 2024
1 parent 1545ab3 commit 5bc3405
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 9 deletions.
4 changes: 4 additions & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ snag = "~> 0.2"
glint = " ~> 0.16.0"
simplifile = "~> 0.3"
argv = "~> 1.0"
shellout = "~> 1.6"
gleam_package_interface = "~> 1.0"
gleam_json = "~> 1.0"
spinner = "~> 1.1"

[dev-dependencies]
gleeunit = "~> 1.0"
15 changes: 13 additions & 2 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,31 @@ packages = [
{ name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" },
{ name = "gleam_community_colour", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "A49A5E3AE8B637A5ACBA80ECB9B1AFE89FD3D5351FF6410A42B84F666D40D7D5" },
{ name = "gleam_erlang", version = "0.24.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "26BDB52E61889F56A291CB34167315780EE4AA20961917314446542C90D1C1A0" },
{ name = "gleam_json", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "8B197DD5D578EA6AC2C0D4BDC634C71A5BCA8E7DB5F47091C263ECB411A60DF3" },
{ name = "gleam_otp", version = "0.9.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "5FADBBEC5ECF3F8B6BE91101D432758503192AE2ADBAD5602158977341489F71" },
{ name = "gleam_package_interface", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_package_interface", source = "hex", outer_checksum = "52A721BCA972C8099BB881195D821AAA64B9F2655BECC102165D5A1097731F01" },
{ name = "gleam_stdlib", version = "0.35.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5443EEB74708454B65650FEBBB1EF5175057D1DEC62AEA9D7C6D96F41DA79152" },
{ name = "glearray", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glearray", source = "hex", outer_checksum = "908154F695D330E06A37FAB2C04119E8F315D643206F8F32B6A6C14A8709FFF4" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "glint", version = "0.16.0-rc1", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "AF9A7CCAD9FC8CDFF2606F97BC52C2D98559F27EB28CD3B8A11A35641740AE2F" },
{ name = "glint", version = "0.16.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "61B7E85CBB0CCD2FD8A9C7AE06CA97A80BF6537716F34362A39DF9C74967BBBC" },
{ name = "repeatedly", version = "2.1.1", build_tools = ["gleam"], requirements = [], otp_app = "repeatedly", source = "hex", outer_checksum = "38808C3EC382B0CD981336D5879C24ECB37FCB9C1D1BD128F7A80B0F74404D79" },
{ name = "shellout", version = "1.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "E2FCD18957F0E9F67E1F497FC9FF57393392F8A9BAEAEA4779541DE7A68DD7E0" },
{ name = "simplifile", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "8F3C94B83F691CCFACD784A4D7C1F7E5A0437D93341549B908EE3B32E3477447" },
{ name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" },
{ name = "spinner", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "glearray", "repeatedly"], otp_app = "spinner", source = "hex", outer_checksum = "200BA3D4A04D468898E63C0D316E23F526E02514BC46454091975CB5BAE41E8F" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
]

[requirements]
argv = { version = "~> 1.0" }
gleam_erlang = { version = "~> 0.7" }
gleam_json = { version = "~> 1.0" }
gleam_otp = { version = "~> 0.4" }
gleam_package_interface = { version = "~> 1.0" }
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
glint = { version = " ~> 0.16.0-rc1" }
glint = { version = " ~> 0.16.0" }
shellout = { version = "~> 1.6" }
simplifile = { version = "~> 0.3" }
snag = { version = "~> 0.2" }
spinner = { version = "~> 1.1"}
65 changes: 58 additions & 7 deletions src/gladvent/internal/runners.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import gleam
import gleam/dynamic.{type Dynamic}
import gleam/int
import gleam/option.{type Option}
import shellout
import gleam/json
import gleam/package_interface
import spinner
import simplifile
import gleam/io

pub type PartRunner =
fn(Dynamic) -> Dynamic
Expand Down Expand Up @@ -55,13 +61,13 @@ fn function_exists(
|> do_function_exists(mod, _)
|> result.replace_error(snag.new(
"module "
<> "src/"
<> int.to_string(year)
<> "/"
<> filename
<> " does not export a function \""
<> func_name
<> "/1\"",
<> "src/"
<> int.to_string(year)
<> "/"
<> filename
<> " does not export a function \""
<> func_name
<> "/1\"",
))
|> snag.context("function missing")
}
Expand Down Expand Up @@ -93,8 +99,53 @@ fn get_runner(year: Int, filename: String) -> Result(#(Day, DayRunner)) {
}

pub fn build_from_days_dir(year: Int) -> Result(Map(Day, DayRunner)) {
let assert Ok(package_interface) = pkg_interface()
dict.get(package_interface.modules, "aoc_")
find_files(matching: "day_*.gleam", in: "src/aoc_" <> int.to_string(year))
|> list.try_map(get_runner(year, _))
|> result.map(map.from_list)
|> snag.context("failed to generate runners list from filesystem")
}

const package_interface_path = "./build/.gladvent/pkg.json"

pub type PkgInterfaceErr {
FailedToGeneratePackageInterface(String)
FailedToReadPackageInterface(simplifile.FileError)
FailedToDecodePackageInterface(json.DecodeError)
}

pub fn pkg_interface() {
let spinner =
spinner.new("generating package interface")
|> spinner.start()

use <- defer(do: fn() { spinner.stop(spinner) })

use _ <- result.try(
shellout.command(
"gleam",
["export", "package-interface", "--out", package_interface_path],
".",
[],
)
|> result.map_error(fn(e) { FailedToGeneratePackageInterface(e.1) }),
)

use pkg_interface_contents <- result.try(
simplifile.read(package_interface_path)
|> result.map_error(FailedToReadPackageInterface),
)
use pkg_interface_details <- result.try(
json.decode(from: pkg_interface_contents, using: package_interface.decoder)
|> result.map_error(FailedToDecodePackageInterface),
)

Ok(io.debug(pkg_interface_details))
}

fn defer(do b: fn() -> _, after a: fn() -> a) -> a {
let a_out = a()
b()
a_out
}
Empty file added src/gladvent/moo.gleam
Empty file.

0 comments on commit 5bc3405

Please sign in to comment.