Skip to content

Commit cc95e2f

Browse files
committed
chore: wip
1 parent ab6009b commit cc95e2f

File tree

7 files changed

+309
-148
lines changed

7 files changed

+309
-148
lines changed

.github/workflows/ci.yml

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ concurrency:
1313
cancel-in-progress: true
1414

1515
jobs:
16-
build-and-test:
16+
zig-core:
17+
name: Zig Core Tests
1718
strategy:
1819
matrix:
1920
os: [ubuntu-latest, macos-latest, windows-latest]
@@ -37,8 +38,8 @@ jobs:
3738
with:
3839
path: |
3940
~/.cache/zig
40-
zig-cache
41-
key: ${{ runner.os }}-zig-${{ matrix.zig-version }}-${{ hashFiles('build.zig') }}
41+
packages/zig/zig-cache
42+
key: ${{ runner.os }}-zig-${{ matrix.zig-version }}-${{ hashFiles('packages/zig/build.zig') }}
4243
restore-keys: |
4344
${{ runner.os }}-zig-${{ matrix.zig-version }}-
4445
@@ -48,24 +49,53 @@ jobs:
4849
sudo apt-get update
4950
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev
5051
51-
- name: Build
52+
- name: Build Zig core
53+
working-directory: packages/zig
5254
run: zig build
5355

54-
- name: Run tests
56+
- name: Run Zig tests
57+
working-directory: packages/zig
5558
run: zig build test
5659

57-
- name: Build examples
58-
run: |
59-
zig build
60-
zig build run-minimal -- --help
61-
6260
- name: Check binary size
6361
if: runner.os == 'Linux'
6462
run: |
65-
ls -lh zig-out/bin/
66-
size zig-out/bin/zyte-minimal || true
63+
ls -lh packages/zig/zig-out/bin/
64+
size packages/zig/zig-out/bin/zyte || true
65+
66+
typescript-sdk:
67+
name: TypeScript SDK Tests
68+
runs-on: ubuntu-latest
69+
70+
steps:
71+
- uses: actions/checkout@v4
72+
73+
- name: Setup Bun
74+
uses: oven-sh/setup-bun@v1
75+
with:
76+
bun-version: latest
77+
78+
- name: Install dependencies
79+
run: bun install
80+
81+
- name: Type check TypeScript SDK
82+
working-directory: packages/typescript
83+
run: bun run typecheck
84+
85+
- name: Run TypeScript SDK tests
86+
working-directory: packages/typescript
87+
run: bun test
88+
89+
- name: Build TypeScript SDK
90+
working-directory: packages/typescript
91+
run: bun run build
92+
93+
- name: Type check create-zyte
94+
working-directory: packages/create-zyte
95+
run: bun run typecheck
6796

6897
lint:
98+
name: Code Formatting
6999
runs-on: ubuntu-latest
70100

71101
steps:
@@ -76,11 +106,14 @@ jobs:
76106
with:
77107
version: '0.15.1'
78108

79-
- name: Check formatting
109+
- name: Check Zig formatting
110+
working-directory: packages/zig
80111
run: zig fmt --check src/ build.zig
81112

82-
cross-compile:
113+
integration:
114+
name: Integration Tests
83115
runs-on: ubuntu-latest
116+
needs: [zig-core, typescript-sdk]
84117

85118
steps:
86119
- uses: actions/checkout@v4
@@ -90,26 +123,27 @@ jobs:
90123
with:
91124
version: '0.15.1'
92125

126+
- name: Setup Bun
127+
uses: oven-sh/setup-bun@v1
128+
with:
129+
bun-version: latest
130+
93131
- name: Install Linux dependencies
94132
run: |
95133
sudo apt-get update
96134
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev
97135
98-
- name: Cache Zig artifacts
99-
uses: actions/cache@v4
100-
with:
101-
path: |
102-
~/.cache/zig
103-
zig-cache
104-
key: cross-compile-zig-0.15.1-${{ hashFiles('build.zig') }}
105-
restore-keys: |
106-
cross-compile-zig-0.15.1-
136+
- name: Build Zig core
137+
run: bun run build:core
107138

108-
- name: Build for all platforms
109-
run: |
110-
zig build build-linux
111-
zig build build-macos
112-
echo "Windows cross-compilation requires additional setup"
139+
- name: Install TypeScript dependencies
140+
run: bun install
141+
142+
- name: Test TypeScript SDK with built binary
143+
run: bun run test:sdk
113144

114-
- name: List built artifacts
115-
run: ls -lh zig-out/bin/
145+
- name: Verify create-zyte works
146+
run: |
147+
bun run create test-app --skip-install
148+
ls -la test-app/
149+
cat test-app/package.json

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,33 @@ Build native menubar/system tray apps with full platform support:
192192
- 🔗 **Custom Protocols** - Register custom URL handlers (zyte://)
193193
- 🎯 **Drag & Drop** - File drag and drop support
194194

195+
## Quick Start
196+
197+
The fastest way to get started is with `create-zyte`:
198+
199+
```bash
200+
# Create a new Zyte app
201+
bun create zyte my-app
202+
203+
# Navigate to your app
204+
cd my-app
205+
206+
# Start development
207+
bun run dev
208+
```
209+
210+
Choose from multiple templates:
211+
- **minimal** - Simplest possible app
212+
- **full-featured** - Modern styled app with examples
213+
- **todo-app** - Interactive todo list
214+
215+
```bash
216+
# Use a specific template
217+
bun create zyte my-app --template full-featured
218+
```
219+
220+
**See [create-zyte documentation](./packages/create-zyte/README.md) for all options.**
221+
195222
## Get Started
196223

197224
### TypeScript/JavaScript (Recommended)

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
"build": "bun run build:core && bun run build:sdk",
1414
"build:core": "cd packages/zig && zig build -Doptimize=ReleaseSafe",
1515
"build:debug": "cd packages/zig && zig build",
16-
"build:sdk": "cd packages/ts-zyte && bun run build",
16+
"build:sdk": "cd packages/typescript && bun run build",
1717
"test": "cd packages/zig && zig build test",
18-
"test:sdk": "cd packages/ts-zyte && bun test",
18+
"test:sdk": "cd packages/typescript && bun test",
19+
"typecheck": "cd packages/typescript && bun run typecheck && cd ../create-zyte && bun run typecheck",
1920
"run": "cd packages/zig && zig build run",
2021
"run:minimal": "cd packages/zig && zig build run-minimal",
22+
"create": "cd packages/create-zyte && bun bin/cli.ts",
2123
"clean": "rm -rf packages/zig/zig-cache packages/zig/zig-out && bun run clean:packages",
2224
"clean:packages": "rm -rf packages/*/dist packages/*/node_modules",
2325
"fmt": "cd packages/zig && zig fmt src/ build.zig",
2426
"fmt:check": "cd packages/zig && zig fmt --check src/ build.zig",
25-
"dev": "cd packages/ts-zyte && bun run dev",
26-
"release": "bun run build && bun run publish:sdk",
27-
"publish:sdk": "cd packages/ts-zyte && bun publish"
27+
"dev": "cd packages/typescript && bun run dev",
28+
"release": "bun run build && bun run publish:all",
29+
"publish:all": "cd packages/typescript && bun publish && cd ../create-zyte && bun publish"
2830
},
2931
"devDependencies": {
3032
"better-dx": "^0.1.7"

packages/create-zyte/README.md

3.22 KB
Binary file not shown.

packages/create-zyte/tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
"isolatedDeclarations": true
66
},
77
"include": [
8-
"src",
9-
"bin",
10-
"test"
11-
],
12-
"exclude": [
13-
"test/outputs"
8+
"bin"
149
]
1510
}

packages/typescript/src/index.ts

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ export class ZyteApp {
116116
private config: AppConfig
117117

118118
constructor(config: AppConfig = {}) {
119+
// Validate window dimensions
120+
if (config.window?.width !== undefined && (config.window.width < 100 || config.window.width > 10000)) {
121+
throw new Error(`Invalid window width: ${config.window.width}. Must be between 100 and 10000 pixels.`)
122+
}
123+
if (config.window?.height !== undefined && (config.window.height < 100 || config.window.height > 10000)) {
124+
throw new Error(`Invalid window height: ${config.window.height}. Must be between 100 and 10000 pixels.`)
125+
}
126+
127+
// Validate that either html or url is provided, not both
128+
if (config.html && config.url) {
129+
console.warn('⚠️ Both html and url provided. URL will take precedence.')
130+
}
131+
119132
this.config = {
120133
window: {
121134
title: 'Zyte App',
@@ -143,6 +156,14 @@ export class ZyteApp {
143156
this.config.html = html
144157
}
145158

159+
// Validate that we have something to show
160+
if (!this.config.html && !this.config.url) {
161+
throw new Error(
162+
'No content to display. Provide either html or url:\n' +
163+
' show(html, options) or loadURL(url, options)'
164+
)
165+
}
166+
146167
const args = this.buildArgs()
147168
const zytePath = await this.findZyteBinary()
148169

@@ -151,13 +172,49 @@ export class ZyteApp {
151172
})
152173

153174
return new Promise((resolve, reject) => {
154-
this.process?.on('error', reject)
175+
this.process?.on('error', (error: Error & { code?: string }) => {
176+
const errorMessage = [
177+
`❌ Failed to start Zyte process: ${error.message}`,
178+
'',
179+
]
180+
181+
// Provide platform-specific troubleshooting
182+
if (error.code === 'EACCES') {
183+
errorMessage.push(
184+
'Permission denied. Try making the binary executable:',
185+
` chmod +x ${zytePath}`,
186+
)
187+
}
188+
else if (error.code === 'ENOENT') {
189+
errorMessage.push(
190+
'Binary not found or not executable.',
191+
'Ensure Zyte core is built:',
192+
' bun run build:core',
193+
)
194+
}
195+
else {
196+
errorMessage.push(
197+
'For troubleshooting, visit:',
198+
' https://github.com/stacksjs/zyte/issues',
199+
)
200+
}
201+
202+
reject(new Error(errorMessage.join('\n')))
203+
})
204+
155205
this.process?.on('exit', (code) => {
156-
if (code === 0) {
206+
if (code === 0 || code === null) {
157207
resolve()
158208
}
159209
else {
160-
reject(new Error(`Zyte process exited with code ${code}`))
210+
reject(new Error(
211+
`❌ Zyte process exited with code ${code}\n\n` +
212+
'This may indicate:\n' +
213+
' • Invalid window configuration\n' +
214+
' • Malformed HTML content\n' +
215+
' • System resource constraints\n\n' +
216+
'Check the console output above for more details.'
217+
))
161218
}
162219
})
163220
})
@@ -229,6 +286,13 @@ export class ZyteApp {
229286

230287
private async findZyteBinary(): Promise<string> {
231288
if (this.config.zytePath) {
289+
if (!existsSync(this.config.zytePath)) {
290+
throw new Error(
291+
`Custom Zyte binary path not found: ${this.config.zytePath}\n\n` +
292+
'Please ensure the path is correct or build the Zyte core:\n' +
293+
' bun run build:core'
294+
)
295+
}
232296
return this.config.zytePath
233297
}
234298

@@ -261,7 +325,28 @@ export class ZyteApp {
261325
}
262326
}
263327

264-
throw new Error('Zyte binary not found. Please build the project first with: bun run build:core')
328+
// Provide helpful error message with troubleshooting steps
329+
const errorMessage = [
330+
'❌ Zyte binary not found',
331+
'',
332+
'Tried the following locations:',
333+
...possiblePaths.map(p => ` • ${p}`),
334+
'',
335+
'To fix this issue:',
336+
'',
337+
'1. Build the Zyte core:',
338+
' bun run build:core',
339+
'',
340+
'2. Or install Zyte globally:',
341+
' bun install -g ts-zyte',
342+
'',
343+
'3. Or specify a custom binary path:',
344+
' createApp({ zytePath: "/path/to/zyte" })',
345+
'',
346+
'For more help, visit: https://github.com/stacksjs/zyte',
347+
].join('\n')
348+
349+
throw new Error(errorMessage)
265350
}
266351

267352
private checkBinaryExists(path: string): Promise<void> {

0 commit comments

Comments
 (0)