Universal Text Pre-Processor (utpp)

website·Indexed 32 days ago

https://utpp.adriansoftware.de/

A tool for preprocessing any file, designed to be used as a single binary or inside containers to modify configuration. It supports template blocks, variables, and commands, with documentation available for versions 0.3.x, 0.4.x, and 0.5.x.

Tokens
9.5K
Snippets
64
Records
85
Agent score
59%

What's inside utpp

  1. Overview of utpp features and capabilities

    utpp is a portable, TypeScript-based tool designed to dynamically modify files across any platform (Windows, Linux, MacOS, Docker). It provides the following core capabilities:

    • Universal File Support: Works with any file format.
    • Branching Logic: Supports if/else logic to include, exclude, or modify specific parts of a file.
    • Variable Replacement: Allows the use of placeholders in files that are replaced by variables.
    • Custom Scripting: Enables the execution of custom JavaScript code within the process.

    Common use cases include dynamically modifying static config files based on user input, replacing placeholders with evaluated JavaScript on startup, conditionally starting supervisor services via docker run arguments, and adjusting compile commands based on system architecture.

  2. Overview of utpp features and capabilities

    utpp is a portable, universal file processing tool (written in TypeScript) that works across Windows, Linux, MacOS, and Docker containers. It allows developers to dynamically modify any file format using the following capabilities:

    • Branching: Implement if/else logic to include, exclude, or modify specific parts of a file.
    • Variables: Use placeholders within files and replace them with defined variables.
    • Scripting: Execute custom JavaScript code during the processing phase.
    • Universal Compatibility: Operates on any file format regardless of the extension.
  3. Overview of utpp features and capabilities

    utpp is a portable, TypeScript-based tool designed to dynamically modify files across any platform (Windows, Linux, MacOS, Docker). It provides the following core capabilities:

    • Universal File Support: Works with any file format.
    • Branching Logic: Supports if/else logic to include, exclude, or modify specific parts of a file.
    • Variable Replacement: Allows the use of placeholders within files that are replaced by variables.
    • Custom Scripting: Enables the execution of custom JavaScript code during the process.
  4. Deploy the application as a self-contained binary

    The application is distributed as a self-contained single binary, ensuring compatibility across all platforms and supporting any file type.
  5. Understand the utpp file processing pipeline

    For every file processed, utpp follows a four-step pipeline:

    1. Read file: The file is read from the filesystem into memory.
    2. Apply template: Template commands and logic (such as conditional blocks) are evaluated and applied.
    3. Apply variables: Key-value pairs provided via CLI arguments are used to replace variables within the template.
    4. Write file: The final processed content is written back to the filesystem or sent to standard output based on the CLI arguments used.
    # Example of the full process: reading a file and applying variables
    utpp foobar.txt foo=bar
  6. Use and declare variables in templates and CLI

    Variables are stored globally and can be used inside a template block's Value argument by referencing the variable name. Because they are global, changes to a variable only affect statements declared after the point of modification.

    Variables can be declared during CLI execution using key=value pairs or by providing a key alone. Multiple variables are passed as space-separated arguments.

    # Example of passing multiple variables via CLI
    command foo=bar foz="baz 123" foobar
  7. Install utpp using precompiled binaries

    Precompiled binaries for Linux (x64, alpine) and Windows (x64) are available in the GitHub releases. For Linux, you can install the binary directly to /usr/local/bin using curl.
    sudo curl -fSsL https://github.com/adrianschubek/utpp/releases/latest/download/utpp-linux -o /usr/local/bin/utpp && sudo chmod +x /usr/local/bin/utpp
  8. Install utpp using npm

    The recommended way to install utpp is via npm. You can install it globally for system-wide access or use npx to run it without a permanent installation.
    # Install globally
    npm install -g utpp
    
    # Run without installing
    npx utpp
  9. Install utpp using precompiled binaries

    Precompiled binaries for Linux (x64, alpine) and Windows (x64) are available in the GitHub releases. For Linux, you can install the binary directly to /usr/local/bin using curl.
    sudo curl -fSsL https://github.com/adrianschubek/utpp/releases/latest/download/utpp-linux -o /usr/local/bin/utpp && sudo chmod +x /usr/local/bin/utpp
  10. Print variables using curly brace syntax

    In UTPP version 0.5.x, you can output a defined variable by wrapping the variable name in double curly braces within a dollar-sign-delimited expression: ${{<value>}}$. This syntax was introduced in version 0.3.0 to replace the older ${<value>}$ format and prevent common conflicts.
    ${{variable_name}}$
  11. Set up the local development environment

    To develop for version 0.3.x, clone the repository, install dependencies, start the build watcher, and execute the compiled index file.
    # 1. Clone the repository
    # git clone <repo-url>
    
    # 2. Install dependencies
    npm install
    
    # 3. Start the build watcher
    npm run build:watch
    
    # 4. Run the application
    node out/index.js
  12. Set up the local development environment

    To develop for the project (version 0.4.x), clone the repository, install dependencies, compile the source code in watch mode, and execute the compiled index file.
    # 1. Clone the repository
    git clone <repo-url>
    
    # 2. Install dependencies
    npm install
    
    # 3. Build and watch for changes
    npm run build:watch
    
    # 4. Run the application
    node out/index.js