-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
393 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/build | ||
erl_crash.dump | ||
src/internal/foo** | ||
src/internal/bar** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Task, Tasks } from "https://deno.land/x/rad/src/mod.ts"; | ||
|
||
const build: Task = `gleam build`; | ||
const clean: Task = `rm -rf src/foo* src/internal/foo* src/bar* src/internal/bar*`; | ||
const format: Task = `gleam format`; | ||
|
||
const gleamTest: Task = { | ||
dependsOn: [clean], | ||
fn: async (toolkit) => { | ||
const { fs, path, logger, Deno, sh, task } = toolkit; | ||
await sh(`gleam test`); | ||
}, | ||
}; | ||
|
||
const test: Task = { | ||
dependsOn: [gleamTest, clean], | ||
// fn: async (toolkit) => { | ||
// const { fs, path, logger, Deno, sh, task } = toolkit; | ||
// await sh(`gleam test`); | ||
// }, | ||
}; | ||
|
||
export const tasks: Tasks = { | ||
clean, | ||
build, | ||
b: build, | ||
format, | ||
f: format, | ||
gleamTest, | ||
gt: gleamTest, | ||
test, | ||
t: test, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import gleam/list | ||
import gleam/string | ||
import request.{type Request} | ||
import evil.{expect} | ||
|
||
pub fn get_import_path_from_mod_name(module_str: String, req: Request) { | ||
list.find_map(in: req.module.imports, with: fn(imp) { | ||
let full_module_str = imp.definition.module | ||
case | ||
full_module_str == module_str | ||
|| string.ends_with(full_module_str, "/" <> module_str) | ||
{ | ||
True -> Ok(full_module_str) | ||
_ -> Error(Nil) | ||
} | ||
}) | ||
|> expect(module_str <> ": module not found in import list") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import justin | ||
import gleam/string | ||
|
||
pub fn decoder_name_of_t(raw_name: String) -> String { | ||
let snake_name = justin.snake_case(raw_name) | ||
let name = case string.ends_with(snake_name, "_json") { | ||
True -> string.drop_right(snake_name, 5) | ||
False -> raw_name | ||
} | ||
"get_decoder_" <> name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import gleam/io | ||
|
||
pub fn expect(x, msg) { | ||
case x { | ||
Ok(v) -> v | ||
Error(_) -> { | ||
io.print_error(msg) | ||
panic | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import gleam/option | ||
import gleam/list | ||
import gleam/string | ||
import gleam/set | ||
import internal/codegen/types.{type GleamType} as t | ||
import internal/codegen/statements.{type GleamStatement} as gens | ||
|
||
pub type Mod { | ||
Mod( | ||
name: String, | ||
functions: List(GleamStatement), | ||
types: List(GleamType), | ||
imports: List(String), | ||
) | ||
} | ||
|
||
pub fn empty() -> Mod { | ||
Mod(name: "", functions: [], types: [], imports: []) | ||
} | ||
|
||
pub fn add_functions(mod: Mod, functions: List(GleamStatement)) -> Mod { | ||
Mod(..mod, functions: list.concat([mod.functions, functions])) | ||
} | ||
|
||
pub fn add_imports(mod: Mod, imports: List(String)) -> Mod { | ||
Mod(..mod, imports: list.concat([mod.imports, imports])) | ||
} | ||
|
||
pub fn merge(m1: Mod, m2: Mod) { | ||
Mod( | ||
name: m1.name, | ||
functions: list.concat([m1.functions, m2.functions]), | ||
types: list.concat([m1.types, m2.types]), | ||
imports: list.concat([m1.imports, m2.imports]) | ||
|> set.from_list | ||
|> set.to_list, | ||
) | ||
} | ||
|
||
pub fn to_string(m: Mod) { | ||
list.concat([ | ||
list.map(m.imports, fn(i) { "import " <> i }), | ||
list.map(m.types, t.generate_type_def), | ||
list.map(m.functions, gens.generate), | ||
]) | ||
|> string.join("\n") | ||
} |
Oops, something went wrong.