create-tarve 0.0.0-stage → 0.10.0

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/README.md CHANGED
@@ -1,3 +1,35 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # create-tarve
2
+
3
+ Scaffold a new [Tarve](https://github.com/omarcosr/tarve) app.
4
+
5
+ ```sh
6
+ bun create tarve my-app
7
+ npm create tarve@latest my-app
8
+ # or: bunx create-tarve my-app / npx create-tarve my-app
9
+ ```
10
+
11
+ Missing answers are prompted for (directory, template, runtime). Flags skip the prompts:
12
+
13
+ ```sh
14
+ bun create tarve my-app --template tailwind --runtime bun --yes
15
+ npm create tarve@latest my-app -- --template svelte --runtime node --yes
16
+ ```
17
+
18
+ | Option | |
19
+ | --- | --- |
20
+ | `-t, --template <name>` | `basic`, `tailwind`, `svelte`, `tray` |
21
+ | `-r, --runtime bun\|node` | scripts, `@types/*` and `engines` for Bun 1.4+ or Node.js 26.10+ (default: the runtime running create-tarve) |
22
+ | `--title <title>` | display name (default: from the directory name) |
23
+ | `-y, --yes` | never prompt; defaults are `basic` and the launching runtime |
24
+ | `-f, --force` | write into a non-empty directory (existing files with the same names are overwritten) |
25
+
26
+ ## Templates
27
+
28
+ - **basic**: a counter with `Window`, `Column`, `Text` and `Button`.
29
+ - **tailwind**: the counter styled with Tailwind CSS 4 classes (compiled natively by `@tarve/core`) and a light/dark switch.
30
+ - **svelte**: a Svelte 5 counter through `@tarve/svelte` (`app.ts` + `App.svelte`; Bun projects get a `bunfig.toml` preload).
31
+ - **tray**: a system tray app with a menu, notifications and hide-on-close.
32
+
33
+ Every project gets a `package.json` with `@tarve/core` and the scripts `dev` (`tarve dev`), `start` (`tarve run`), `build` (`tarve build`) and `typecheck`, the README's `tsconfig.json`, a `.gitignore` and a `README.md`.
34
+
35
+ No dependencies: the CLI is one ESM file using `node:readline`, so it runs on Node.js 26.10+ and Bun.
package/index.js ADDED
@@ -0,0 +1,362 @@
1
+ #!/usr/bin/env node
2
+ // create-tarve: scaffolds a Tarve app. Plain ESM JavaScript with no dependencies so it runs
3
+ // unchanged under `bun create tarve`, `bunx create-tarve`, `npm create tarve` and `npx create-tarve`
4
+ // (Node refuses to strip TypeScript types inside node_modules).
5
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
6
+ import { basename, dirname, join, relative, resolve } from "node:path";
7
+ import { createInterface } from "node:readline/promises";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ /** The release of create-tarve, which is also the Tarve release its templates depend on. */
11
+ export const VERSION = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version;
12
+ export const TEMPLATES_DIR = join(dirname(fileURLToPath(import.meta.url)), "templates");
13
+ export const RUNTIMES = /** @type {const} */ (["bun", "node"]);
14
+
15
+ const TEXT_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".json", ".md", ".svelte", ".toml", ".css", ".txt", ""]);
16
+ const IGNORED_EXISTING = new Set([".git", ".DS_Store", "Thumbs.db"]);
17
+
18
+ /**
19
+ * @typedef {{ name: string, description: string, entry: string, dependencies?: Record<string, string>, tarve?: Record<string, unknown>, bunPreload?: string[], types?: string[] }} TemplateInfo
20
+ * @typedef {{ dir?: string, template?: string, runtime?: string, yes: boolean, force: boolean, help: boolean, version: boolean, title?: string }} Options
21
+ */
22
+
23
+ /** @returns {Array<TemplateInfo & { id: string }>} */
24
+ export function listTemplates() {
25
+ return readdirSync(TEMPLATES_DIR)
26
+ .filter(id => existsSync(join(TEMPLATES_DIR, id, "template.json")))
27
+ .map(id => ({ id, .../** @type {TemplateInfo} */ (JSON.parse(readFileSync(join(TEMPLATES_DIR, id, "template.json"), "utf8"))) }))
28
+ .sort((a, b) => order(a.id) - order(b.id) || a.id.localeCompare(b.id));
29
+ }
30
+
31
+ /** @param {string} id */
32
+ function order(id) {
33
+ const index = ["basic", "tailwind", "svelte", "tray"].indexOf(id);
34
+ return index < 0 ? 99 : index;
35
+ }
36
+
37
+ /** @param {string[]} argv @returns {Options} */
38
+ export function parseArgs(argv) {
39
+ /** @type {Options} */
40
+ const options = { yes: false, force: false, help: false, version: false };
41
+ for (let i = 0; i < argv.length; i++) {
42
+ const arg = argv[i];
43
+ const [flag, inline] = arg.startsWith("--") && arg.includes("=") ? [arg.slice(0, arg.indexOf("=")), arg.slice(arg.indexOf("=") + 1)] : [arg, undefined];
44
+ const value = () => {
45
+ if (inline !== undefined) return inline;
46
+ const next = argv[++i];
47
+ if (next === undefined || next.startsWith("-")) throw new Error(`${flag} needs a value`);
48
+ return next;
49
+ };
50
+ switch (flag) {
51
+ case "-t": case "--template": options.template = value(); break;
52
+ case "-r": case "--runtime": options.runtime = value(); break;
53
+ case "--title": options.title = value(); break;
54
+ case "-y": case "--yes": options.yes = true; break;
55
+ case "-f": case "--force": options.force = true; break;
56
+ case "-h": case "--help": options.help = true; break;
57
+ case "-v": case "--version": options.version = true; break;
58
+ default:
59
+ if (flag.startsWith("-")) throw new Error(`Unknown option ${flag}`);
60
+ if (options.dir !== undefined) throw new Error(`Unexpected argument ${flag}`);
61
+ options.dir = flag;
62
+ }
63
+ }
64
+ return options;
65
+ }
66
+
67
+ /** A valid npm package name derived from a directory name. @param {string} input */
68
+ export function toPackageName(input) {
69
+ const name = input.trim().toLowerCase()
70
+ .replace(/[^a-z0-9._~-]+/g, "-")
71
+ .replace(/^[._-]+/, "")
72
+ .replace(/-+$/, "");
73
+ return name || "tarve-app";
74
+ }
75
+
76
+ /** "my-cool_app" -> "My Cool App". @param {string} name */
77
+ export function toTitle(name) {
78
+ return name.split(/[-_.\s]+/).filter(Boolean).map(word => word[0].toUpperCase() + word.slice(1)).join(" ") || "Tarve App";
79
+ }
80
+
81
+ /** The runtime/package manager that launched us. @returns {{ runtime: "bun" | "node", pm: string }} */
82
+ export function detectEnvironment(env = process.env) {
83
+ const agent = env.npm_config_user_agent ?? "";
84
+ const pm = agent.split("/")[0] || (process.versions.bun ? "bun" : "npm");
85
+ const runtime = pm === "bun" || (!agent && process.versions.bun) ? "bun" : "node";
86
+ return { runtime, pm };
87
+ }
88
+
89
+ /** @param {string} dir */
90
+ export function isEmptyDir(dir) {
91
+ if (!existsSync(dir)) return true;
92
+ if (!statSync(dir).isDirectory()) return false;
93
+ return readdirSync(dir).every(entry => IGNORED_EXISTING.has(entry));
94
+ }
95
+
96
+ /**
97
+ * Writes the project. Throws if `dir` is not empty and `force` is false.
98
+ * @param {{ dir: string, template: string, runtime: "bun" | "node", name?: string, title?: string, force?: boolean }} input
99
+ * @returns {{ dir: string, name: string, title: string, entry: string, files: string[] }}
100
+ */
101
+ export function scaffold(input) {
102
+ const dir = resolve(input.dir);
103
+ const templates = listTemplates();
104
+ const template = templates.find(item => item.id === input.template);
105
+ if (!template) throw new Error(`Unknown template "${input.template}". Available: ${templates.map(item => item.id).join(", ")}`);
106
+ if (!RUNTIMES.includes(/** @type {never} */ (input.runtime))) throw new Error(`Unknown runtime "${input.runtime}". Use bun or node.`);
107
+ if (existsSync(dir) && !statSync(dir).isDirectory()) throw new Error(`${dir} exists and is not a directory`);
108
+ if (!input.force && !isEmptyDir(dir)) throw new Error(`${dir} is not empty. Use --force to write into it anyway.`);
109
+ const name = toPackageName(input.name ?? basename(dir));
110
+ const title = input.title ?? toTitle(name);
111
+ const replacements = { __APP_NAME__: name, __APP_TITLE__: title, __TARVE_VERSION__: VERSION, __RUNTIME__: input.runtime, __ENTRY__: template.entry };
112
+ /** @type {string[]} */
113
+ const files = [];
114
+ const write = (/** @type {string} */ path, /** @type {string | Buffer} */ content) => {
115
+ const target = join(dir, path);
116
+ mkdirSync(dirname(target), { recursive: true });
117
+ writeFileSync(target, content);
118
+ files.push(path.replaceAll("\\", "/"));
119
+ };
120
+
121
+ const filesDir = join(TEMPLATES_DIR, template.id, "files");
122
+ for (const path of walk(filesDir)) {
123
+ const rel = relative(filesDir, path);
124
+ const out = rel.replace(/(^|[\\/])_gitignore$/, "$1.gitignore");
125
+ const ext = rel.includes(".") ? rel.slice(rel.lastIndexOf(".")) : "";
126
+ if (TEXT_EXTENSIONS.has(ext)) write(out, replace(readFileSync(path, "utf8"), replacements));
127
+ else { mkdirSync(dirname(join(dir, out)), { recursive: true }); copyFileSync(path, join(dir, out)); files.push(out.replaceAll("\\", "/")); }
128
+ }
129
+
130
+ write("package.json", JSON.stringify(packageJson(template, name, title, input.runtime), null, 2) + "\n");
131
+ write("tsconfig.json", JSON.stringify(tsconfig(template, input.runtime), null, 2) + "\n");
132
+ if (!files.includes(".gitignore")) write(".gitignore", "node_modules/\ndist/\n*.log\n.DS_Store\n# update signing keys (tarve keygen)\ntarve-update.key\n");
133
+ if (!files.includes("README.md")) write("README.md", readme(template, title, input.runtime));
134
+ if (input.runtime === "bun" && template.bunPreload?.length) {
135
+ write("bunfig.toml", `# Lets plain \`bun ${template.entry}\` load the same way \`tarve run\` does.\npreload = [${template.bunPreload.map(item => JSON.stringify(item)).join(", ")}]\n`);
136
+ }
137
+ return { dir, name, title, entry: template.entry, files: files.sort() };
138
+ }
139
+
140
+ /** @param {string} text @param {Record<string, string>} values */
141
+ function replace(text, values) {
142
+ return text.replace(/__(APP_NAME|APP_TITLE|TARVE_VERSION|RUNTIME|ENTRY)__/g, match => values[match] ?? match);
143
+ }
144
+
145
+ /** @param {string} dir @returns {string[]} */
146
+ function walk(dir) {
147
+ if (!existsSync(dir)) return [];
148
+ return readdirSync(dir, { withFileTypes: true }).flatMap(entry => entry.isDirectory() ? walk(join(dir, entry.name)) : [join(dir, entry.name)]);
149
+ }
150
+
151
+ /** @param {TemplateInfo} template @param {string} name @param {string} title @param {"bun" | "node"} runtime */
152
+ export function packageJson(template, name, title, runtime) {
153
+ const flag = ` --runtime ${runtime}`;
154
+ return {
155
+ name,
156
+ version: "0.1.0",
157
+ private: true,
158
+ type: "module",
159
+ scripts: {
160
+ dev: `tarve dev ${template.entry}${flag}`,
161
+ start: `tarve run ${template.entry}${flag}`,
162
+ build: `tarve build ${template.entry}${flag}`,
163
+ typecheck: "tsc --noEmit",
164
+ },
165
+ tarve: { name: title, ...(template.tarve ?? {}) },
166
+ dependencies: { "@tarve/core": `^${VERSION}`, ...Object.fromEntries(Object.entries(template.dependencies ?? {}).map(([name, range]) => [name, range.replaceAll("__TARVE_VERSION__", VERSION)])) },
167
+ devDependencies: {
168
+ ...(runtime === "bun" ? { "@types/bun": "^1.4.2" } : { "@types/node": ">=24" }),
169
+ typescript: "^7.0.2",
170
+ },
171
+ engines: runtime === "bun" ? { bun: ">=1.4.0" } : { node: ">=26.10.0" },
172
+ };
173
+ }
174
+
175
+ /** The tsconfig from the Tarve README. @param {TemplateInfo} template @param {"bun" | "node"} runtime */
176
+ export function tsconfig(template, runtime) {
177
+ return {
178
+ compilerOptions: {
179
+ target: "ESNext",
180
+ module: "ESNext",
181
+ moduleResolution: "Bundler",
182
+ strict: true,
183
+ noEmit: true,
184
+ skipLibCheck: true,
185
+ jsx: "react-jsx",
186
+ jsxImportSource: "@tarve/core",
187
+ types: [runtime, "@tarve/core/assets", ...(template.types ?? [])],
188
+ },
189
+ include: ["**/*.ts", "**/*.tsx"],
190
+ exclude: ["node_modules", "dist"],
191
+ };
192
+ }
193
+
194
+ /** @param {"bun" | "node"} runtime */
195
+ function commands(runtime) {
196
+ return runtime === "bun"
197
+ ? { install: "bun install", run: (/** @type {string} */ script) => `bun run ${script}` }
198
+ : { install: "npm install", run: (/** @type {string} */ script) => script === "start" ? "npm start" : `npm run ${script}` };
199
+ }
200
+
201
+ /** @param {TemplateInfo} template @param {string} title @param {"bun" | "node"} runtime */
202
+ function readme(template, title, runtime) {
203
+ const cmd = commands(runtime);
204
+ return `# ${title}
205
+
206
+ A [Tarve](https://github.com/omarcosr/tarve) app (${template.description}), created with \`create-tarve\` for ${runtime === "bun" ? "Bun 1.4+" : "Node.js 26.10+"}.
207
+
208
+ \`\`\`sh
209
+ ${cmd.install}
210
+ ${cmd.run("dev")} # hot reload into the same window (tarve dev ${template.entry})
211
+ ${cmd.run("start")} # run once (tarve run ${template.entry})
212
+ ${cmd.run("build")} # standalone executable in dist/ (tarve build ${template.entry})
213
+ \`\`\`
214
+
215
+ The entry is \`${template.entry}\`. App name, icon and publisher live under \`"tarve"\` in \`package.json\`.
216
+ See the Tarve README for components, Tailwind classes, Android builds and more.
217
+ `;
218
+ }
219
+
220
+ /** @param {{ dir: string, entry: string }} result @param {"bun" | "node"} runtime @param {string} [cwd] */
221
+ export function nextSteps(result, runtime, cwd = process.cwd()) {
222
+ const cmd = commands(runtime);
223
+ const rel = relative(cwd, result.dir) || ".";
224
+ const lines = [];
225
+ if (rel !== ".") lines.push(`cd ${/\s/.test(rel) ? JSON.stringify(rel) : rel}`);
226
+ lines.push(cmd.install, cmd.run("dev"));
227
+ return lines;
228
+ }
229
+
230
+ function help() {
231
+ const ids = listTemplates().map(item => `${item.id.padEnd(10)} ${item.description}`).join("\n ");
232
+ return `create-tarve ${VERSION}: scaffold a Tarve app
233
+
234
+ Usage:
235
+ bun create tarve [dir] [options]
236
+ npm create tarve@latest [dir] -- [options]
237
+
238
+ Options:
239
+ -t, --template <name> app template (prompted when omitted)
240
+ -r, --runtime bun|node runtime for the scripts and types (default: the one running this)
241
+ --title <title> window/app display name (default: from the directory name)
242
+ -y, --yes accept defaults, never prompt
243
+ -f, --force write into a non-empty directory (existing files may be overwritten)
244
+ -h, --help show this help
245
+ -v, --version show the version
246
+
247
+ Templates:
248
+ ${ids}
249
+ `;
250
+ }
251
+
252
+ /** Minimal line-based prompts over node:readline (no dependencies). */
253
+ class Prompter {
254
+ constructor() {
255
+ this.rl = createInterface({ input: process.stdin, output: process.stdout, terminal: Boolean(process.stdin.isTTY && process.stdout.isTTY) });
256
+ /** @type {string[]} */
257
+ this.buffered = [];
258
+ /** @type {Array<(line: string | undefined) => void>} */
259
+ this.waiting = [];
260
+ this.closed = false;
261
+ this.rl.on("line", line => { const next = this.waiting.shift(); if (next) next(line); else this.buffered.push(line); });
262
+ this.rl.on("close", () => { this.closed = true; for (const next of this.waiting.splice(0)) next(undefined); });
263
+ }
264
+
265
+ /** @param {string} question @returns {Promise<string | undefined>} */
266
+ async line(question) {
267
+ process.stdout.write(question);
268
+ if (this.buffered.length) { const value = /** @type {string} */ (this.buffered.shift()); if (!process.stdin.isTTY) process.stdout.write(value + "\n"); return value; }
269
+ if (this.closed) { process.stdout.write("\n"); return undefined; }
270
+ return new Promise(resolveLine => this.waiting.push(resolveLine));
271
+ }
272
+
273
+ /** @param {string} question @param {string} fallback */
274
+ async text(question, fallback) {
275
+ const answer = (await this.line(`? ${question} (${fallback}) `))?.trim();
276
+ return answer || fallback;
277
+ }
278
+
279
+ /** @param {string} question @param {Array<{ value: string, label: string }>} choices @param {string} fallback */
280
+ async select(question, choices, fallback) {
281
+ const fallbackIndex = Math.max(0, choices.findIndex(choice => choice.value === fallback));
282
+ process.stdout.write(`? ${question}\n`);
283
+ choices.forEach((choice, index) => process.stdout.write(` ${index + 1}) ${choice.label}${index === fallbackIndex ? " (default)" : ""}\n`));
284
+ for (;;) {
285
+ const answer = (await this.line(` Choose 1-${choices.length}: `))?.trim();
286
+ if (answer === undefined || answer === "") return choices[fallbackIndex].value;
287
+ const byNumber = choices[Number(answer) - 1];
288
+ const byName = choices.find(choice => choice.value === answer.toLowerCase());
289
+ if (/^\d+$/.test(answer) && byNumber) return byNumber.value;
290
+ if (byName) return byName.value;
291
+ process.stdout.write(` Please answer a number from 1 to ${choices.length}.\n`);
292
+ }
293
+ }
294
+
295
+ /** @param {string} question @param {boolean} fallback */
296
+ async confirm(question, fallback) {
297
+ const answer = (await this.line(`? ${question} (${fallback ? "Y/n" : "y/N"}) `))?.trim().toLowerCase();
298
+ if (!answer) return fallback;
299
+ return answer === "y" || answer === "yes";
300
+ }
301
+
302
+ close() { this.rl.close(); }
303
+ }
304
+
305
+ /** @param {string[]} argv @returns {Promise<number>} */
306
+ export async function main(argv = process.argv.slice(2)) {
307
+ /** @type {Options} */
308
+ let options;
309
+ try { options = parseArgs(argv); } catch (error) { console.error(`error: ${/** @type {Error} */ (error).message}\n\n${help()}`); return 1; }
310
+ if (options.help) { console.log(help()); return 0; }
311
+ if (options.version) { console.log(VERSION); return 0; }
312
+
313
+ const env = detectEnvironment();
314
+ const templates = listTemplates();
315
+ if (options.template && !templates.some(item => item.id === options.template)) {
316
+ console.error(`error: unknown template "${options.template}". Available: ${templates.map(item => item.id).join(", ")}`);
317
+ return 1;
318
+ }
319
+ if (options.runtime && !RUNTIMES.includes(/** @type {never} */ (options.runtime))) {
320
+ console.error(`error: unknown runtime "${options.runtime}". Use bun or node.`);
321
+ return 1;
322
+ }
323
+ const interactive = !options.yes && (!options.dir || !options.template || !options.runtime);
324
+ const prompter = interactive ? new Prompter() : undefined;
325
+ try {
326
+ let dir = options.dir;
327
+ if (!dir) dir = prompter ? await prompter.text("Project directory:", "tarve-app") : "tarve-app";
328
+ const template = options.template ?? (prompter
329
+ ? await prompter.select("Template:", templates.map(item => ({ value: item.id, label: `${item.id.padEnd(10)} ${item.description}` })), "basic")
330
+ : "basic");
331
+ const runtime = /** @type {"bun" | "node"} */ (options.runtime ?? (prompter
332
+ ? await prompter.select("Runtime:", [{ value: "bun", label: "bun Bun 1.4+" }, { value: "node", label: "node Node.js 26.10+" }], env.runtime)
333
+ : env.runtime));
334
+ let force = options.force;
335
+ const target = resolve(dir);
336
+ if (!force && !isEmptyDir(target)) {
337
+ if (prompter && process.stdin.isTTY) force = await prompter.confirm(`${target} is not empty. Write into it anyway?`, false);
338
+ if (!force) { console.error(`error: ${target} is not empty. Use --force to write into it anyway.`); return 1; }
339
+ }
340
+ prompter?.close();
341
+ const result = scaffold({ dir, template, runtime, title: options.title, force });
342
+ console.log(`\nCreated ${result.title} (${template}, ${runtime}) in ${result.dir}\n`);
343
+ console.log("Next steps:");
344
+ for (const line of nextSteps(result, runtime)) console.log(` ${line}`);
345
+ console.log(`\nBuild a standalone executable with: ${commands(runtime).run("build")}`);
346
+ return 0;
347
+ } catch (error) {
348
+ console.error(`error: ${/** @type {Error} */ (error).message}`);
349
+ return 1;
350
+ } finally {
351
+ prompter?.close();
352
+ }
353
+ }
354
+
355
+ function isMain() {
356
+ // @ts-ignore Bun-only
357
+ if (import.meta.main !== undefined) return Boolean(import.meta.main);
358
+ if (!process.argv[1]) return false;
359
+ try { return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url)); } catch { return false; }
360
+ }
361
+
362
+ if (isMain()) process.exitCode = await main();
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "create-tarve",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.10.0",
4
+ "description": "Scaffold a new Tarve app: bun create tarve my-app / npm create tarve@latest my-app",
5
+ "license": "Apache-2.0",
6
+ "keywords": [
7
+ "tarve",
8
+ "create",
9
+ "scaffold",
10
+ "template",
11
+ "gui",
12
+ "desktop",
13
+ "native"
14
+ ],
15
+ "homepage": "https://github.com/omarcosr/tarve/tree/main/packages/create-tarve#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/omarcosr/tarve.git",
19
+ "directory": "packages/create-tarve"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/omarcosr/tarve/issues"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "provenance": true
27
+ },
28
+ "type": "module",
29
+ "bin": {
30
+ "create-tarve": "./index.js"
31
+ },
32
+ "exports": {
33
+ ".": "./index.js"
34
+ },
35
+ "files": [
36
+ "index.js",
37
+ "templates",
38
+ "README.md"
39
+ ],
40
+ "engines": {
41
+ "bun": ">=1.4.0",
42
+ "node": ">=26.10.0"
43
+ }
44
+ }
@@ -0,0 +1,23 @@
1
+ import { Button, Column, Row, Text, Window, createApp } from "@tarve/core";
2
+
3
+ // State is plain variables: Tarve re-renders after every event handler.
4
+ let count = 0;
5
+
6
+ function App() {
7
+ return (
8
+ <Window title="__APP_TITLE__" width={520} height={360}>
9
+ <Column flex={1} align="center" justify="center" gap={16}>
10
+ <Text size={20} weight={600}>__APP_TITLE__</Text>
11
+ <Text size={42} weight={700}>{count}</Text>
12
+ <Row gap={8}>
13
+ <Button variant="outline" onClick={() => count--}>Decrease</Button>
14
+ <Button onClick={() => count++}>Increase</Button>
15
+ </Row>
16
+ </Column>
17
+ </Window>
18
+ );
19
+ }
20
+
21
+ const app = createApp(App);
22
+ await app.ready;
23
+ await app.closed;
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Basic",
3
+ "description": "a counter with Tarve components",
4
+ "entry": "app.tsx"
5
+ }
@@ -0,0 +1,13 @@
1
+ <script lang="ts">
2
+ let count = $state(0);
3
+ </script>
4
+
5
+ <svelte:head><title>__APP_TITLE__</title></svelte:head>
6
+ <div class="flex flex-1 flex-col items-center justify-center gap-4 p-6">
7
+ <span class="text-sm font-semibold text-muted-foreground">__APP_TITLE__</span>
8
+ <span class="text-5xl font-bold">{count}</span>
9
+ <div class="flex flex-row gap-2">
10
+ <button class="px-4 py-2 rounded-md border border-border" onclick={() => count--}>Decrease</button>
11
+ <button class="px-4 py-2 rounded-md bg-primary text-primary-foreground" onclick={() => count++}>Increase</button>
12
+ </div>
13
+ </div>
@@ -0,0 +1,6 @@
1
+ // `tarve run|dev|build` compile .svelte imports through @tarve/svelte.
2
+ import { mount } from "@tarve/svelte";
3
+ import App from "./App.svelte";
4
+
5
+ const { app } = mount(App, { window: { title: "__APP_TITLE__", width: 480, height: 360, titleBar: true } });
6
+ await app.closed;
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "Svelte",
3
+ "description": "a Svelte 5 counter through @tarve/svelte",
4
+ "entry": "app.ts",
5
+ "dependencies": {
6
+ "@tarve/svelte": "^__TARVE_VERSION__",
7
+ "svelte": "^5.57.2"
8
+ },
9
+ "bunPreload": ["@tarve/svelte/bun-preload"],
10
+ "types": ["@tarve/svelte/elements"]
11
+ }
@@ -0,0 +1,32 @@
1
+ import { TitleBar, Window, createApp, darkTheme, lightTheme, tw } from "@tarve/core";
2
+
3
+ // Tailwind classes are compiled natively by @tarve/core: no PostCSS or build step.
4
+ let count = 0;
5
+ let dark = false;
6
+
7
+ function App() {
8
+ return (
9
+ <Window title="__APP_TITLE__" width={560} height={420} theme={dark ? darkTheme : lightTheme} style={tw("bg-background")}>
10
+ <TitleBar title="__APP_TITLE__" />
11
+ <div class="flex flex-1 flex-col items-center justify-center gap-6 p-8">
12
+ <span class="text-sm font-semibold uppercase tracking-wider text-muted-foreground">__APP_TITLE__</span>
13
+ <span class="text-6xl font-bold text-foreground">{count}</span>
14
+ <div class="flex flex-row gap-3">
15
+ <div class="px-4 py-2 rounded-lg border border-border text-foreground hover:bg-muted active:scale-95 transition" onClick={() => count--}>
16
+ Decrease
17
+ </div>
18
+ <div class="px-4 py-2 rounded-lg bg-primary text-primary-foreground shadow-md hover:bg-primary/90 active:scale-95 transition" onClick={() => count++}>
19
+ Increase
20
+ </div>
21
+ </div>
22
+ <div class="px-3 py-1.5 rounded-md text-xs bg-muted text-muted-foreground hover:bg-accent" onClick={() => { dark = !dark; }}>
23
+ {dark ? "Light theme" : "Dark theme"}
24
+ </div>
25
+ </div>
26
+ </Window>
27
+ );
28
+ }
29
+
30
+ const app = createApp(App);
31
+ await app.ready;
32
+ await app.closed;
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Tailwind",
3
+ "description": "a counter styled with Tailwind CSS 4 classes",
4
+ "entry": "app.tsx"
5
+ }
@@ -0,0 +1,61 @@
1
+ import { Button, Column, Row, Text, TitleBar, Window, createApp, theme } from "@tarve/core";
2
+
3
+ // tray: whether the tray icon can be seen (undefined until the system answers).
4
+ const state = { muted: false, sent: 0, tray: undefined as boolean | undefined };
5
+
6
+ function App() {
7
+ return (
8
+ <Window title="__APP_TITLE__" width={420} height={280} position="center"
9
+ onCloseRequest={event => { if (state.tray) { event.preventDefault(); app.hide(); } }}>
10
+ <TitleBar title="__APP_TITLE__" />
11
+ <Column flex={1} gap={12} padding={24} style={{ background: theme.colors.background }}>
12
+ <Text style={{ fontSize: 18, fontWeight: 600 }}>__APP_TITLE__</Text>
13
+ <Text style={{ color: theme.colors.mutedForeground }}>
14
+ {state.tray === false
15
+ ? "No system tray host is running on this desktop, so the window stays open and closing it quits."
16
+ : "Closing the window hides it. Click the tray icon to bring it back; right-click it for the menu."}
17
+ </Text>
18
+ <Text>Notifications sent: {String(state.sent)}{state.muted ? " (muted)" : ""}</Text>
19
+ <Row gap={8}>
20
+ <Button disabled={state.muted} onClick={() => ping()}>Send notification</Button>
21
+ <Button variant="outline" disabled={!state.tray} onClick={() => app.hide()}>Hide to tray</Button>
22
+ </Row>
23
+ </Column>
24
+ </Window>
25
+ );
26
+ }
27
+
28
+ // Closing the window keeps the app alive in the tray (App's onCloseRequest) while the icon
29
+ // can be seen; with no tray host it quits. The tray icon defaults to package.json
30
+ // "tarve.icon" (assets/icon.png).
31
+ const app = createApp(App);
32
+
33
+ function menu() {
34
+ return [
35
+ { id: "show", label: "Show window", onSelect: () => app.show() },
36
+ { id: "mute", label: "Mute notifications", checked: state.muted, onSelect: () => { state.muted = !state.muted; sync(); } },
37
+ { type: "separator" as const },
38
+ { id: "notify", label: "Send a notification", disabled: state.muted, onSelect: () => ping() },
39
+ { type: "separator" as const },
40
+ { id: "quit", label: "Quit", onSelect: () => app.close() },
41
+ ];
42
+ }
43
+
44
+ const tray = app.tray({
45
+ tooltip: "__APP_TITLE__", onClick: () => app.show(), menu: menu(),
46
+ // No tray host (GNOME without AppIndicator): keep the window; a host starting later shows the icon.
47
+ onAvailability: ({ available }) => { state.tray = available; },
48
+ });
49
+
50
+ function sync(): void {
51
+ tray.update({ tooltip: state.muted ? "__APP_TITLE__ (muted)" : "__APP_TITLE__", menu: menu() });
52
+ app.update();
53
+ }
54
+
55
+ function ping(): void {
56
+ state.sent++;
57
+ app.notify({ title: "__APP_TITLE__", body: `Notification #${state.sent}`, onClick: () => app.show() });
58
+ app.update();
59
+ }
60
+
61
+ await app.closed;
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "Tray",
3
+ "description": "a system tray app with menu and notifications",
4
+ "entry": "app.tsx",
5
+ "tarve": {
6
+ "icon": "assets/icon.png"
7
+ }
8
+ }