@zappdev/cli 0.5.0-alpha.2 → 0.5.0-alpha.4
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/native/app/app.zc +7 -7
- package/native/build.zc +1 -1
- package/package.json +1 -1
- package/src/config.ts +1 -0
- package/src/init.ts +18 -8
- package/src/workers.ts +7 -5
package/native/app/app.zc
CHANGED
|
@@ -39,7 +39,7 @@ fn app_get_bootstrap_name() -> string {
|
|
|
39
39
|
fn app_get_bootstrap_web_content_inspectable() -> bool {
|
|
40
40
|
let app = (App*)app_get_active();
|
|
41
41
|
if app == NULL { return false; }
|
|
42
|
-
match app.config.
|
|
42
|
+
match app.config.webContentInspectable {
|
|
43
43
|
ZappInspectable::On => { return true; },
|
|
44
44
|
ZappInspectable::Off => { return false; },
|
|
45
45
|
ZappInspectable::Auto => { return zapp_build_dev_tools_default() > 0; },
|
|
@@ -179,7 +179,7 @@ enum ZappInspectable {
|
|
|
179
179
|
struct AppConfig {
|
|
180
180
|
name: string;
|
|
181
181
|
applicationShouldTerminateAfterLastWindowClosed: bool;
|
|
182
|
-
|
|
182
|
+
webContentInspectable: ZappInspectable;
|
|
183
183
|
maxWorkers: int;
|
|
184
184
|
qjsStackSize: int;
|
|
185
185
|
backend: bool; // enable backend worker (src/backend.ts)
|
|
@@ -189,13 +189,13 @@ struct AppConfig {
|
|
|
189
189
|
// Zapp namespace — convenience accessors for framework enums and values.
|
|
190
190
|
//
|
|
191
191
|
// Usage:
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
//
|
|
192
|
+
// webContentInspectable: Zapp::inspectable_auto(),
|
|
193
|
+
// webContentInspectable: Zapp::inspectable_on(),
|
|
194
|
+
// webContentInspectable: Zapp::inspectable_off(),
|
|
195
195
|
//
|
|
196
196
|
// These return the proper enum type so you get match exhaustiveness and
|
|
197
197
|
// type checking. The enum constructors also work directly if you prefer:
|
|
198
|
-
//
|
|
198
|
+
// webContentInspectable: ZappInspectable::Auto(),
|
|
199
199
|
//
|
|
200
200
|
// As Zapp adds more framework-level options (log levels, security modes,
|
|
201
201
|
// etc.), new accessors will appear here under the same Zapp:: namespace.
|
|
@@ -221,7 +221,7 @@ struct App {
|
|
|
221
221
|
impl App {
|
|
222
222
|
fn new(config: AppConfig) -> App {
|
|
223
223
|
let wm = WindowManager::new();
|
|
224
|
-
match config.
|
|
224
|
+
match config.webContentInspectable {
|
|
225
225
|
ZappInspectable::On => { wm.webContentInspectable = true; },
|
|
226
226
|
ZappInspectable::Off => { wm.webContentInspectable = false; },
|
|
227
227
|
ZappInspectable::Auto => {
|
package/native/build.zc
CHANGED
|
@@ -53,7 +53,7 @@ fn main() -> int {
|
|
|
53
53
|
let config = AppConfig{
|
|
54
54
|
name: "Zapp v2 Test",
|
|
55
55
|
applicationShouldTerminateAfterLastWindowClosed: true,
|
|
56
|
-
|
|
56
|
+
webContentInspectable: Zapp::inspectable_on(),
|
|
57
57
|
maxWorkers: 0,
|
|
58
58
|
qjsStackSize: 0,
|
|
59
59
|
backend: false,
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -26,6 +26,7 @@ export interface ZappConfig {
|
|
|
26
26
|
version?: string;
|
|
27
27
|
assetDir?: string; // Default: "./dist" (Vite), configurable for static sites
|
|
28
28
|
devPort?: number; // Default: 5173
|
|
29
|
+
backend?: string; // Path to backend worker source (e.g. "src/server.ts"). Omit for no backend.
|
|
29
30
|
deepLinkSchemes?: string[]; // e.g. ["myapp"] → registers myapp:// URL scheme
|
|
30
31
|
macos?: MacOSConfig;
|
|
31
32
|
security?: SecurityConfig;
|
package/src/init.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Does NOT modify the Vite template files — users add Zapp imports themselves.
|
|
4
4
|
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { mkdir } from "node:fs/promises";
|
|
6
|
+
import { mkdir, rm } from "node:fs/promises";
|
|
7
7
|
import { existsSync } from "node:fs";
|
|
8
8
|
|
|
9
9
|
interface InitOptions {
|
|
@@ -22,8 +22,11 @@ export async function runInit(opts: InitOptions) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// 1. Create Vite project
|
|
25
|
+
// Use bunx create-vite (not `bun create vite`) to avoid auto-installing
|
|
26
|
+
// deps and triggering template postinstall scripts that can start a dev
|
|
27
|
+
// server. The user runs `bun install` themselves after init.
|
|
25
28
|
process.stdout.write(`[zapp] creating ${name} with template ${template}...\n`);
|
|
26
|
-
const viteProc = Bun.spawn(["
|
|
29
|
+
const viteProc = Bun.spawn(["bunx", "create-vite", name, "--template", template], {
|
|
27
30
|
cwd: root,
|
|
28
31
|
stdout: "inherit",
|
|
29
32
|
stderr: "inherit",
|
|
@@ -33,6 +36,11 @@ export async function runInit(opts: InitOptions) {
|
|
|
33
36
|
process.exit(1);
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
// Remove node_modules if create-vite auto-installed — we modify
|
|
40
|
+
// package.json (add zapp deps/scripts) before the user installs.
|
|
41
|
+
const autoModules = path.join(projectDir, "node_modules");
|
|
42
|
+
try { await rm(autoModules, { recursive: true }); } catch {}
|
|
43
|
+
|
|
36
44
|
// 2. Add zapp/ native code
|
|
37
45
|
const zappDir = path.join(projectDir, "zapp");
|
|
38
46
|
await mkdir(zappDir, { recursive: true });
|
|
@@ -51,7 +59,7 @@ fn run_app() -> int {
|
|
|
51
59
|
let config = AppConfig{
|
|
52
60
|
name: "${name}",
|
|
53
61
|
applicationShouldTerminateAfterLastWindowClosed: true,
|
|
54
|
-
|
|
62
|
+
webContentInspectable: Zapp::inspectable_auto(),
|
|
55
63
|
maxWorkers: 0,
|
|
56
64
|
qjsStackSize: 0,
|
|
57
65
|
backend: false,
|
|
@@ -117,17 +125,18 @@ fn main() -> int {
|
|
|
117
125
|
...pkgObj.scripts,
|
|
118
126
|
"dev": "zapp dev",
|
|
119
127
|
"build": "zapp build",
|
|
128
|
+
"package": "zapp package",
|
|
120
129
|
"generate": "zapp generate",
|
|
121
130
|
};
|
|
122
131
|
|
|
123
132
|
pkgObj.dependencies = {
|
|
124
133
|
...(pkgObj.dependencies ?? {}),
|
|
125
|
-
"@zappdev/runtime": "^0.5.0",
|
|
134
|
+
"@zappdev/runtime": "^0.5.0-alpha.0",
|
|
126
135
|
};
|
|
127
136
|
pkgObj.devDependencies = {
|
|
128
137
|
...(pkgObj.devDependencies ?? {}),
|
|
129
|
-
"@zappdev/cli": "^0.5.0",
|
|
130
|
-
"@zappdev/vite": "^0.5.0",
|
|
138
|
+
"@zappdev/cli": "^0.5.0-alpha.0",
|
|
139
|
+
"@zappdev/vite": "^0.5.0-alpha.0",
|
|
131
140
|
};
|
|
132
141
|
|
|
133
142
|
await Bun.write(pkgPath, JSON.stringify(pkgObj, null, 2));
|
|
@@ -158,6 +167,7 @@ export default defineConfig({
|
|
|
158
167
|
process.stdout.write(` Then add to your entry file (e.g. src/main.ts):\n\n`);
|
|
159
168
|
process.stdout.write(` import { Window, WindowEvent, Services } from "@zappdev/runtime";\n\n`);
|
|
160
169
|
process.stdout.write(` Run:\n`);
|
|
161
|
-
process.stdout.write(`
|
|
162
|
-
process.stdout.write(`
|
|
170
|
+
process.stdout.write(` bun run dev # development with Vite HMR\n`);
|
|
171
|
+
process.stdout.write(` bun run build # production build\n`);
|
|
172
|
+
process.stdout.write(` bun run package # .app bundle (macOS)\n\n`);
|
|
163
173
|
}
|
package/src/workers.ts
CHANGED
|
@@ -45,7 +45,7 @@ async function discoverWorkers(srcDir: string): Promise<WorkerEntry[]> {
|
|
|
45
45
|
return [...found.entries()].map(([entryPath, specifier]) => ({ entryPath, specifier }));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export async function bundleWorkers(root: string): Promise<number> {
|
|
48
|
+
export async function bundleWorkers(root: string, backendConfig?: string): Promise<number> {
|
|
49
49
|
const srcDir = path.join(root, "src");
|
|
50
50
|
const outDir = path.join(root, ".zapp", "workers");
|
|
51
51
|
await mkdir(outDir, { recursive: true });
|
|
@@ -81,8 +81,10 @@ export async function bundleWorkers(root: string): Promise<number> {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
// Backend worker —
|
|
85
|
-
const backendPath =
|
|
84
|
+
// Backend worker — from config or fall back to src/backend.ts convention
|
|
85
|
+
const backendPath = backendConfig
|
|
86
|
+
? path.resolve(root, backendConfig)
|
|
87
|
+
: path.join(root, "src", "backend.ts");
|
|
86
88
|
try {
|
|
87
89
|
await stat(backendPath);
|
|
88
90
|
const outPath = path.join(outDir, "backend.mjs");
|
|
@@ -95,12 +97,12 @@ export async function bundleWorkers(root: string): Promise<number> {
|
|
|
95
97
|
minify: false,
|
|
96
98
|
});
|
|
97
99
|
if (result.success) {
|
|
98
|
-
process.stdout.write(
|
|
100
|
+
process.stdout.write(`[zapp] backend worker: ${path.relative(root, backendPath)}\n`);
|
|
99
101
|
} else {
|
|
100
102
|
process.stderr.write("[zapp] backend bundle failed\n");
|
|
101
103
|
}
|
|
102
104
|
} catch {
|
|
103
|
-
// No backend
|
|
105
|
+
// No backend file — that's fine, backend is optional
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
return workers.length;
|