@powerhousedao/desktop 0.0.0-stage → 6.2.3-dev.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,333 @@
1
+ import { z } from "zod";
2
+ import { ChildProcess } from "node:child_process";
3
+ import "@powerhousedao/host-core";
4
+ import { PHBackground } from "@powerhousedao/shared/clis";
5
+ //#region src/app-json.d.ts
6
+ export declare const appJsonSchema: z.ZodObject<{
7
+ identifier: z.ZodString;
8
+ productName: z.ZodString;
9
+ signIn: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
10
+ icon: z.ZodString;
11
+ background: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
12
+ color: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
13
+ light: z.ZodString;
14
+ dark: z.ZodOptional<z.ZodNullable<z.ZodString>>;
15
+ }, z.core.$strict>]>>>;
16
+ layers: z.ZodArray<z.ZodObject<{
17
+ src: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
18
+ light: z.ZodString;
19
+ dark: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
+ }, z.core.$strict>]>;
21
+ position: z.ZodOptional<z.ZodNullable<z.ZodObject<{
22
+ top: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
23
+ right: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
24
+ bottom: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
25
+ left: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
26
+ }, z.core.$strict>>>;
27
+ width: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
28
+ height: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
29
+ minWidth: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
30
+ minHeight: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
31
+ maxWidth: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
32
+ maxHeight: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
33
+ opacity: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
34
+ fade: z.ZodOptional<z.ZodNullable<z.ZodObject<{
35
+ top: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
36
+ right: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
37
+ bottom: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
38
+ left: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
39
+ }, z.core.$strict>>>;
40
+ }, z.core.$strict>>;
41
+ }, z.core.$strict>]>>>;
42
+ splash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
43
+ splashDark: z.ZodOptional<z.ZodNullable<z.ZodString>>;
44
+ loading: z.ZodOptional<z.ZodNullable<z.ZodObject<{
45
+ background: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
+ color: z.ZodOptional<z.ZodNullable<z.ZodString>>;
47
+ accent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
48
+ message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
49
+ dark: z.ZodOptional<z.ZodNullable<z.ZodObject<{
50
+ background: z.ZodOptional<z.ZodNullable<z.ZodString>>;
51
+ color: z.ZodOptional<z.ZodNullable<z.ZodString>>;
52
+ accent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
53
+ }, z.core.$strict>>>;
54
+ art: z.ZodOptional<z.ZodNullable<z.ZodString>>;
55
+ artDark: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ }, z.core.$strict>>>;
57
+ window: z.ZodOptional<z.ZodObject<{
58
+ title: z.ZodOptional<z.ZodString>;
59
+ width: z.ZodOptional<z.ZodNumber>;
60
+ height: z.ZodOptional<z.ZodNumber>;
61
+ resizable: z.ZodOptional<z.ZodBoolean>;
62
+ minWidth: z.ZodOptional<z.ZodNumber>;
63
+ minHeight: z.ZodOptional<z.ZodNumber>;
64
+ }, z.core.$strict>>;
65
+ fileAssociations: z.ZodOptional<z.ZodArray<z.ZodObject<{
66
+ ext: z.ZodArray<z.ZodString>;
67
+ name: z.ZodString;
68
+ description: z.ZodOptional<z.ZodString>;
69
+ mimeType: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$strict>>>;
71
+ shell: z.ZodOptional<z.ZodObject<{
72
+ path: z.ZodOptional<z.ZodString>;
73
+ git: z.ZodOptional<z.ZodString>;
74
+ tag: z.ZodOptional<z.ZodString>;
75
+ rev: z.ZodOptional<z.ZodString>;
76
+ version: z.ZodOptional<z.ZodString>;
77
+ }, z.core.$strict>>;
78
+ }, z.core.$strict>;
79
+ type AppJson = z.infer<typeof appJsonSchema>;
80
+ type AppJsonShellSource = NonNullable<AppJson["shell"]>;
81
+ /** Default crates.io version requirement for the shell crate (D7.b: the flip
82
+ * to crates.io default once published — the crate is live). A floor, not just
83
+ * a series: 0.1.0 can't run a stack from ph-run, and a Cargo.lock that still
84
+ * holds it satisfies "0.1", so a builder's lock would keep it forever. The
85
+ * 0.1.0-dev.N releases sort below 0.1.0 and never match either. */
86
+ export declare const DEFAULT_SHELL_CRATE_VERSION = "0.1.1";
87
+ export declare const APP_JSON_FILE = "app.json";
88
+ /** Read + validate hosts/<host>/app.json. Throws with the field named on a
89
+ * bad value, and a clear message when the file is absent. */
90
+ export declare function loadAppJson(hostDir: string): AppJson;
91
+ /** A filesystem/crate-safe slug of the product name — the generated binary
92
+ * and Cargo package name. Falls back to the identifier's last segment. */
93
+ export declare function appSlug(app: AppJson): string;
94
+ //#endregion
95
+ //#region src/bundle-stack.d.ts
96
+ interface BundleStackOptions {
97
+ projectRoot: string;
98
+ shellProjectDir: string;
99
+ /** Vendor the runtime packages (slow). Skipped when false — an existing
100
+ * vendored tree is left in place. */
101
+ vendor?: boolean;
102
+ /** The version/tag of ph-run to vendor, which ph-cli publishes alongside.
103
+ * Default: the ph-cli the project has installed, else "dev". Until a nightly
104
+ * carries it, pass `phCliSpec` with a locally packed tarball instead. */
105
+ phCliVersion?: string;
106
+ /** Overrides ph-run's install spec entirely (e.g. a `pnpm pack` tarball path
107
+ * for a not-yet-published build). */
108
+ phCliSpec?: string;
109
+ /** A directory of `pnpm pack` tarballs (env PH_DESKTOP_LOCAL_PACKAGES).
110
+ * Each replaces its package everywhere in the vendored tree: a packed
111
+ * ph-run alone would still pull its dependencies, at the same version
112
+ * number, from the registry. `pnpm pack:desktop-stack` in the monorepo
113
+ * packs the set ph-run and host-core need. */
114
+ localPackagesDir?: string;
115
+ /** Packages the hosts' plugins come from. The stack resolves them from its
116
+ * own node_modules, and ph-run brings only what it depends on. */
117
+ plugins?: readonly string[];
118
+ /** Files the hosts name by a project path, such as drive icons, staged at
119
+ * the same paths: at run time the stack is the project root. */
120
+ projectFiles?: readonly string[];
121
+ /** The connect member's port — written into the stack's shell.json so the
122
+ * shell knows where to probe/navigate with no environment at all. */
123
+ connectPort?: number;
124
+ /** Absolute paths to skip when staging `hosts/` — in mode 1 the generated
125
+ * shell dir sits under `hosts/` and must not be copied into itself. */
126
+ excludeDirs?: string[];
127
+ logger?: (message: string) => void;
128
+ }
129
+ interface BundleStackResult {
130
+ stackDir: string;
131
+ vendored: boolean;
132
+ }
133
+ /**
134
+ * Removes what a running app never reads. Windows creates and scans each file
135
+ * on its own, so these, over half the stack, were over half the install.
136
+ *
137
+ * @returns How many files went
138
+ */
139
+ export declare function pruneStack(dir: string, inPackages?: boolean): number;
140
+ export declare function bundleStack(options: BundleStackOptions): BundleStackResult;
141
+ //#endregion
142
+ //#region src/shell-project.d.ts
143
+ /**
144
+ * P7.3 — project `hosts/desktop/app.json` into a generated `tauri-shell/`:
145
+ * a STANDALONE tauri crate that depends on the published `ph-desktop-shell`
146
+ * library, carries the builder's identity, and is built/run by the desktop
147
+ * runner's dev/build verbs. The builder never writes Rust.
148
+ *
149
+ * Everything here mirrors the known-good reference app
150
+ * (ph-desktop-shell/apps/powerhouse-desktop): the tauri plumbing (main.rs,
151
+ * build.rs, capabilities, the loading page, externalBin + icon mechanics) is
152
+ * copied verbatim; only identity/port fields are projected from app.json. The
153
+ * projection is idempotent and stale-detected — a file is rewritten only when
154
+ * its content changes, so Cargo.lock, the generated icon set, and tauri-build
155
+ * output are never disturbed by a regen with an unchanged app.json.
156
+ */
157
+ export declare const SHELL_DIR = "tauri-shell";
158
+ /** The icon source the runner feeds to `tauri icon` (copied from app.icon). */
159
+ export declare const ICON_SOURCE = "app-icon.png";
160
+ interface ProjectShellInput {
161
+ /** hosts/<host>/ — where app.json lives and tauri-shell/ is written. */
162
+ hostDir: string;
163
+ app: AppJson;
164
+ /** The connect member's port — baked into the remote capability so the
165
+ * served Connect origin can reach the shell's launch-queue commands. */
166
+ connectPort: number;
167
+ /** The app's version: the project's package.json version. */
168
+ version?: string;
169
+ /** The sign-in page's script, where the built one isn't to hand. */
170
+ signInScript?: Buffer;
171
+ }
172
+ interface ProjectShellResult {
173
+ shellDir: string;
174
+ /** The crate/bin name (and the built exe stem the runner looks for). */
175
+ binName: string;
176
+ /** True when any projected file was created or changed this call. */
177
+ changed: boolean;
178
+ }
179
+ /**
180
+ * Materialize/refresh `<hostDir>/tauri-shell/` from app.json. Idempotent:
181
+ * unchanged app.json rewrites nothing. Does NOT run `tauri icon` or fetch the
182
+ * node binary — those are toolchain steps the runner performs at dev/build.
183
+ */
184
+ export declare function projectShell(input: ProjectShellInput): ProjectShellResult;
185
+ //#endregion
186
+ //#region src/scaffold.d.ts
187
+ /**
188
+ * P7.5 — scaffold a builder-owned desktop identity: `hosts/desktop/app.json`
189
+ * (the ONE file a builder edits), a placeholder square icon source, and a
190
+ * `.gitignore` for the generated shell. `ph generate desktop-shell` calls
191
+ * this; the runner's dev/build then project app.json into `tauri-shell/`.
192
+ */
193
+ interface ScaffoldDesktopShellOptions {
194
+ /** Reverse-DNS app identifier (e.g. com.acme.app). */
195
+ identifier: string;
196
+ /** Human product name (the window title + macOS app name). */
197
+ productName: string;
198
+ /** Overwrite an existing app.json (default: refuse, to protect edits). */
199
+ force?: boolean;
200
+ /** The loading page's background, with its paths already relative to the
201
+ * host directory (see `rebaseBackground`); `ph generate desktop-shell`
202
+ * passes Connect's `connect.home.background`. Default: none. */
203
+ background?: PHBackground | null;
204
+ }
205
+ /**
206
+ * A background whose project-relative paths are rewritten to be relative to
207
+ * another directory (powerhouse.config.json's root -> hosts/desktop, where
208
+ * app.json resolves them from). URLs and data URIs are left as they are.
209
+ */
210
+ export declare function rebaseBackground(background: PHBackground, fromDir: string, toDir: string): PHBackground;
211
+ interface ScaffoldResult {
212
+ hostDir: string;
213
+ /** Files created this call (absolute paths). */
214
+ created: string[];
215
+ /** Files already present and left untouched. */
216
+ skipped: string[];
217
+ }
218
+ /** Minimal PNG encoder — a solid square so `tauri icon` always has a valid
219
+ * source. Pure Node (zlib); no binary asset ships in the package. The builder
220
+ * replaces it with their real 1024×1024 artwork. */
221
+ export declare function solidPng(size: number, rgba: [number, number, number, number]): Buffer;
222
+ export declare function scaffoldDesktopShell(hostDir: string, options: ScaffoldDesktopShellOptions): ScaffoldResult;
223
+ //#endregion
224
+ //#region src/shell-toolchain.d.ts
225
+ /**
226
+ * The native toolchain the generated shell (mode 1) needs to build/run, and
227
+ * the provisioning steps around it. `cargo tauri dev|build` compiles the
228
+ * generated crate — but tauri-build validates two things AT COMPILE TIME that
229
+ * must exist first (both confirmed against a live `cargo check`):
230
+ * - the node sidecar `binaries/node-<triple>` (externalBin), and
231
+ * - `icons/icon.ico` on Windows (the app's Win32 resource).
232
+ * So dev/build provision the sidecar + icon set before invoking tauri, and
233
+ * fail with install guidance when cargo or the Tauri CLI is absent — a
234
+ * missing executable must read as a clear instruction, never a deep cargo
235
+ * stack trace.
236
+ */
237
+ interface NodeTarget {
238
+ triple: string;
239
+ dist: string;
240
+ /** Path within the extracted archive (POSIX) / "node.exe" on Windows. */
241
+ bin: string;
242
+ ext: string;
243
+ }
244
+ /** The Node release triple for a build host — the sidecar filename tauri
245
+ * resolves (`node-<triple>`). Pure, so the mapping is unit-tested. */
246
+ export declare function nodeSidecarTarget(platform: NodeJS.Platform, arch: string): NodeTarget;
247
+ /** Fetch the stock Node the shell ships as its sidecar into `<shellDir>/
248
+ * binaries`, named per target triple. No-op when already present. Ported from
249
+ * the reference repo's fetch-node.mjs (the builder has no such script). */
250
+ export declare function fetchNodeSidecar(shellDir: string, version?: string, platform?: NodeJS.Platform, arch?: string): string;
251
+ /** Default bundle targets for the build host (`cargo tauri build --bundles`).
252
+ * macOS gets app+dmg, Windows nsis, Linux deb+appimage — a host only builds
253
+ * installers it can produce. */
254
+ export declare function tauriBundlesForHost(platform?: NodeJS.Platform): string[];
255
+ interface TauriCommand {
256
+ /** The executable to spawn (e.g. "cargo" or a node path). */
257
+ cmd: string;
258
+ /** Args that precede the tauri subcommand (e.g. ["tauri"] for cargo). */
259
+ prefix: string[];
260
+ /** How the CLI was found — for logging + the preflight message. */
261
+ via: "cargo-tauri" | "node-cli";
262
+ }
263
+ /** Resolve a Tauri CLI: a global `cargo tauri`, else a `@tauri-apps/cli`
264
+ * resolvable from the project. Returns null when neither is available. */
265
+ export declare function resolveTauriCommand(projectRoot: string): TauriCommand | null;
266
+ interface Toolchain {
267
+ cargo: boolean;
268
+ tauri: TauriCommand | null;
269
+ }
270
+ export declare function detectToolchain(projectRoot: string): Toolchain;
271
+ /** Throw a clear, actionable error when the native toolchain is incomplete —
272
+ * the desktop verbs call this before any cargo work so a missing executable
273
+ * is an instruction, not a stack trace. */
274
+ export declare function preflightOrThrow(tc: Toolchain, hostName: string): TauriCommand;
275
+ /** `<tauri> icon <source>` — generates the per-platform icon set (icon.ico +
276
+ * icon.icns + pngs) the bundle references and tauri-build requires. */
277
+ export declare function runTauriIcon(tauri: TauriCommand, shellDir: string, iconSource: string): void;
278
+ //#endregion
279
+ //#region src/shell.d.ts
280
+ /**
281
+ * Shell discovery and launch. The Rust/Tauri shell lives in the
282
+ * ph-win-desktop repo (cargo cannot ride an npm package); the runner locates
283
+ * a checkout via `runner.shell.project` or PH_DESKTOP_SHELL and prefers its
284
+ * BUILT exe (dev config like window title is baked into a build — the
285
+ * `--config` projection below applies to tauri-cli invocations only).
286
+ */
287
+ interface ShellOptions {
288
+ /** Path to a ph-win-desktop checkout (absolute or project-relative). */
289
+ project?: string;
290
+ window?: {
291
+ title?: string;
292
+ width?: number;
293
+ height?: number;
294
+ };
295
+ tray?: boolean;
296
+ fileAssociations?: string[];
297
+ }
298
+ interface ResolvedShell {
299
+ projectDir: string;
300
+ /** A built exe when one exists (debug preferred for dev), else undefined →
301
+ * fall back to `pnpm tauri dev`. */
302
+ exe?: string;
303
+ }
304
+ export declare function resolveShell(projectRoot: string, options: ShellOptions | undefined, env: Record<string, string | undefined>): ResolvedShell;
305
+ /** Resolve the project's ph-cli entry from ITS dependency tree — the same
306
+ * resolution `ph run` itself uses. */
307
+ export declare function resolvePhCliEntry(projectRoot: string): string;
308
+ /** The env trio (plus flag and userData) the shell's uniform-runners mode
309
+ * reads — wired by the RUNNER so nobody exports variables by hand. */
310
+ export declare function shellEnv(projectRoot: string, connectPort: number, env: Record<string, string | undefined>): Record<string, string>;
311
+ /** Project host shell options onto a tauri `--config` merge patch (D6.d) —
312
+ * the host file stays the single source for app identity on tauri-cli
313
+ * invocations; a built exe has these baked. */
314
+ export declare function tauriConfigPatch(options: ShellOptions | undefined): Record<string, unknown> | undefined;
315
+ export declare function launchShell(shell: ResolvedShell, envVars: Record<string, string>, options: ShellOptions | undefined): ChildProcess;
316
+ //#endregion
317
+ //#region src/bundle-backend.d.ts
318
+ interface BundleBackendOptions {
319
+ /** A staged stack, with its node_modules installed. */
320
+ stackDir: string;
321
+ logger?: (line: string) => void;
322
+ }
323
+ interface BundleBackendResult {
324
+ chunks: number;
325
+ removedPackages: number;
326
+ keptPackages: number;
327
+ }
328
+ /** Replaces a staged stack's node_modules with a bundle of it. */
329
+ export declare function bundleBackend(options: BundleBackendOptions): Promise<BundleBackendResult>;
330
+ //#endregion
331
+ export type { AppJson, AppJsonShellSource, BundleBackendResult, BundleStackOptions, BundleStackResult, NodeTarget, ProjectShellInput, ProjectShellResult, ResolvedShell, ScaffoldDesktopShellOptions, ScaffoldResult, ShellOptions, TauriCommand, Toolchain };
332
+ export {};
333
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/app-json.ts","../src/bundle-stack.ts","../src/shell-project.ts","../src/scaffold.ts","../src/shell-toolchain.ts","../src/shell.ts","../src/bundle-backend.ts"],"mappings":";;;;;qBA8Ja,eAAa,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyBxB,EAAA,KAAA;KAEU,UAAU,EAAE,aAAa;KACzB,qBAAqB,YAAY;;;;;;qBAOhC;qBAEA;;;wBAIG,YAAY,kBAAkB;;;wBA2B9B,QAAQ,KAAK;;;UCvGZ;EACf;EACA;;;EAGA;;;;EAIA;;;EAGA;;;;;;EAMA;;;EAGA;;;EAGA;;;EAGA;;;EAGA;EACA,UAAU;;UAGK;EACf;EACA;;;;;;;;wBAiNc,WAAW,aAAa;wBA2BxB,YAAY,SAAS,qBAAqB;;;;;;;;;;;;;;;;;qBC3W7C;;qBAEA;UAEI;;EAEf;EACA,KAAK;;;EAGL;;EAEA;;EAEA,eAAe;;UAUA;EACf;;EAEA;;EAEA;;;;;;;wBAwdc,aAAa,OAAO,oBAAoB;;;;;;;;;UCtgBvC;;EAEf;;EAEA;;EAEA;;;;EAIA,aAAa;;;;;;;wBAQC,iBACd,YAAY,cACZ,iBACA,gBACC;UAcc;EACf;;EAEA;;EAEA;;;;;wBAMc,SACd,cACA,yCACC;wBAoEa,qBACd,iBACA,SAAS,8BACR;;;;;;;;;;;;;;;UCrHc;EACf;EACA;;EAEA;EACA;;;;wBAKc,kBACd,UAAU,OAAO,UACjB,eACC;;;;wBAwCa,iBACd,kBACA,kBACA,WAAU,OAAO,UACjB;;;;wBA2Bc,oBACd,WAAU,OAAO;UAYF;;EAEf;;EAEA;;EAEA;;;;wBAuCc,oBAAoB,sBAAsB;UA6BzC;EACf;EACA,OAAO;;wBAGO,gBAAgB,sBAAsB;;;;wBAOtC,iBACd,IAAI,WACJ,mBACC;;;wBA2Ba,aACd,OAAO,cACP,kBACA;;;;;;;;;;UC7Ne;;EAEf;EACA;IAAW;IAAgB;IAAgB;;EAC3C;EACA;;UAGe;EACf;;;EAGA;;wBAGc,aACd,qBACA,SAAS,0BACT,KAAK,qCACJ;;;wBA4Ba,kBAAkB;;;wBAUlB,SACd,qBACA,qBACA,KAAK,qCACJ;;;;wBAaa,iBACd,SAAS,2BACR;wBA2Ba,YACd,OAAO,eACP,SAAS,wBACT,SAAS,2BACR;;;UCyLc;;EAEf;EACA,UAAU;;UAGK;EACf;EACA;EACA;;;wBAIoB,cACpB,SAAS,uBACR,QAAQ"}
package/dist/index.mjs ADDED
@@ -0,0 +1,149 @@
1
+ import { C as appJsonSchema, S as DEFAULT_SHELL_CRATE_VERSION, T as loadAppJson, _ as projectShell, a as shellEnv, b as pruneStack, c as fetchNodeSidecar, d as resolveTauriCommand, f as runTauriIcon, g as SHELL_DIR, h as ICON_SOURCE, i as resolveShell, l as nodeSidecarTarget, n as launchShell, o as tauriConfigPatch, p as tauriBundlesForHost, r as resolvePhCliEntry, s as detectToolchain, t as bundleBackend, u as preflightOrThrow, v as bundleStack, w as appSlug, x as APP_JSON_FILE } from "./bundle-backend-CvUS8-oc.mjs";
2
+ import { mapBackgroundImages } from "@powerhousedao/shared/connect";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { isPassthroughImageRef } from "@powerhousedao/shared/connect/image-ref";
6
+ import { deflateSync } from "node:zlib";
7
+ //#region src/scaffold.ts
8
+ /**
9
+ * A background whose project-relative paths are rewritten to be relative to
10
+ * another directory (powerhouse.config.json's root -> hosts/desktop, where
11
+ * app.json resolves them from). URLs and data URIs are left as they are.
12
+ */
13
+ function rebaseBackground(background, fromDir, toDir) {
14
+ const rebase = (ref) => {
15
+ if (isPassthroughImageRef(ref)) return ref;
16
+ const rel = path.relative(toDir, path.resolve(fromDir, ref)).split(path.sep).join("/");
17
+ return rel.startsWith(".") ? rel : `./${rel}`;
18
+ };
19
+ return typeof background === "string" ? rebase(background) : mapBackgroundImages(background, rebase);
20
+ }
21
+ /** Minimal PNG encoder — a solid square so `tauri icon` always has a valid
22
+ * source. Pure Node (zlib); no binary asset ships in the package. The builder
23
+ * replaces it with their real 1024×1024 artwork. */
24
+ function solidPng(size, rgba) {
25
+ const [r, g, b, a] = rgba;
26
+ const row = Buffer.alloc(1 + size * 4);
27
+ for (let x = 0; x < size; x++) {
28
+ const o = 1 + x * 4;
29
+ row[o] = r;
30
+ row[o + 1] = g;
31
+ row[o + 2] = b;
32
+ row[o + 3] = a;
33
+ }
34
+ const raw = Buffer.concat(Array.from({ length: size }, () => row));
35
+ const idat = deflateSync(raw);
36
+ const chunk = (type, data) => {
37
+ const len = Buffer.alloc(4);
38
+ len.writeUInt32BE(data.length, 0);
39
+ const typeBuf = Buffer.from(type, "ascii");
40
+ const body = Buffer.concat([typeBuf, data]);
41
+ const crc = Buffer.alloc(4);
42
+ crc.writeUInt32BE(crc32(body) >>> 0, 0);
43
+ return Buffer.concat([
44
+ len,
45
+ body,
46
+ crc
47
+ ]);
48
+ };
49
+ const ihdr = Buffer.alloc(13);
50
+ ihdr.writeUInt32BE(size, 0);
51
+ ihdr.writeUInt32BE(size, 4);
52
+ ihdr[8] = 8;
53
+ ihdr[9] = 6;
54
+ ihdr[10] = 0;
55
+ ihdr[11] = 0;
56
+ ihdr[12] = 0;
57
+ return Buffer.concat([
58
+ Buffer.from([
59
+ 137,
60
+ 80,
61
+ 78,
62
+ 71,
63
+ 13,
64
+ 10,
65
+ 26,
66
+ 10
67
+ ]),
68
+ chunk("IHDR", ihdr),
69
+ chunk("IDAT", idat),
70
+ chunk("IEND", Buffer.alloc(0))
71
+ ]);
72
+ }
73
+ let crcTable;
74
+ function crc32(buf) {
75
+ if (!crcTable) {
76
+ crcTable = [];
77
+ for (let n = 0; n < 256; n++) {
78
+ let c = n;
79
+ for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
80
+ crcTable[n] = c;
81
+ }
82
+ }
83
+ let crc = 4294967295;
84
+ for (let i = 0; i < buf.length; i++) crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
85
+ return crc ^ 4294967295;
86
+ }
87
+ const GITIGNORE = `# Generated tauri shell — only Cargo.lock and app-icon.png are tracked.
88
+ /tauri-shell/target
89
+ /tauri-shell/gen
90
+ /tauri-shell/icons
91
+ /tauri-shell/dist-stack
92
+ /tauri-shell/binaries
93
+ `;
94
+ function scaffoldDesktopShell(hostDir, options) {
95
+ const created = [];
96
+ const skipped = [];
97
+ fs.mkdirSync(hostDir, { recursive: true });
98
+ const iconFile = "icon.png";
99
+ const app = {
100
+ identifier: options.identifier,
101
+ productName: options.productName,
102
+ icon: `./${iconFile}`,
103
+ background: options.background ?? null,
104
+ loading: null,
105
+ window: {
106
+ title: options.productName,
107
+ width: 1440,
108
+ height: 900
109
+ },
110
+ fileAssociations: [{
111
+ ext: ["phd"],
112
+ name: "Powerhouse Document",
113
+ mimeType: "application/vnd.powerhouse.document+zip"
114
+ }]
115
+ };
116
+ appJsonSchema.parse(app);
117
+ const appJsonPath = path.join(hostDir, APP_JSON_FILE);
118
+ if (fs.existsSync(appJsonPath) && !options.force) skipped.push(appJsonPath);
119
+ else {
120
+ fs.writeFileSync(appJsonPath, `${JSON.stringify(app, null, 2)}\n`);
121
+ created.push(appJsonPath);
122
+ }
123
+ const iconPath = path.join(hostDir, iconFile);
124
+ if (fs.existsSync(iconPath)) skipped.push(iconPath);
125
+ else {
126
+ fs.writeFileSync(iconPath, solidPng(1024, [
127
+ 79,
128
+ 70,
129
+ 229,
130
+ 255
131
+ ]));
132
+ created.push(iconPath);
133
+ }
134
+ const gitignorePath = path.join(hostDir, ".gitignore");
135
+ if (fs.existsSync(gitignorePath)) skipped.push(gitignorePath);
136
+ else {
137
+ fs.writeFileSync(gitignorePath, GITIGNORE);
138
+ created.push(gitignorePath);
139
+ }
140
+ return {
141
+ hostDir,
142
+ created,
143
+ skipped
144
+ };
145
+ }
146
+ //#endregion
147
+ export { APP_JSON_FILE, DEFAULT_SHELL_CRATE_VERSION, ICON_SOURCE, SHELL_DIR, appJsonSchema, appSlug, bundleBackend, bundleStack, detectToolchain, fetchNodeSidecar, launchShell, loadAppJson, nodeSidecarTarget, preflightOrThrow, projectShell, pruneStack, rebaseBackground, resolvePhCliEntry, resolveShell, resolveTauriCommand, runTauriIcon, scaffoldDesktopShell, shellEnv, solidPng, tauriBundlesForHost, tauriConfigPatch };
148
+
149
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/scaffold.ts"],"sourcesContent":["import type { PHBackground } from \"@powerhousedao/shared/clis\";\nimport { mapBackgroundImages } from \"@powerhousedao/shared/connect\";\nimport { isPassthroughImageRef } from \"@powerhousedao/shared/connect/image-ref\";\nimport { deflateSync } from \"node:zlib\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { appJsonSchema, APP_JSON_FILE, type AppJson } from \"./app-json.js\";\n\n/**\n * P7.5 — scaffold a builder-owned desktop identity: `hosts/desktop/app.json`\n * (the ONE file a builder edits), a placeholder square icon source, and a\n * `.gitignore` for the generated shell. `ph generate desktop-shell` calls\n * this; the runner's dev/build then project app.json into `tauri-shell/`.\n */\n\nexport interface ScaffoldDesktopShellOptions {\n /** Reverse-DNS app identifier (e.g. com.acme.app). */\n identifier: string;\n /** Human product name (the window title + macOS app name). */\n productName: string;\n /** Overwrite an existing app.json (default: refuse, to protect edits). */\n force?: boolean;\n /** The loading page's background, with its paths already relative to the\n * host directory (see `rebaseBackground`); `ph generate desktop-shell`\n * passes Connect's `connect.home.background`. Default: none. */\n background?: PHBackground | null;\n}\n\n/**\n * A background whose project-relative paths are rewritten to be relative to\n * another directory (powerhouse.config.json's root -> hosts/desktop, where\n * app.json resolves them from). URLs and data URIs are left as they are.\n */\nexport function rebaseBackground(\n background: PHBackground,\n fromDir: string,\n toDir: string,\n): PHBackground {\n const rebase = (ref: string): string => {\n if (isPassthroughImageRef(ref)) return ref;\n const rel = path\n .relative(toDir, path.resolve(fromDir, ref))\n .split(path.sep)\n .join(\"/\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n };\n return typeof background === \"string\"\n ? rebase(background)\n : mapBackgroundImages(background, rebase);\n}\n\nexport interface ScaffoldResult {\n hostDir: string;\n /** Files created this call (absolute paths). */\n created: string[];\n /** Files already present and left untouched. */\n skipped: string[];\n}\n\n/** Minimal PNG encoder — a solid square so `tauri icon` always has a valid\n * source. Pure Node (zlib); no binary asset ships in the package. The builder\n * replaces it with their real 1024×1024 artwork. */\nexport function solidPng(\n size: number,\n rgba: [number, number, number, number],\n): Buffer {\n const [r, g, b, a] = rgba;\n // raw image: each row is a filter byte (0) + size*4 RGBA bytes\n const row = Buffer.alloc(1 + size * 4);\n for (let x = 0; x < size; x++) {\n const o = 1 + x * 4;\n row[o] = r;\n row[o + 1] = g;\n row[o + 2] = b;\n row[o + 3] = a;\n }\n const raw = Buffer.concat(Array.from({ length: size }, () => row));\n const idat = deflateSync(raw);\n\n const chunk = (type: string, data: Buffer): Buffer => {\n const len = Buffer.alloc(4);\n len.writeUInt32BE(data.length, 0);\n const typeBuf = Buffer.from(type, \"ascii\");\n const body = Buffer.concat([typeBuf, data]);\n const crc = Buffer.alloc(4);\n crc.writeUInt32BE(crc32(body) >>> 0, 0);\n return Buffer.concat([len, body, crc]);\n };\n\n const ihdr = Buffer.alloc(13);\n ihdr.writeUInt32BE(size, 0);\n ihdr.writeUInt32BE(size, 4);\n ihdr[8] = 8; // bit depth\n ihdr[9] = 6; // color type RGBA\n ihdr[10] = 0; // compression\n ihdr[11] = 0; // filter\n ihdr[12] = 0; // interlace\n\n return Buffer.concat([\n Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),\n chunk(\"IHDR\", ihdr),\n chunk(\"IDAT\", idat),\n chunk(\"IEND\", Buffer.alloc(0)),\n ]);\n}\n\nlet crcTable: number[] | undefined;\nfunction crc32(buf: Buffer): number {\n if (!crcTable) {\n crcTable = [];\n for (let n = 0; n < 256; n++) {\n let c = n;\n for (let k = 0; k < 8; k++) {\n c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;\n }\n crcTable[n] = c;\n }\n }\n let crc = 0xffffffff;\n for (let i = 0; i < buf.length; i++) {\n crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);\n }\n return crc ^ 0xffffffff;\n}\n\nconst GITIGNORE = `# Generated tauri shell — only Cargo.lock and app-icon.png are tracked.\n/tauri-shell/target\n/tauri-shell/gen\n/tauri-shell/icons\n/tauri-shell/dist-stack\n/tauri-shell/binaries\n`;\n\nexport function scaffoldDesktopShell(\n hostDir: string,\n options: ScaffoldDesktopShellOptions,\n): ScaffoldResult {\n const created: string[] = [];\n const skipped: string[] = [];\n fs.mkdirSync(hostDir, { recursive: true });\n\n const iconFile = \"icon.png\";\n const app: AppJson = {\n identifier: options.identifier,\n productName: options.productName,\n icon: `./${iconFile}`,\n // The loading page's branding; null = the defaults (see app-json.ts).\n background: options.background ?? null,\n loading: null,\n window: { title: options.productName, width: 1440, height: 900 },\n fileAssociations: [\n {\n ext: [\"phd\"],\n name: \"Powerhouse Document\",\n mimeType: \"application/vnd.powerhouse.document+zip\",\n },\n ],\n };\n // Fail fast if we ever emit something the loader would reject.\n appJsonSchema.parse(app);\n\n const appJsonPath = path.join(hostDir, APP_JSON_FILE);\n if (fs.existsSync(appJsonPath) && !options.force) {\n skipped.push(appJsonPath);\n } else {\n fs.writeFileSync(appJsonPath, `${JSON.stringify(app, null, 2)}\\n`);\n created.push(appJsonPath);\n }\n\n const iconPath = path.join(hostDir, iconFile);\n if (fs.existsSync(iconPath)) {\n skipped.push(iconPath);\n } else {\n // 1024² indigo placeholder — a real, square, replaceable source icon.\n fs.writeFileSync(iconPath, solidPng(1024, [79, 70, 229, 255]));\n created.push(iconPath);\n }\n\n const gitignorePath = path.join(hostDir, \".gitignore\");\n if (fs.existsSync(gitignorePath)) {\n skipped.push(gitignorePath);\n } else {\n fs.writeFileSync(gitignorePath, GITIGNORE);\n created.push(gitignorePath);\n }\n\n return { hostDir, created, skipped };\n}\n"],"mappings":";;;;;;;;;;;;AAiCA,SAAgB,iBACd,YACA,SACA,OACc;CACd,MAAM,UAAU,QAAwB;EACtC,IAAI,sBAAsB,GAAG,GAAG,OAAO;EACvC,MAAM,MAAM,KACT,SAAS,OAAO,KAAK,QAAQ,SAAS,GAAG,CAAC,CAAC,CAC3C,MAAM,KAAK,GAAG,CAAC,CACf,KAAK,GAAG;EACX,OAAO,IAAI,WAAW,GAAG,IAAI,MAAM,KAAK;CAC1C;CACA,OAAO,OAAO,eAAe,WACzB,OAAO,UAAU,IACjB,oBAAoB,YAAY,MAAM;AAC5C;;;;AAaA,SAAgB,SACd,MACA,MACQ;CACR,MAAM,CAAC,GAAG,GAAG,GAAG,KAAK;CAErB,MAAM,MAAM,OAAO,MAAM,IAAI,OAAO,CAAC;CACrC,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,KAAK;EAC7B,MAAM,IAAI,IAAI,IAAI;EAClB,IAAI,KAAK;EACT,IAAI,IAAI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