ownerlens 0.1.9 → 0.1.10-preview0

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 CHANGED
@@ -57,10 +57,11 @@ flowchart TD
57
57
  npx ownerlens start
58
58
  ```
59
59
 
60
- `npx ownerlens start` builds the app, starts Vite preview on `127.0.0.1`,
61
- creates `./data` in the directory where you run the command, and reads snapshot
62
- files from that directory. Open the Vite URL printed by the command, usually
63
- `http://127.0.0.1:4173`.
60
+ `npx ownerlens start` starts the packaged app on `127.0.0.1`, creates `./data`
61
+ in the directory where you run the command, and reads snapshot files from that
62
+ directory. Open the local URL printed by the command, usually
63
+ `http://127.0.0.1:4173`. When running from a source checkout, run `npm run build`
64
+ before `npm run start`.
64
65
 
65
66
  ## Create Snapshot Files
66
67
 
package/bin/ownerlens.js CHANGED
@@ -1,17 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn, spawnSync } from "node:child_process";
4
- import { mkdirSync, readdirSync, statSync } from "node:fs";
5
- import { createRequire } from "node:module";
6
- import { dirname, join } from "node:path";
7
- import { fileURLToPath } from "node:url";
4
+ import { existsSync, mkdirSync, readdirSync, statSync } from "node:fs";
5
+ import { dirname, isAbsolute, join, resolve } from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
8
7
 
9
8
  const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
10
9
  const invocationRoot = process.cwd();
11
- const require = createRequire(import.meta.url);
12
10
  const [, , command = "help", ...args] = process.argv;
13
11
 
14
- const dataDir = ensureDataDirectory(invocationRoot);
12
+ const dataDir = resolveDataDirectory(invocationRoot);
15
13
  printDataDirectorySummary(dataDir);
16
14
 
17
15
  const commands = new Map([
@@ -28,8 +26,8 @@ if (command === "help" || command === "--help" || command === "-h") {
28
26
 
29
27
  if (commands.has(command)) {
30
28
  runPowerShellScript(commands.get(command), args);
31
- } else if (command === "start" || command === "preview") {
32
- runViteProductionServer(args);
29
+ } else if (command === "start") {
30
+ runOwnerLensServer(args);
33
31
  } else {
34
32
  console.error(`Unknown command: ${command}`);
35
33
  printHelp();
@@ -65,53 +63,50 @@ function runPowerShellScript(script, args, options = {}) {
65
63
  return child;
66
64
  }
67
65
 
68
- function runViteProductionServer(args) {
69
- const build = runViteSync(["build"]);
70
-
71
- if (build.signal) {
72
- process.kill(process.pid, build.signal);
73
- return build;
74
- }
75
-
76
- if (build.status !== 0) {
77
- process.exit(build.status ?? 1);
78
- }
79
-
80
- return runVite(["preview", "--host", "127.0.0.1", ...args]);
66
+ function runOwnerLensServer(args) {
67
+ assertBuiltApp();
68
+ assertBuiltServer();
69
+ const { host, port } = parseServerArgs(args);
70
+ const serverModulePath = join(packageRoot, "dist-server", "ownerlens-server.js");
71
+
72
+ process.chdir(packageRoot);
73
+ import(pathToFileURL(serverModulePath).href)
74
+ .then(async ({ startOwnerLensServer }) => {
75
+ const started = await startOwnerLensServer({
76
+ appRoot: packageRoot,
77
+ dataDir,
78
+ host,
79
+ port,
80
+ runtimeToken: process.env.OWNERLENS_RUNTIME_TOKEN
81
+ });
82
+ console.log(`OwnerLens running at ${started.url}`);
83
+ })
84
+ .catch((error) => {
85
+ console.error(error instanceof Error ? error.message : String(error));
86
+ process.exit(1);
87
+ });
81
88
  }
82
89
 
83
- function runVite(args) {
84
- return runNodeScript([resolveViteScript(), ...args]);
85
- }
86
-
87
- function runViteSync(args) {
88
- return spawnSync(process.execPath, [resolveViteScript(), ...args], {
89
- cwd: packageRoot,
90
- env: viteEnv(),
91
- stdio: "inherit"
92
- });
93
- }
90
+ function assertBuiltApp() {
91
+ const indexPath = join(packageRoot, "dist", "index.html");
92
+ if (existsSync(indexPath)) {
93
+ return;
94
+ }
94
95
 
95
- function resolveViteScript() {
96
- return join(dirname(require.resolve("vite/package.json")), "bin", "vite.js");
96
+ console.error("OwnerLens build output was not found at ./dist.");
97
+ console.error("Run `npm run build` before `ownerlens start`, or use a packaged OwnerLens release that includes dist.");
98
+ process.exit(1);
97
99
  }
98
100
 
99
- function runNodeScript(args) {
100
- const child = spawn(process.execPath, args, { cwd: packageRoot, env: viteEnv(), stdio: "inherit" });
101
- child.on("exit", (code, signal) => {
102
- if (signal) {
103
- process.kill(process.pid, signal);
104
- return;
105
- }
106
-
107
- process.exit(code ?? 1);
108
- });
109
-
110
- return child;
111
- }
101
+ function assertBuiltServer() {
102
+ const serverPath = join(packageRoot, "dist-server", "ownerlens-server.js");
103
+ if (existsSync(serverPath)) {
104
+ return;
105
+ }
112
106
 
113
- function viteEnv() {
114
- return { ...process.env, OWNERLENS_DATA_DIR: dataDir };
107
+ console.error("OwnerLens runtime server build was not found at ./dist-server.");
108
+ console.error("Use a packaged OwnerLens release that includes dist-server.");
109
+ process.exit(1);
115
110
  }
116
111
 
117
112
  function resolvePowerShell() {
@@ -135,8 +130,11 @@ function commandExists(name) {
135
130
  return result.status === 0;
136
131
  }
137
132
 
138
- function ensureDataDirectory(rootDir) {
139
- const dataDir = join(rootDir, "data");
133
+ function resolveDataDirectory(rootDir) {
134
+ const configuredDataDir = process.env.OWNERLENS_DATA_DIR?.trim();
135
+ const dataDir = configuredDataDir
136
+ ? resolvePath(rootDir, configuredDataDir)
137
+ : join(rootDir, "data");
140
138
 
141
139
  try {
142
140
  if (statSync(dataDir, { throwIfNoEntry: false })?.isDirectory()) {
@@ -152,11 +150,12 @@ function ensureDataDirectory(rootDir) {
152
150
  }
153
151
 
154
152
  function printDataDirectorySummary(dataDir) {
155
- console.log(`Working data directory: ./data`);
153
+ const displayPath = dataDir === join(invocationRoot, "data") ? "./data" : dataDir;
154
+ console.log(`Working data directory: ${displayPath}`);
156
155
  console.log("Depth 1 data files:");
157
156
 
158
157
  const entries = readdirSync(dataDir, { withFileTypes: true })
159
- .map((entry) => `${entry.isDirectory() ? "d" : "f"} ./data/${entry.name}`)
158
+ .map((entry) => `${entry.isDirectory() ? "d" : "f"} ${displayPath}/${entry.name}`)
160
159
  .sort();
161
160
 
162
161
  if (entries.length === 0) {
@@ -167,16 +166,65 @@ function printDataDirectorySummary(dataDir) {
167
166
  }
168
167
  }
169
168
 
170
- console.log("OwnerLens will read local snapshots and runtime state from ./data.");
169
+ console.log(`OwnerLens will read local snapshots and runtime state from ${displayPath}.`);
171
170
  console.log("");
172
171
  }
173
172
 
173
+ function parseServerArgs(args) {
174
+ const parsed = {
175
+ host: "127.0.0.1",
176
+ port: 4173
177
+ };
178
+
179
+ for (let index = 0; index < args.length; index += 1) {
180
+ const arg = args[index];
181
+ if (arg === "--host") {
182
+ parsed.host = readRequiredArg(args, index, "--host");
183
+ index += 1;
184
+ } else if (arg.startsWith("--host=")) {
185
+ parsed.host = arg.slice("--host=".length);
186
+ } else if (arg === "--port") {
187
+ parsed.port = parsePort(readRequiredArg(args, index, "--port"));
188
+ index += 1;
189
+ } else if (arg.startsWith("--port=")) {
190
+ parsed.port = parsePort(arg.slice("--port=".length));
191
+ } else {
192
+ console.error(`Unknown start argument: ${arg}`);
193
+ printHelp();
194
+ process.exit(1);
195
+ }
196
+ }
197
+
198
+ return parsed;
199
+ }
200
+
201
+ function readRequiredArg(args, index, name) {
202
+ const value = args[index + 1];
203
+ if (!value) {
204
+ console.error(`Missing value for ${name}.`);
205
+ process.exit(1);
206
+ }
207
+ return value;
208
+ }
209
+
210
+ function parsePort(value) {
211
+ const port = Number(value);
212
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
213
+ console.error(`Invalid port: ${value}`);
214
+ process.exit(1);
215
+ }
216
+ return port;
217
+ }
218
+
219
+ function resolvePath(rootDir, candidate) {
220
+ return isAbsolute(candidate) ? candidate : resolve(rootDir, candidate);
221
+ }
222
+
174
223
  function printHelp() {
175
224
  console.log(`OwnerLens
176
225
 
177
226
  Usage:
178
- ownerlens start [Vite preview args]
179
- ownerlens preview [Vite preview args]
227
+ ownerlens start [--host 127.0.0.1] [--port 4173]
180
228
  ownerlens collect:entra [PowerShell args]
181
229
  ownerlens collect:azure [PowerShell args]
182
230