Lustre's CLI and development tooling: zero-config dev server, bundling, and scaffolding.
at main 2.5 kB view raw
1// IMPORTS --------------------------------------------------------------------- 2 3import glint.{type Command} 4import lustre_dev_tools/cli.{do} 5import lustre_dev_tools/cli/flag 6import lustre_dev_tools/error 7import lustre_dev_tools/esbuild 8import lustre_dev_tools/tailwind 9 10// DESCRIPTION ----------------------------------------------------------------- 11 12pub const description: String = " 13Commands for adding external binaries to your project. These are run and managed 14by Lustre, and while not typically intended to be run manually, they can be found 15inside `build/.lustre/bin`. 16 " 17 18// COMMANDS -------------------------------------------------------------------- 19 20pub fn esbuild() -> Command(Nil) { 21 let description = 22 " 23Download a platform-appropriate version of the esbuild binary. Lustre uses this 24to bundle applications and act as a development server, and will automatically 25download the binary if either the `build` or `start` commands are run. 26 " 27 28 use <- glint.command_help(description) 29 use <- glint.unnamed_args(glint.EqArgs(0)) 30 use os <- glint.flag(flag.esbuild_os()) 31 use cpu <- glint.flag(flag.esbuild_cpu()) 32 use _, _, flags <- glint.command() 33 let script = { 34 use os <- do(cli.get_string("os", get_os(), ["add"], os)) 35 use cpu <- do(cli.get_string("cpu", get_cpu(), ["add"], cpu)) 36 37 esbuild.download(os, cpu) 38 } 39 40 case cli.run(script, flags) { 41 Ok(_) -> Nil 42 Error(error) -> error.explain(error) 43 } 44} 45 46pub fn tailwind() -> Command(Nil) { 47 let description = 48 " 49Download a platform-appropriate version of the Tailwind binary. Lustre will 50automatically use this to compile your styles if it detects a `tailwind.config.js` 51in your project but will not download it automatically. 52 " 53 use <- glint.command_help(description) 54 use <- glint.unnamed_args(glint.EqArgs(0)) 55 use os <- glint.flag(flag.tailwind_os()) 56 use cpu <- glint.flag(flag.tailwind_cpu()) 57 use _, _, flags <- glint.command() 58 let script = { 59 use os <- do(cli.get_string("os", get_os(), ["add"], os)) 60 use cpu <- do(cli.get_string("cpu", get_cpu(), ["add"], cpu)) 61 62 tailwind.setup(os, cpu) 63 } 64 65 case cli.run(script, flags) { 66 Ok(_) -> Nil 67 Error(error) -> error.explain(error) 68 } 69} 70 71// EXTERNALS ------------------------------------------------------------------- 72 73@external(erlang, "lustre_dev_tools_ffi", "get_os") 74fn get_os() -> String 75 76@external(erlang, "lustre_dev_tools_ffi", "get_cpu") 77fn get_cpu() -> String