@x-tech-laboratories/x-app 0.98.0 → 0.100.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 +18 -0
- package/config/tsconfig/base.json +19 -0
- package/config/tsconfig/node.json +8 -0
- package/config/tsconfig/tests.json +9 -0
- package/config/tsconfig/web.json +9 -0
- package/dist/app_new.d.ts +22 -0
- package/dist/app_new.js +611 -0
- package/dist/config/electron_vite.d.ts +5 -0
- package/dist/config/electron_vite.js +23 -0
- package/dist/config/vite.d.ts +7 -0
- package/dist/config/vite.js +35 -0
- package/dist/config/vitest.d.ts +2 -0
- package/dist/config/vitest.js +16 -0
- package/package.json +18 -1
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
13
13
|
| `app/server`, `app/daemon` | `run_server(app, { web_folder })`: the web server from `<PREFIX>_CONFIG` with accounts, the calls, OpenAPI, MCP, the server's backups and its sync peer; `run_daemon(app)`: the desktop daemon from `<PREFIX>_DB` with sync, letting devices connect, backups, certificates and the desktop settings; `build_server`, `start_daemon`, `open_app_database` and `register_app_calls` for tests and apps that add their own. |
|
|
14
14
|
| `app/desktop`, `app/preload` | `run_desktop(app, electron, { main_dir })`: Electron's main process as a portal onto this computer's daemon or a server, with the window, the login entry, a second launch and `--daemon`; `run_preload(app, electron)` puts every bridge on the page. Electron is handed in, so neither imports it. |
|
|
15
15
|
| `app/web/app_page`, `app/web/page` | `render_app({ app, pages, general_settings })`: the page on the web, the desktop or Android in the `Shell`, with sign-in in a browser, Your account, Settings (the app's general sections, each page's own, Connections, Desktop app, Sync and Backups) and `SyncButton`; `page_hooks<Methods>()` gives the app's typed `calls`, `use_data` and `use_settings`. The phone's host (`app/web/android`) loads only on Android. |
|
|
16
|
+
| `config/vite`, `config/electron_vite`, `config/vitest`, `config/tsconfig/*.json` | An X-app's configs as presets: `web_vite_config({ port })` and `android_vite_config()` for the page, `desktop_vite_config()` for electron-vite's window, daemon, preload and page, `vitest_config()` for tests in `tests/` in UTC with coverage of `src/` to the terminal, merged with the app's own floor so `autoUpdate` still raises it, and `base`, `node`, `web` and `tests` tsconfigs to extend. |
|
|
17
|
+
| `app_new` | The `x-app-new <X-Name>` command: a new X-app's files written once, laid out as the Application Standard asks, on the base app, the presets, X-App's Nix lib and its CI actions, with an example notes feature; `--port`, `--folder`, `--no-desktop` and `--no-android`. |
|
|
16
18
|
| `durations` | `parse_duration` for settings such as `"2h30m"`, `format_duration` in months down to seconds and "less than a second" below one, `format_age`, and `format_clock` for a playing time such as `"3:07"`, with `{ hours: "always" }` writing `"0:03:07"` so a column of times lines up and `empty` for no time. |
|
|
17
19
|
| `log` | Loggers by scope and level from a setting such as `"warn,play:debug"`; a malformed setting falls back instead of silencing logging, and a setting read through a function applies to loggers made before it arrived; a dotted scope such as `app.core.db` without its own level takes its nearest parent's. |
|
|
18
20
|
| `cron` | `CronSchedule.parse`: five-field cron lines read in local time, with `@daily`-style aliases, month and weekday names, steps, ranges and lists, 7 as Sunday, a restricted day of month and weekday matching either as cron does, and a line that never matches a real date refused; `next_after` gives the first run strictly after a moment. |
|
|
@@ -205,6 +207,22 @@ void render_app({ app, pages: [{ id: "plan", label: "Plan", view: () => <PlanVie
|
|
|
205
207
|
|
|
206
208
|
A change an app needs in the base goes into the base, so no app keeps a copy of a base file.
|
|
207
209
|
|
|
210
|
+
The rest of an app's files are short calls into X-App too:
|
|
211
|
+
|
|
212
|
+
- **Configs** sit in the app's `config/` folder: `tsconfig.<target>.json` extends `tsconfig.base.json` and
|
|
213
|
+
`@x-tech-laboratories/x-app/config/tsconfig/<target>.json`; `vite.config.ts`, `electron.vite.config.ts` and
|
|
214
|
+
`vite.android.config.ts` export a preset from `config/vite` or `config/electron_vite`; `vitest.config.ts` merges
|
|
215
|
+
`vitest_config()` with the app's coverage floor. The npm scripts pass each with `-c` or `--config`; only
|
|
216
|
+
`tsconfig.json` (its references), `package.json` and `capacitor.config.json` stay at the root, where the tools look.
|
|
217
|
+
- **Nix**: X-App's flake has a `lib` with `package`, `desktop_package`, `module`, `shell` and `android_shell`, each
|
|
218
|
+
taking the app's package set and its `nix/app.nix` (name, display name, variables' prefix, port, database file and
|
|
219
|
+
words); the app's `nix/flake.nix` takes `github:x-tech-laboratories/X-App` as an input and calls them.
|
|
220
|
+
- **CI**: the app's `ci` job runs `x-tech-laboratories/X-App/.github/actions/app-ci@main`, its `nix` job
|
|
221
|
+
`app-nix@main` with the targets to build, and its Dependabot workflow `app-dependabot-auto-merge@main`. They are
|
|
222
|
+
composite actions, so the jobs keep the names `ci` and `nix` the ruleset requires.
|
|
223
|
+
|
|
224
|
+
`npx x-app-new X-Notes` writes all of it for a new app.
|
|
225
|
+
|
|
208
226
|
## A web app's server
|
|
209
227
|
|
|
210
228
|
The server modules are small Fastify pieces an app registers one by one, so each app keeps only what it needs.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"skipLibCheck": true,
|
|
4
|
+
"strict": true,
|
|
5
|
+
"noUncheckedIndexedAccess": true,
|
|
6
|
+
"target": "es2024",
|
|
7
|
+
"module": "esnext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"allowImportingTsExtensions": true,
|
|
10
|
+
"verbatimModuleSyntax": true,
|
|
11
|
+
"erasableSyntaxOnly": true,
|
|
12
|
+
"moduleDetection": "force",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"noUnusedLocals": true,
|
|
15
|
+
"noUnusedParameters": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noEmit": true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export interface NewAppOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
port: number;
|
|
5
|
+
desktop: boolean;
|
|
6
|
+
android: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface Names {
|
|
9
|
+
name: string;
|
|
10
|
+
slug: string;
|
|
11
|
+
env_prefix: string;
|
|
12
|
+
short: string;
|
|
13
|
+
app_id: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function names_of(name: string): Names;
|
|
16
|
+
export declare function new_app_files(options: NewAppOptions): Record<string, string>;
|
|
17
|
+
export declare function write_new_app(folder: string, options: NewAppOptions): string[];
|
|
18
|
+
export declare function parse_new_app_args(args: string[]): {
|
|
19
|
+
folder: string;
|
|
20
|
+
options: NewAppOptions;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
package/dist/app_new.js
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `x-app-new <X-Name>` command: a new X-app's few files, written once, laid out as the Application Standard asks
|
|
3
|
+
// and built on the base app. The app gets an example notes feature, its configs from X-App's presets, its Nix from
|
|
4
|
+
// X-App's lib and its CI from X-App's actions, so it runs on the web, the desktop and Android from the first commit.
|
|
5
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
import { parseArgs } from "node:util";
|
|
9
|
+
export function names_of(name) {
|
|
10
|
+
if (!/^X-[A-Z][A-Za-z0-9]*(-[A-Z][A-Za-z0-9]*)*$/.test(name))
|
|
11
|
+
throw new Error(`${name} is not an X-app name such as X-Notes or X-Media-Tracker`);
|
|
12
|
+
const slug = name.toLowerCase();
|
|
13
|
+
return { name, slug, env_prefix: slug.replaceAll("-", "_").toUpperCase(), short: slug.slice(2), app_id: `com.xtechlaboratories.${slug.replaceAll("-", "")}` };
|
|
14
|
+
}
|
|
15
|
+
const package_root = new URL("../", import.meta.url);
|
|
16
|
+
const manifest = JSON.parse(readFileSync(new URL("package.json", package_root), "utf8"));
|
|
17
|
+
// The range X-App itself is tested with, or the newest of the ranges it accepts.
|
|
18
|
+
function version_of(name) {
|
|
19
|
+
const range = manifest.devDependencies[name] ?? manifest.peerDependencies[name];
|
|
20
|
+
if (!range)
|
|
21
|
+
throw new Error(`X-App names no version of ${name}`);
|
|
22
|
+
return range.split("||").at(-1).trim();
|
|
23
|
+
}
|
|
24
|
+
// Packages X-App does not use itself, kept at the versions the X-apps run.
|
|
25
|
+
const own_versions = {
|
|
26
|
+
"@capacitor/android": version_of("@capacitor/core"),
|
|
27
|
+
"@capacitor/cli": version_of("@capacitor/core"),
|
|
28
|
+
electron: "^45.5.0",
|
|
29
|
+
};
|
|
30
|
+
function versions(names) {
|
|
31
|
+
return Object.fromEntries(names.map((name) => [name, own_versions[name] ?? version_of(name)]));
|
|
32
|
+
}
|
|
33
|
+
// ── Files ────────────────────────────────────────────────────────────────────
|
|
34
|
+
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
35
|
+
function package_json(names, options) {
|
|
36
|
+
const prefix = names.env_prefix;
|
|
37
|
+
const scripts = {
|
|
38
|
+
"dev:server": `${prefix}_CONFIG=\${${prefix}_CONFIG:-config.example.json} ${prefix}_PASSWORD_HASH_FILE=\${${prefix}_PASSWORD_HASH_FILE:-dev-data/password.hash} node --watch src/server/main.ts`,
|
|
39
|
+
"dev:web": "vite -c config/vite.config.ts",
|
|
40
|
+
...(options.desktop ? { dev: `${prefix}_USER_DATA=\${${prefix}_USER_DATA:-dev-data/desktop} electron-vite dev -c config/electron.vite.config.ts` } : {}),
|
|
41
|
+
build: "tsc -b && vite build -c config/vite.config.ts",
|
|
42
|
+
...(options.desktop ? { "build:desktop": "tsc -b && electron-vite build -c config/electron.vite.config.ts" } : {}),
|
|
43
|
+
...(options.android ? { "build:android": "tsc -b && vite build -c config/vite.android.config.ts && cap sync android" } : {}),
|
|
44
|
+
start: "NODE_ENV=production node src/server/main.ts",
|
|
45
|
+
...(options.desktop ? { "start:desktop": "electron-vite preview -c config/electron.vite.config.ts" } : {}),
|
|
46
|
+
typecheck: "tsc -b",
|
|
47
|
+
test: "vitest run --config config/vitest.config.ts",
|
|
48
|
+
coverage: "vitest run --coverage --config config/vitest.config.ts",
|
|
49
|
+
lint: "oxlint",
|
|
50
|
+
"hash-password": "node src/server/hash_password.ts",
|
|
51
|
+
icons: "x-app-icons",
|
|
52
|
+
};
|
|
53
|
+
const dependencies = [
|
|
54
|
+
...(options.android ? ["@capacitor/app", "@capacitor/core"] : []),
|
|
55
|
+
"@fastify/cookie",
|
|
56
|
+
"@fastify/cors",
|
|
57
|
+
"@fastify/formbody",
|
|
58
|
+
"@fastify/rate-limit",
|
|
59
|
+
"@fastify/static",
|
|
60
|
+
"@modelcontextprotocol/server",
|
|
61
|
+
...(options.android ? ["@sqlite.org/sqlite-wasm"] : []),
|
|
62
|
+
"@x-tech-laboratories/halon",
|
|
63
|
+
"fastify",
|
|
64
|
+
"react",
|
|
65
|
+
"react-dom",
|
|
66
|
+
];
|
|
67
|
+
const dev_dependencies = [
|
|
68
|
+
...(options.android ? ["@capacitor/android", "@capacitor/cli"] : []),
|
|
69
|
+
"@resvg/resvg-js",
|
|
70
|
+
"@testing-library/dom",
|
|
71
|
+
"@testing-library/react",
|
|
72
|
+
"@types/node",
|
|
73
|
+
"@types/react",
|
|
74
|
+
"@types/react-dom",
|
|
75
|
+
"@vitejs/plugin-react",
|
|
76
|
+
"@vitest/coverage-v8",
|
|
77
|
+
...(options.desktop ? ["electron", "electron-vite"] : []),
|
|
78
|
+
"jsdom",
|
|
79
|
+
"oxlint",
|
|
80
|
+
"typescript",
|
|
81
|
+
"vite",
|
|
82
|
+
"vitest",
|
|
83
|
+
];
|
|
84
|
+
return json({
|
|
85
|
+
name: names.slug,
|
|
86
|
+
version: "0.1.0",
|
|
87
|
+
private: true,
|
|
88
|
+
description: `${names.name}: what it keeps, in one sentence`,
|
|
89
|
+
license: "GPL-3.0-or-later",
|
|
90
|
+
type: "module",
|
|
91
|
+
...(options.desktop ? { main: "out/main/index.js" } : {}),
|
|
92
|
+
engines: { node: ">=24" },
|
|
93
|
+
scripts,
|
|
94
|
+
dependencies: { ...versions(dependencies), "@x-tech-laboratories/x-app": `^${manifest.version}` },
|
|
95
|
+
devDependencies: versions(dev_dependencies),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function app_ts(names, options) {
|
|
99
|
+
return `// ${names.name} as the base app runs it: its name, ports and files, and its features.
|
|
100
|
+
|
|
101
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
import { define_app, type AppMethodsOf } from "@x-tech-laboratories/x-app/app/define";
|
|
104
|
+
|
|
105
|
+
import package_json from "../package.json" with { type: "json" };
|
|
106
|
+
import { notes_feature } from "./shared/notes/store.ts";
|
|
107
|
+
|
|
108
|
+
// ── App ──────────────────────────────────────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
export const app = define_app({
|
|
111
|
+
id: "${names.slug}",
|
|
112
|
+
name: "${names.name}",
|
|
113
|
+
env_prefix: "${names.env_prefix}",
|
|
114
|
+
version: package_json.version,
|
|
115
|
+
summary: "Serves ${names.name} as a web app and syncs its devices.",
|
|
116
|
+
instructions: "${names.name} holds notes. Start with list_notes.",
|
|
117
|
+
data_name: "notes",
|
|
118
|
+
database_file: "${names.short}.db",
|
|
119
|
+
backup_prefix: "${names.short}",
|
|
120
|
+
ports: { server: ${options.port}, peer: ${options.port + 1} },
|
|
121
|
+
server_example: "https://${names.short}.example.org",
|
|
122
|
+
features: [notes_feature],
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Every call the page can make, as it makes them.
|
|
126
|
+
export type AppMethods = AppMethodsOf<typeof app>;
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
const notes_store_ts = `// Notes, each a title, as the example feature: its table, its calls and what each call does for other programs.
|
|
130
|
+
|
|
131
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
132
|
+
|
|
133
|
+
import { define_feature } from "@x-tech-laboratories/x-app/app/define";
|
|
134
|
+
import type { SqlDatabase } from "@x-tech-laboratories/x-app/sql";
|
|
135
|
+
|
|
136
|
+
// ── Notes ────────────────────────────────────────────────────────────────────
|
|
137
|
+
|
|
138
|
+
export interface Note {
|
|
139
|
+
id: string;
|
|
140
|
+
title: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const notes_feature = define_feature({
|
|
144
|
+
id: "notes",
|
|
145
|
+
// Each step runs once, in order; a released step is never edited, only followed by a new one.
|
|
146
|
+
migrations: ["CREATE TABLE notes (id TEXT PRIMARY KEY, title TEXT NOT NULL)"],
|
|
147
|
+
tables: [{ name: "notes", key_columns: ["id"] }],
|
|
148
|
+
methods: {
|
|
149
|
+
list_notes: (database: SqlDatabase): Note[] => database.prepare("SELECT id, title FROM notes ORDER BY title").all() as unknown as Note[],
|
|
150
|
+
add_note: (database: SqlDatabase, title: string): string => {
|
|
151
|
+
const id = crypto.randomUUID();
|
|
152
|
+
database.prepare("INSERT INTO notes (id, title) VALUES (?, ?)").run(id, title.trim() || "Note");
|
|
153
|
+
return id;
|
|
154
|
+
},
|
|
155
|
+
remove_note: (database: SqlDatabase, id: string): void => void database.prepare("DELETE FROM notes WHERE id = ?").run(id),
|
|
156
|
+
},
|
|
157
|
+
api: {
|
|
158
|
+
list_notes: { description: "Every note, by title.", params: [] },
|
|
159
|
+
add_note: { description: "Adds a note and gives its id.", params: [{ name: "title", schema: { type: "string", description: "The note's title." } }] },
|
|
160
|
+
remove_note: { description: "Removes a note.", params: [{ name: "id", schema: { type: "string", description: "The note's id, as list_notes gives it." } }] },
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
`;
|
|
164
|
+
function entry_points(names) {
|
|
165
|
+
return {
|
|
166
|
+
"src/server/main.ts": `// Starts the ${names.name} web server on the database the config names.
|
|
167
|
+
|
|
168
|
+
import { run_server } from "@x-tech-laboratories/x-app/app/server";
|
|
169
|
+
|
|
170
|
+
import { app } from "../app.ts";
|
|
171
|
+
|
|
172
|
+
await run_server(app, { web_folder: new URL("../../out/web", import.meta.url) });
|
|
173
|
+
`,
|
|
174
|
+
"src/server/hash_password.ts": `// Adds or replaces a user's line in the accounts file ${names.env_prefix}_PASSWORD_HASH_FILE names, asking at a terminal so the
|
|
175
|
+
// password never lands in argv or shell history.
|
|
176
|
+
|
|
177
|
+
import { hash_password_command } from "@x-tech-laboratories/x-app/server/hash_password";
|
|
178
|
+
|
|
179
|
+
await hash_password_command("${names.env_prefix}_PASSWORD_HASH_FILE");
|
|
180
|
+
`,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function desktop_entry_points(names) {
|
|
184
|
+
return {
|
|
185
|
+
"src/daemon/main.ts": `// Starts the desktop app's daemon on the database and socket the window names, and ends the process once it stops.
|
|
186
|
+
|
|
187
|
+
import { run_daemon } from "@x-tech-laboratories/x-app/app/daemon";
|
|
188
|
+
|
|
189
|
+
import { app } from "../app.ts";
|
|
190
|
+
|
|
191
|
+
await run_daemon(app);
|
|
192
|
+
`,
|
|
193
|
+
"src/main/index.ts": `// The desktop app's window: Electron's main process, which shows ${names.name} and leaves the work to this computer's daemon
|
|
194
|
+
// or to the ${names.name} server chosen under Settings → Connections.
|
|
195
|
+
|
|
196
|
+
import * as electron from "electron";
|
|
197
|
+
import { run_desktop } from "@x-tech-laboratories/x-app/app/desktop";
|
|
198
|
+
|
|
199
|
+
import { app } from "../app.ts";
|
|
200
|
+
|
|
201
|
+
run_desktop(app, electron, { main_dir: import.meta.dirname });
|
|
202
|
+
`,
|
|
203
|
+
"src/preload/index.ts": `// Gives the desktop app's page its calls to the main process, under the names the page looks for.
|
|
204
|
+
|
|
205
|
+
import { contextBridge, ipcRenderer } from "electron";
|
|
206
|
+
import { run_preload } from "@x-tech-laboratories/x-app/app/preload";
|
|
207
|
+
|
|
208
|
+
import { app } from "../app.ts";
|
|
209
|
+
|
|
210
|
+
run_preload(app, { contextBridge, ipcRenderer });
|
|
211
|
+
`,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function web_files(names) {
|
|
215
|
+
return {
|
|
216
|
+
"src/web/index.html": `<!doctype html>
|
|
217
|
+
<html lang="en">
|
|
218
|
+
<head>
|
|
219
|
+
<meta charset="UTF-8" />
|
|
220
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
221
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self'" />
|
|
222
|
+
<link rel="icon" href="./icon.svg" type="image/svg+xml" />
|
|
223
|
+
<title>${names.name}</title>
|
|
224
|
+
</head>
|
|
225
|
+
<body>
|
|
226
|
+
<div id="app"></div>
|
|
227
|
+
<script type="module" src="./main.tsx"></script>
|
|
228
|
+
</body>
|
|
229
|
+
</html>
|
|
230
|
+
`,
|
|
231
|
+
"src/web/main.tsx": `// Starts the page on whichever host it runs: the desktop app, the phone app or a browser.
|
|
232
|
+
|
|
233
|
+
import "./app.css";
|
|
234
|
+
import { render_app } from "@x-tech-laboratories/x-app/app/web/app_page";
|
|
235
|
+
|
|
236
|
+
import { app } from "../app.ts";
|
|
237
|
+
import { pages } from "./pages.tsx";
|
|
238
|
+
|
|
239
|
+
void render_app({ app, pages });
|
|
240
|
+
`,
|
|
241
|
+
"src/web/api.ts": `// The page's calls typed with ${names.name}'s own, on whichever host the base app started the page.
|
|
242
|
+
|
|
243
|
+
import { page_hooks } from "@x-tech-laboratories/x-app/app/web/page";
|
|
244
|
+
|
|
245
|
+
import type { AppMethods } from "../app.ts";
|
|
246
|
+
|
|
247
|
+
export const { calls, page, use_data, use_settings } = page_hooks<AppMethods>();
|
|
248
|
+
`,
|
|
249
|
+
"src/web/pages.tsx": `// The sections of the app, each a page with its own settings, in the order the sidebar lists them.
|
|
250
|
+
|
|
251
|
+
import type { AppPage } from "@x-tech-laboratories/x-app/app/web/app_page";
|
|
252
|
+
|
|
253
|
+
import { NotesView } from "./notes/NotesView.tsx";
|
|
254
|
+
|
|
255
|
+
export const pages: AppPage[] = [{ id: "notes", label: "Notes", view: () => <NotesView /> }];
|
|
256
|
+
`,
|
|
257
|
+
"src/web/notes/NotesView.tsx": `// The notes, and a field to add one.
|
|
258
|
+
|
|
259
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
260
|
+
|
|
261
|
+
import { useState } from "react";
|
|
262
|
+
import { PageHeading } from "@x-tech-laboratories/x-app/web/react/layout";
|
|
263
|
+
import { Loaded } from "@x-tech-laboratories/x-app/web/react/states";
|
|
264
|
+
import { attempt } from "@x-tech-laboratories/x-app/web/react/toasts";
|
|
265
|
+
|
|
266
|
+
import { calls, use_data } from "../api.ts";
|
|
267
|
+
|
|
268
|
+
// ── Notes ────────────────────────────────────────────────────────────────────
|
|
269
|
+
|
|
270
|
+
export function NotesView() {
|
|
271
|
+
const notes = use_data((api) => api.list_notes());
|
|
272
|
+
const [title, set_title] = useState("");
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<>
|
|
276
|
+
<PageHeading title="Notes" />
|
|
277
|
+
<form
|
|
278
|
+
onSubmit={(event) => {
|
|
279
|
+
event.preventDefault();
|
|
280
|
+
attempt(calls().add_note(title).then(() => set_title("")));
|
|
281
|
+
}}
|
|
282
|
+
>
|
|
283
|
+
<input aria-label="New note" value={title} onChange={(event) => set_title(event.currentTarget.value)} />
|
|
284
|
+
<button type="submit">Add note</button>
|
|
285
|
+
</form>
|
|
286
|
+
<Loaded resource={notes}>{(list) => <ul>{list.map((note) => <li key={note.id}>{note.title}</li>)}</ul>}</Loaded>
|
|
287
|
+
</>
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
`,
|
|
291
|
+
"src/web/app.css": "/* Layout only; every colour, size and widget look comes from Halon's tokens and stylesheet. */\n",
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function config_files(names, options) {
|
|
295
|
+
const preset = "@x-tech-laboratories/x-app/config/tsconfig";
|
|
296
|
+
const node_include = ["../src/app.ts", "../src/server", ...(options.desktop ? ["../src/daemon", "../src/main", "../src/preload"] : []), "../src/shared", "vite.config.ts", ...(options.android ? ["vite.android.config.ts"] : []), ...(options.desktop ? ["electron.vite.config.ts"] : []), "vitest.config.ts"];
|
|
297
|
+
const target = (name, include) => json({ extends: ["./tsconfig.base.json", `${preset}/${name}.json`], include, compilerOptions: { tsBuildInfoFile: `../node_modules/.tmp/tsconfig.${name}.tsbuildinfo` } });
|
|
298
|
+
return {
|
|
299
|
+
"tsconfig.json": json({ files: [], references: ["node", "web", "tests"].map((name) => ({ path: `./config/tsconfig.${name}.json` })) }),
|
|
300
|
+
"config/tsconfig.base.json": json({ extends: `${preset}/base.json` }),
|
|
301
|
+
"config/tsconfig.node.json": target("node", node_include),
|
|
302
|
+
"config/tsconfig.web.json": target("web", ["../src/app.ts", "../src/web", "../src/shared"]),
|
|
303
|
+
"config/tsconfig.tests.json": target("tests", ["../tests", "../src"]),
|
|
304
|
+
"config/vite.config.ts": `// The page for a browser, from X-App's preset.
|
|
305
|
+
|
|
306
|
+
import { defineConfig } from "vite";
|
|
307
|
+
import { web_vite_config } from "@x-tech-laboratories/x-app/config/vite";
|
|
308
|
+
|
|
309
|
+
export default defineConfig(web_vite_config({ port: ${options.port} }));
|
|
310
|
+
`,
|
|
311
|
+
"config/vitest.config.ts": `// X-App's test preset, with this app's coverage floor, which only rises.
|
|
312
|
+
|
|
313
|
+
import { defineConfig, mergeConfig } from "vitest/config";
|
|
314
|
+
import { vitest_config } from "@x-tech-laboratories/x-app/config/vitest";
|
|
315
|
+
|
|
316
|
+
export default mergeConfig(
|
|
317
|
+
vitest_config(),
|
|
318
|
+
defineConfig({
|
|
319
|
+
test: {
|
|
320
|
+
coverage: {
|
|
321
|
+
thresholds: {
|
|
322
|
+
autoUpdate: (new_threshold) => Math.floor(new_threshold),
|
|
323
|
+
lines: 0,
|
|
324
|
+
statements: 0,
|
|
325
|
+
functions: 0,
|
|
326
|
+
branches: 0,
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
}),
|
|
331
|
+
);
|
|
332
|
+
`,
|
|
333
|
+
...(options.desktop
|
|
334
|
+
? {
|
|
335
|
+
"config/electron.vite.config.ts": `// The desktop app's window, daemon, preload and page, from X-App's preset.
|
|
336
|
+
|
|
337
|
+
import { defineConfig } from "electron-vite";
|
|
338
|
+
import { desktop_vite_config } from "@x-tech-laboratories/x-app/config/electron_vite";
|
|
339
|
+
|
|
340
|
+
export default defineConfig(desktop_vite_config());
|
|
341
|
+
`,
|
|
342
|
+
}
|
|
343
|
+
: {}),
|
|
344
|
+
...(options.android
|
|
345
|
+
? {
|
|
346
|
+
"config/vite.android.config.ts": `// The page for the Capacitor app, which keeps its database on the phone, from X-App's preset.
|
|
347
|
+
|
|
348
|
+
import { defineConfig } from "vite";
|
|
349
|
+
import { android_vite_config } from "@x-tech-laboratories/x-app/config/vite";
|
|
350
|
+
|
|
351
|
+
export default defineConfig(android_vite_config());
|
|
352
|
+
`,
|
|
353
|
+
"capacitor.config.json": json({ appId: names.app_id, appName: names.name, webDir: "out/android", android: { allowMixedContent: true }, plugins: { CapacitorHttp: { enabled: true } } }),
|
|
354
|
+
}
|
|
355
|
+
: {}),
|
|
356
|
+
"config.example.json": json({ database: `dev-data/server/${names.short}.db`, backups_folder: "dev-data/server/backups" }),
|
|
357
|
+
".gitignore": [".claude/", "node_modules", "out/", "dist/", "result", "result-*", "*.tsbuildinfo", "dev-data/", "coverage/", ""].join("\n"),
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function nix_files(names, options) {
|
|
361
|
+
return {
|
|
362
|
+
"nix/app.nix": `# ${names.name} as X-App's Nix lib builds it; the flake and shell.nix both read it.
|
|
363
|
+
{
|
|
364
|
+
name = "${names.slug}";
|
|
365
|
+
display_name = "${names.name}";
|
|
366
|
+
env_prefix = "${names.env_prefix}";
|
|
367
|
+
src = ../.;
|
|
368
|
+
description = "${names.name}: what it keeps, synced through your own server";
|
|
369
|
+
module_description = "a web app that its devices sync with";
|
|
370
|
+
desktop_comment = "${names.name}";
|
|
371
|
+
port = ${options.port};
|
|
372
|
+
database_file = "${names.short}.db";
|
|
373
|
+
sync_example = "https://${names.short}.example.org/api/";
|
|
374
|
+
desktop = ${options.desktop};
|
|
375
|
+
}
|
|
376
|
+
`,
|
|
377
|
+
"nix/flake.nix": `{
|
|
378
|
+
description = "${names.name}";
|
|
379
|
+
|
|
380
|
+
inputs = {
|
|
381
|
+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
382
|
+
flake-utils.url = "github:numtide/flake-utils";
|
|
383
|
+
x-app.url = "github:x-tech-laboratories/X-App";
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
outputs = { self, nixpkgs, flake-utils, x-app }:
|
|
387
|
+
let
|
|
388
|
+
app = import ./app.nix;
|
|
389
|
+
in
|
|
390
|
+
flake-utils.lib.eachDefaultSystem (system:
|
|
391
|
+
let
|
|
392
|
+
pkgs = import nixpkgs { inherit system; };
|
|
393
|
+
in
|
|
394
|
+
{
|
|
395
|
+
packages.default = x-app.lib.package pkgs app;${options.desktop ? "\n packages.desktop = x-app.lib.desktop_package pkgs app;" : ""}
|
|
396
|
+
devShells.default = x-app.lib.shell pkgs app;${options.android ? "\n devShells.android = x-app.lib.android_shell nixpkgs system;" : ""}
|
|
397
|
+
}
|
|
398
|
+
) // {
|
|
399
|
+
nixosModules.default = x-app.lib.module self app;
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
`,
|
|
403
|
+
"nix/shell.nix": `# The flake's dev shell for nix-shell, with X-App's lib at the version flake.lock pins.
|
|
404
|
+
{ pkgs ? import <nixpkgs> { } }:
|
|
405
|
+
|
|
406
|
+
let
|
|
407
|
+
pinned = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.x-app.locked;
|
|
408
|
+
x_app = builtins.fetchTarball "https://github.com/\${pinned.owner}/\${pinned.repo}/archive/\${pinned.rev}.tar.gz";
|
|
409
|
+
in
|
|
410
|
+
(import "\${x_app}/nix/lib.nix").shell pkgs (import ./app.nix)
|
|
411
|
+
`,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function github_files(options) {
|
|
415
|
+
return {
|
|
416
|
+
".github/workflows/ci.yml": `name: CI
|
|
417
|
+
|
|
418
|
+
on:
|
|
419
|
+
push:
|
|
420
|
+
branches: [main]
|
|
421
|
+
pull_request:
|
|
422
|
+
branches: [main]
|
|
423
|
+
workflow_dispatch:
|
|
424
|
+
|
|
425
|
+
jobs:
|
|
426
|
+
ci:
|
|
427
|
+
runs-on: ubuntu-latest
|
|
428
|
+
steps:
|
|
429
|
+
- uses: x-tech-laboratories/X-App/.github/actions/app-ci@main
|
|
430
|
+
|
|
431
|
+
# Builds the package TechNet deploys${options.desktop ? " and the desktop app" : ""}, so a dependency bump that breaks either fails here.
|
|
432
|
+
nix:
|
|
433
|
+
runs-on: ubuntu-latest
|
|
434
|
+
steps:
|
|
435
|
+
- uses: x-tech-laboratories/X-App/.github/actions/app-nix@main
|
|
436
|
+
with:
|
|
437
|
+
targets: ./nix#default${options.desktop ? " ./nix#desktop" : ""}
|
|
438
|
+
`,
|
|
439
|
+
".github/workflows/dependabot-auto-merge.yml": `name: Dependabot auto-merge
|
|
440
|
+
|
|
441
|
+
on: pull_request
|
|
442
|
+
|
|
443
|
+
permissions:
|
|
444
|
+
contents: write
|
|
445
|
+
pull-requests: write
|
|
446
|
+
|
|
447
|
+
jobs:
|
|
448
|
+
auto-merge:
|
|
449
|
+
if: github.event.pull_request.user.login == 'dependabot[bot]'
|
|
450
|
+
runs-on: ubuntu-latest
|
|
451
|
+
steps:
|
|
452
|
+
- uses: x-tech-laboratories/X-App/.github/actions/app-dependabot-auto-merge@main
|
|
453
|
+
with:
|
|
454
|
+
github-token: \${{ secrets.GITHUB_TOKEN }}
|
|
455
|
+
`,
|
|
456
|
+
".github/dependabot.yml": `version: 2
|
|
457
|
+
updates:
|
|
458
|
+
- package-ecosystem: npm
|
|
459
|
+
directory: /
|
|
460
|
+
schedule:
|
|
461
|
+
interval: weekly
|
|
462
|
+
groups:
|
|
463
|
+
# X-App and Halon in one pull request, so the Halon peer of X-App matches.
|
|
464
|
+
x-tech:
|
|
465
|
+
patterns: ["@x-tech-laboratories/*"]
|
|
466
|
+
# Third-party patch and minor updates in one pull request; a major update comes on its own.
|
|
467
|
+
npm:
|
|
468
|
+
patterns: ["*"]
|
|
469
|
+
exclude-patterns: ["@x-tech-laboratories/*"]
|
|
470
|
+
update-types: [minor, patch]
|
|
471
|
+
ignore:
|
|
472
|
+
# The types follow the Node runtime, 24 in CI and the flakes, so their majors move with it by hand.
|
|
473
|
+
- dependency-name: "@types/node"
|
|
474
|
+
update-types: ["version-update:semver-major"]
|
|
475
|
+
# Our own releases skip the default 3-day cooldown.
|
|
476
|
+
cooldown:
|
|
477
|
+
exclude: ["@x-tech-laboratories/*"]
|
|
478
|
+
`,
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function doc_files(names, options) {
|
|
482
|
+
const agents = `# Instructions for AI agents
|
|
483
|
+
|
|
484
|
+
${names.name} runs on the X-App base app: \`src/app.ts\` describes it with \`define_app\`, and each entry point is one call
|
|
485
|
+
into X-App. Its own code is its features (\`src/shared/<feature>/\`) and pages (\`src/web/\`).
|
|
486
|
+
|
|
487
|
+
## X-Tech standards
|
|
488
|
+
|
|
489
|
+
- Follow the [Application Standard](https://x-tech-laboratories.github.io/standards/application/) and the
|
|
490
|
+
[Design Guidelines](https://x-tech-laboratories.github.io/standards/design/), whose source is \`src/content/docs/standards/\`
|
|
491
|
+
in [x-tech-laboratories.github.io](https://github.com/x-tech-laboratories/x-tech-laboratories.github.io). Ask before
|
|
492
|
+
changing either, since a change applies to every X-app.
|
|
493
|
+
- Use [X-App](https://github.com/x-tech-laboratories/X-App) and Halon ([X-Themes](https://github.com/x-tech-laboratories/X-Themes))
|
|
494
|
+
before writing your own code: check the module table in the X-App README first.
|
|
495
|
+
- A feature another app could use belongs in X-App, or Halon for styling, with tests and a README row. A change the
|
|
496
|
+
base needs goes into X-App, never into a copy here.
|
|
497
|
+
`;
|
|
498
|
+
return {
|
|
499
|
+
"README.md": `# ${names.name}
|
|
500
|
+
|
|
501
|
+
${names.name}: what it keeps, in one sentence. It runs in a browser against its own server${options.desktop ? ", as a desktop app" : ""}${options.android ? ", and on Android" : ""}, all syncing
|
|
502
|
+
through the server, on the [X-App](https://github.com/x-tech-laboratories/X-App) base app.
|
|
503
|
+
|
|
504
|
+
## Development
|
|
505
|
+
|
|
506
|
+
\`\`\`
|
|
507
|
+
nix-shell nix/shell.nix # or nix develop ./nix
|
|
508
|
+
npm install
|
|
509
|
+
npm run dev:server # the server, against config.example.json
|
|
510
|
+
npm run dev:web # the page, in a browser${options.desktop ? "\nnpm run dev # the desktop app" : ""}
|
|
511
|
+
npm test
|
|
512
|
+
\`\`\`
|
|
513
|
+
|
|
514
|
+
## License
|
|
515
|
+
|
|
516
|
+
GPL-3.0-or-later.
|
|
517
|
+
`,
|
|
518
|
+
"AGENTS.md": agents,
|
|
519
|
+
"CLAUDE.md": agents,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
const test_ts = `import { DatabaseSync } from "node:sqlite";
|
|
523
|
+
|
|
524
|
+
import { describe, expect, it } from "vitest";
|
|
525
|
+
|
|
526
|
+
import { app } from "../src/app.ts";
|
|
527
|
+
|
|
528
|
+
describe("notes", () => {
|
|
529
|
+
it("adds a note and lists it", () => {
|
|
530
|
+
const database = new DatabaseSync(":memory:");
|
|
531
|
+
app.open_store(database);
|
|
532
|
+
const methods = app.bind_methods(() => database, () => undefined);
|
|
533
|
+
|
|
534
|
+
const id = methods.add_note("Groceries");
|
|
535
|
+
|
|
536
|
+
expect(methods.list_notes()).toEqual([{ id, title: "Groceries" }]);
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
`;
|
|
540
|
+
// The X-Tech hexagon with a plain mark, to be redrawn as the app's own glyph.
|
|
541
|
+
const icon_svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
|
542
|
+
<path d="M32 3 57 17.5v29L32 61 7 46.5v-29z" fill="#2563eb" />
|
|
543
|
+
<path d="M22 22h20v4H22zm0 8h20v4H22zm0 8h14v4H22z" fill="#fff" />
|
|
544
|
+
</svg>
|
|
545
|
+
`;
|
|
546
|
+
// Every file the app starts with, by path.
|
|
547
|
+
export function new_app_files(options) {
|
|
548
|
+
const names = names_of(options.name);
|
|
549
|
+
return {
|
|
550
|
+
"package.json": package_json(names, options),
|
|
551
|
+
"src/app.ts": app_ts(names, options),
|
|
552
|
+
"src/shared/notes/store.ts": notes_store_ts,
|
|
553
|
+
...entry_points(names),
|
|
554
|
+
...(options.desktop ? desktop_entry_points(names) : {}),
|
|
555
|
+
...web_files(names),
|
|
556
|
+
"src/web/public/icon.svg": icon_svg,
|
|
557
|
+
"resources/icon.svg": icon_svg,
|
|
558
|
+
"tests/app.test.ts": test_ts,
|
|
559
|
+
...config_files(names, options),
|
|
560
|
+
...nix_files(names, options),
|
|
561
|
+
...github_files(options),
|
|
562
|
+
...doc_files(names, options),
|
|
563
|
+
LICENSE: readFileSync(new URL("LICENSE", package_root), "utf8"),
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
// Writes the app into a folder that is empty or not there yet, and gives the paths written.
|
|
567
|
+
export function write_new_app(folder, options) {
|
|
568
|
+
if (existsSync(join(folder, "package.json")))
|
|
569
|
+
throw new Error(`${folder} already holds an app`);
|
|
570
|
+
const written = [];
|
|
571
|
+
for (const [path, text] of Object.entries(new_app_files(options))) {
|
|
572
|
+
const target = join(folder, path);
|
|
573
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
574
|
+
writeFileSync(target, text);
|
|
575
|
+
written.push(target);
|
|
576
|
+
}
|
|
577
|
+
return written;
|
|
578
|
+
}
|
|
579
|
+
// ── Command ──────────────────────────────────────────────────────────────────
|
|
580
|
+
const usage = `Usage: x-app-new <X-Name> [--port <port>] [--folder <folder>] [--no-desktop] [--no-android]
|
|
581
|
+
|
|
582
|
+
Writes a new X-app built on X-App into the folder, ./<X-Name> unless given, with an example notes feature.`;
|
|
583
|
+
export function parse_new_app_args(args) {
|
|
584
|
+
const { values, positionals } = parseArgs({
|
|
585
|
+
args,
|
|
586
|
+
allowPositionals: true,
|
|
587
|
+
options: { port: { type: "string" }, folder: { type: "string" }, "no-desktop": { type: "boolean" }, "no-android": { type: "boolean" } },
|
|
588
|
+
});
|
|
589
|
+
const [name] = positionals;
|
|
590
|
+
if (!name || positionals.length > 1)
|
|
591
|
+
throw new Error(usage);
|
|
592
|
+
const port = Number(values.port ?? 7800);
|
|
593
|
+
if (!Number.isInteger(port) || port < 1024 || port > 65534)
|
|
594
|
+
throw new Error(`not a port: ${values.port}`);
|
|
595
|
+
return { folder: resolve(values.folder ?? name), options: { name, port, desktop: !values["no-desktop"], android: !values["no-android"] } };
|
|
596
|
+
}
|
|
597
|
+
if (import.meta.main) {
|
|
598
|
+
try {
|
|
599
|
+
const { folder, options } = parse_new_app_args(process.argv.slice(2));
|
|
600
|
+
write_new_app(folder, options);
|
|
601
|
+
console.info(`Wrote ${options.name} into ${folder}. Next:
|
|
602
|
+
cd ${folder} && git init && npm install
|
|
603
|
+
nix flake lock ./nix
|
|
604
|
+
npm run icons${options.android ? "\n npx cap add android" : ""}
|
|
605
|
+
npm test`);
|
|
606
|
+
}
|
|
607
|
+
catch (error) {
|
|
608
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
609
|
+
process.exit(2);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The base app's electron-vite config: the desktop app's main process and daemon, its preload, and the page.
|
|
2
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import react from "@vitejs/plugin-react";
|
|
5
|
+
import { externalizeDepsPlugin } from "electron-vite";
|
|
6
|
+
export function desktop_vite_config(options = {}) {
|
|
7
|
+
const daemon = options.daemon === undefined ? "src/daemon/main.ts" : options.daemon;
|
|
8
|
+
return {
|
|
9
|
+
main: {
|
|
10
|
+
plugins: [externalizeDepsPlugin()],
|
|
11
|
+
build: { rollupOptions: { input: { index: resolve("src/main/index.ts"), ...(daemon ? { daemon: resolve(daemon) } : {}) } } },
|
|
12
|
+
},
|
|
13
|
+
preload: {
|
|
14
|
+
plugins: [externalizeDepsPlugin()],
|
|
15
|
+
build: { rollupOptions: { input: { index: resolve("src/preload/index.ts") } } },
|
|
16
|
+
},
|
|
17
|
+
renderer: {
|
|
18
|
+
root: resolve("src/web"),
|
|
19
|
+
plugins: [react()],
|
|
20
|
+
build: { rollupOptions: { input: { index: resolve("src/web/index.html") } } },
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UserConfig } from "vite";
|
|
2
|
+
export interface WebViteOptions {
|
|
3
|
+
port: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function web_vite_config({ port }: WebViteOptions): UserConfig;
|
|
6
|
+
export declare const android_content_policy = "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' https: http:";
|
|
7
|
+
export declare function android_vite_config(): UserConfig;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The base app's Vite configs: the page for a browser, and the page for the phone app, built from src/web.
|
|
2
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
3
|
+
import react from "@vitejs/plugin-react";
|
|
4
|
+
// The page for a browser, with relative paths so a proxy can serve it under a folder; the dev page reaches the API
|
|
5
|
+
// through the separately running server.
|
|
6
|
+
export function web_vite_config({ port }) {
|
|
7
|
+
const server = `http://127.0.0.1:${Number(process.env.PORT ?? port)}`;
|
|
8
|
+
return {
|
|
9
|
+
root: "src/web",
|
|
10
|
+
base: "./",
|
|
11
|
+
plugins: [react()],
|
|
12
|
+
build: { outDir: "../../out/web", emptyOutDir: true },
|
|
13
|
+
server: { proxy: { "/api": server, "/login": server } },
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
// ── Android ──────────────────────────────────────────────────────────────────
|
|
17
|
+
// The phone runs SQLite as WebAssembly and syncs with a server elsewhere, which the browser page's policy forbids.
|
|
18
|
+
export const android_content_policy = "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' https: http:";
|
|
19
|
+
function set_content_policy() {
|
|
20
|
+
return {
|
|
21
|
+
name: "x-app-android-content-policy",
|
|
22
|
+
transformIndexHtml: (html) => html.replace(/(http-equiv="Content-Security-Policy" content=")[^"]*/, `$1${android_content_policy}`),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// The page for the Capacitor app, built into out/android with its own content policy.
|
|
26
|
+
export function android_vite_config() {
|
|
27
|
+
return {
|
|
28
|
+
root: "src/web",
|
|
29
|
+
base: "./",
|
|
30
|
+
mode: "android",
|
|
31
|
+
plugins: [react(), set_content_policy()],
|
|
32
|
+
optimizeDeps: { exclude: ["@sqlite.org/sqlite-wasm"] },
|
|
33
|
+
build: { outDir: "../../out/android", emptyOutDir: true },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The base app's Vitest config: tests in tests/, coverage of src/ reported to the terminal, and one time zone for all
|
|
2
|
+
// runs. An app merges its own coverage floor into it, kept in its vitest.config.ts so autoUpdate can raise it there.
|
|
3
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
4
|
+
import react from "@vitejs/plugin-react";
|
|
5
|
+
// ── Tests ────────────────────────────────────────────────────────────────────
|
|
6
|
+
export function vitest_config() {
|
|
7
|
+
// Tests read local dates, so every run uses the same time zone.
|
|
8
|
+
process.env.TZ = "UTC";
|
|
9
|
+
return {
|
|
10
|
+
plugins: [react()],
|
|
11
|
+
test: {
|
|
12
|
+
include: ["tests/**/*.test.ts", "tests/**/*.test.tsx"],
|
|
13
|
+
coverage: { provider: "v8", include: ["src/**/*.{ts,tsx}"], reporter: ["text"] },
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.100.0",
|
|
4
4
|
"description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
+
"config",
|
|
16
17
|
"android/build.gradle",
|
|
17
18
|
"android/src/main/"
|
|
18
19
|
],
|
|
@@ -20,9 +21,11 @@
|
|
|
20
21
|
"x-app-bundle-migrations": "dist/drizzle_migrations.js",
|
|
21
22
|
"x-app-check": "dist/change_checks_cli.js",
|
|
22
23
|
"x-app-icons": "dist/app_icons.js",
|
|
24
|
+
"x-app-new": "dist/app_new.js",
|
|
23
25
|
"x-app-site": "dist/site/cli.js"
|
|
24
26
|
},
|
|
25
27
|
"exports": {
|
|
28
|
+
"./config/tsconfig/*": "./config/tsconfig/*",
|
|
26
29
|
"./*": {
|
|
27
30
|
"types": "./dist/*.d.ts",
|
|
28
31
|
"default": "./dist/*.js"
|
|
@@ -50,7 +53,9 @@
|
|
|
50
53
|
"@resvg/resvg-js": "^2.6.2",
|
|
51
54
|
"@shikijs/rehype": "^4.6.0",
|
|
52
55
|
"@sqlite.org/sqlite-wasm": "3.53.4-build2",
|
|
56
|
+
"@vitejs/plugin-react": "^6.2.1",
|
|
53
57
|
"@x-tech-laboratories/halon": "^0.31.0 || ^0.32.0 || ^0.33.0 || ^0.34.0",
|
|
58
|
+
"electron-vite": "^6.0.0",
|
|
54
59
|
"fastify": "^5.12.7",
|
|
55
60
|
"mermaid": "^11.0.0",
|
|
56
61
|
"nodemailer": "^10.3.1",
|
|
@@ -65,6 +70,7 @@
|
|
|
65
70
|
"shiki": "^4.6.0",
|
|
66
71
|
"unist-util-visit": "^5.2.0",
|
|
67
72
|
"vite": "^8.3.8",
|
|
73
|
+
"vitest": "^5.0.5",
|
|
68
74
|
"yaml": "^2.9.1"
|
|
69
75
|
},
|
|
70
76
|
"peerDependenciesMeta": {
|
|
@@ -110,9 +116,15 @@
|
|
|
110
116
|
"@sqlite.org/sqlite-wasm": {
|
|
111
117
|
"optional": true
|
|
112
118
|
},
|
|
119
|
+
"@vitejs/plugin-react": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
113
122
|
"@x-tech-laboratories/halon": {
|
|
114
123
|
"optional": true
|
|
115
124
|
},
|
|
125
|
+
"electron-vite": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
116
128
|
"fastify": {
|
|
117
129
|
"optional": true
|
|
118
130
|
},
|
|
@@ -155,6 +167,9 @@
|
|
|
155
167
|
"vite": {
|
|
156
168
|
"optional": true
|
|
157
169
|
},
|
|
170
|
+
"vitest": {
|
|
171
|
+
"optional": true
|
|
172
|
+
},
|
|
158
173
|
"yaml": {
|
|
159
174
|
"optional": true
|
|
160
175
|
}
|
|
@@ -184,8 +199,10 @@
|
|
|
184
199
|
"@types/semver": "^7.8.0",
|
|
185
200
|
"@types/spdx-satisfies": "^6.0.0",
|
|
186
201
|
"@types/sshpk": "^1.17.5",
|
|
202
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
187
203
|
"@vitest/coverage-v8": "^5.1.1",
|
|
188
204
|
"@x-tech-laboratories/halon": "^0.34.0",
|
|
205
|
+
"electron-vite": "^6.0.0",
|
|
189
206
|
"fast-check": "^4.10.2",
|
|
190
207
|
"fastify": "^5.12.7",
|
|
191
208
|
"jsdom": "^31.0.0",
|