### Generate Escript with Custom Output Directory (CLI) Source: https://context7.com/lpil/gleescript/llms.txt Command-line examples for specifying a custom output directory for the generated escript using the `--out` flag. Shows both `--out=./bin` and `--out ./dist` syntax. ```shell # Generate escript in a specific directory gleam run -m gleescript -- --out=./bin # Running gleescript.main # Generated ./bin/your_project_name # Or use equals syntax gleam run -m gleescript -- --out ./dist # Running gleescript.main # Generated ./dist/your_project_name # Run from custom location ./bin/your_project_name # Hello from your_project_name! ``` -------------------------------- ### Project Configuration Requirements (TOML) Source: https://context7.com/lpil/gleescript/llms.txt Example `gleam.toml` file structure required by gleescript. It specifies the project's name, version, description, and dependencies, where the 'name' field is used for the output escript filename. ```toml # gleam.toml - Required configuration name = "my_cli_tool" version = "1.0.0" description = "A command-line tool built with Gleam" [dependencies] gleam_stdlib = ">= 0.60.0 and < 2.0.0" gleescript = "~> 1.5" # After running gleescript, generates: ./my_cli_tool ``` -------------------------------- ### Generate Escript using gleescript Source: https://github.com/lpil/gleescript/blob/main/README.md This command initiates the escript generation process using the 'gleescript' package. It builds your Gleam project and creates a standalone executable. The escript can be run on any system with an Erlang VM installed. Older VM versions might have compatibility issues. ```shell gleam build gleam run -m gleescript # Running gleescript.main # Generated ./your_project ./your_project # Hello from your_project! ``` -------------------------------- ### Escript Runtime Shim (Erlang) Source: https://context7.com/lpil/gleescript/llms.txt Embedded Erlang code within each generated escript. This shim sets up UTF-8 encoding for I/O, ensures all required OTP applications are started, and then invokes the main function of the Gleam project. ```erlang % gleescript_main_shim.erl - Embedded in every generated escript -module(gleescript_main_shim). -export([main/1]). main(_) -> % Configure UTF-8 encoding for standard I/O io:setopts(standard_io, [binary, {encoding, utf8}]), io:setopts(standard_error, [{encoding, utf8}]), % Get the application name from environment variable ApplicationModule = list_to_atom(os:getenv("GLEESCRIPT_MAIN")), % Start all OTP applications this project depends on {ok, _} = application:ensure_all_started(ApplicationModule), % Call the Gleam project's main function ApplicationModule:main(). ``` -------------------------------- ### Bundle Gleam Project into Escript (CLI) Source: https://context7.com/lpil/gleescript/llms.txt Command-line usage to add gleescript, build a Gleam project, and generate a portable escript in the current directory. Demonstrates basic escript creation and execution. ```shell gleam add gleescript gleam build # Generate escript in current directory gleam run -m gleescript # Running gleescript.main # Generated ./your_project_name # Run the generated escript ./your_project_name # Hello from your_project_name! ``` -------------------------------- ### main() Function Entry Point (Gleam) Source: https://context7.com/lpil/gleescript/llms.txt The primary entry point for the gleescript CLI tool written in Gleam. This function orchestrates the escript generation process by calling `gleescript.main()` and handles success or error output. ```gleam import gleescript pub fn main() { // This is the entry point called by `gleam run -m gleescript` gleescript.main() // On success: Prints "Generated ./package_name" // On error: Prints formatted error message and exits with status 1 } ``` -------------------------------- ### run() Function - Core Build Logic (Gleam) Source: https://context7.com/lpil/gleescript/llms.txt The core Gleam function responsible for the escript building process. It returns a `snag.Result` for error handling, performing configuration loading, file scanning, escript creation, and permission setting. ```gleam import gleescript import snag pub fn build_escript() -> snag.Result(Nil) { // Load config from gleam.toml // Scan build/dev/erlang for .beam and .app files // Create escript with embedded BEAM files // Set executable permissions (0o777) // Returns Ok(Nil) on success case gleescript.run() { Ok(_) -> { // Escript successfully created at ./package_name io.println("Build successful") } Error(error) -> { // Error contains context about what failed: // - "Failed to load configuration" // - "Failed to scan packages in build directory" // - "Failed to read gleam.toml" // - "Failed to create output directory" io.println_error(snag.pretty_print(error)) } } } ``` -------------------------------- ### Generate Escript to a Custom Output Directory Source: https://github.com/lpil/gleescript/blob/main/README.md This command demonstrates how to specify a custom output directory for the generated escript using the '--out' flag with 'gleescript'. This allows for flexible placement of the executable. ```shell gleam run -m gleescript -- --out=./some/directory # Running gleescript.main # Generated ./some/directory/your_project ./some/directory/your_project # Hello from your_project! ``` -------------------------------- ### Add gleescript to Gleam Project Source: https://github.com/lpil/gleescript/blob/main/README.md This command adds the 'gleescript' package as a dependency to your Gleam project, preparing it for building escripts. It utilizes the Gleam package manager. ```shell gleam add gleescript ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.