novaapp-sdk 1.4.1 → 1.4.2

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/bin/nova.mjs ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ // Nova CLI shebang wrapper.
3
+ // Resolves the compiled `dist/cli.js` relative to this file so it works
4
+ // whether the SDK is installed globally or locally (npx novaapp-sdk).
5
+
6
+ import { createRequire } from 'node:module'
7
+ import { fileURLToPath } from 'node:url'
8
+ import { resolve, dirname } from 'node:path'
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url))
11
+
12
+ // Dynamic import so the error message is clear if build is missing
13
+ let run
14
+ try {
15
+ ;({ run } = await import(resolve(__dirname, '../dist/cli.js')))
16
+ } catch {
17
+ console.error(
18
+ '\x1b[31m✖\x1b[0m Could not load dist/cli.js — run \x1b[36mnpm run build\x1b[0m first.'
19
+ )
20
+ process.exit(1)
21
+ }
22
+
23
+ await run(process.argv.slice(2))
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __esm = (fn, res) => function __init() {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ };
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ export {
23
+ __esm,
24
+ __export,
25
+ __toCommonJS
26
+ };
@@ -0,0 +1,124 @@
1
+ // src/devtools/HotLoader.ts
2
+ import { EventEmitter } from "events";
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ var HotLoader = class extends EventEmitter {
6
+ constructor(watchPath, options = {}) {
7
+ super();
8
+ this.watcher = null;
9
+ this.debounceTimer = null;
10
+ this.lastChanged = null;
11
+ this.restartFn = null;
12
+ this.restarting = false;
13
+ this.watchPath = path.resolve(watchPath);
14
+ this.debounceMs = options.debounce ?? 250;
15
+ this.recursive = options.recursive ?? true;
16
+ this.extensions = new Set(
17
+ options.extensions ?? [".ts", ".js", ".mjs", ".cjs", ".json"]
18
+ );
19
+ }
20
+ // ── Lifecycle ──────────────────────────────────────────────────────────────
21
+ /**
22
+ * Start watching for file changes.
23
+ *
24
+ * Calling `start()` again after `stop()` is safe — it creates a new watcher.
25
+ */
26
+ start() {
27
+ if (this.watcher) return;
28
+ this.watcher = fs.watch(
29
+ this.watchPath,
30
+ { recursive: this.recursive, encoding: "utf8" },
31
+ (event, filename) => {
32
+ if (!filename) return;
33
+ const ext = path.extname(filename);
34
+ if (!this.extensions.has(ext)) return;
35
+ const full = path.join(this.watchPath, filename);
36
+ this.emit("change", full);
37
+ this.lastChanged = full;
38
+ if (this.debounceTimer) clearTimeout(this.debounceTimer);
39
+ this.debounceTimer = setTimeout(() => {
40
+ this.debounceTimer = null;
41
+ if (this.lastChanged) {
42
+ const f = this.lastChanged;
43
+ this.lastChanged = null;
44
+ this.emit("reload", f);
45
+ this.triggerRestart();
46
+ }
47
+ }, this.debounceMs);
48
+ }
49
+ );
50
+ this.watcher.on("error", (err) => {
51
+ this.emit("error", err);
52
+ });
53
+ }
54
+ /**
55
+ * Stop watching. Safe to call even if not started.
56
+ */
57
+ stop() {
58
+ if (this.debounceTimer) {
59
+ clearTimeout(this.debounceTimer);
60
+ this.debounceTimer = null;
61
+ }
62
+ if (this.watcher) {
63
+ this.watcher.close();
64
+ this.watcher = null;
65
+ }
66
+ }
67
+ // ── Restart helper ─────────────────────────────────────────────────────────
68
+ /**
69
+ * Register a callback that runs after every debounced `reload` event.
70
+ *
71
+ * If the callback is already running when another reload fires it will be
72
+ * queued once and run again after the current run finishes.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * loader.restart(async () => {
77
+ * await client.disconnect()
78
+ * await build()
79
+ * await client.connect()
80
+ * })
81
+ * ```
82
+ */
83
+ restart(fn) {
84
+ this.restartFn = fn;
85
+ }
86
+ triggerRestart() {
87
+ if (!this.restartFn || this.restarting) return;
88
+ const fn = this.restartFn;
89
+ this.restarting = true;
90
+ const result = fn();
91
+ const finish = () => {
92
+ this.restarting = false;
93
+ };
94
+ if (result instanceof Promise) {
95
+ result.then(finish, (err) => {
96
+ finish();
97
+ this.emit("error", err instanceof Error ? err : new Error(String(err)));
98
+ });
99
+ } else {
100
+ finish();
101
+ }
102
+ }
103
+ // ── Typed event overloads ──────────────────────────────────────────────────
104
+ on(event, listener) {
105
+ return super.on(event, listener);
106
+ }
107
+ once(event, listener) {
108
+ return super.once(event, listener);
109
+ }
110
+ off(event, listener) {
111
+ return super.off(event, listener);
112
+ }
113
+ emit(event, ...args) {
114
+ return super.emit(event, ...args);
115
+ }
116
+ /** Whether the loader is currently active. */
117
+ get watching() {
118
+ return this.watcher !== null;
119
+ }
120
+ };
121
+
122
+ export {
123
+ HotLoader
124
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Main CLI dispatcher. Keeps `index.ts` clean and avoids circular imports.
3
+ */
4
+ declare function run(argv: string[]): Promise<void>;
5
+
6
+ export { run };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Main CLI dispatcher. Keeps `index.ts` clean and avoids circular imports.
3
+ */
4
+ declare function run(argv: string[]): Promise<void>;
5
+
6
+ export { run };