Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Generate licence information

+103 -12
+2
licence-bundler/gleam.toml
··· 17 17 simplifile = ">= 2.4.0 and < 3.0.0" 18 18 shellout = ">= 1.8.0 and < 2.0.0" 19 19 tom = ">= 2.0.2 and < 3.0.0" 20 + htmb = ">= 2.1.0 and < 3.0.0" 21 + argv = ">= 1.0.2 and < 2.0.0" 20 22 21 23 [dev_dependencies] 22 24 gleeunit = ">= 1.0.0 and < 2.0.0"
+4
licence-bundler/manifest.toml
··· 2 2 # You typically do not need to edit this file 3 3 4 4 packages = [ 5 + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, 5 6 { name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" }, 6 7 { name = "gleam_stdlib", version = "0.71.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "702F3BC2A14793906880B1078B19A6165F87323AEE8D0C4A34085846336FCAAE" }, 7 8 { name = "gleam_time", version = "1.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_time", source = "hex", outer_checksum = "533D8723774D61AD4998324F5DD1DABDCDBFABAFB9E87CB5D03C6955448FC97D" }, 8 9 { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" }, 10 + { name = "htmb", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "htmb", source = "hex", outer_checksum = "023218E5A4DE7A1BA5E2BB449F063382F8F747A11F13423433D60AEA14CC2655" }, 9 11 { name = "shellout", version = "1.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "C416356D45151F298108C9DB9CD1EDE0313F620B5EDBB5766CD7237659D87841" }, 10 12 { name = "simplifile", version = "2.4.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "7C18AFA4FED0B4CE1FA5B0B4BAC1FA1744427054EA993565F6F3F82E5453170D" }, 11 13 { name = "tom", version = "2.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_time"], otp_app = "tom", source = "hex", outer_checksum = "234A842F3D087D35737483F5DFB6DE9839E3366EF0CAF8726D2D094210227670" }, 12 14 ] 13 15 14 16 [requirements] 17 + argv = { version = ">= 1.0.2 and < 2.0.0" } 15 18 gleam_stdlib = { version = ">= 0.70.0 and < 2.0.0" } 16 19 gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 20 + htmb = { version = ">= 2.1.0 and < 3.0.0" } 17 21 shellout = { version = ">= 1.8.0 and < 2.0.0" } 18 22 simplifile = { version = ">= 2.4.0 and < 3.0.0" } 19 23 tom = { version = ">= 2.0.2 and < 3.0.0" }
+97 -12
licence-bundler/src/licence_bundler.gleam
··· 1 - import gleam/io 1 + import argv 2 + import gleam/bool 2 3 import gleam/list 4 + import gleam/result 3 5 import gleam/set.{type Set} 4 6 import gleam/string 7 + import gleam/string_tree 8 + import htmb 5 9 import shellout 6 10 import simplifile 7 11 import tom ··· 9 13 pub fn main() -> Nil { 10 14 let gleam_crates = determine_gleam_crates() 11 15 let active_licences = determine_licences() 16 + let assert [output_path] = argv.load().arguments 17 + as "USAGE: gleam run out/licences.html" 18 + assert string.ends_with(output_path, ".html") 19 + as "Output path should end with .html" 12 20 13 21 let assert Ok(output) = 14 22 shellout.command( ··· 24 32 opt: [], 25 33 ) 26 34 27 - let lines = 35 + let rust_dependencies = 28 36 output 29 37 |> string.split("\n") 30 38 |> list.filter(fn(line) { line != "" }) 31 39 |> list.map(trim_line_prefix) 32 - |> list.map(crate_information(_, active_licences)) 33 - |> list.filter(is_dependency(_, gleam_crates)) 40 + |> list.filter_map(dependency_information(_, gleam_crates, active_licences)) 34 41 |> set.from_list 35 42 |> set.to_list 36 - |> list.map(string.inspect) 43 + |> list.sort(fn(a, b) { 44 + string.compare( 45 + a.name <> a.licence_identifier, 46 + b.name <> b.licence_identifier, 47 + ) 48 + }) 49 + 50 + let assert Ok(licences) = 51 + active_licences 52 + |> set.to_list 53 + |> list.sort(string.compare) 54 + |> list.try_map(fn(identifier) { 55 + simplifile.read("../licences/" <> identifier <> ".txt") 56 + |> result.map(Licence(identifier:, text: _)) 57 + }) 58 + 59 + let h = htmb.h 60 + let t = htmb.text 61 + 62 + let licence_slug = fn(identifier) { string.replace(identifier, " ", "-") } 63 + let licence_link = fn(licence_identifier) { 64 + let slug = licence_slug(licence_identifier) 65 + h("a", [#("href", "#" <> slug)], [t(licence_identifier)]) 66 + } 67 + 68 + let html = 69 + h("html", [#("lang", "en")], [ 70 + h("head", [], []), 71 + h("body", [], [ 72 + h("h1", [], [t("Gleam dependency licences")]), 73 + h("section", [], [ 74 + h("h2", [], [t("Rust dependency packages")]), 75 + h_ul(rust_dependencies, fn(package) { 76 + assert licences != [] as { package.name <> " missing licences" } 77 + let licences = 78 + list.map(package.used_licences, licence_link) 79 + |> list.intersperse(t(" or ")) 80 + let url = 81 + "https://crates.io/crates/" 82 + <> package.name 83 + <> "/" 84 + <> package.version 85 + [ 86 + h("a", [#("href", url)], [ 87 + t(package.name <> "@" <> package.version), 88 + ]), 89 + t(" using "), 90 + ..licences 91 + ] 92 + }), 93 + ]), 94 + h("section", [], [ 95 + h("h2", [], [t("Licences")]), 96 + h_ul(licences, fn(licence) { 97 + let id = licence.identifier 98 + [ 99 + h("h3", [#("id", licence_slug(id))], [t(id)]), 100 + h("pre", [], [t(licence.text)]), 101 + ] 102 + }), 103 + ]), 104 + ]), 105 + ]) 106 + |> htmb.render_page 107 + |> string_tree.to_string 37 108 38 - io.println(string.join(lines, "\n")) 109 + let assert Ok(_) = simplifile.write(output_path, html) 110 + 39 111 Nil 112 + } 113 + 114 + fn h_ul(items: List(a), mapper: fn(a) -> List(htmb.Html)) -> htmb.Html { 115 + htmb.h("ul", [], list.map(items, fn(item) { htmb.h("li", [], mapper(item)) })) 40 116 } 41 117 42 118 fn determine_licences() -> Set(String) { ··· 44 120 files 45 121 |> list.map(string.remove_suffix(_, ".txt")) 46 122 |> set.from_list 47 - } 48 - 49 - fn is_dependency(crate: Crate, gleam_crates: Set(String)) -> Bool { 50 - !set.contains(gleam_crates, crate.name) 51 123 } 52 124 53 125 fn determine_gleam_crates() -> Set(String) { ··· 74 146 ) 75 147 } 76 148 77 - fn crate_information(line: String, active_licences: Set(String)) -> Crate { 149 + type Licence { 150 + Licence(identifier: String, text: String) 151 + } 152 + 153 + fn dependency_information( 154 + line: String, 155 + gleam_crates: Set(String), 156 + active_licences: Set(String), 157 + ) -> Result(Crate, Nil) { 78 158 let line = string.remove_suffix(line, " (*)") 79 159 let assert [name, version, ..licence_parts] = string.split(line, " ") 160 + use <- bool.guard(set.contains(gleam_crates, name), return: Error(Nil)) 161 + let version = string.remove_prefix(version, "v") 80 162 let licence_identifier = string.join(licence_parts, " ") 81 163 let used_licences = 82 164 licence_identifier ··· 85 167 |> list.flat_map(string.split(_, "/")) 86 168 |> list.map(string.remove_prefix(_, "(")) 87 169 |> list.map(string.remove_suffix(_, ")")) 170 + |> list.map(string.remove_suffix(_, "+")) 88 171 |> list.filter(set.contains(active_licences, _)) 89 - Crate(name:, version:, licence_identifier:, used_licences:) 172 + assert used_licences != [] 173 + as { string.inspect(line) <> " parsed to no used licences" } 174 + Ok(Crate(name:, version:, licence_identifier:, used_licences:)) 90 175 } 91 176 92 177 /// Convert lines like these: