The VS Code of video editing, built for agents.
TypeScript
Refactor development scripts and update README for clarity
konstantin-paulus4037744faf95
diff --git a/README.md b/README.mdindex c54202d7..f3738cc2 100644--- a/README.md+++ b/README.md@@ -111,16 +111,19 @@ npm installcp apps/web/.env.example apps/web/.env # required: the app won't run without it-npm run dev # editor in the browser (Vite dev server)-npm run dev:desktop # editor as a desktop app (Electron)+npm run dev:web # editor in the browser (Vite dev server)+# or+npm run dev:desktop # editor as a desktop app (Electron): builds the CLI, starts the web server, launches the app```-To build the CLI and put `dapi` on your PATH (macOS/Homebrew layout; adjust the link target for other setups):+To put `dapi` on your PATH (macOS/Homebrew layout; adjust the link target for other setups), link it once:```shnpm run symlink:create --workspace=@diffusionstudio/cli```+The link points at the CLI build, which `npm run dev:desktop` refreshes on every start, so the linked `dapi` always runs the latest code.+Before sending a PR:```shdiff --git a/apps/web/vite.config.ts b/apps/web/vite.config.tsindex f578fc6a..0c0c594a 100644--- a/apps/web/vite.config.ts+++ b/apps/web/vite.config.ts@@ -19,6 +19,8 @@ export default defineConfig({APP_VERSION: JSON.stringify(pkg.version),},server: {+ port: 5173,+ strictPort: true,headers: {'Cross-Origin-Opener-Policy': 'same-origin','Cross-Origin-Embedder-Policy': 'credentialless',diff --git a/package.json b/package.jsonindex df95d903..c922e5f4 100644--- a/package.json+++ b/package.json@@ -6,8 +6,9 @@"type": "module","workspaces": ["apps/*", "packages/*"],"scripts": {- "dev": "npm run dev --workspace=@diffusionstudio/web",- "dev:desktop": "npm run dev --workspace=@diffusionstudio/desktop",+ "dev": "npm run dev:web",+ "dev:web": "npm run dev --workspace=@diffusionstudio/web",+ "dev:desktop": "node scripts/dev-desktop.mjs","build": "npm run build --workspace=@diffusionstudio/web","build:web": "npm run build --workspace=@diffusionstudio/web","build:desktop": "npm run build --workspace=@diffusionstudio/desktop",diff --git a/scripts/dev-desktop.mjs b/scripts/dev-desktop.mjsnew file mode 100644index 00000000..553b0840--- /dev/null+++ b/scripts/dev-desktop.mjs@@ -0,0 +1,90 @@+/* This Source Code Form is subject to the terms of the Mozilla Public+ * License, v. 2.0. If a copy of the MPL was not distributed with this+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */++// One command to develop the desktop app from source. It:+// 1. builds the CLI, so a linked `dapi` (see symlink:create) runs the+// latest code and the app's headless server matches it;+// 2. starts the web dev server (Vite on :5173);+// 3. waits for that server, then launches Electron, which loads it.+// Ctrl-C tears the whole tree down.++import { spawn, execFileSync } from "node:child_process";+import { get } from "node:http";++const DEV_URL = "http://localhost:5173";+const children = [];+let shuttingDown = false;++function run(name, args) {+ // Own process group (detached) so we can signal the npm process *and* its+ // grandchildren (vite, electron) in one shot on teardown.+ const child = spawn("npm", args, { stdio: "inherit", detached: true });+ child.on("exit", (code) => {+ if (shuttingDown) return;+ // A child dying on its own (e.g. Vite crashed) should bring the rest down.+ console.error(`\n[dev:desktop] ${name} exited (${code}); shutting down.`);+ shutdown(code ?? 1);+ });+ children.push(child);+ return child;+}++function shutdown(code) {+ if (shuttingDown) return;+ shuttingDown = true;+ for (const child of children) {+ try {+ process.kill(-child.pid, "SIGTERM");+ } catch {+ // Already gone.+ }+ }+ process.exit(code);+}++// Resolves once the dev server answers. Probes over HTTP against the same URL+// Electron loads, so we follow its host resolution (Vite binds localhost as+// IPv6 ::1) rather than guessing an address family.+function waitForServer(url, timeoutMs = 30000) {+ const deadline = Date.now() + timeoutMs;+ return new Promise((resolve, reject) => {+ const tryOnce = () => {+ const req = get(url, (res) => {+ res.destroy();+ resolve(); // Any response means the server is up.+ });+ req.once("error", () => {+ req.destroy();+ if (Date.now() > deadline) {+ reject(new Error(`Vite did not come up at ${url} in time`));+ } else {+ setTimeout(tryOnce, 200);+ }+ });+ };+ tryOnce();+ });+}++for (const signal of ["SIGINT", "SIGTERM"]) {+ process.on(signal, () => shutdown(0));+}++// 1. Build the CLI (blocking) so `dapi` and the app agree on the latest code.+console.log("[dev:desktop] building CLI…");+execFileSync("npm", ["run", "build", "--workspace=@diffusionstudio/cli"], { stdio: "inherit" });++// 2. Start the web dev server.+console.log("[dev:desktop] starting web dev server…");+run("web", ["run", "dev", "--workspace=@diffusionstudio/web"]);++// 3. Once it is up, launch Electron (its own build runs first, loads :5173).+try {+ await waitForServer(DEV_URL);+} catch (err) {+ console.error(`[dev:desktop] ${err.message}`);+ shutdown(1);+}+console.log("[dev:desktop] starting desktop app…");+run("desktop", ["run", "dev", "--workspace=@diffusionstudio/desktop"]);