@powerhousedao/desktop 6.2.3-dev.59 → 6.2.3-dev.61
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.
- package/dist/index.d.mts +172 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +132 -2
- package/dist/index.mjs.map +1 -0
- package/dist/runner.d.mts +20 -13
- package/dist/runner.d.mts.map +1 -1
- package/dist/runner.mjs +137 -20
- package/dist/runner.mjs.map +1 -1
- package/dist/shell-BL61-fyi.mjs +656 -0
- package/dist/shell-BL61-fyi.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/shell-DcBLVLVz.mjs +0 -148
- package/dist/shell-DcBLVLVz.mjs.map +0 -1
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { execSync, spawn, spawnSync } from "node:child_process";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
//#region src/app-json.ts
|
|
8
|
+
/**
|
|
9
|
+
* `hosts/desktop/app.json` — the builder's desktop identity (phase 7, mode 1:
|
|
10
|
+
* the builder ships under THEIR identity without writing Rust). It is the ONE
|
|
11
|
+
* file a builder edits; `shell-project.ts` projects it into a generated
|
|
12
|
+
* `tauri-shell/` that depends on the published `ph-desktop-shell` crate. Every
|
|
13
|
+
* field validates strictly so a typo fails with the field named, not silently.
|
|
14
|
+
*/
|
|
15
|
+
const identifierSchema = z.string().min(1).regex(/^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/, "identifier must be reverse-DNS (e.g. com.acme.app): dot-separated alphanumeric segments");
|
|
16
|
+
const windowSchema = z.strictObject({
|
|
17
|
+
title: z.string().min(1).optional(),
|
|
18
|
+
width: z.number().int().positive().optional(),
|
|
19
|
+
height: z.number().int().positive().optional(),
|
|
20
|
+
resizable: z.boolean().optional()
|
|
21
|
+
}).optional();
|
|
22
|
+
const fileAssociationSchema = z.strictObject({
|
|
23
|
+
/** Extensions WITHOUT the leading dot ("phd", not ".phd"). */
|
|
24
|
+
ext: z.array(z.string().min(1).regex(/^[^.]/, "drop the leading dot")).min(1),
|
|
25
|
+
name: z.string().min(1),
|
|
26
|
+
description: z.string().optional(),
|
|
27
|
+
mimeType: z.string().optional()
|
|
28
|
+
});
|
|
29
|
+
/** Where the generated Cargo.toml resolves `ph-desktop-shell` from. Default
|
|
30
|
+
* (omitted) = the published crates.io version. */
|
|
31
|
+
const shellSourceSchema = z.strictObject({
|
|
32
|
+
/** Local checkout for shell development (the lab points here). */
|
|
33
|
+
path: z.string().min(1).optional(),
|
|
34
|
+
/** Git source, pinned to a tag/rev, for pre-publication consumption. */
|
|
35
|
+
git: z.string().min(1).optional(),
|
|
36
|
+
tag: z.string().min(1).optional(),
|
|
37
|
+
rev: z.string().min(1).optional(),
|
|
38
|
+
/** crates.io version requirement (default DEFAULT_SHELL_CRATE_VERSION). */
|
|
39
|
+
version: z.string().min(1).optional()
|
|
40
|
+
}).refine((s) => !(s.path && s.git), { message: "shell.source: set path OR git, not both" }).optional();
|
|
41
|
+
const appJsonSchema = z.strictObject({
|
|
42
|
+
identifier: identifierSchema,
|
|
43
|
+
productName: z.string().min(1),
|
|
44
|
+
/** Single source image (square PNG, 1024×1024 recommended); the icon set
|
|
45
|
+
* for every platform is generated from it via `tauri icon`. */
|
|
46
|
+
icon: z.string().min(1),
|
|
47
|
+
window: windowSchema,
|
|
48
|
+
fileAssociations: z.array(fileAssociationSchema).optional(),
|
|
49
|
+
shell: shellSourceSchema
|
|
50
|
+
});
|
|
51
|
+
/** Default crates.io version requirement for the shell crate (D7.b: the flip
|
|
52
|
+
* to crates.io default once published — the crate is live). */
|
|
53
|
+
const DEFAULT_SHELL_CRATE_VERSION = "0.1";
|
|
54
|
+
const APP_JSON_FILE = "app.json";
|
|
55
|
+
/** Read + validate hosts/<host>/app.json. Throws with the field named on a
|
|
56
|
+
* bad value, and a clear message when the file is absent. */
|
|
57
|
+
function loadAppJson(hostDir) {
|
|
58
|
+
const file = path.join(hostDir, APP_JSON_FILE);
|
|
59
|
+
if (!fs.existsSync(file)) throw new Error(`No ${APP_JSON_FILE} in ${hostDir} — run \`ph generate desktop-shell\` to scaffold the builder identity, or set runner.shell.project to a prebuilt shell.`);
|
|
60
|
+
let raw;
|
|
61
|
+
try {
|
|
62
|
+
raw = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error(`${file}: not valid JSON — ${String(error)}`, { cause: error });
|
|
65
|
+
}
|
|
66
|
+
const result = appJsonSchema.safeParse(raw);
|
|
67
|
+
if (!result.success) {
|
|
68
|
+
const issues = result.error.issues.map((i) => ` ${i.path.join(".") || "(root)"}: ${i.message}`).join("\n");
|
|
69
|
+
throw new Error(`${file} is invalid:\n${issues}`);
|
|
70
|
+
}
|
|
71
|
+
return result.data;
|
|
72
|
+
}
|
|
73
|
+
/** A filesystem/crate-safe slug of the product name — the generated binary
|
|
74
|
+
* and Cargo package name. Falls back to the identifier's last segment. */
|
|
75
|
+
function appSlug(app) {
|
|
76
|
+
const fromName = app.productName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
77
|
+
if (fromName) return fromName;
|
|
78
|
+
return (app.identifier.split(".").pop() ?? "app").toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/bundle-stack.ts
|
|
82
|
+
function copyIfExists(from, to) {
|
|
83
|
+
if (!fs.existsSync(from)) return false;
|
|
84
|
+
fs.cpSync(from, to, { recursive: true });
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Recursively copy `src` → `dest`, skipping any path in `excludes`. Unlike
|
|
89
|
+
* fs.cpSync this tolerates `dest` living INSIDE `src`: in mode 1 the generated
|
|
90
|
+
* shell (and its `dist-stack`) sits under `hosts/<desktop>/`, so staging the
|
|
91
|
+
* project's `hosts/` straight into the shell would be a copy-into-self that
|
|
92
|
+
* cpSync rejects outright. Excluding the shell subtree both avoids that and
|
|
93
|
+
* keeps the crate + node sidecar out of the shippable stack.
|
|
94
|
+
*/
|
|
95
|
+
function copyDirFiltered(src, dest, excludes) {
|
|
96
|
+
if (!fs.existsSync(src)) return false;
|
|
97
|
+
const skip = new Set(excludes.map((e) => path.resolve(e)));
|
|
98
|
+
const walk = (s, d) => {
|
|
99
|
+
if (skip.has(path.resolve(s))) return;
|
|
100
|
+
if (fs.statSync(s).isDirectory()) {
|
|
101
|
+
fs.mkdirSync(d, { recursive: true });
|
|
102
|
+
for (const entry of fs.readdirSync(s)) walk(path.join(s, entry), path.join(d, entry));
|
|
103
|
+
} else fs.copyFileSync(s, d);
|
|
104
|
+
};
|
|
105
|
+
walk(src, dest);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
function bundleStack(options) {
|
|
109
|
+
const log = options.logger ?? console.log;
|
|
110
|
+
const stackDir = path.join(options.shellProjectDir, "dist-stack");
|
|
111
|
+
for (const entry of [
|
|
112
|
+
"hosts",
|
|
113
|
+
"agents",
|
|
114
|
+
"dist",
|
|
115
|
+
"powerhouse.config.json",
|
|
116
|
+
"package.json"
|
|
117
|
+
]) fs.rmSync(path.join(stackDir, entry), {
|
|
118
|
+
recursive: true,
|
|
119
|
+
force: true
|
|
120
|
+
});
|
|
121
|
+
fs.mkdirSync(stackDir, { recursive: true });
|
|
122
|
+
log(` hosts/ ${copyDirFiltered(path.join(options.projectRoot, "hosts"), path.join(stackDir, "hosts"), options.excludeDirs ?? []) ? "staged" : "absent — skipped"}`);
|
|
123
|
+
for (const dir of ["agents", "dist"]) log(` ${dir}/ ${copyIfExists(path.join(options.projectRoot, dir), path.join(stackDir, dir)) ? "staged" : "absent — skipped"}`);
|
|
124
|
+
const stagedDesktopHost = path.join(stackDir, "hosts", "desktop", "host.js");
|
|
125
|
+
if (fs.existsSync(stagedDesktopHost)) {
|
|
126
|
+
const source = fs.readFileSync(stagedDesktopHost, "utf8");
|
|
127
|
+
if (source.includes("@powerhousedao/desktop/runner")) {
|
|
128
|
+
fs.writeFileSync(stagedDesktopHost, "// STAGED COPY (bundle-stack): runner.module rewritten to the generic\n// compound — the packaged shell is the window; there is no nested shell.\n" + source.replace(/@powerhousedao\/desktop\/runner/g, "@powerhousedao/host-core/runners/compound"));
|
|
129
|
+
log(" hosts/desktop/host.js: runner rewritten to the generic compound (staged copy)");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
copyIfExists(path.join(options.projectRoot, "powerhouse.config.json"), path.join(stackDir, "powerhouse.config.json"));
|
|
133
|
+
if (typeof options.connectPort === "number") {
|
|
134
|
+
fs.writeFileSync(path.join(stackDir, "shell.json"), `${JSON.stringify({ connectPort: options.connectPort }, null, 2)}\n`);
|
|
135
|
+
log(` shell.json: connectPort ${options.connectPort}`);
|
|
136
|
+
}
|
|
137
|
+
const sourcePkg = JSON.parse(fs.readFileSync(path.join(options.projectRoot, "package.json"), "utf8"));
|
|
138
|
+
const version = options.phCliVersion ?? "dev";
|
|
139
|
+
fs.writeFileSync(path.join(stackDir, "package.json"), `${JSON.stringify({
|
|
140
|
+
name: sourcePkg.name ?? "powerhouse-desktop-stack",
|
|
141
|
+
private: true,
|
|
142
|
+
type: "module",
|
|
143
|
+
dependencies: { "@powerhousedao/ph-cli": version }
|
|
144
|
+
}, null, 2)}\n`);
|
|
145
|
+
let vendored = false;
|
|
146
|
+
if (options.vendor !== false) {
|
|
147
|
+
const specs = `"${options.phCliSpec ?? `@powerhousedao/ph-cli@${version}`}" "@powerhousedao/host-core@${version}"`;
|
|
148
|
+
log(` vendoring ${specs} (hoisted, real files)…`);
|
|
149
|
+
const result = spawnSync(`npm install ${specs} --install-strategy=hoisted --omit=dev --no-audit --no-fund`, {
|
|
150
|
+
cwd: stackDir,
|
|
151
|
+
stdio: "pipe",
|
|
152
|
+
shell: true,
|
|
153
|
+
windowsHide: true
|
|
154
|
+
});
|
|
155
|
+
if (result.status !== 0) throw new Error(`bundle-stack: vendoring failed (${result.status}):\n${result.stderr.toString().slice(-800)}`);
|
|
156
|
+
vendored = true;
|
|
157
|
+
} else log(" vendoring skipped (vendor: false) — existing tree left in place");
|
|
158
|
+
return {
|
|
159
|
+
stackDir,
|
|
160
|
+
vendored
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/shell-project.ts
|
|
165
|
+
/**
|
|
166
|
+
* P7.3 — project `hosts/desktop/app.json` into a generated `tauri-shell/`:
|
|
167
|
+
* a STANDALONE tauri crate that depends on the published `ph-desktop-shell`
|
|
168
|
+
* library, carries the builder's identity, and is built/run by the desktop
|
|
169
|
+
* runner's dev/build verbs. The builder never writes Rust.
|
|
170
|
+
*
|
|
171
|
+
* Everything here mirrors the known-good reference app
|
|
172
|
+
* (ph-desktop-shell/apps/powerhouse-desktop): the tauri plumbing (main.rs,
|
|
173
|
+
* build.rs, capabilities, the loading page, externalBin + icon mechanics) is
|
|
174
|
+
* copied verbatim; only identity/port fields are projected from app.json. The
|
|
175
|
+
* projection is idempotent and stale-detected — a file is rewritten only when
|
|
176
|
+
* its content changes, so Cargo.lock, the generated icon set, and tauri-build
|
|
177
|
+
* output are never disturbed by a regen with an unchanged app.json.
|
|
178
|
+
*/
|
|
179
|
+
const SHELL_DIR = "tauri-shell";
|
|
180
|
+
/** The icon source the runner feeds to `tauri icon` (copied from app.icon). */
|
|
181
|
+
const ICON_SOURCE = "app-icon.png";
|
|
182
|
+
/** `ph-desktop-shell` dependency line for the generated Cargo.toml, from
|
|
183
|
+
* app.json's shell.source (path > git > crates.io version). */
|
|
184
|
+
function shellDependency(source) {
|
|
185
|
+
if (source?.path) {
|
|
186
|
+
const p = source.path.replace(/\\/g, "/");
|
|
187
|
+
return `ph-desktop-shell = { path = ${JSON.stringify(p)} }`;
|
|
188
|
+
}
|
|
189
|
+
if (source?.git) {
|
|
190
|
+
const parts = [`git = ${JSON.stringify(source.git)}`];
|
|
191
|
+
if (source.tag) parts.push(`tag = ${JSON.stringify(source.tag)}`);
|
|
192
|
+
if (source.rev) parts.push(`rev = ${JSON.stringify(source.rev)}`);
|
|
193
|
+
return `ph-desktop-shell = { ${parts.join(", ")} }`;
|
|
194
|
+
}
|
|
195
|
+
const version = source?.version ?? "0.1";
|
|
196
|
+
return `ph-desktop-shell = ${JSON.stringify(version)}`;
|
|
197
|
+
}
|
|
198
|
+
function cargoToml(app, binName) {
|
|
199
|
+
return `# GENERATED from ../app.json by @powerhousedao/desktop — do not edit by
|
|
200
|
+
# hand; edit app.json and re-run \`ph run desktop dev|build\`. Cargo.lock is
|
|
201
|
+
# preserved across regens.
|
|
202
|
+
[package]
|
|
203
|
+
name = ${JSON.stringify(binName)}
|
|
204
|
+
version = "0.1.0"
|
|
205
|
+
edition = "2021"
|
|
206
|
+
|
|
207
|
+
[build-dependencies]
|
|
208
|
+
tauri-build = { version = "2", features = [] }
|
|
209
|
+
|
|
210
|
+
[dependencies]
|
|
211
|
+
tauri = { version = "2", features = ["tray-icon", "devtools"] }
|
|
212
|
+
# Plugins must be DIRECT deps of the app crate: tauri-build only sees
|
|
213
|
+
# permission manifests (shell:allow-spawn etc.) from direct dependencies.
|
|
214
|
+
tauri-plugin-shell = "2"
|
|
215
|
+
tauri-plugin-single-instance = "2"
|
|
216
|
+
${shellDependency(app.shell)}
|
|
217
|
+
|
|
218
|
+
[[bin]]
|
|
219
|
+
name = ${JSON.stringify(binName)}
|
|
220
|
+
path = "src/main.rs"
|
|
221
|
+
|
|
222
|
+
[profile.release]
|
|
223
|
+
codegen-units = 1
|
|
224
|
+
lto = true
|
|
225
|
+
`;
|
|
226
|
+
}
|
|
227
|
+
const MAIN_RS = `// GENERATED — identity bakes from tauri.conf.json via generate_context!;
|
|
228
|
+
// behavior is the shared ph-desktop-shell library. Edit ../app.json, not this.
|
|
229
|
+
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
230
|
+
|
|
231
|
+
fn main() {
|
|
232
|
+
ph_desktop_shell::run(tauri::generate_context!(), Default::default());
|
|
233
|
+
}
|
|
234
|
+
`;
|
|
235
|
+
const BUILD_RS = `// GENERATED — mirrors the reference shell. Connect is served over
|
|
236
|
+
// http://127.0.0.1 (a remote origin to Tauri), so the launch-queue commands
|
|
237
|
+
// need an explicit ACL; declaring the command manifest here generates the
|
|
238
|
+
// allow-<command> permissions that capabilities/*.json grant.
|
|
239
|
+
fn main() {
|
|
240
|
+
tauri_build::try_build(tauri_build::Attributes::new().app_manifest(
|
|
241
|
+
tauri_build::AppManifest::new().commands(&[
|
|
242
|
+
"take_launch_files",
|
|
243
|
+
"read_launch_file",
|
|
244
|
+
"log_from_webview",
|
|
245
|
+
]),
|
|
246
|
+
))
|
|
247
|
+
.expect("failed to run tauri-build");
|
|
248
|
+
}
|
|
249
|
+
`;
|
|
250
|
+
function loadingHtml(productName) {
|
|
251
|
+
const name = productName.replace(/[<&]/g, (c) => c === "<" ? "<" : "&");
|
|
252
|
+
return `<!doctype html>
|
|
253
|
+
<html lang="en">
|
|
254
|
+
<head>
|
|
255
|
+
<meta charset="utf-8" />
|
|
256
|
+
<title>${name}</title>
|
|
257
|
+
<style>
|
|
258
|
+
:root { color-scheme: light dark; }
|
|
259
|
+
body {
|
|
260
|
+
margin: 0; height: 100vh;
|
|
261
|
+
display: flex; align-items: center; justify-content: center;
|
|
262
|
+
font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
263
|
+
background: #0f1115; color: #e6e8eb;
|
|
264
|
+
}
|
|
265
|
+
.box { text-align: center; }
|
|
266
|
+
.dot {
|
|
267
|
+
width: 10px; height: 10px; border-radius: 50%;
|
|
268
|
+
background: #4ade80; display: inline-block; margin-right: 8px;
|
|
269
|
+
animation: pulse 1.2s ease-in-out infinite;
|
|
270
|
+
}
|
|
271
|
+
@keyframes pulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }
|
|
272
|
+
</style>
|
|
273
|
+
</head>
|
|
274
|
+
<body>
|
|
275
|
+
<div class="box"><span class="dot"></span>Starting ${name}…</div>
|
|
276
|
+
</body>
|
|
277
|
+
</html>
|
|
278
|
+
`;
|
|
279
|
+
}
|
|
280
|
+
function tauriConf(input) {
|
|
281
|
+
const { app } = input;
|
|
282
|
+
const win = app.window ?? {};
|
|
283
|
+
const fileAssociations = app.fileAssociations && app.fileAssociations.length > 0 ? app.fileAssociations.map((fa) => ({
|
|
284
|
+
ext: fa.ext,
|
|
285
|
+
name: fa.name,
|
|
286
|
+
...fa.description ? { description: fa.description } : {},
|
|
287
|
+
...fa.mimeType ? { mimeType: fa.mimeType } : {}
|
|
288
|
+
})) : void 0;
|
|
289
|
+
const conf = {
|
|
290
|
+
$schema: "https://schema.tauri.app/config/2",
|
|
291
|
+
productName: app.productName,
|
|
292
|
+
version: "0.1.0",
|
|
293
|
+
identifier: app.identifier,
|
|
294
|
+
build: { frontendDist: "./ui" },
|
|
295
|
+
app: {
|
|
296
|
+
windows: [{
|
|
297
|
+
title: win.title ?? app.productName,
|
|
298
|
+
width: win.width ?? 1440,
|
|
299
|
+
height: win.height ?? 900,
|
|
300
|
+
resizable: win.resizable ?? true,
|
|
301
|
+
visible: true,
|
|
302
|
+
dragDropEnabled: false,
|
|
303
|
+
create: false
|
|
304
|
+
}],
|
|
305
|
+
security: { csp: null }
|
|
306
|
+
},
|
|
307
|
+
bundle: {
|
|
308
|
+
active: true,
|
|
309
|
+
targets: [
|
|
310
|
+
"nsis",
|
|
311
|
+
"app",
|
|
312
|
+
"dmg"
|
|
313
|
+
],
|
|
314
|
+
icon: [
|
|
315
|
+
"icons/32x32.png",
|
|
316
|
+
"icons/128x128.png",
|
|
317
|
+
"icons/128x128@2x.png",
|
|
318
|
+
"icons/icon.icns",
|
|
319
|
+
"icons/icon.ico"
|
|
320
|
+
],
|
|
321
|
+
...fileAssociations ? { fileAssociations } : {},
|
|
322
|
+
externalBin: ["binaries/node"],
|
|
323
|
+
resources: { "./dist-stack": "stack" }
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
return JSON.stringify(conf, null, 2) + "\n";
|
|
327
|
+
}
|
|
328
|
+
function defaultCapability() {
|
|
329
|
+
return JSON.stringify({
|
|
330
|
+
$schema: "../gen/schemas/desktop-schema.json",
|
|
331
|
+
identifier: "default",
|
|
332
|
+
description: "Lets the shell spawn the bundled node sidecar.",
|
|
333
|
+
windows: ["main"],
|
|
334
|
+
permissions: [
|
|
335
|
+
"core:default",
|
|
336
|
+
"allow-take-launch-files",
|
|
337
|
+
"allow-read-launch-file",
|
|
338
|
+
"allow-log-from-webview",
|
|
339
|
+
{
|
|
340
|
+
identifier: "shell:allow-spawn",
|
|
341
|
+
allow: [{
|
|
342
|
+
name: "binaries/node",
|
|
343
|
+
sidecar: true,
|
|
344
|
+
args: true
|
|
345
|
+
}]
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
identifier: "shell:allow-execute",
|
|
349
|
+
allow: [{
|
|
350
|
+
name: "binaries/node",
|
|
351
|
+
sidecar: true,
|
|
352
|
+
args: true
|
|
353
|
+
}]
|
|
354
|
+
}
|
|
355
|
+
]
|
|
356
|
+
}, null, 2) + "\n";
|
|
357
|
+
}
|
|
358
|
+
function connectCapability(connectPort) {
|
|
359
|
+
const origin = `http://127.0.0.1:${connectPort}`;
|
|
360
|
+
return JSON.stringify({
|
|
361
|
+
$schema: "../gen/schemas/desktop-schema.json",
|
|
362
|
+
identifier: "connect",
|
|
363
|
+
description: "Connect is served over http://127.0.0.1 (a remote origin to Tauri); without this the launch-queue commands are rejected before they run.",
|
|
364
|
+
windows: ["main"],
|
|
365
|
+
remote: { urls: [origin, `${origin}/*`] },
|
|
366
|
+
permissions: [
|
|
367
|
+
"allow-take-launch-files",
|
|
368
|
+
"allow-read-launch-file",
|
|
369
|
+
"allow-log-from-webview"
|
|
370
|
+
]
|
|
371
|
+
}, null, 2) + "\n";
|
|
372
|
+
}
|
|
373
|
+
const GITIGNORE = `# Generated tauri shell — only Cargo.lock and app-icon.png are tracked.
|
|
374
|
+
/target
|
|
375
|
+
/gen
|
|
376
|
+
/icons
|
|
377
|
+
/dist-stack
|
|
378
|
+
/binaries
|
|
379
|
+
`;
|
|
380
|
+
const DIST_STACK_README = `This directory is replaced at \`ph run desktop build\` with the shippable
|
|
381
|
+
stack (hosts + powerhouse.config.json + built Connect + vendored ph-cli). It
|
|
382
|
+
is bundled as the app's \`stack\` resource so the installed app runs with no
|
|
383
|
+
environment. Kept as a placeholder so tauri's resource glob resolves in dev.
|
|
384
|
+
`;
|
|
385
|
+
/** Write a file only when its content differs; returns whether it changed. */
|
|
386
|
+
function writeIfChanged(file, content) {
|
|
387
|
+
if (fs.existsSync(file) && fs.readFileSync(file, "utf8") === content) return false;
|
|
388
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
389
|
+
fs.writeFileSync(file, content);
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Materialize/refresh `<hostDir>/tauri-shell/` from app.json. Idempotent:
|
|
394
|
+
* unchanged app.json rewrites nothing. Does NOT run `tauri icon` or fetch the
|
|
395
|
+
* node binary — those are toolchain steps the runner performs at dev/build.
|
|
396
|
+
*/
|
|
397
|
+
function projectShell(input) {
|
|
398
|
+
const { hostDir, app, connectPort } = input;
|
|
399
|
+
const binName = appSlug(app);
|
|
400
|
+
const shellDir = path.join(hostDir, SHELL_DIR);
|
|
401
|
+
const files = [
|
|
402
|
+
["Cargo.toml", cargoToml(app, binName)],
|
|
403
|
+
["src/main.rs", MAIN_RS],
|
|
404
|
+
["build.rs", BUILD_RS],
|
|
405
|
+
["tauri.conf.json", tauriConf(input)],
|
|
406
|
+
["ui/index.html", loadingHtml(app.productName)],
|
|
407
|
+
["capabilities/default.json", defaultCapability()],
|
|
408
|
+
["capabilities/connect.json", connectCapability(connectPort)],
|
|
409
|
+
[".gitignore", GITIGNORE],
|
|
410
|
+
["dist-stack/README.md", DIST_STACK_README]
|
|
411
|
+
];
|
|
412
|
+
let changed = false;
|
|
413
|
+
for (const [rel, content] of files) if (writeIfChanged(path.join(shellDir, rel), content)) changed = true;
|
|
414
|
+
const iconSrc = path.resolve(hostDir, app.icon);
|
|
415
|
+
const iconDest = path.join(shellDir, ICON_SOURCE);
|
|
416
|
+
if (fs.existsSync(iconSrc)) {
|
|
417
|
+
const bytes = fs.readFileSync(iconSrc);
|
|
418
|
+
if (!fs.existsSync(iconDest) || !fs.readFileSync(iconDest).equals(bytes)) {
|
|
419
|
+
fs.mkdirSync(shellDir, { recursive: true });
|
|
420
|
+
fs.writeFileSync(iconDest, bytes);
|
|
421
|
+
changed = true;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
shellDir,
|
|
426
|
+
binName,
|
|
427
|
+
changed
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/shell-toolchain.ts
|
|
432
|
+
/** The Node release triple for a build host — the sidecar filename tauri
|
|
433
|
+
* resolves (`node-<triple>`). Pure, so the mapping is unit-tested. */
|
|
434
|
+
function nodeSidecarTarget(platform, arch) {
|
|
435
|
+
const target = {
|
|
436
|
+
"win32 x64": {
|
|
437
|
+
triple: "x86_64-pc-windows-msvc",
|
|
438
|
+
dist: "win-x64",
|
|
439
|
+
bin: "node.exe",
|
|
440
|
+
ext: ".exe"
|
|
441
|
+
},
|
|
442
|
+
"darwin arm64": {
|
|
443
|
+
triple: "aarch64-apple-darwin",
|
|
444
|
+
dist: "darwin-arm64",
|
|
445
|
+
bin: "bin/node",
|
|
446
|
+
ext: ""
|
|
447
|
+
},
|
|
448
|
+
"darwin x64": {
|
|
449
|
+
triple: "x86_64-apple-darwin",
|
|
450
|
+
dist: "darwin-x64",
|
|
451
|
+
bin: "bin/node",
|
|
452
|
+
ext: ""
|
|
453
|
+
},
|
|
454
|
+
"linux x64": {
|
|
455
|
+
triple: "x86_64-unknown-linux-gnu",
|
|
456
|
+
dist: "linux-x64",
|
|
457
|
+
bin: "bin/node",
|
|
458
|
+
ext: ""
|
|
459
|
+
}
|
|
460
|
+
}[`${platform} ${arch}`];
|
|
461
|
+
if (!target) throw new Error(`No Node sidecar mapping for ${platform} ${arch} — the desktop shell supports win32/x64, darwin/arm64, darwin/x64, linux/x64.`);
|
|
462
|
+
return target;
|
|
463
|
+
}
|
|
464
|
+
/** Fetch the stock Node the shell ships as its sidecar into `<shellDir>/
|
|
465
|
+
* binaries`, named per target triple. No-op when already present. Ported from
|
|
466
|
+
* the reference repo's fetch-node.mjs (the builder has no such script). */
|
|
467
|
+
function fetchNodeSidecar(shellDir, version = process.versions.node, platform = process.platform, arch = process.arch) {
|
|
468
|
+
const target = nodeSidecarTarget(platform, arch);
|
|
469
|
+
const binariesDir = path.join(shellDir, "binaries");
|
|
470
|
+
fs.mkdirSync(binariesDir, { recursive: true });
|
|
471
|
+
const dest = path.join(binariesDir, `node-${target.triple}${target.ext}`);
|
|
472
|
+
if (fs.existsSync(dest)) return dest;
|
|
473
|
+
if (platform === "win32") {
|
|
474
|
+
const url = `https://nodejs.org/dist/v${version}/win-x64/node.exe`;
|
|
475
|
+
execSync(`curl -fsSL -o "${dest}" "${url}"`, { stdio: "inherit" });
|
|
476
|
+
} else {
|
|
477
|
+
const name = `node-v${version}-${target.dist}`;
|
|
478
|
+
const url = `https://nodejs.org/dist/v${version}/${name}.tar.gz`;
|
|
479
|
+
execSync(`curl -fsSL "${url}" | tar -xz -C "${binariesDir}" --strip-components=2 ${name}/${target.bin}`, {
|
|
480
|
+
stdio: "inherit",
|
|
481
|
+
shell: "/bin/sh"
|
|
482
|
+
});
|
|
483
|
+
fs.renameSync(path.join(binariesDir, "node"), dest);
|
|
484
|
+
fs.chmodSync(dest, 493);
|
|
485
|
+
}
|
|
486
|
+
return dest;
|
|
487
|
+
}
|
|
488
|
+
/** Default bundle targets for the build host (`cargo tauri build --bundles`).
|
|
489
|
+
* macOS gets app+dmg, Windows nsis, Linux deb+appimage — a host only builds
|
|
490
|
+
* installers it can produce. */
|
|
491
|
+
function tauriBundlesForHost(platform = process.platform) {
|
|
492
|
+
switch (platform) {
|
|
493
|
+
case "darwin": return ["app", "dmg"];
|
|
494
|
+
case "win32": return ["nsis"];
|
|
495
|
+
default: return ["deb", "appimage"];
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/** Spawn parameters that avoid DEP0190 (args array + shell:true): cargo on
|
|
499
|
+
* Windows needs the shell for PATH/.exe + subcommand resolution — pass ONE
|
|
500
|
+
* string, empty args; everything else runs argv directly (shell:false). The
|
|
501
|
+
* joined tokens here are our own constants/paths, never user input. */
|
|
502
|
+
function tauriSpawn(tauri, subcommand) {
|
|
503
|
+
const argv = [...tauri.prefix, ...subcommand];
|
|
504
|
+
if (tauri.cmd === "cargo" && process.platform === "win32") return {
|
|
505
|
+
command: ["cargo", ...argv].join(" "),
|
|
506
|
+
args: [],
|
|
507
|
+
shell: true
|
|
508
|
+
};
|
|
509
|
+
return {
|
|
510
|
+
command: tauri.cmd,
|
|
511
|
+
args: argv,
|
|
512
|
+
shell: false
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function probe(cmd, args) {
|
|
516
|
+
const onWin = process.platform === "win32";
|
|
517
|
+
try {
|
|
518
|
+
return spawnSync(onWin ? [cmd, ...args].join(" ") : cmd, onWin ? [] : args, {
|
|
519
|
+
stdio: "ignore",
|
|
520
|
+
shell: onWin
|
|
521
|
+
}).status === 0;
|
|
522
|
+
} catch {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
/** Is a Rust `cargo` on PATH? (needed to compile the shell crate). */
|
|
527
|
+
function hasCargo() {
|
|
528
|
+
return probe("cargo", ["--version"]);
|
|
529
|
+
}
|
|
530
|
+
/** Resolve a Tauri CLI: a global `cargo tauri`, else a `@tauri-apps/cli`
|
|
531
|
+
* resolvable from the project. Returns null when neither is available. */
|
|
532
|
+
function resolveTauriCommand(projectRoot) {
|
|
533
|
+
if (probe("cargo", ["tauri", "--version"])) return {
|
|
534
|
+
cmd: "cargo",
|
|
535
|
+
prefix: ["tauri"],
|
|
536
|
+
via: "cargo-tauri"
|
|
537
|
+
};
|
|
538
|
+
try {
|
|
539
|
+
const pkgJson = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href).resolve("@tauri-apps/cli/package.json");
|
|
540
|
+
const pkgDir = path.dirname(pkgJson);
|
|
541
|
+
const bin = JSON.parse(fs.readFileSync(pkgJson, "utf8")).bin;
|
|
542
|
+
const rel = typeof bin === "string" ? bin : bin?.tauri;
|
|
543
|
+
if (rel) return {
|
|
544
|
+
cmd: process.execPath,
|
|
545
|
+
prefix: [path.join(pkgDir, rel)],
|
|
546
|
+
via: "node-cli"
|
|
547
|
+
};
|
|
548
|
+
} catch {}
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
551
|
+
function detectToolchain(projectRoot) {
|
|
552
|
+
return {
|
|
553
|
+
cargo: hasCargo(),
|
|
554
|
+
tauri: resolveTauriCommand(projectRoot)
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
/** Throw a clear, actionable error when the native toolchain is incomplete —
|
|
558
|
+
* the desktop verbs call this before any cargo work so a missing executable
|
|
559
|
+
* is an instruction, not a stack trace. */
|
|
560
|
+
function preflightOrThrow(tc, hostName) {
|
|
561
|
+
const missing = [];
|
|
562
|
+
if (!tc.cargo) missing.push(" • Rust/cargo — install from https://rustup.rs (then restart your shell)");
|
|
563
|
+
if (!tc.tauri) missing.push(" • Tauri CLI — `cargo install tauri-cli --version \"^2\"` (or add @tauri-apps/cli@^2 to your project's devDependencies)");
|
|
564
|
+
if (missing.length > 0 || !tc.tauri) throw new Error(`hosts/${hostName}: the desktop shell needs a native toolchain that is not installed:\n${missing.join("\n")}\nInstall the above, then re-run \`ph run ${hostName} dev\` / \`ph run ${hostName} build\`. (The headless stack — \`ph run ${hostName}\` — needs none of this.)`);
|
|
565
|
+
return tc.tauri;
|
|
566
|
+
}
|
|
567
|
+
/** `<tauri> icon <source>` — generates the per-platform icon set (icon.ico +
|
|
568
|
+
* icon.icns + pngs) the bundle references and tauri-build requires. */
|
|
569
|
+
function runTauriIcon(tauri, shellDir, iconSource) {
|
|
570
|
+
const { command, args, shell } = tauriSpawn(tauri, ["icon", iconSource]);
|
|
571
|
+
const r = spawnSync(command, args, {
|
|
572
|
+
cwd: shellDir,
|
|
573
|
+
stdio: "inherit",
|
|
574
|
+
shell
|
|
575
|
+
});
|
|
576
|
+
if (r.status !== 0) throw new Error(`\`tauri icon ${iconSource}\` failed (exit ${r.status ?? "?"}) in ${shellDir} — check that app.icon is a square PNG.`);
|
|
577
|
+
}
|
|
578
|
+
//#endregion
|
|
579
|
+
//#region src/shell.ts
|
|
580
|
+
function resolveShell(projectRoot, options, env) {
|
|
581
|
+
const configured = options?.project ?? env.PH_DESKTOP_SHELL;
|
|
582
|
+
if (!configured) throw new Error("No desktop shell configured: set runner.shell.project in the host file (path to a ph-win-desktop checkout) or the PH_DESKTOP_SHELL environment variable. `ph run desktop` (headless stack) needs neither.");
|
|
583
|
+
const projectDir = path.resolve(projectRoot, configured);
|
|
584
|
+
if (!fs.existsSync(path.join(projectDir, "src-tauri"))) throw new Error(`Desktop shell not found at ${projectDir} (no src-tauri/) — check runner.shell.project / PH_DESKTOP_SHELL.`);
|
|
585
|
+
return {
|
|
586
|
+
projectDir,
|
|
587
|
+
exe: [
|
|
588
|
+
path.join(projectDir, "src-tauri", "target", "debug", "ph-win.exe"),
|
|
589
|
+
path.join(projectDir, "src-tauri", "target", "release", "ph-win.exe"),
|
|
590
|
+
path.join(projectDir, "src-tauri", "target", "debug", "ph-win"),
|
|
591
|
+
path.join(projectDir, "src-tauri", "target", "release", "ph-win")
|
|
592
|
+
].find((c) => fs.existsSync(c))
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
/** Resolve the project's ph-cli entry from ITS dependency tree — the same
|
|
596
|
+
* resolution `ph run` itself uses. */
|
|
597
|
+
function resolvePhCliEntry(projectRoot) {
|
|
598
|
+
const pkgPath = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href).resolve("@powerhousedao/ph-cli/package.json");
|
|
599
|
+
return path.join(path.dirname(pkgPath), "dist", "cli.mjs");
|
|
600
|
+
}
|
|
601
|
+
/** The env trio (plus flag and userData) the shell's uniform-runners mode
|
|
602
|
+
* reads — wired by the RUNNER so nobody exports variables by hand. */
|
|
603
|
+
function shellEnv(projectRoot, connectPort, env) {
|
|
604
|
+
return {
|
|
605
|
+
FEATURE_UNIFORM_RUNNERS_ENABLED: "1",
|
|
606
|
+
PH_RUN_PROJECT: projectRoot,
|
|
607
|
+
PH_RUN_CLI: resolvePhCliEntry(projectRoot),
|
|
608
|
+
PH_WIN_CONNECT_PORT: String(connectPort),
|
|
609
|
+
...env.PH_USER_DATA_DIR ? { PH_USER_DATA_DIR: env.PH_USER_DATA_DIR } : {}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
/** Project host shell options onto a tauri `--config` merge patch (D6.d) —
|
|
613
|
+
* the host file stays the single source for app identity on tauri-cli
|
|
614
|
+
* invocations; a built exe has these baked. */
|
|
615
|
+
function tauriConfigPatch(options) {
|
|
616
|
+
if (!options) return void 0;
|
|
617
|
+
const patch = {};
|
|
618
|
+
if (options.window) patch.app = { windows: [{
|
|
619
|
+
...options.window.title ? { title: options.window.title } : {},
|
|
620
|
+
...options.window.width ? { width: options.window.width } : {},
|
|
621
|
+
...options.window.height ? { height: options.window.height } : {}
|
|
622
|
+
}] };
|
|
623
|
+
if (options.fileAssociations?.length) patch.bundle = { fileAssociations: [{
|
|
624
|
+
ext: options.fileAssociations.map((e) => e.replace(/^\./, "")),
|
|
625
|
+
name: "Powerhouse Document"
|
|
626
|
+
}] };
|
|
627
|
+
return Object.keys(patch).length > 0 ? patch : void 0;
|
|
628
|
+
}
|
|
629
|
+
function launchShell(shell, envVars, options) {
|
|
630
|
+
if (shell.exe) return spawn(shell.exe, [], {
|
|
631
|
+
cwd: shell.projectDir,
|
|
632
|
+
env: {
|
|
633
|
+
...process.env,
|
|
634
|
+
...envVars
|
|
635
|
+
},
|
|
636
|
+
stdio: "inherit",
|
|
637
|
+
windowsHide: true
|
|
638
|
+
});
|
|
639
|
+
const patch = tauriConfigPatch(options);
|
|
640
|
+
const args = ["tauri", "dev"];
|
|
641
|
+
if (patch) args.push("--config", JSON.stringify(patch));
|
|
642
|
+
return spawn("pnpm", args, {
|
|
643
|
+
cwd: shell.projectDir,
|
|
644
|
+
env: {
|
|
645
|
+
...process.env,
|
|
646
|
+
...envVars
|
|
647
|
+
},
|
|
648
|
+
stdio: "inherit",
|
|
649
|
+
shell: true,
|
|
650
|
+
windowsHide: true
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
//#endregion
|
|
654
|
+
export { loadAppJson as S, bundleStack as _, tauriConfigPatch as a, appJsonSchema as b, nodeSidecarTarget as c, runTauriIcon as d, tauriBundlesForHost as f, projectShell as g, SHELL_DIR as h, shellEnv as i, preflightOrThrow as l, ICON_SOURCE as m, resolvePhCliEntry as n, detectToolchain as o, tauriSpawn as p, resolveShell as r, fetchNodeSidecar as s, launchShell as t, resolveTauriCommand as u, APP_JSON_FILE as v, appSlug as x, DEFAULT_SHELL_CRATE_VERSION as y };
|
|
655
|
+
|
|
656
|
+
//# sourceMappingURL=shell-BL61-fyi.mjs.map
|