aem-ext-daemon 0.3.7 → 0.3.9
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/dist/daemon.js +2 -0
- package/dist/dispatcher.js +16 -0
- package/dist/logger.d.ts +15 -0
- package/dist/logger.js +60 -0
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -17,6 +17,7 @@ import { DaemonConnection } from "./connection.js";
|
|
|
17
17
|
import { ensureIdentity, getWorkspaceRoot, setWorkspaceRoot } from "./identity.js";
|
|
18
18
|
import { generatePairCode, displayPairCode } from "./pairing.js";
|
|
19
19
|
import { dispatch } from "./dispatcher.js";
|
|
20
|
+
import { getLogFilePath } from "./logger.js";
|
|
20
21
|
// Read version from package.json so it stays in sync automatically
|
|
21
22
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
22
23
|
const pkgPath = path.resolve(__dirname, "..", "package.json");
|
|
@@ -57,6 +58,7 @@ export class Daemon {
|
|
|
57
58
|
if (workspace) {
|
|
58
59
|
console.log(` Workspace: ${workspace}`);
|
|
59
60
|
}
|
|
61
|
+
console.log(` Log file: ${getLogFilePath()}`);
|
|
60
62
|
console.log("");
|
|
61
63
|
console.log(" Connecting...");
|
|
62
64
|
this.connection.connect();
|
package/dist/dispatcher.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { getWorkspaceRoot, setWorkspaceRoot } from "./identity.js";
|
|
9
|
+
import { logCommand, logResult, logError } from "./logger.js";
|
|
9
10
|
import * as fsCap from "./capabilities/fs.js";
|
|
10
11
|
import * as gitCap from "./capabilities/git.js";
|
|
11
12
|
import * as shellCap from "./capabilities/shell.js";
|
|
@@ -29,6 +30,21 @@ function validatePath(targetPath) {
|
|
|
29
30
|
* Dispatch a command to the appropriate capability handler.
|
|
30
31
|
*/
|
|
31
32
|
export async function dispatch(command, payload, connection) {
|
|
33
|
+
logCommand(command, payload);
|
|
34
|
+
const start = Date.now();
|
|
35
|
+
try {
|
|
36
|
+
const result = await dispatchInner(command, payload, connection);
|
|
37
|
+
const resultStr = typeof result === "string" ? result : JSON.stringify(result);
|
|
38
|
+
logResult(command, resultStr, Date.now() - start);
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
43
|
+
logError(command, message, Date.now() - start);
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function dispatchInner(command, payload, connection) {
|
|
32
48
|
switch (command) {
|
|
33
49
|
// ─── Filesystem ─────────────────────────────────────
|
|
34
50
|
case "fs:roots": {
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon logger — writes timestamped entries to a log file and the terminal.
|
|
3
|
+
*
|
|
4
|
+
* Log file: ~/.adobe-ext-builder/daemon.log (always available, regardless of workspace config)
|
|
5
|
+
*/
|
|
6
|
+
/** Log a command being dispatched. */
|
|
7
|
+
export declare function logCommand(command: string, payload: Record<string, unknown>): void;
|
|
8
|
+
/** Log a command result (success). */
|
|
9
|
+
export declare function logResult(command: string, result: string, durationMs: number): void;
|
|
10
|
+
/** Log a command error. */
|
|
11
|
+
export declare function logError(command: string, error: string, durationMs: number): void;
|
|
12
|
+
/** Log a general info message. */
|
|
13
|
+
export declare function logInfo(message: string): void;
|
|
14
|
+
/** Return the log file path for display purposes. */
|
|
15
|
+
export declare function getLogFilePath(): string;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon logger — writes timestamped entries to a log file and the terminal.
|
|
3
|
+
*
|
|
4
|
+
* Log file: ~/.adobe-ext-builder/daemon.log (always available, regardless of workspace config)
|
|
5
|
+
*/
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
const LOG_DIR = path.join(os.homedir(), ".adobe-ext-builder");
|
|
10
|
+
const LOG_PATH = path.join(LOG_DIR, "daemon.log");
|
|
11
|
+
let logStream = null;
|
|
12
|
+
function ensureStream() {
|
|
13
|
+
if (!logStream) {
|
|
14
|
+
try {
|
|
15
|
+
fs.mkdirSync(LOG_DIR, { recursive: true });
|
|
16
|
+
logStream = fs.createWriteStream(LOG_PATH, { flags: "a" });
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return logStream;
|
|
23
|
+
}
|
|
24
|
+
function ts() {
|
|
25
|
+
return new Date().toISOString();
|
|
26
|
+
}
|
|
27
|
+
/** Log a command being dispatched. */
|
|
28
|
+
export function logCommand(command, payload) {
|
|
29
|
+
const line = `[${ts()}] CMD ${command} ${JSON.stringify(payload)}`;
|
|
30
|
+
const stream = ensureStream();
|
|
31
|
+
stream?.write(line + "\n");
|
|
32
|
+
console.log(` ▶ ${command}`);
|
|
33
|
+
}
|
|
34
|
+
/** Log a command result (success). */
|
|
35
|
+
export function logResult(command, result, durationMs) {
|
|
36
|
+
const preview = result.length > 500 ? result.slice(0, 500) + "..." : result;
|
|
37
|
+
const line = `[${ts()}] OK ${command} (${durationMs}ms) ${preview}`;
|
|
38
|
+
const stream = ensureStream();
|
|
39
|
+
stream?.write(line + "\n");
|
|
40
|
+
console.log(` ✓ ${command} (${durationMs}ms)`);
|
|
41
|
+
}
|
|
42
|
+
/** Log a command error. */
|
|
43
|
+
export function logError(command, error, durationMs) {
|
|
44
|
+
const line = `[${ts()}] ERR ${command} (${durationMs}ms) ${error}`;
|
|
45
|
+
const stream = ensureStream();
|
|
46
|
+
stream?.write(line + "\n");
|
|
47
|
+
// Print the FULL error to the terminal so users can diagnose issues
|
|
48
|
+
console.log(` ✗ ${command} (${durationMs}ms)`);
|
|
49
|
+
console.log(` Error: ${error}`);
|
|
50
|
+
}
|
|
51
|
+
/** Log a general info message. */
|
|
52
|
+
export function logInfo(message) {
|
|
53
|
+
const line = `[${ts()}] INFO ${message}`;
|
|
54
|
+
const stream = ensureStream();
|
|
55
|
+
stream?.write(line + "\n");
|
|
56
|
+
}
|
|
57
|
+
/** Return the log file path for display purposes. */
|
|
58
|
+
export function getLogFilePath() {
|
|
59
|
+
return LOG_PATH;
|
|
60
|
+
}
|