Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

4.1 KB
Raw Blame
#!/bin/sh
set -e

pnpm exec lint-staged

# Compile lingui translations if any relevant files were modified
if git diff --cached --name-only | grep -qE '\.(tsx?|jsx?)$|\.po$'; then
    echo "Compiling translations..."
    # Not a blocker — a catalog that won't compile is worth knowing about, but it
    # is not a reason to refuse the commit. It DOES stop the staging below, so a
    # failed run can never commit half-written catalogs.
    if pnpm lingui:check; then
        # Strip `#:` origin refs before committing — they shift on any upstream
        # code edit and are the biggest PR-conflict source. They're kept in the
        # working dir during the translate flow (linguito needs them for LLM
        # context) and only stripped right before commit.
        pnpm lingui:clean

        # Add compiled locale files to the commit
        git add packages/locale/locales/**/*.po
    else
        echo "⚠ Translations did not compile — catalogs left unstaged for this commit."
    fi
fi

# Regenerate MCP tools if a service file, or a module's .server.ts (where the
# defineServiceFn operations and the router live), was modified
if git diff --cached --name-only | grep -qE '\.service\.ts$|^apps/erp/app/modules/.*\.server\.ts$'; then
    if ! npx tsx scripts/generate-mcp.ts; then
        echo "✗ MCP tool metadata could not be regenerated. Nothing was staged."
        exit 1
    fi
    # The manifest itself is gitignored (see 633f134b0b) — the DIGEST is what is
    # committed, and `git add` on an ignored path exits 1, which failed this hook
    # for every commit that touched a *.service.ts.
    git add apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json
fi

# Demo-dataset drift only shows up when the datasets actually run. This dry-runs
# all four (~3s) — each rolls back, so it writes nothing.
# Set CARBON_SKIP_DATASET_CHECK=1 to skip.
if [ -z "$CARBON_SKIP_DATASET_CHECK" ] && git diff --cached --name-only | grep -q '^packages/database/'; then
    echo "Checking demo datasets against the schema..."
    # --silent so pnpm's ELIFECYCLE trailer doesn't bury the script's own advice.
    if ! pnpm --silent db:check:datasets; then
        echo ""
        echo "Commit blocked by the demo-dataset check. The reason is printed above."
        echo "Skip it with: CARBON_SKIP_DATASET_CHECK=1 git commit ..."
        exit 1
    fi
fi

# A migration can make a backup a customer already holds unrestorable, without the
# backup changing at all. This compares the schema baseline on main with your live
# schema, then updates and stages the baseline. Set CARBON_SKIP_BACKUP_CHECK=1 to skip.
if [ -z "$CARBON_SKIP_BACKUP_CHECK" ] && git diff --cached --name-only | grep -q '^packages/database/supabase/migrations/'; then
    echo "Checking backup compatibility against the schema..."
    if ! pnpm --silent db:check:backups -- --stage; then
        echo ""
        echo "Commit blocked by the backup compatibility check. The reason is printed above."
        echo "Skip it with: CARBON_SKIP_BACKUP_CHECK=1 git commit ..."
        exit 1
    fi
fi
# The published operation contract lives in a GITIGNORED manifest, so its committed
# digest is the only record a reviewer can see. Regenerate and refuse the commit if
# a change to anything the generator reads did not update it — a stale digest is
# worse than none, since it reads as "nothing changed". The file set is the
# //#generate:mcp inputs in turbo.json; keep the two in step.
# Set CARBON_SKIP_MANIFEST_CHECK=1 to skip.
if [ -z "$CARBON_SKIP_MANIFEST_CHECK" ] && git diff --cached --name-only | grep -qE '^(apps/erp/app/(modules|components/TreeView|services|types|utils)/.*|apps/erp/tsconfig\.json|packages/(account|api|auth|database|documents|ee|env|files|form|jobs|kv|lib|locale|logger|notifications|onboarding|planning|printing|react|stripe|utils)/src/.*|scripts/generate-mcp\.ts|scripts/lib/.*)$'; then
    echo "Checking the API operation manifest digest..."
    if ! pnpm --silent check:manifest; then
        echo ""
        echo "Run: pnpm generate:mcp   then stage tool-manifest.digest.json"
        echo "Skip it with: CARBON_SKIP_MANIFEST_CHECK=1 git commit ..."
        exit 1
    fi
fi