Lustre's CLI and development tooling: zero-config dev server, bundling, and scaffolding.
0
fork

Configure Feed

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

:memo: Update documentation and remove old flags.

+17 -55
+11 -3
README.md
··· 66 66 ## Installation 67 67 68 68 Lustre's dev tools are published on [Hex](https://hex.pm/packages/lustre_dev_tools)! 69 - You can add them to your Gleam projects from the command line: 69 + You can add them as a dev dependency to your Gleam projects from the command line: 70 70 71 71 ```sh 72 72 gleam add lustre_dev_tools --dev 73 73 ``` 74 74 75 - > **Note**: make sure you remember the `--dev` flag! This ensures the dev tools 76 - > are never included in production builds. 75 + The `--dev` flag is important to make sure the dev tools are not included in your 76 + application's build! 77 + 78 + > **Note**: The included development server uses the erlang package [`fs`](https://github.com/5HT/fs) 79 + > as a file watcher. For Linux uses, you need to have [inotify-tools](https://github.com/inotify-tools/inotify-tools) 80 + > installed on your system. Both Linux and MacOS users must also have a C compiler. 77 81 78 82 To run any of the commands provided by the dev tools, you should run the 79 83 `lustre/dev` module using Gleam's `run` command: ··· 83 87 ``` 84 88 85 89 ## Commands 90 + 91 + You can run `gleam run -m lustre/dev -- --help` to see a list of all the available 92 + commands. Each command also has its own help text that lists the available flags 93 + and options. Here's a brief overview of the commands provided by Lustre's dev tools: 86 94 87 95 - `lustre/dev add` - Commands for adding external binaries to your project. These 88 96 are run and managed by Lustre, and while not typically intended to be run manually,
+3 -27
src/lustre/dev.gleam
··· 126 126 //// 127 127 //// The `lustre/dev start` command starts a development server that builds and serves your 128 128 //// project. This lets you focus on development without having to worry about a backend 129 - //// or additional tooling. 130 - //// 131 - //// Currently the server does _not_ watch for changes to your Gleam source files. You 132 - //// must **restart the server** for changes to take effect. There have been discussions 133 - //// about including a `watch` command in the Gleam compiler that would make this 134 - //// possible. 129 + //// or additional tooling. The page will automatically reload when you make changes 130 + //// to your project. 135 131 //// 136 132 //// Flags: 137 133 //// 138 134 //// - `--port` - The port to serve the project on. Defaults to `1234`. 139 135 //// 140 - //// - `--host` - The host to serve the project on. Defaults to `0.0.0.0` and is 141 - //// accessible on localhosts and any other devices on the same network. 142 - //// 143 - //// - `--html` - Provide a custom HTML file to serve. This is useful if you want to 144 - //// include your own styles or scripts. 145 - //// 146 - //// To make sure the Lustre bundle can be loaded, you must include the following 147 - //// script tag somewhere in your HTML file: 148 - //// 149 - //// ```html 150 - //// <script type="application/lustre"></script> 151 - //// ``` 152 - //// 153 - //// - `--use-example-styles` - Include the stylesheet from 154 - //// [lustre/ui](https://hexdocs.pm/lustre_ui/). This is mainly used in the example 155 - //// projects, but you may use this option to quickly experiment with the library 156 - //// yourself. 157 - //// 158 - //// If the `--html` flag is provided, this flag will be ignored. 159 - //// 160 136 //// Example: 161 137 //// 162 138 //// ```sh 163 - //// gleam run -m lustre/dev start --port=8080 --use-example-styles 139 + //// gleam run -m lustre/dev start --port=8080 164 140 //// ``` 165 141 //// 166 142 //// ## Getting help
+3 -25
src/lustre_dev_tools/cli/start.gleam
··· 28 28 glint.command(fn(input) { 29 29 let CommandInput(flags: flags, ..) = input 30 30 let assert Ok(port) = flag.get_int(flags, "port") 31 - let assert Ok(use_example_styles) = 32 - flag.get_bool(flags, "use-example-styles") 33 31 34 32 let script = { 35 33 use _ <- cli.do(build.do_app(False)) 36 - use _ <- cli.do(prepare_html(use_example_styles)) 34 + use _ <- cli.do(prepare_html()) 37 35 use _ <- cli.do(cli.from_result(server.start(port))) 38 36 39 37 cli.return(Nil) ··· 55 53 |> flag.default(default) 56 54 |> flag.description(description) 57 55 }) 58 - |> glint.flag("use-example-styles", { 59 - let description = 60 - "Inject the lustre/ui stylesheet. This is primarily intended to be used when running any of Lustre's examples and is ignored if the `--html` flag is set." 61 - let default = False 62 - 63 - flag.bool() 64 - |> flag.default(default) 65 - |> flag.description(description) 66 - }) 67 - |> glint.flag("html", { 68 - let description = 69 - "Supply a custom HTML file to use as the entry point. To inject the Lustre bundle, make sure it includes the following empty script: <script type=\"application/lustre\"></script>" 70 - |> string.trim_right 71 - 72 - flag.string() 73 - |> flag.description(description) 74 - }) 75 56 } 76 57 77 58 // STEPS ----------------------------------------------------------------------- 78 59 79 - fn prepare_html(include_example_styles: Bool) -> Cli(any, Nil, Error) { 60 + fn prepare_html() -> Cli(any, Nil, Error) { 80 61 let assert Ok(cwd) = cli.cwd() 81 62 let assert Ok(root) = filepath.expand(filepath.join(cwd, project.root())) 82 63 let index = filepath.join(root, "index.html") ··· 84 65 case simplifile.verify_is_file(index) { 85 66 Ok(True) -> cli.return(Nil) 86 67 Ok(False) | Error(_) -> { 87 - use html <- cli.template(case include_example_styles { 88 - True -> "index-with-lustre-ui.html" 89 - False -> "index.html" 90 - }) 68 + use html <- cli.template("index.html") 91 69 use config <- cli.do(cli.from_result(project.config(False))) 92 70 let html = string.replace(html, "{app_name}", config.name) 93 71 use _ <- cli.try(simplifile.write(index, html), fn(reason) {