Skip to content

Open source CapCut alternative.

TypeScript

build(app): build the Cut engine automatically in dev and packaging

David Le9cbdb9f3291c
diff --git a/.github/workflows/nightly-donkey-build.yml b/.github/workflows/nightly-donkey-build.yml
index 4e53eb6a..01e30c73 100644
--- a/.github/workflows/nightly-donkey-build.yml
+++ b/.github/workflows/nightly-donkey-build.yml
@@ -89,24 +89,15 @@ jobs:
brew install imagemagick
fi
- # The Donkey Cut engine — the local server behind cut.donkeyuse.com — ships inside the
- # app and is version-locked to it. Built from site/ with bun (a devDependency there).
- - name: Build Donkey Cut engine
- if: steps.changes.outputs.should_build == 'true'
- working-directory: site
- run: |
- npm ci
- npm run engine:build
-
# The bundled CLI tools (ffmpeg, lit, pdf-fill, …) are NOT baked into the app: it downloads
# them on first run from the artifact published by the Publish Bundled Tools workflow, so the
- # nightly package builds without vendoring them here.
+ # nightly package builds without vendoring them here. The Donkey Cut engine (the local server
+ # behind cut.donkeyuse.com) IS built and bundled by package-donkey-app.sh — no separate step.
- name: Package Donkey
if: steps.changes.outputs.should_build == 'true'
env:
DONKEY_APP_VERSION: ${{ steps.nightly.outputs.version }}
DONKEY_APP_BUILD: ${{ steps.nightly.outputs.build }}
- DONKEY_CUT_ENGINE_BIN: ${{ github.workspace }}/site/dist/cut-engine/donkey-cut-engine-arm64
run: ./scripts/package-donkey-app.sh
- name: Generate checksum
diff --git a/docs/guides/cut.md b/docs/guides/cut.md
index e96d11f3..da64a74c 100644
--- a/docs/guides/cut.md
+++ b/docs/guides/cut.md
@@ -28,7 +28,7 @@ Every Cut API route is a framework-free handler (web-standard request in, respon
## The engine
-The engine is a single compiled binary built from the site's Cut code (`npm run engine:build` in `site/`) and version-locked to the app: the app stamps its own release version into the engine's environment, and updates ride app releases. The Donkey app spawns it at launch — regardless of sign-in, since Cut is free and standalone — restarts it with backoff if it dies, skips spawning when another engine already answers on the port, and stops it on quit. Its data lives under the user's Application Support; its logs under the user's Logs folder.
+The engine is a single compiled binary built from the site's Cut code and version-locked to the app: the app's dev run script and release packaging build and bundle it automatically (no separate step), and the app stamps its own release version into the engine's environment, so updates ride app releases. The Donkey app spawns it at launch — regardless of sign-in, since Cut is free and standalone — restarts it with backoff if it dies, skips spawning when another engine already answers on the port, and stops it on quit. Its data lives under the user's Application Support; its logs under the user's Logs folder.
Because a GUI-spawned process inherits a bare PATH, the engine rebuilds it: the app's bundled tools first (bundled tool always wins), then the user's login-shell PATH and common install dirs. That is how it finds ffmpeg, the user's `claude` and `codex`, and the prebuilt speech tool.
diff --git a/plans/cut-engine.md b/plans/cut-engine.md
index bf56e239..9eb94634 100644
--- a/plans/cut-engine.md
+++ b/plans/cut-engine.md
@@ -26,7 +26,7 @@ page polls → connects → works ├─ data: ~/Library/App
└─ version in /api/cut/engine/health
```
-- **Slice 3 — app-side supervision (done)**: the Donkey app spawns the engine at launch regardless of sign-in (Cut is free and standalone), via a supervisor in the runtime module: shell environment from the app's existing helper plus the engine flag, app version stamp, and tools dir; crash restarts with backoff; a health preflight skips spawning when another engine already owns the port; the app's quit path stops it. Engine logs go to the user's Logs folder, size-capped. Staging: dev builds symlink the built binary into the app bundle; release packaging copies and signs it with the JIT entitlements a bun binary needs under the hardened runtime; the nightly workflow builds the engine and passes it to packaging. The app builds clean with all of it.
+- **Slice 3 — app-side supervision (done)**: the Donkey app spawns the engine at launch regardless of sign-in (Cut is free and standalone), via a supervisor in the runtime module: shell environment from the app's existing helper plus the engine flag, app version stamp, and tools dir; crash restarts with backoff; a health preflight skips spawning when another engine already owns the port; the app's quit path stops it. Engine logs go to the user's Logs folder, size-capped. Staging is one automatic step: the dev run script and release packaging each build the engine (via `site/scripts/build-cut-engine.sh`, which installs site deps if missing) and stage it — dev symlinks it, release copies and signs it with the JIT entitlements a bun binary needs under the hardened runtime. `DONKEY_CUT_ENGINE_BIN` can point at a prebuilt binary to skip the build. The app builds clean with all of it.
- **Slice 6 — docs (done)**: `docs/guides/cut.md` describes the app-hosted engine as supported behavior.
## Verification left
@@ -38,4 +38,4 @@ Code-complete and verified as far as this machine allows (engine smoke-tested en
## What Should Be Done Next
-Run a nightly (or local `package-donkey-app.sh` with `DONKEY_CUT_ENGINE_BIN` set), install the dmg, and verify the live path: app launch → engine on 41417 → cut.donkeyuse.com connects and edits. Then move this plan to `plans/done/`.
+Run a nightly (or local `package-donkey-app.sh`, which now builds and bundles the engine itself), install the dmg, and verify the live path: app launch → engine on 41417 → cut.donkeyuse.com connects and edits. Then move this plan to `plans/done/`.
diff --git a/scripts/package-donkey-app.sh b/scripts/package-donkey-app.sh
index 3482b3dd..e81cd13b 100755
--- a/scripts/package-donkey-app.sh
+++ b/scripts/package-donkey-app.sh
@@ -323,17 +323,20 @@ stage_bundled_tools() {
echo "Baked bundled tools from $source_dir into $dest_dir (offline override)."
}
-# The Donkey Cut engine — the local server behind cut.donkeyuse.com — is built from site/ by
-# `npm run engine:build` and version-locked to the app. Point DONKEY_CUT_ENGINE_BIN at the built
-# binary to bundle it; unset ships the app without Cut support.
+# The Donkey Cut engine — the local server behind cut.donkeyuse.com — is version-locked to the
+# app and built here as part of packaging, so one command produces a complete app. Set
+# DONKEY_CUT_ENGINE_BIN to reuse a prebuilt binary (e.g. a cross-arch or cached CI build) instead.
stage_cut_engine() {
local source_bin="${DONKEY_CUT_ENGINE_BIN:-}"
if [ -z "$source_bin" ]; then
- echo "Not bundling the Donkey Cut engine (DONKEY_CUT_ENGINE_BIN unset)."
- return 0
+ local arch
+ arch="$(uname -m)"; [ "$arch" = "x86_64" ] && arch="x64"
+ echo "Building the Donkey Cut engine..."
+ bash "$ROOT_DIR/site/scripts/build-cut-engine.sh"
+ source_bin="$ROOT_DIR/site/dist/cut-engine/donkey-cut-engine-$arch"
fi
if [ ! -f "$source_bin" ]; then
- echo "DONKEY_CUT_ENGINE_BIN=$source_bin does not exist." >&2
+ echo "Donkey Cut engine binary not found at $source_bin." >&2
exit 1
fi
local dest_dir="$RESOURCES_DIR/cut-engine"
diff --git a/scripts/run-donkey-dev.sh b/scripts/run-donkey-dev.sh
index 62be8cb1..6e318bf8 100755
--- a/scripts/run-donkey-dev.sh
+++ b/scripts/run-donkey-dev.sh
@@ -483,11 +483,17 @@ create_debug_app_bundle() {
ln -sfn "$ROOT_DIR/vendor/donkey-tools" "$RESOURCES_DIR/donkey-tools"
fi
- # Stage the Donkey Cut engine (built by `npm run engine:build` in site/) so the app
- # supervises it in dev. Optional: a build without it simply runs Donkey without Cut.
+ # Build and stage the Donkey Cut engine so the app supervises a current copy — no separate
+ # manual build step. Non-fatal: a Cut build hiccup shouldn't block Donkey dev (the app just
+ # runs without Cut). Set DONKEY_BUILD_CUT_ENGINE=0 to skip.
cut_engine_arch="$(uname -m)"
[ "$cut_engine_arch" = "x86_64" ] && cut_engine_arch="x64"
cut_engine="$ROOT_DIR/site/dist/cut-engine/donkey-cut-engine-$cut_engine_arch"
+ if [ "${DONKEY_BUILD_CUT_ENGINE:-1}" != "0" ] && [ -d "$ROOT_DIR/site" ]; then
+ echo "Building Donkey Cut engine..."
+ bash "$ROOT_DIR/site/scripts/build-cut-engine.sh" ||
+ echo "Warning: Cut engine build failed; running Donkey without Cut." >&2
+ fi
if [ -f "$cut_engine" ]; then
mkdir -p "$RESOURCES_DIR/cut-engine"
ln -sf "$cut_engine" "$RESOURCES_DIR/cut-engine/donkey-cut-engine"
diff --git a/site/scripts/build-cut-engine.sh b/site/scripts/build-cut-engine.sh
index 307e6206..51f76b70 100755
--- a/site/scripts/build-cut-engine.sh
+++ b/site/scripts/build-cut-engine.sh
@@ -1,17 +1,24 @@
#!/bin/bash
# Compile the Donkey Cut engine into single-file Mac binaries.
#
-# scripts/build-cut-engine.sh # arm64 (default)
-# ENGINE_ARCHES="arm64 x64" scripts/... # both architectures
+# scripts/build-cut-engine.sh # host arch (default)
+# ENGINE_ARCHES="arm64 x64" scripts/... # explicit architectures
#
-# Output: dist/cut-engine/donkey-cut-engine-<arch>. The Donkey app bundles
-# the binary and spawns it with DONKEY_CUT_ENGINE=1 (see plans/cut-engine.md).
+# Self-contained: installs site deps if they're missing, so dev and packaging can
+# call it directly with no separate setup step. Output:
+# dist/cut-engine/donkey-cut-engine-<arch>. The Donkey app bundles the binary and
+# spawns it with DONKEY_CUT_ENGINE=1 (see plans/cut-engine.md).
set -euo pipefail
cd "$(dirname "$0")/.."
-read -ra arches <<< "${ENGINE_ARCHES:-arm64}"
-mkdir -p dist/cut-engine
+host_arch="$(uname -m)"
+[ "$host_arch" = "x86_64" ] && host_arch="x64"
+read -ra arches <<< "${ENGINE_ARCHES:-$host_arch}"
+
+# bun ships as a site devDependency; make sure it and the engine's imports are present.
+[ -d node_modules ] || npm ci
+mkdir -p dist/cut-engine
for arch in "${arches[@]}"; do
out="dist/cut-engine/donkey-cut-engine-$arch"
echo "==> bun build --compile ($arch)"