Skip to content

Commit

Permalink
fix: faulty release params
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaringe committed Jan 21, 2024
1 parent 210f395 commit a79d598
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
7 changes: 5 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
name = "gserde"
version = "1.0.0"
version = "1.0.1"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
#
description = "gleam codegen for serialization and deserialization"
licences = ["MIT"]
repository = { type = "github", user = "cdaringe", repo = "gserde" }
internal_modules = [
"src/internal",
"src/internal/*",
]
# links = [{ title = "Website", href = "https://gleam.run" }]
#
# For a full reference of all the available options, you can have a look at
Expand All @@ -17,7 +21,6 @@ gleam_stdlib = "~> 0.34 or ~> 1.0"
gleam_json = "~> 1.0"
glance = "~> 0.8"
simplifile = "~> 1.2"
tom = "~> 0.3"
fswalk = "~> 2.0"
shellout = "~> 1.5"

Expand Down
8 changes: 3 additions & 5 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# You typically do not need to edit this file

packages = [
{ name = "fswalk", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_community_path", "gleam_stdlib", "simplifile"], otp_app = "fswalk", source = "hex", outer_checksum = "50C250FA4CF97D6C383ECF69D7446EFB9D4F8261328A13099478AAAD0CEDC081" },
{ name = "glance", version = "0.8.2", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "ACF09457E8B564AD7A0D823DAFDD326F58263C01ACB0D432A9BEFDEDD1DA8E73" },
{ name = "fswalk", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_community_path", "simplifile", "gleam_stdlib"], otp_app = "fswalk", source = "hex", outer_checksum = "50C250FA4CF97D6C383ECF69D7446EFB9D4F8261328A13099478AAAD0CEDC081" },
{ name = "glance", version = "0.8.2", build_tools = ["gleam"], requirements = ["glexer", "gleam_stdlib"], otp_app = "glance", source = "hex", outer_checksum = "ACF09457E8B564AD7A0D823DAFDD326F58263C01ACB0D432A9BEFDEDD1DA8E73" },
{ name = "gleam_community_path", version = "0.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_path", source = "hex", outer_checksum = "916C2829E2ED81036BBA180CFD5E8633D05E25C304FDF6E3BC8A048459B89725" },
{ name = "gleam_json", version = "1.0.0", build_tools = ["gleam"], requirements = ["thoas", "gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "8B197DD5D578EA6AC2C0D4BDC634C71A5BCA8E7DB5F47091C263ECB411A60DF3" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
Expand All @@ -12,15 +12,13 @@ packages = [
{ name = "shellout", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "7B5DE499DBB3DDC25051FC1BB3770DD5466938B6A2AFA91A6FB4A4D49F4CB0D4" },
{ name = "simplifile", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "359CD7006E2F69255025C858CCC6407C11A876EC179E6ED1E46809E8DC6B1AAD" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
{ name = "tom", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "0831C73E45405A2153091226BF98FB485ED16376988602CC01A5FD086B82D577" },
]

[requirements]
fswalk = { version = "~> 2.0"}
fswalk = { version = "~> 2.0" }
glance = { version = "~> 0.8" }
gleam_json = { version = "~> 1.0" }
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
shellout = { version = "~> 1.5" }
simplifile = { version = "~> 1.2" }
tom = { version = "~> 0.3" }
8 changes: 2 additions & 6 deletions src/gserde.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import gleam/bool
import gleam/string
import gleam/result
import glance
import serializer
import deserializer
import internal/serializer
import internal/deserializer
import simplifile
import request.{type Request, Request}
import fswalk
Expand Down Expand Up @@ -51,10 +51,6 @@ pub fn main() {
}

pub fn process_single(src_filename: String) {
io.debug(#(src_filename))
// let assert Ok(gleam_toml_str) = simplifile.read(from: "gleam.toml")
// let assert Ok(gleam_toml) = tom.parse(gleam_toml_str)
// let assert Ok(pkg_name) = tom.get_string(gleam_toml, ["name"])
let src_module_name =
src_filename
|> string.replace("src/", "")
Expand Down
2 changes: 1 addition & 1 deletion src/deserializer.gleam → src/internal/deserializer.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn gen_root_decoder(req) {
gens.call("json.decode", [
gens.VarPrimitive("json_str"),
gens.call("dynamic.decode" <> n_str, [
gens.VarPrimitive( basename(src_module_name) <> "." <> variant.name),
gens.VarPrimitive(basename(src_module_name) <> "." <> variant.name),
..list.map(req.variant.fields, fn(field) {
gens.call("dynamic.field", [
gens.VarPrimitive(
Expand Down
14 changes: 12 additions & 2 deletions src/serializer.gleam → src/internal/serializer.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ fn gen_to_json(req) {
gens.Function(
// string.lowercase(variant.name) <> "_to_json",
"to_json",
[gens.arg_typed("t", t.AnonymousType(basename(src_module_name) <> "." <> type_name))],
[
gens.arg_typed(
"t",
t.AnonymousType(basename(src_module_name) <> "." <> type_name),
),
],
[
gens.call("json.object", [
gens.list(
Expand Down Expand Up @@ -160,7 +165,12 @@ fn gen_to_string(req) {
let Request(src_module_name: src_module_name, type_name: type_name, ..) = req
gens.Function(
"to_string",
[gens.arg_typed("t", t.AnonymousType(basename(src_module_name) <> "." <> type_name))],
[
gens.arg_typed(
"t",
t.AnonymousType(basename(src_module_name) <> "." <> type_name),
),
],
[gens.call("json.to_string", [gens.call("to_json", [gens.variable("t")])])],
)
}
Expand Down
17 changes: 10 additions & 7 deletions test/gserde_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,37 @@ pub fn main() {
"

fn exec(bin: String, args: List(String)) {
let assert Ok(output) = shellout.command(bin, args, in: ".", opt: [
shellout.LetBeStderr
])
let assert Ok(output) =
shellout.command(bin, args, in: ".", opt: [shellout.LetBeStderr])
output
}

//
/// This test is thorough, but a bit zany. We:
/// - write a dummy "foo" module into the current project's source. hopefully it compiles!
/// - run our CLI against the project, which should produce a serde module next to foo
/// - write an entrypoint module--foo_json_test--into our source, then run it!
//
pub fn end_to_end_test() {
// create the foo fixture
let assert Ok(_) = simplifile.write(to: "src/internal/foo.gleam", contents: foo_module)
let assert Ok(_) =
simplifile.write(to: "src/internal/foo.gleam", contents: foo_module)

// run our gen cli
exec("gleam", ["run"])

// write our test module and run it
let assert Ok(_) =
simplifile.write(to: "src/internal/foo_json_test.gleam", contents: foo_json_test)
simplifile.write(
to: "src/internal/foo_json_test.gleam",
contents: foo_json_test,
)
let assert Ok(last_output_line) =
exec("gleam", ["run", "-m=internal/foo_json_test"])
|> string.split("\n")
|> list.last

last_output_line
|> should.equal(
"{\"a_bool\":true,\"b_int\":1,\"c_float\":1,\"d_two_tuple\":[2,\"3\"],\"e_option_int\":4,\"f_string_list\":[\"a\",\"b\"]}",
"{\"a_bool\":true,\"b_int\":1,\"c_float\":1.0,\"d_two_tuple\":[2,\"3\"],\"e_option_int\":4,\"f_string_list\":[\"a\",\"b\"]}",
)
}

0 comments on commit a79d598

Please sign in to comment.