@dokebi/cli 0.4.35 → 0.4.37
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/AI.md +2 -2
- package/catalog.json +57 -7
- package/dist/dev-log.d.ts +14 -0
- package/dist/dev-log.js +113 -0
- package/dist/dev-watch.d.ts +21 -0
- package/dist/dev-watch.js +21 -0
- package/dist/output.d.ts +1 -1
- package/dist/output.js +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +63 -16
- package/package.json +1 -1
package/AI.md
CHANGED
|
@@ -93,7 +93,7 @@ The `blog` plan, depending on the answers: `init` (when the folder is not a proj
|
|
|
93
93
|
| `dokebi app remove <name>` · `app link <app> <domain> [--template] [--seal]` · `app unlink <domain>` · `app list` | Manage apps and domains. `app remove` fails with `APP_IN_USE` while a domain still points to the app (unlink first); it removes the registration and `options.dokebi-app.apps.<name>` (D-0061 per-app settings) from dokebi.yaml and the sample (0.2.5; otherwise the next start fails with `UNKNOWN_APP`) and the app's recorded view from `.dokebi/recipe.json`. The folder stays (user code; the result lists it in `preserved` with the warning `APP_FOLDER_KEPT`) |
|
|
94
94
|
| `dokebi module add <name> [--no-views]` · `module remove` · `module list` | Feature modules `src/shared/modules/<name>` (D-0032). `--no-views`: the routes answer JSON |
|
|
95
95
|
| `dokebi settings add <section>` · `settings sync` · `settings remove <section>` · `settings list` | The settings of the application itself in `options.<section>` (D-0155): `add` writes `src/shared/settings/<section>.ts` (core's `defineSettings` with a `defineOptions` declaration; an existing one default-exporting it is adopted), its schema `src/shared/settings/<section>.schema.json`, the defaults in dokebi.yaml and the example (with the `# reloadable` marks), and registers it, so the app checks the section at start and `config show/set/unset/secret`, doctor and reloads treat it like a plugin section. Code reads `<name>Settings.read(context.app.config)` (typed, cached per configuration, new after a reload). After changing the declaration run `settings sync` (doctor warns `SETTINGS_SCHEMA_STALE`). A value that is still the default the CLI wrote (the old schema's, such as the `pageSize: 50` and `workers: 2` placeholders of `settings add`) follows a changed default, in dokebi.yaml and the example (`sections[].followed`); a value set by hand stays. Then each section is checked against the new schema as doctor checks it: a missing required value is `configRequired`, anything else (a value set by hand above a lowered maximum, a value of an option the declaration dropped) is `INVALID_PLUGIN_OPTIONS` with `details.paths` and a `fix` (`npx dokebi config unset <paths>` or correct it by hand, then sync again), and nothing is written (AI-M49 D2: sync answered ok on what doctor and the app refuse). A section of a plugin, `logging` or `reload` is `SETTINGS_SECTION_CONFLICT`; `remove` keeps the files and the options. A section nothing declares has one code in every config command: `UNDECLARED_SECTION` (`UNKNOWN_PLUGIN` when the name is a plugin that is not installed); `config set` and `secret` refuse it, `config show` (text values hidden) and `unset` work on what is there and warn with it, and doctor and `dokebi check` (`undeclared-section`) report it |
|
|
96
|
-
| `dokebi dev` | Development run (in the foreground). The app leads a process group of its own: what it started and left running when it stops (a restart, Ctrl+C) or crashes is ended (SIGTERM, SIGKILL after 2 s) and dev says so, so a restart never meets a port a helper of the old app holds. When `src/` or `.env` change it drains and starts again; when only `dokebi.yaml` changed it first asks the running app to read it again (D-0154): every changed option reloadable → applied without a restart (`dokebi.yaml reloaded without a restart: <paths>`), an invalid file → the app keeps its settings, anything else (an option that needs a restart, an app without reloads) → a restart as before. With a Vite config and template-inertia ≥0.1.2 it serves views from the Vite dev server with `DOKEBI_VITE_DEV=1` for **HMR** (no build needed; `.vue` and `views/` changes need no restart, D-0045). With template-inertia 0.4.0 that Vite is one host process per dev session, shared by every cluster worker and kept across app restarts (`DOKEBI_VITE_DEV_URL`, `DOKEBI_VITE_DEV_KEY`, D-0045 addendum 3); with 0.1.2 to 0.3 it runs inside the app. With an older template-inertia: a watch build and restarts. The app gets `DOKEBI_DEV=1`, so a cluster app runs one worker (`DOKEBI_DEV_WORKERS`, D-0044, D-0045), and the project's `.env`, read again at every restart (§2.2) |
|
|
96
|
+
| `dokebi dev` | Development run (in the foreground). The app leads a process group of its own: what it started and left running when it stops (a restart, Ctrl+C) or crashes is ended (SIGTERM, SIGKILL after 2 s) and dev says so, so a restart never meets a port a helper of the old app holds. When `src/` or `.env` change it drains and starts again; when only `dokebi.yaml` changed it first asks the running app to read it again (D-0154): every changed option reloadable → applied without a restart (`dokebi.yaml reloaded without a restart: <paths>`), an invalid file → the app keeps its settings, anything else (an option that needs a restart, an app without reloads) → a restart as before. With a Vite config and template-inertia ≥0.1.2 it serves views from the Vite dev server with `DOKEBI_VITE_DEV=1` for **HMR** (no build needed; `.vue` and `views/` changes need no restart, D-0045). With @dokebi/pages installed, `src/apps/<app>/site/` changes need no restart either: the plugin reads the site again itself and keeps the last good version of a broken save (D-0198); a restart would refuse that save and stop the app. That holds while the app runs: an app that is not running (its site refused the start) starts again on a site save. With template-inertia 0.4.0 that Vite is one host process per dev session, shared by every cluster worker and kept across app restarts (`DOKEBI_VITE_DEV_URL`, `DOKEBI_VITE_DEV_KEY`, D-0045 addendum 3); with 0.1.2 to 0.3 it runs inside the app. With an older template-inertia: a watch build and restarts. The app gets `DOKEBI_DEV=1`, so a cluster app runs one worker (`DOKEBI_DEV_WORKERS`, D-0044, D-0045), and the project's `.env`, read again at every restart (§2.2). What dev shows (the app, Vite and its own `[dokebi dev]` lines) is also written to `.dokebi/run/dev.log` (the previous session and one past 16 MB move to `dev.log.1`) and dev writes its pid to `.dokebi/run/dev.pid`, so `dokebi logs [-f]` shows the dev session from another shell (D-0201); with a terminal the app gets `DOKEBI_LOG_COLOR=1`, so the logger keeps its colours through the pipe |
|
|
97
97
|
| `dokebi reload [--timeout-ms <ms>]` | Makes the background app (`dokebi start`) read dokebi.yaml again (D-0154): SIGHUP to the proven pid (through its log writer when this shell may not signal it), then the outcome the app wrote (`.dokebi/run/reload.json`, whatever its log level). `outcome: applied` (with `paths` and `revision`) or `unchanged`; `RELOAD_RESTART_REQUIRED` (`details.restartRequired`: nothing applied, restart to apply), `RELOAD_INVALID` (the app keeps its settings; `details` names the line or paths), `RELOAD_FAILED`, `RELOAD_UNSUPPORTED` (core older than 0.4.2, or `src/main.ts` gives the app no `configFile` or changed after the start: no signal is sent, it would end the app). Not running: exit 3. A running app also reads the file when it is saved (`options.reload.watch`) |
|
|
98
98
|
| `dokebi start [--foreground] [--wait-ms <ms>] [--log-max-mb <MB>] [--log-files <n>]` · `stop [--timeout-ms <ms>] [--force]` · `status` · `logs [-n <lines>] [-f]` | Background run, stop, state, logs and log rotation (§2.1 below, D-0044, D-0053) |
|
|
99
99
|
|
|
@@ -142,7 +142,7 @@ Most commands support `--json` (one machine document); interactive `dev`, `logs`
|
|
|
142
142
|
- `stop`: SIGTERM **to the app** for a drain (the writer ends after the app's output ends; when it does not end within 5 seconds, `warnings`). When the app does not end within `--timeout-ms` (default 30000): `STOP_TIMEOUT` (the process stays), with `--force` a SIGKILL then. When nothing runs: `stopped: false`.
|
|
143
143
|
- `status`: while running, pid, uptime seconds, RSS (with `ps`), `proof` (`process`, `log-writer` or `http`, above) and `logWriter: { pid, running }` (running false means the app's output is not being written). Always `logFiles` (app.log and rotated files, newest first, `{ file, bytes }`), and `logWriterLog` when the writer has diagnostics. Stopped is **exit code 3**. When only a PID file is left (killed from outside, a crash) it reports `stale: true` and deletes the file.
|
|
144
144
|
- PIDs are reused, so a signal goes out only when `ps` shows this project's `src/main.ts` in that pid's command line and the start time matches (otherwise the PID file counts as stale), or, without `ps`, when the app or its log writer proved the instance token.
|
|
145
|
-
- `logs`: the last `-n` lines (default 100; filled from `app.log.1`, `.2`… when app.log has fewer), `-f` follows until Ctrl+C (it remembers the file by inode; after a rotation it reads the old file to its end, then the newer rotated files from oldest to newest, then the new `app.log`, so no line is skipped even when several rotations happen within the 250 ms check interval, and there is no gap between the first `-n` lines and following. When it falls so far behind that the file it read was deleted past `--log-files`, it prints one line `--- dokebi: logs -f fell behind … ---` and continues from the oldest file left). `logs`, `dev` and `start --foreground` have no `--json`.
|
|
145
|
+
- `logs`: reads `.dokebi/run/dev.log` while a `dokebi dev` runs (its `dev.pid` names a live process), otherwise `logs/app.log` of `start` (or the last dev session's dev.log when there is no app.log; neither → `NO_LOG`, D-0201). The last `-n` lines (default 100; filled from `app.log.1`, `.2`… when app.log has fewer), `-f` follows until Ctrl+C (it remembers the file by inode; after a rotation it reads the old file to its end, then the newer rotated files from oldest to newest, then the new `app.log`, so no line is skipped even when several rotations happen within the 250 ms check interval, and there is no gap between the first `-n` lines and following. When it falls so far behind that the file it read was deleted past `--log-files`, it prints one line `--- dokebi: logs -f fell behind … ---` and continues from the oldest file left). `logs`, `dev` and `start --foreground` have no `--json`.
|
|
146
146
|
- Not done: automatic restart after a crash, start at boot, time-based rotation, compression. For production servers, `dokebi start --foreground` (or `node src/main.ts`) under systemd or Docker is the better fit. On Windows, `start` (background) and `stop` are `UNSUPPORTED_PLATFORM`.
|
|
147
147
|
- If you edit `src/main.ts` and remove the started line, start cannot tell whether the app is ready. Keep it.
|
|
148
148
|
|
package/catalog.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$comment": "Generated by scripts/catalog/build.ts from package.json dokebiCatalog fields and packages/cli/catalog-src (D-0065). Do not edit; run node scripts/catalog/build.ts.",
|
|
3
3
|
"schemaVersion": 1,
|
|
4
|
-
"cli": "0.4.
|
|
4
|
+
"cli": "0.4.37",
|
|
5
5
|
"core": {
|
|
6
6
|
"package": "@dokebi/core",
|
|
7
7
|
"version": "0.4.6"
|
|
@@ -343,6 +343,10 @@
|
|
|
343
343
|
"summary": "load shedding with 503 and Retry-After when the event loop stalls or memory runs high, health routes served",
|
|
344
344
|
"en": "overload load shedding under pressure event loop delay backpressure 503"
|
|
345
345
|
},
|
|
346
|
+
"web.pages": {
|
|
347
|
+
"summary": "app definition files (app.yaml, pages, layouts and components in HTML with Tailwind classes) drawn on the server with module widgets, sent through Inertia one page at a time, read again in development",
|
|
348
|
+
"en": "pages site builder editor html tailwind layout widget app definition no-code"
|
|
349
|
+
},
|
|
346
350
|
"web.routing": {
|
|
347
351
|
"summary": "routes grouped under a prefix (mount)",
|
|
348
352
|
"en": "router routes prefix"
|
|
@@ -815,7 +819,7 @@
|
|
|
815
819
|
{
|
|
816
820
|
"id": null,
|
|
817
821
|
"package": "@dokebi/cli",
|
|
818
|
-
"version": "0.4.
|
|
822
|
+
"version": "0.4.37",
|
|
819
823
|
"kind": "cli",
|
|
820
824
|
"summary": "Commands to create a project, browse the plugin catalog, run recipes, install plugins and verify (dokebi)",
|
|
821
825
|
"description": "Project scaffolding, plugin catalog, recipes, install and verification CLI for Dokebi.",
|
|
@@ -1814,7 +1818,7 @@
|
|
|
1814
1818
|
{
|
|
1815
1819
|
"id": "dokebi-logger",
|
|
1816
1820
|
"package": "@dokebi/logger",
|
|
1817
|
-
"version": "0.1.
|
|
1821
|
+
"version": "0.1.1",
|
|
1818
1822
|
"kind": "plugin",
|
|
1819
1823
|
"summary": "The app logger on pino: JSON to stdout, rotating files, pretty development output and network targets (NDJSON batches to Dokebi Studio, OTLP/HTTP JSON) at once, written in worker threads with bounded buffers, secrets redacted, levels per plugin, flushed on shutdown",
|
|
1820
1824
|
"description": "Production logging for Dokebi apps on pino: stdout, rotating files, pretty output and HTTP/OTLP log shipping at once, written off the event loop, with redaction, per-plugin levels and flush on shutdown.",
|
|
@@ -1956,7 +1960,7 @@
|
|
|
1956
1960
|
{
|
|
1957
1961
|
"id": "dokebi-mcp",
|
|
1958
1962
|
"package": "@dokebi/mcp",
|
|
1959
|
-
"version": "0.1.
|
|
1963
|
+
"version": "0.1.1",
|
|
1960
1964
|
"kind": "plugin",
|
|
1961
1965
|
"summary": "MCP server on @dokebi/oauth: stateless Streamable HTTP at /mcp, tool classes with checked input schemas and scopes, a forced result envelope with paging, per-grant limits and coded tool errors",
|
|
1962
1966
|
"description": "MCP server for @dokebi/web on @dokebi/oauth: stateless Streamable HTTP, tool classes with checked schemas, a forced result envelope, per-grant limits and coded tool errors.",
|
|
@@ -2076,7 +2080,7 @@
|
|
|
2076
2080
|
{
|
|
2077
2081
|
"id": "dokebi-migrate",
|
|
2078
2082
|
"package": "@dokebi/migrate",
|
|
2079
|
-
"version": "0.4.
|
|
2083
|
+
"version": "0.4.5",
|
|
2080
2084
|
"kind": "plugin",
|
|
2081
2085
|
"summary": "Migration and seed runner for dokebi-db connections (dokebi-migrate up in the deploy step)",
|
|
2082
2086
|
"description": "Migrations and seeds for dokebi-db connections: history and lock for PostgreSQL, MySQL, MariaDB and MongoDB, run from the deployment.",
|
|
@@ -2113,6 +2117,7 @@
|
|
|
2113
2117
|
"optional": [],
|
|
2114
2118
|
"optionKeys": [
|
|
2115
2119
|
"connections",
|
|
2120
|
+
"directories",
|
|
2116
2121
|
"directory",
|
|
2117
2122
|
"lockRetries",
|
|
2118
2123
|
"lockRetryDelayMs",
|
|
@@ -2133,7 +2138,7 @@
|
|
|
2133
2138
|
{
|
|
2134
2139
|
"id": "dokebi-module",
|
|
2135
2140
|
"package": "@dokebi/module",
|
|
2136
|
-
"version": "0.4.
|
|
2141
|
+
"version": "0.4.2",
|
|
2137
2142
|
"kind": "plugin",
|
|
2138
2143
|
"summary": "Modules that hold one feature each (src/shared/modules/<module>); an app attaches them under a prefix",
|
|
2139
2144
|
"description": "Feature modules for Dokebi apps: controllers, models, views and routes in one folder mounted under a prefix.",
|
|
@@ -2380,6 +2385,51 @@
|
|
|
2380
2385
|
},
|
|
2381
2386
|
"install": "npx dokebi add @dokebi/outbox"
|
|
2382
2387
|
},
|
|
2388
|
+
{
|
|
2389
|
+
"id": "dokebi-pages",
|
|
2390
|
+
"package": "@dokebi/pages",
|
|
2391
|
+
"version": "0.1.0",
|
|
2392
|
+
"kind": "plugin",
|
|
2393
|
+
"summary": "App definition files (app.yaml, pages, layouts and components in HTML with Tailwind classes, theme.css) drawn on the server with module widgets, sent to an Inertia app as one page at a time (the layout once) or as HTML, read again in development",
|
|
2394
|
+
"description": "App definition files for @dokebi/app apps: app.yaml, pages, layouts and components in HTML with Tailwind classes, drawn on the server with module widgets, sent through Inertia or as HTML, read again when they change.",
|
|
2395
|
+
"keywords": [
|
|
2396
|
+
"dokebi",
|
|
2397
|
+
"dokebi-plugin",
|
|
2398
|
+
"web",
|
|
2399
|
+
"pages",
|
|
2400
|
+
"site",
|
|
2401
|
+
"tailwind",
|
|
2402
|
+
"builder"
|
|
2403
|
+
],
|
|
2404
|
+
"maturity": "experimental",
|
|
2405
|
+
"core": "^0.4.2",
|
|
2406
|
+
"provides": [
|
|
2407
|
+
"web.pages"
|
|
2408
|
+
],
|
|
2409
|
+
"variants": [],
|
|
2410
|
+
"doesNot": [
|
|
2411
|
+
"No scripts in pages: script, style, iframe, on… attributes and javascript: addresses are refused",
|
|
2412
|
+
"No editor: the files are written by people, the Dokebi Solution editor or AI tools"
|
|
2413
|
+
],
|
|
2414
|
+
"recipes": [],
|
|
2415
|
+
"requires": [],
|
|
2416
|
+
"optional": [
|
|
2417
|
+
{
|
|
2418
|
+
"id": "dokebi-module",
|
|
2419
|
+
"range": "^0.4.2"
|
|
2420
|
+
}
|
|
2421
|
+
],
|
|
2422
|
+
"optionKeys": [
|
|
2423
|
+
"maxSites",
|
|
2424
|
+
"watch",
|
|
2425
|
+
"watchPollMs"
|
|
2426
|
+
],
|
|
2427
|
+
"docs": {
|
|
2428
|
+
"ai": "AI.md",
|
|
2429
|
+
"readme": "README.md"
|
|
2430
|
+
},
|
|
2431
|
+
"install": "npx dokebi add @dokebi/pages"
|
|
2432
|
+
},
|
|
2383
2433
|
{
|
|
2384
2434
|
"id": "dokebi-payment",
|
|
2385
2435
|
"package": "@dokebi/payment",
|
|
@@ -2765,7 +2815,7 @@
|
|
|
2765
2815
|
{
|
|
2766
2816
|
"id": null,
|
|
2767
2817
|
"package": "@dokebi/rich-text",
|
|
2768
|
-
"version": "0.1.
|
|
2818
|
+
"version": "0.1.3",
|
|
2769
2819
|
"kind": "library",
|
|
2770
2820
|
"summary": "Editor documents (Tiptap or ProseMirror JSON) checked whole against a declared schema of nodes, marks, links and image sources, with coded 422 errors, then safe HTML, plain text and excerpts",
|
|
2771
2821
|
"description": "Rich text documents for Dokebi: editor JSON (Tiptap, ProseMirror) checked whole against a declared schema with coded 422 errors, then safe HTML, plain text and excerpts.",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Bytes of one dev.log before it rotates to dev.log.1 (the one before is dropped). */
|
|
2
|
+
export declare const DEV_LOG_BYTES: number;
|
|
3
|
+
export declare class DevLog {
|
|
4
|
+
#private;
|
|
5
|
+
readonly file: string;
|
|
6
|
+
constructor(file: string, limit?: number);
|
|
7
|
+
/** Appends `chunk` (a line of dev, or what a child wrote). Never throws: a failure is reported once. */
|
|
8
|
+
write(chunk: string | Uint8Array): void;
|
|
9
|
+
close(): void;
|
|
10
|
+
}
|
|
11
|
+
/** Whether `.dokebi/run/dev.pid` names a dev process that is running now. */
|
|
12
|
+
export declare function devRunning(pidFile: string, alive: (pid: number) => boolean): boolean;
|
|
13
|
+
/** Writes `.dokebi/run/dev.pid`; the returned function removes it (when it is still this one). */
|
|
14
|
+
export declare function writeDevPid(pidFile: string): () => void;
|
package/dist/dev-log.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// What `dokebi dev` prints, kept in `.dokebi/run/dev.log` too (D-0201), so `dokebi logs [-f]`
|
|
2
|
+
// shows a dev session as it shows a background app: the app's output, Vite's and dev's own lines,
|
|
3
|
+
// as they appear in the terminal. The previous session moves to `dev.log.1` when dev starts; a
|
|
4
|
+
// session larger than DEV_LOG_BYTES rotates to `dev.log.1` as well (the follower of `logs -f`
|
|
5
|
+
// moves across that by inode). `dev.pid` names the running dev process, so `logs` knows a dev
|
|
6
|
+
// session is the one to show.
|
|
7
|
+
import { closeSync, mkdirSync, openSync, readSync, renameSync, rmSync, writeSync } from 'node:fs';
|
|
8
|
+
import { dirname } from 'node:path';
|
|
9
|
+
import { debug, isMissing, reportError } from './diagnostics.js';
|
|
10
|
+
/** Bytes of one dev.log before it rotates to dev.log.1 (the one before is dropped). */
|
|
11
|
+
export const DEV_LOG_BYTES = 16 * 1024 * 1024;
|
|
12
|
+
export class DevLog {
|
|
13
|
+
file;
|
|
14
|
+
#limit;
|
|
15
|
+
#fd;
|
|
16
|
+
#size = 0;
|
|
17
|
+
#failed = false;
|
|
18
|
+
constructor(file, limit = DEV_LOG_BYTES) {
|
|
19
|
+
this.file = file;
|
|
20
|
+
this.#limit = limit;
|
|
21
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
22
|
+
this.#rotate();
|
|
23
|
+
this.#fd = openSync(file, 'w');
|
|
24
|
+
}
|
|
25
|
+
/** Appends `chunk` (a line of dev, or what a child wrote). Never throws: a failure is reported once. */
|
|
26
|
+
write(chunk) {
|
|
27
|
+
if (this.#failed || this.#fd === undefined)
|
|
28
|
+
return;
|
|
29
|
+
try {
|
|
30
|
+
const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : chunk;
|
|
31
|
+
if (this.#size > 0 && this.#size + bytes.length > this.#limit) {
|
|
32
|
+
closeSync(this.#fd);
|
|
33
|
+
this.#rotate();
|
|
34
|
+
this.#fd = openSync(this.file, 'w');
|
|
35
|
+
this.#size = 0;
|
|
36
|
+
}
|
|
37
|
+
writeSync(this.#fd, bytes);
|
|
38
|
+
this.#size += bytes.length;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
// The terminal still shows everything; only the copy for `dokebi logs` stops.
|
|
42
|
+
this.#failed = true;
|
|
43
|
+
reportError('DEV_LOG_FAILED', 'Unable to write .dokebi/run/dev.log; dokebi logs will not show this session', error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
close() {
|
|
47
|
+
if (this.#fd === undefined)
|
|
48
|
+
return;
|
|
49
|
+
try {
|
|
50
|
+
closeSync(this.#fd);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
this.#fd = undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** dev.log → dev.log.1 (replacing it), when there is a dev.log. */
|
|
57
|
+
#rotate() {
|
|
58
|
+
try {
|
|
59
|
+
renameSync(this.file, `${this.file}.1`);
|
|
60
|
+
debug('dev log rotated', { file: this.file });
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (!isMissing(error))
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Whether `.dokebi/run/dev.pid` names a dev process that is running now. */
|
|
69
|
+
export function devRunning(pidFile, alive) {
|
|
70
|
+
let pid;
|
|
71
|
+
try {
|
|
72
|
+
pid = readPid(pidFile);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (isMissing(error))
|
|
76
|
+
return false;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
return Number.isSafeInteger(pid) && pid > 0 && alive(pid);
|
|
80
|
+
}
|
|
81
|
+
/** The pid of `.dokebi/run/dev.pid` (a small file dev writes: its pid on one line). */
|
|
82
|
+
function readPid(file) {
|
|
83
|
+
const fd = openSync(file, 'r');
|
|
84
|
+
try {
|
|
85
|
+
const buffer = Buffer.alloc(32);
|
|
86
|
+
const read = readSync(fd, buffer, 0, buffer.length, 0);
|
|
87
|
+
return Number(buffer.subarray(0, read).toString('utf8').trim());
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
closeSync(fd);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Writes `.dokebi/run/dev.pid`; the returned function removes it (when it is still this one). */
|
|
94
|
+
export function writeDevPid(pidFile) {
|
|
95
|
+
mkdirSync(dirname(pidFile), { recursive: true });
|
|
96
|
+
const fd = openSync(pidFile, 'w');
|
|
97
|
+
try {
|
|
98
|
+
writeSync(fd, `${process.pid}\n`);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
closeSync(fd);
|
|
102
|
+
}
|
|
103
|
+
return () => {
|
|
104
|
+
try {
|
|
105
|
+
if (readPid(pidFile) === process.pid)
|
|
106
|
+
rmSync(pidFile, { force: true });
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (!isMissing(error))
|
|
110
|
+
reportError('DEV_PID_FAILED', 'Unable to remove .dokebi/run/dev.pid', error);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
package/dist/dev-watch.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
/** Files the Vite dev server owns: a change reaches the browser by HMR, not by a restart. */
|
|
2
|
+
export declare const VIEW_FILE: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* Site folders of @dokebi/pages (D-0198): `apps/<app>/site/…` under src. The plugin reads them again
|
|
5
|
+
* itself and keeps the last good version when a save has problems; a restart would lose that (the
|
|
6
|
+
* start refuses a site with problems, so one broken save stopped the app).
|
|
7
|
+
*/
|
|
8
|
+
export declare const SITE_FILE: RegExp;
|
|
9
|
+
/**
|
|
10
|
+
* Whether a change of `name` (relative to src) reaches the app without a restart: a view through
|
|
11
|
+
* the Vite dev server (`hot`) or a watch build (`builds`), a site file through @dokebi/pages
|
|
12
|
+
* (`pages`: the package is installed) — only while the app runs (`running`, default true): an app
|
|
13
|
+
* that is not running, because a site with problems refused its start, must start again when the
|
|
14
|
+
* site is saved.
|
|
15
|
+
*/
|
|
16
|
+
export declare function reachesWithoutRestart(name: string, has: {
|
|
17
|
+
readonly hot: boolean;
|
|
18
|
+
readonly builds: boolean;
|
|
19
|
+
readonly pages: boolean;
|
|
20
|
+
readonly running?: boolean;
|
|
21
|
+
}): boolean;
|
|
1
22
|
/**
|
|
2
23
|
* The recorded state of the watched paths. `changed(path)` answers whether a reported path really
|
|
3
24
|
* changed since it was recorded (or since its last change) and records its new state.
|
package/dist/dev-watch.js
CHANGED
|
@@ -15,6 +15,27 @@
|
|
|
15
15
|
import { readdirSync, statSync } from 'node:fs';
|
|
16
16
|
import { basename, join, sep } from 'node:path';
|
|
17
17
|
import { debug, isMissing, reportError } from './diagnostics.js';
|
|
18
|
+
/** Files the Vite dev server owns: a change reaches the browser by HMR, not by a restart. */
|
|
19
|
+
export const VIEW_FILE = /(^|[\\/])views[\\/].*\.(js|mjs|ts)$|\.(vue|css|scss|sass|less)$/;
|
|
20
|
+
/**
|
|
21
|
+
* Site folders of @dokebi/pages (D-0198): `apps/<app>/site/…` under src. The plugin reads them again
|
|
22
|
+
* itself and keeps the last good version when a save has problems; a restart would lose that (the
|
|
23
|
+
* start refuses a site with problems, so one broken save stopped the app).
|
|
24
|
+
*/
|
|
25
|
+
export const SITE_FILE = /^apps[\\/][^\\/]+[\\/]site(?:[\\/]|$)/;
|
|
26
|
+
/**
|
|
27
|
+
* Whether a change of `name` (relative to src) reaches the app without a restart: a view through
|
|
28
|
+
* the Vite dev server (`hot`) or a watch build (`builds`), a site file through @dokebi/pages
|
|
29
|
+
* (`pages`: the package is installed) — only while the app runs (`running`, default true): an app
|
|
30
|
+
* that is not running, because a site with problems refused its start, must start again when the
|
|
31
|
+
* site is saved.
|
|
32
|
+
*/
|
|
33
|
+
export function reachesWithoutRestart(name, has) {
|
|
34
|
+
// A site file (its theme.css too) is decided by the site alone, never as a Vite style.
|
|
35
|
+
if (has.pages && SITE_FILE.test(name))
|
|
36
|
+
return has.running !== false;
|
|
37
|
+
return ((has.hot && VIEW_FILE.test(name)) || (has.builds && /\.(vue|css|scss|sass|less)$/.test(name)));
|
|
38
|
+
}
|
|
18
39
|
/** Entries recorded at most; past it, unknown paths count as changed. */
|
|
19
40
|
const DEFAULT_LIMIT = 100_000;
|
|
20
41
|
/** A folder is its identity (what is in it is compared entry by entry); a file also its content. */
|
package/dist/output.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const CLI_VERSION = "0.4.
|
|
1
|
+
export declare const CLI_VERSION = "0.4.37";
|
|
2
2
|
export declare function envelope(command: string, result: unknown, ok?: boolean): object;
|
|
3
3
|
export declare function failure(command: string, error: unknown, mutationStarted: boolean): object;
|
package/dist/output.js
CHANGED
package/dist/server.d.ts
CHANGED
|
@@ -209,7 +209,7 @@ export declare function installedVersion(root: string, name: string): [number, n
|
|
|
209
209
|
* worker and kept across app restarts (D-0045 addendum 3); older ones start it inside the app.
|
|
210
210
|
* The first Ctrl+C drains everything; a second one kills.
|
|
211
211
|
*/
|
|
212
|
-
export declare function dev(root: string,
|
|
212
|
+
export declare function dev(root: string, print: (line: string) => void): Promise<number>;
|
|
213
213
|
/** What `dokebi reload` found and did (D-0154). */
|
|
214
214
|
export interface ReloadResult {
|
|
215
215
|
readonly running: boolean;
|
package/dist/server.js
CHANGED
|
@@ -36,7 +36,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
36
36
|
import { promisify } from 'node:util';
|
|
37
37
|
import { appUrls, readAppHosts } from './app-urls.js';
|
|
38
38
|
import { CONFIG_FILE, configTarget, parseProjectConfig, readProjectSettings, } from './configuration.js';
|
|
39
|
-
import {
|
|
39
|
+
import { DevLog, devRunning, writeDevPid } from './dev-log.js';
|
|
40
|
+
import { reachesWithoutRestart, WatchedState } from './dev-watch.js';
|
|
40
41
|
import { debug, debugEnabled, describeError, isMissing, reportError } from './diagnostics.js';
|
|
41
42
|
import { appEnvironment, envFileWarnings, readEnvFile } from './env-file.js';
|
|
42
43
|
import { CliError } from './errors.js';
|
|
@@ -65,6 +66,10 @@ const paths = (root) => ({
|
|
|
65
66
|
pid: join(root, RUN, 'app.pid'),
|
|
66
67
|
log: join(root, RUN, 'app.log'),
|
|
67
68
|
writerLog: join(root, RUN, 'log-writer.log'),
|
|
69
|
+
/** D-0201: what `dokebi dev` printed (this session; the one before is dev.log.1). */
|
|
70
|
+
devLog: join(root, RUN, 'dev.log'),
|
|
71
|
+
/** D-0201: the pid of the running `dokebi dev`. */
|
|
72
|
+
devPid: join(root, RUN, 'dev.pid'),
|
|
68
73
|
/** D-0154: the outcome of the app's last configuration reload (RELOAD_STATUS_ENV). */
|
|
69
74
|
reloadStatus: join(root, RUN, 'reload.json'),
|
|
70
75
|
lock: join(root, RUN, 'start.lock'),
|
|
@@ -1264,10 +1269,17 @@ export async function stopStarted(root, started, timeoutMs = 30_000, force = fal
|
|
|
1264
1269
|
export async function logs(root, lines = 100, follow = false,
|
|
1265
1270
|
// dokebi-check: allow console-output dokebi logs prints the app log lines to the terminal
|
|
1266
1271
|
write = (text) => process.stdout.write(text), signal) {
|
|
1267
|
-
|
|
1272
|
+
// D-0201: a running `dokebi dev` is the session to show; else the background app's log, else
|
|
1273
|
+
// the last dev session's.
|
|
1274
|
+
const files = paths(root);
|
|
1275
|
+
const file = devRunning(files.devPid, (pid) => pidState(pid, (id, signal) => process.kill(id, signal)) === 'alive')
|
|
1276
|
+
? files.devLog
|
|
1277
|
+
: existsSync(files.log) || !existsSync(files.devLog)
|
|
1278
|
+
? files.log
|
|
1279
|
+
: files.devLog;
|
|
1268
1280
|
if (!follow) {
|
|
1269
1281
|
if (!existsSync(file))
|
|
1270
|
-
throw new CliError('NO_LOG', `${RUN}/app.log
|
|
1282
|
+
throw new CliError('NO_LOG', `${RUN}/app.log and ${RUN}/dev.log do not exist; start the app with npx dokebi dev or npx dokebi start`);
|
|
1271
1283
|
write(await tail(file, lines));
|
|
1272
1284
|
return;
|
|
1273
1285
|
}
|
|
@@ -1504,8 +1516,6 @@ function inertiaDevServer(root) {
|
|
|
1504
1516
|
const [major, minor, patch] = version;
|
|
1505
1517
|
return major > 0 || minor > 1 || (minor === 1 && patch >= 2);
|
|
1506
1518
|
}
|
|
1507
|
-
/** Files the Vite dev server owns: a change reaches the browser by HMR, not by a restart. */
|
|
1508
|
-
const VIEW_FILE = /(^|[\\/])views[\\/].*\.(js|mjs|ts)$|\.(vue|css|scss|sass|less)$/;
|
|
1509
1519
|
let devReloadId = 0;
|
|
1510
1520
|
/**
|
|
1511
1521
|
* D-0154: asks the app `dokebi dev` runs to read dokebi.yaml again (through the IPC channel of
|
|
@@ -1578,8 +1588,19 @@ async function devReloadTimeout(root) {
|
|
|
1578
1588
|
* worker and kept across app restarts (D-0045 addendum 3); older ones start it inside the app.
|
|
1579
1589
|
* The first Ctrl+C drains everything; a second one kills.
|
|
1580
1590
|
*/
|
|
1581
|
-
export async function dev(root,
|
|
1591
|
+
export async function dev(root, print) {
|
|
1582
1592
|
const entry = await checkProject(root);
|
|
1593
|
+
// D-0201: everything dev prints goes to .dokebi/run/dev.log too, for `dokebi logs [-f]`.
|
|
1594
|
+
const devLog = new DevLog(paths(root).devLog);
|
|
1595
|
+
const removePid = writeDevPid(paths(root).devPid);
|
|
1596
|
+
process.once('exit', () => {
|
|
1597
|
+
removePid();
|
|
1598
|
+
devLog.close();
|
|
1599
|
+
});
|
|
1600
|
+
const say = (line) => {
|
|
1601
|
+
print(line);
|
|
1602
|
+
devLog.write(`[dokebi dev] ${line}\n`);
|
|
1603
|
+
};
|
|
1583
1604
|
// R4CC-7: a DOKEBI_CONFIG line of .env is not passed to the app; dev says so once.
|
|
1584
1605
|
for (const warning of envFileWarnings(root))
|
|
1585
1606
|
say(`${warning.code} (${warning.path}): ${warning.hint}`);
|
|
@@ -1609,13 +1630,31 @@ export async function dev(root, say) {
|
|
|
1609
1630
|
// its own (POSIX), so what it started and left running when it exits (a restart, a crash) is
|
|
1610
1631
|
// found there and ended instead of holding a port against the next start. Ctrl+C reaches it
|
|
1611
1632
|
// through dev (SIGTERM), and the guard still ends it when dev dies.
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1633
|
+
// D-0201: the children write to pipes that dev copies to its own output and to dev.log. They
|
|
1634
|
+
// are not a terminal then, so dev tells them to colour when its own output is one.
|
|
1635
|
+
const colour = process.stdout.isTTY
|
|
1636
|
+
? { DOKEBI_LOG_COLOR: '1', FORCE_COLOR: '1' }
|
|
1637
|
+
: {};
|
|
1638
|
+
const child = (args, extra = {}, group = false) => {
|
|
1639
|
+
const started = spawn(process.execPath, ['--import', guard, ...args], {
|
|
1640
|
+
cwd: root,
|
|
1641
|
+
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
|
1642
|
+
detached: group && PROCESS_GROUPS,
|
|
1643
|
+
// DOKEBI_DEV: a cluster app runs one worker (@dokebi/cluster, DOKEBI_DEV_WORKERS for more).
|
|
1644
|
+
env: appEnvironment(root, 'development', { DOKEBI_DEV: '1', ...colour, ...(hot ? { DOKEBI_VITE_DEV: '1' } : {}), ...extra }, fileEnv),
|
|
1645
|
+
});
|
|
1646
|
+
started.stdout?.on('data', (chunk) => {
|
|
1647
|
+
// dokebi-check: allow console-output dev passes the app's own output on to the terminal as it was (D-0201)
|
|
1648
|
+
process.stdout.write(chunk);
|
|
1649
|
+
devLog.write(chunk);
|
|
1650
|
+
});
|
|
1651
|
+
started.stderr?.on('data', (chunk) => {
|
|
1652
|
+
// dokebi-check: allow console-output dev passes the app's own output on to the terminal as it was (D-0201)
|
|
1653
|
+
process.stderr.write(chunk);
|
|
1654
|
+
devLog.write(chunk);
|
|
1655
|
+
});
|
|
1656
|
+
return started;
|
|
1657
|
+
};
|
|
1619
1658
|
// One Vite for the session (D-0045 addendum 3) when template-inertia has the host script.
|
|
1620
1659
|
const hostScript = hot ? viteHostScript(root) : undefined;
|
|
1621
1660
|
const viteHost = hostScript ? new ViteHostProcess(() => child([hostScript]), say) : undefined;
|
|
@@ -1795,9 +1834,17 @@ export async function dev(root, say) {
|
|
|
1795
1834
|
// dev-watch.ts: macOS also reports writes made before the watch started). An event without a
|
|
1796
1835
|
// name cannot be checked and restarts.
|
|
1797
1836
|
const source = join(root, 'src');
|
|
1798
|
-
// Styles and components reach the app through Vite (HMR, or the watch builds that restart it)
|
|
1799
|
-
|
|
1800
|
-
|
|
1837
|
+
// Styles and components reach the app through Vite (HMR, or the watch builds that restart it);
|
|
1838
|
+
// site files of @dokebi/pages through the plugin, which reads them again itself (D-0198).
|
|
1839
|
+
const reaches = {
|
|
1840
|
+
hot,
|
|
1841
|
+
builds: helpers.length > 0,
|
|
1842
|
+
pages: installedVersion(root, '@dokebi/pages') !== undefined,
|
|
1843
|
+
};
|
|
1844
|
+
// A site file reaches only a running app: one that is not running (a site with problems refuses
|
|
1845
|
+
// the start, PAGES_INVALID) starts again on the save that fixes it.
|
|
1846
|
+
const appRunning = () => app !== undefined && app.exitCode === null && app.signalCode === null;
|
|
1847
|
+
const viewFile = (name) => reachesWithoutRestart(name, { ...reaches, running: appRunning() });
|
|
1801
1848
|
const watched = new WatchedState({ skip: (path) => viewFile(relative(source, path)) });
|
|
1802
1849
|
const watchers = [
|
|
1803
1850
|
watch(source, { recursive: true }, (_event, name) => {
|