aux4
Documentation
HomeGetting StartedInstallationIDEsVariablesExecutorsFunctionsConfigurationCommandsHooksSecurityRenderTestingPackage ManagerPackagingGitHub ActionsDocker

Package with System Dependencies

This guide shows how to create a package that requires system-level dependencies (e.g., Node.js, Python, AWS CLI). When your package is installed, aux4 automatically installs the required system packages using the appropriate package manager for the user's operating system.

Package Structure

1my-package/ 2├── .aux4 # Package metadata with system dependencies 3├── LICENSE 4├── README.md 5└── lib/ 6 └── script.js

Step 1: Create the Package

Create the .aux4 file

Add the system field to specify system-level dependencies:

1{ 2 "scope": "myorg", 3 "name": "pdf-generator", 4 "version": "1.0.0", 5 "description": "Generate PDF documents", 6 "license": "MIT", 7 "system": [ 8 [ 9 "test:node --version", 10 "brew:node", 11 "apt:nodejs", 12 "dnf:nodejs", 13 "apk:nodejs" 14 ], 15 [ 16 "test:gs --version", 17 "brew:ghostscript", 18 "apt:ghostscript", 19 "dnf:ghostscript", 20 "apk:ghostscript" 21 ] 22 ], 23 "profiles": [ 24 { 25 "name": "main", 26 "commands": [ 27 { 28 "name": "pdf", 29 "execute": [ 30 "profile:pdf" 31 ], 32 "help": { 33 "text": "PDF generation commands" 34 } 35 } 36 ] 37 }, 38 { 39 "name": "pdf", 40 "commands": [ 41 { 42 "name": "generate", 43 "execute": [ 44 "node ${packageDir}/lib/generate-pdf.js ${input} ${output}" 45 ], 46 "help": { 47 "text": "Generate a PDF from input file", 48 "variables": [ 49 { 50 "name": "input", 51 "text": "Input file", 52 "arg": true 53 }, 54 { 55 "name": "output", 56 "text": "Output PDF file", 57 "default": "output.pdf" 58 } 59 ] 60 } 61 } 62 ] 63 } 64 ] 65}

System Dependency Format

Each system dependency is an array with:

  1. A test command to check if the dependency is installed
  2. Package manager and package name pairs for different systems
1{ 2 "system": [ 3 [ 4 "test:<command to verify installation>", 5 "<package-manager>:<package-name>", 6 "<package-manager>:<package-name>" 7 ] 8 ] 9}

Test Command

The test command verifies if the dependency is already installed. If the command succeeds (exit code 0), the dependency is skipped.

1"test:node --version" 2"test:python3 --version" 3"test:aws --version" 4"test:gs --version"

Supported Package Managers

  • brew: Homebrew (macOS)
  • apt: APT (Debian/Ubuntu)
  • dnf: DNF (Fedora/RHEL)
  • yum: YUM (CentOS/RHEL)
  • apk: APK (Alpine Linux)
  • npm: Node Package Manager
  • pkgx: pkgx package manager
  • linux: Generic alias used by all Linux package managers (apt, dnf, yum, apk)

Using the linux Alias

The linux alias is a convenience that works with any Linux package manager:

1{ 2 "system": [ 3 [ 4 "test:node --version", 5 "brew:node", 6 "linux:nodejs" 7 ] 8 ] 9}

This is equivalent to specifying all Linux package managers individually.

Step 2: Create the Script

Create lib/generate-pdf.js:

1const input = process.argv[2]; 2const output = process.argv[3]; 3 4console.log(`Generating PDF from ${input} to ${output}`); 5// PDF generation logic here

Step 3: Create Supporting Files

LICENSE

1cat > LICENSE << 'EOF' 2MIT License 3... 4EOF

Tip: You can also use aux4/license to generate your LICENSE file:

1aux4 license use \ 2 --name mit \ 3 --owner "MyOrg" \ 4 --year 2024 \ 5 --project "pdf-generator"

README.md

1cat > README.md << 'EOF' 2# PDF Generator 3 4Generate PDF documents from various input formats. 5 6## System Requirements 7 8This package requires: 9- Node.js 10- Ghostscript 11 12These are installed automatically based on your operating system. 13 14## Usage 15 16```bash 17aux4 pdf generate input.txt --output result.pdf 18``` 19EOF

Step 4: Build the Package

1aux4 aux4 pkger build ./out .

Step 5: Install from File

1aux4 aux4 pkger install --fromFile ./out/myorg_pdf-generator_1.0.0.zip

During installation, aux4:

  1. Runs each test command
  2. If the test fails, installs the package using the appropriate package manager
  3. Skips installation if the dependency is already present

Step 6: Publish

1aux4 aux4 login 2aux4 aux4 pkger publish ./out/myorg_pdf-generator_1.0.0.zip

Step 7: Install from aux4 Hub

1aux4 aux4 pkger install myorg/pdf-generator

Common System Dependencies

Node.js

1[ 2 "test:node --version", 3 "brew:node", 4 "apt:nodejs", 5 "dnf:nodejs", 6 "apk:nodejs" 7]

Python 3

1[ 2 "test:python3 --version", 3 "brew:python3", 4 "apt:python3", 5 "dnf:python3", 6 "apk:python3" 7]

AWS CLI

1[ 2 "test:aws --version", 3 "brew:awscli", 4 "pkgx:aws" 5]

jq

1[ 2 "test:jq --version", 3 "brew:jq", 4 "apt:jq", 5 "dnf:jq", 6 "apk:jq" 7]

npm Packages

For global npm packages:

1[ 2 "test:jest --version", 3 "npm:jest" 4]

Combining aux4 and System Dependencies

You can use both dependencies (aux4 packages) and system (system packages) together:

1{ 2 "scope": "myorg", 3 "name": "full-stack-tool", 4 "version": "1.0.0", 5 "license": "MIT", 6 "dependencies": [ 7 "aux4/config", 8 "aux4/validator" 9 ], 10 "system": [ 11 [ 12 "test:node --version", 13 "brew:node", 14 "linux:nodejs" 15 ], 16 [ 17 "test:docker --version", 18 "brew:docker", 19 "apt:docker.io" 20 ] 21 ], 22 "profiles": [...] 23}

See Also