@dokebi/cli 0.4.36 → 0.4.38
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 +6 -6
- package/dist/dev-log.d.ts +14 -0
- package/dist/dev-log.js +113 -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 +51 -10
- 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 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.38",
|
|
5
5
|
"core": {
|
|
6
6
|
"package": "@dokebi/core",
|
|
7
7
|
"version": "0.4.6"
|
|
@@ -815,7 +815,7 @@
|
|
|
815
815
|
{
|
|
816
816
|
"id": null,
|
|
817
817
|
"package": "@dokebi/cli",
|
|
818
|
-
"version": "0.4.
|
|
818
|
+
"version": "0.4.38",
|
|
819
819
|
"kind": "cli",
|
|
820
820
|
"summary": "Commands to create a project, browse the plugin catalog, run recipes, install plugins and verify (dokebi)",
|
|
821
821
|
"description": "Project scaffolding, plugin catalog, recipes, install and verification CLI for Dokebi.",
|
|
@@ -1814,7 +1814,7 @@
|
|
|
1814
1814
|
{
|
|
1815
1815
|
"id": "dokebi-logger",
|
|
1816
1816
|
"package": "@dokebi/logger",
|
|
1817
|
-
"version": "0.1.
|
|
1817
|
+
"version": "0.1.1",
|
|
1818
1818
|
"kind": "plugin",
|
|
1819
1819
|
"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
1820
|
"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 +1956,7 @@
|
|
|
1956
1956
|
{
|
|
1957
1957
|
"id": "dokebi-mcp",
|
|
1958
1958
|
"package": "@dokebi/mcp",
|
|
1959
|
-
"version": "0.1.
|
|
1959
|
+
"version": "0.1.2",
|
|
1960
1960
|
"kind": "plugin",
|
|
1961
1961
|
"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
1962
|
"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 +2076,7 @@
|
|
|
2076
2076
|
{
|
|
2077
2077
|
"id": "dokebi-migrate",
|
|
2078
2078
|
"package": "@dokebi/migrate",
|
|
2079
|
-
"version": "0.4.
|
|
2079
|
+
"version": "0.4.6",
|
|
2080
2080
|
"kind": "plugin",
|
|
2081
2081
|
"summary": "Migration and seed runner for dokebi-db connections (dokebi-migrate up in the deploy step)",
|
|
2082
2082
|
"description": "Migrations and seeds for dokebi-db connections: history and lock for PostgreSQL, MySQL, MariaDB and MongoDB, run from the deployment.",
|
|
@@ -2133,7 +2133,7 @@
|
|
|
2133
2133
|
{
|
|
2134
2134
|
"id": "dokebi-module",
|
|
2135
2135
|
"package": "@dokebi/module",
|
|
2136
|
-
"version": "0.4.
|
|
2136
|
+
"version": "0.4.3",
|
|
2137
2137
|
"kind": "plugin",
|
|
2138
2138
|
"summary": "Modules that hold one feature each (src/shared/modules/<module>); an app attaches them under a prefix",
|
|
2139
2139
|
"description": "Feature modules for Dokebi apps: controllers, models, views and routes in one folder mounted under a prefix.",
|
|
@@ -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/output.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const CLI_VERSION = "0.4.
|
|
1
|
+
export declare const CLI_VERSION = "0.4.38";
|
|
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,6 +36,7 @@ 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 { DevLog, devRunning, writeDevPid } from './dev-log.js';
|
|
39
40
|
import { 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';
|
|
@@ -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
|
}
|
|
@@ -1578,8 +1590,19 @@ async function devReloadTimeout(root) {
|
|
|
1578
1590
|
* worker and kept across app restarts (D-0045 addendum 3); older ones start it inside the app.
|
|
1579
1591
|
* The first Ctrl+C drains everything; a second one kills.
|
|
1580
1592
|
*/
|
|
1581
|
-
export async function dev(root,
|
|
1593
|
+
export async function dev(root, print) {
|
|
1582
1594
|
const entry = await checkProject(root);
|
|
1595
|
+
// D-0201: everything dev prints goes to .dokebi/run/dev.log too, for `dokebi logs [-f]`.
|
|
1596
|
+
const devLog = new DevLog(paths(root).devLog);
|
|
1597
|
+
const removePid = writeDevPid(paths(root).devPid);
|
|
1598
|
+
process.once('exit', () => {
|
|
1599
|
+
removePid();
|
|
1600
|
+
devLog.close();
|
|
1601
|
+
});
|
|
1602
|
+
const say = (line) => {
|
|
1603
|
+
print(line);
|
|
1604
|
+
devLog.write(`[dokebi dev] ${line}\n`);
|
|
1605
|
+
};
|
|
1583
1606
|
// R4CC-7: a DOKEBI_CONFIG line of .env is not passed to the app; dev says so once.
|
|
1584
1607
|
for (const warning of envFileWarnings(root))
|
|
1585
1608
|
say(`${warning.code} (${warning.path}): ${warning.hint}`);
|
|
@@ -1609,13 +1632,31 @@ export async function dev(root, say) {
|
|
|
1609
1632
|
// its own (POSIX), so what it started and left running when it exits (a restart, a crash) is
|
|
1610
1633
|
// found there and ended instead of holding a port against the next start. Ctrl+C reaches it
|
|
1611
1634
|
// through dev (SIGTERM), and the guard still ends it when dev dies.
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1635
|
+
// D-0201: the children write to pipes that dev copies to its own output and to dev.log. They
|
|
1636
|
+
// are not a terminal then, so dev tells them to colour when its own output is one.
|
|
1637
|
+
const colour = process.stdout.isTTY
|
|
1638
|
+
? { DOKEBI_LOG_COLOR: '1', FORCE_COLOR: '1' }
|
|
1639
|
+
: {};
|
|
1640
|
+
const child = (args, extra = {}, group = false) => {
|
|
1641
|
+
const started = spawn(process.execPath, ['--import', guard, ...args], {
|
|
1642
|
+
cwd: root,
|
|
1643
|
+
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
|
1644
|
+
detached: group && PROCESS_GROUPS,
|
|
1645
|
+
// DOKEBI_DEV: a cluster app runs one worker (@dokebi/cluster, DOKEBI_DEV_WORKERS for more).
|
|
1646
|
+
env: appEnvironment(root, 'development', { DOKEBI_DEV: '1', ...colour, ...(hot ? { DOKEBI_VITE_DEV: '1' } : {}), ...extra }, fileEnv),
|
|
1647
|
+
});
|
|
1648
|
+
started.stdout?.on('data', (chunk) => {
|
|
1649
|
+
// dokebi-check: allow console-output dev passes the app's own output on to the terminal as it was (D-0201)
|
|
1650
|
+
process.stdout.write(chunk);
|
|
1651
|
+
devLog.write(chunk);
|
|
1652
|
+
});
|
|
1653
|
+
started.stderr?.on('data', (chunk) => {
|
|
1654
|
+
// dokebi-check: allow console-output dev passes the app's own output on to the terminal as it was (D-0201)
|
|
1655
|
+
process.stderr.write(chunk);
|
|
1656
|
+
devLog.write(chunk);
|
|
1657
|
+
});
|
|
1658
|
+
return started;
|
|
1659
|
+
};
|
|
1619
1660
|
// One Vite for the session (D-0045 addendum 3) when template-inertia has the host script.
|
|
1620
1661
|
const hostScript = hot ? viteHostScript(root) : undefined;
|
|
1621
1662
|
const viteHost = hostScript ? new ViteHostProcess(() => child([hostScript]), say) : undefined;
|