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

Configure Feed

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

Start licence page script

+220
+4
licence-bundler/.gitignore
··· 1 + *.beam 2 + *.ez 3 + /build 4 + erl_crash.dump
+24
licence-bundler/README.md
··· 1 + # licence_bundler 2 + 3 + [![Package Version](https://img.shields.io/hexpm/v/licence_bundler)](https://hex.pm/packages/licence_bundler) 4 + [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/licence_bundler/) 5 + 6 + ```sh 7 + gleam add licence_bundler@1 8 + ``` 9 + ```gleam 10 + import licence_bundler 11 + 12 + pub fn main() -> Nil { 13 + // TODO: An example of the project in use 14 + } 15 + ``` 16 + 17 + Further documentation can be found at <https://hexdocs.pm/licence_bundler>. 18 + 19 + ## Development 20 + 21 + ```sh 22 + gleam run # Run the project 23 + gleam test # Run the tests 24 + ```
+22
licence-bundler/gleam.toml
··· 1 + name = "licence_bundler" 2 + version = "1.0.0" 3 + 4 + # Fill out these fields if you intend to generate HTML documentation or publish 5 + # your project to the Hex package manager. 6 + # 7 + # description = "" 8 + # licences = ["Apache-2.0"] 9 + # repository = { type = "github", user = "", repo = "" } 10 + # links = [{ title = "Website", href = "" }] 11 + # 12 + # For a full reference of all the available options, you can have a look at 13 + # https://gleam.run/writing-gleam/gleam-toml/. 14 + 15 + [dependencies] 16 + gleam_stdlib = ">= 0.70.0 and < 2.0.0" 17 + simplifile = ">= 2.4.0 and < 3.0.0" 18 + shellout = ">= 1.8.0 and < 2.0.0" 19 + tom = ">= 2.0.2 and < 3.0.0" 20 + 21 + [dev_dependencies] 22 + gleeunit = ">= 1.0.0 and < 2.0.0"
+19
licence-bundler/manifest.toml
··· 1 + # This file was generated by Gleam 2 + # You typically do not need to edit this file 3 + 4 + packages = [ 5 + { name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" }, 6 + { name = "gleam_stdlib", version = "0.71.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "702F3BC2A14793906880B1078B19A6165F87323AEE8D0C4A34085846336FCAAE" }, 7 + { name = "gleam_time", version = "1.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_time", source = "hex", outer_checksum = "533D8723774D61AD4998324F5DD1DABDCDBFABAFB9E87CB5D03C6955448FC97D" }, 8 + { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" }, 9 + { name = "shellout", version = "1.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "C416356D45151F298108C9DB9CD1EDE0313F620B5EDBB5766CD7237659D87841" }, 10 + { name = "simplifile", version = "2.4.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "7C18AFA4FED0B4CE1FA5B0B4BAC1FA1744427054EA993565F6F3F82E5453170D" }, 11 + { name = "tom", version = "2.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_time"], otp_app = "tom", source = "hex", outer_checksum = "234A842F3D087D35737483F5DFB6DE9839E3366EF0CAF8726D2D094210227670" }, 12 + ] 13 + 14 + [requirements] 15 + gleam_stdlib = { version = ">= 0.70.0 and < 2.0.0" } 16 + gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 17 + shellout = { version = ">= 1.8.0 and < 2.0.0" } 18 + simplifile = { version = ">= 2.4.0 and < 3.0.0" } 19 + tom = { version = ">= 2.0.2 and < 3.0.0" }
+138
licence-bundler/src/licence_bundler.gleam
··· 1 + import gleam/io 2 + import gleam/list 3 + import gleam/set.{type Set} 4 + import gleam/string 5 + import shellout 6 + import simplifile 7 + import tom 8 + 9 + pub fn main() -> Nil { 10 + let gleam_crates = determine_gleam_crates() 11 + let active_licences = determine_licences() 12 + 13 + let assert Ok(output) = 14 + shellout.command( 15 + run: "cargo", 16 + with: [ 17 + "tree", 18 + "--format", 19 + "{p} {l}", 20 + "--edges", 21 + "no-dev,no-build,no-proc-macro", 22 + ], 23 + in: "..", 24 + opt: [], 25 + ) 26 + 27 + let lines = 28 + output 29 + |> string.split("\n") 30 + |> list.filter(fn(line) { line != "" }) 31 + |> list.map(trim_line_prefix) 32 + |> list.map(crate_information(_, active_licences)) 33 + |> list.filter(is_dependency(_, gleam_crates)) 34 + |> set.from_list 35 + |> set.to_list 36 + |> list.map(string.inspect) 37 + 38 + io.println(string.join(lines, "\n")) 39 + Nil 40 + } 41 + 42 + fn determine_licences() -> Set(String) { 43 + let assert Ok(files) = simplifile.read_directory("../licences") 44 + files 45 + |> list.map(string.remove_suffix(_, ".txt")) 46 + |> set.from_list 47 + } 48 + 49 + fn is_dependency(crate: Crate, gleam_crates: Set(String)) -> Bool { 50 + !set.contains(gleam_crates, crate.name) 51 + } 52 + 53 + fn determine_gleam_crates() -> Set(String) { 54 + let assert Ok(toml) = simplifile.read("../Cargo.toml") 55 + let assert Ok(config) = tom.parse(toml) 56 + let assert Ok(crates) = tom.get_array(config, ["workspace", "members"]) 57 + let assert Ok(paths) = list.try_map(crates, tom.as_string) 58 + let crates = 59 + list.map(paths, fn(path) { 60 + let assert Ok(toml) = simplifile.read("../" <> path <> "/Cargo.toml") 61 + let assert Ok(config) = tom.parse(toml) 62 + let assert Ok(name) = tom.get_string(config, ["package", "name"]) 63 + name 64 + }) 65 + set.from_list(crates) 66 + } 67 + 68 + type Crate { 69 + Crate( 70 + name: String, 71 + version: String, 72 + licence_identifier: String, 73 + used_licences: List(String), 74 + ) 75 + } 76 + 77 + fn crate_information(line: String, active_licences: Set(String)) -> Crate { 78 + let line = string.remove_suffix(line, " (*)") 79 + let assert [name, version, ..licence_parts] = string.split(line, " ") 80 + let licence_identifier = string.join(licence_parts, " ") 81 + let used_licences = 82 + licence_identifier 83 + |> string.split(" OR ") 84 + |> list.flat_map(string.split(_, " AND ")) 85 + |> list.flat_map(string.split(_, "/")) 86 + |> list.map(string.remove_prefix(_, "(")) 87 + |> list.map(string.remove_suffix(_, ")")) 88 + |> list.filter(set.contains(active_licences, _)) 89 + Crate(name:, version:, licence_identifier:, used_licences:) 90 + } 91 + 92 + /// Convert lines like these: 93 + /// 94 + /// ```txt 95 + /// │ └── wasm-bindgen v0.2.106 MIT OR Apache-2.0 96 + /// ``` 97 + /// 98 + /// into lines like these 99 + /// 100 + /// ```txt 101 + /// wasm-bindgen v0.2.106 MIT OR Apache-2.0 102 + /// ``` 103 + /// 104 + fn trim_line_prefix(line: String) -> String { 105 + case line { 106 + " " <> line | "│" <> line | "─" <> line | "├" <> line | "└" <> line -> 107 + trim_line_prefix(line) 108 + 109 + "" 110 + | "a" <> _ 111 + | "b" <> _ 112 + | "c" <> _ 113 + | "d" <> _ 114 + | "e" <> _ 115 + | "f" <> _ 116 + | "g" <> _ 117 + | "h" <> _ 118 + | "i" <> _ 119 + | "j" <> _ 120 + | "k" <> _ 121 + | "l" <> _ 122 + | "m" <> _ 123 + | "n" <> _ 124 + | "o" <> _ 125 + | "p" <> _ 126 + | "q" <> _ 127 + | "r" <> _ 128 + | "s" <> _ 129 + | "t" <> _ 130 + | "u" <> _ 131 + | "v" <> _ 132 + | "w" <> _ 133 + | "x" <> _ 134 + | "y" <> _ 135 + | "z" <> _ -> line 136 + _ -> panic as { "Unexpected line prefix: " <> string.inspect(line) } 137 + } 138 + }
+13
licence-bundler/test/licence_bundler_test.gleam
··· 1 + import gleeunit 2 + 3 + pub fn main() -> Nil { 4 + gleeunit.main() 5 + } 6 + 7 + // gleeunit test functions end in `_test` 8 + pub fn hello_world_test() { 9 + let name = "Joe" 10 + let greeting = "Hello, " <> name <> "!" 11 + 12 + assert greeting == "Hello, Joe!" 13 + }