Spaces:
Running

File size: 1,404 Bytes
6f5f15e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { existsSync, readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

const THIS_DIR = dirname(fileURLToPath(import.meta.url));

function resolveUiDir(): string {
  if (process.env.MCP_WEBCAM_UI_DIR) {
    return resolve(process.env.MCP_WEBCAM_UI_DIR);
  }
  // Built layout: dist/node/server/paths.js -> dist/ui
  const builtUiDir = resolve(THIS_DIR, '../../ui');
  if (existsSync(builtUiDir)) {
    return builtUiDir;
  }
  // Source/dev layout: server/paths.ts -> dist/ui
  const devUiDir = resolve(THIS_DIR, '../dist/ui');
  if (existsSync(devUiDir)) {
    return devUiDir;
  }
  return builtUiDir;
}

function resolvePackageVersion(): string {
  const candidates = [
    resolve(THIS_DIR, '../../../package.json'), // dist/node/server/paths.js -> package.json
    resolve(THIS_DIR, '../package.json'), // server/paths.ts -> package.json
  ];
  for (const candidate of candidates) {
    if (existsSync(candidate)) {
      try {
        const parsed = JSON.parse(readFileSync(candidate, 'utf8')) as { version?: unknown };
        if (typeof parsed.version === 'string' && parsed.version.length > 0) {
          return parsed.version;
        }
      } catch {
        // ignore and try next candidate
      }
    }
  }
  return '0.3.0';
}

export const UI_DIR = resolveUiDir();
export const PKG_VERSION = resolvePackageVersion();