Skip to content

cas8398/bridge-cli

Repository files navigation

🌉 Bridge CLI

Write your logic once. Compile it everywhere.

Bridge lets you define business logic in a clean .bridge syntax and compile it into PHP (Laravel), TypeScript, and Node.js (ESM) — all from a single source of truth.

npm License: MIT


Table of Contents


Installation

npm install -g @cas8398/bridge-cli

Verify the install:

bridge --help

Quick Start

# 1. Create a new project
bridge new my-app
cd my-app

# 2. Edit your logic
# src/logic.bridge is created automatically — open it and define your functions

# 3. Compile to all targets
bridge build

After bridge build, your outputs land in .bridge/:

my-app/
├── .bridge/
│   ├── php/        ← Laravel-ready PHP class
│   ├── ts/         ← TypeScript with typed signatures
│   └── node/       ← Node.js ESM module
├── bridge.config.json
└── src/
    └── logic.bridge

Commands

Command Description
bridge new <name> Scaffold a new Bridge project
bridge build Compile all .bridge files in src/ to configured targets
bridge to-bridge <file> Reverse-compile a PHP or TS file back into .bridge syntax
bridge help Show available commands

The .bridge Syntax

Bridge uses a TypeScript-like syntax with a small set of familiar types.

function calculateTotal(price: float, tax: float): float {
  let total = price * (1 + tax)
  return total
}

Supported types

Bridge type PHP TypeScript / Node
float float number
int int number
string string string
bool bool boolean

Configuration

bridge.config.json controls what gets compiled and where:

{
  "src": "src",
  "outDir": ".bridge",
  "targets": ["php", "ts", "node"],
  "preserveName": true
}
Field Default Description
src "src" Directory containing your .bridge source files
outDir ".bridge" Output directory for compiled files
targets ["php","ts","node"] Compile targets — any combination of php, ts, node
preserveName true Keep the original filename casing in output

Output Examples

Given this source:

// src/logic.bridge

function calculateTotal(price: float, tax: float): float {
  let total = price * (1 + tax)
  return total
}

TypeScript (.bridge/ts/logic.ts)

/**
 * Generated by Bridge from logic.bridge
 */

export function calculateTotal(price: number, tax: number): number {
  let total = price * (1 + tax);
  return total;
}

Node.js ESM (.bridge/node/logic.js)

/**
 * Generated by Bridge from logic.bridge
 * Target: Node.js (Bare JavaScript)
 */

export function calculateTotal(price, tax) {
  let total = price * (1 + tax);
  return total;
}

PHP / Laravel (.bridge/php/Logic.php)

<?php

namespace App\Bridge;

/**
 * Generated by Bridge
 */
class Logic
{
    public function calculateTotal(float $price, float $tax): float
    {
        $total = $price * (1 + $tax);
        return $total;
    }
}

Reverse Compilation

You can reverse an existing PHP or TypeScript file back into .bridge syntax:

bridge to-bridge .bridge/php/Logic.php

The reversed file lands in .bridge/to-bridge/. Move it to src/ to include it in future builds:

mv .bridge/to-bridge/Logic.bridge src/

Note: to-bridge works best on files that were originally compiled by Bridge. Hand-written PHP or TS with complex patterns may not reverse cleanly.


VS Code Extension

Get syntax highlighting and snippets for .bridge files:

👉 Bridge Language Support on the VS Code Marketplace


License

MIT

About

CLI compiler for the Bridge language—compile .bridge files to PHP, TypeScript, and Node.js.

Topics

Resources

License

Stars

Watchers

Forks

Contributors