moon-embed

    Embed files into MoonBit source as String or Bytes bindings.

    Download zip
    Version
    0.0.1
    License
    Apache-2.0
    Last updated
    9 months ago
    Downloads
    64

    #moon-embed

    Embed files into MoonBit source as String or Bytes bindings. The tool reads an input file and emits a .mbt file that you can import in your package.

    #Usage

    Usage: moon-embed <input> -o <output> [options] Options: -o, --output <path> Output .mbt file (required) --name <ident> Binding name (default: derived from input) --binary Embed as Bytes (default: text) --pub Use pub binding --const Use const binding (name default UpperCamel) --help Show this help

    #Examples

    Run from the module root using moon:

    moon run . -- assets/logo.txt -o assets/logo_embed.mbt

    Embed binary data as Bytes and export it:

    moon run . -- assets/logo.png -o assets/logo_png.mbt --binary --pub

    Provide a custom name and emit a const binding:

    moon run . -- assets/config.json -o assets/config_embed.mbt --name ConfigJson --const

    #Output Format

    The generated .mbt file contains a single top-level binding:

    • Text embeds use MoonBit multiline strings with #| lines.
    • Binary embeds use a Bytes array of hex literals.
    • Each output starts with ///| so the block can be parsed reliably by MoonBit tooling.

    Example (text):

    ///|
    let my_file : String =
    #|Hello
    #|World

    Example (bytes):

    ///|
    let data : Bytes =
    [
    0x00, 0x01, 0xff
    ]

    #Name Derivation

    If --name is not provided, the tool derives a name from the input filename:

    • Default: lower_snake (e.g. my-file.txt → my_file)
    • With --const: UpperCamel (e.g. my-file.txt → MyFile)

    #Development

    Common commands:

    moon check moon test

    #License

    Apache-2.0. See LICENSE.

    CliError

    pub(all) suberror CliError {
    Usage(String)
    }

    impl Eq for CliError
    impl Show for CliError

    Config

    type Config