@realtimex/email-automator 2.3.5 → 2.3.6

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/api/server.ts CHANGED
@@ -74,18 +74,23 @@ function getDistPath() {
74
74
  return process.env.ELECTRON_STATIC_PATH;
75
75
  }
76
76
 
77
- // 2. Try to find dist relative to this file
78
- // In dev: dist is at ../dist
79
- // In npx/dist: dist is at ../../dist
77
+ // 2. Try to find dist relative to packageRoot (from config)
78
+ // This is the most reliable way in compiled app
79
+ const fromRoot = join(config.rootDir || process.cwd(), 'dist');
80
+ if (existsSync(join(fromRoot, 'index.html'))) {
81
+ return fromRoot;
82
+ }
83
+
84
+ // 3. Try to find dist relative to this file
80
85
  let current = __dirname;
81
86
  for (let i = 0; i < 4; i++) {
82
87
  const potential = join(current, 'dist');
83
- if (existsSync(potential)) return potential;
88
+ if (existsSync(join(potential, 'index.html'))) return potential;
84
89
  current = path.dirname(current);
85
90
  }
86
91
 
87
- // 3. Fallback to current working directory
88
- return join(process.cwd(), 'dist');
92
+ // 4. Fallback to current working directory
93
+ return join(config.packageRoot || process.cwd(), 'dist');
89
94
  }
90
95
 
91
96
  const distPath = getDistPath();
@@ -6,11 +6,11 @@ import { existsSync } from 'fs';
6
6
  const __filename = fileURLToPath(import.meta.url);
7
7
  const __dirname = dirname(__filename);
8
8
 
9
- // Robustly find package root (directory containing package.json)
9
+ // Robustly find package root (directory containing package.json and bin folder)
10
10
  function findPackageRoot(startDir: string): string {
11
11
  let current = startDir;
12
12
  while (current !== path.parse(current).root) {
13
- if (existsSync(join(current, 'package.json'))) {
13
+ if (existsSync(join(current, 'package.json')) && existsSync(join(current, 'bin'))) {
14
14
  return current;
15
15
  }
16
16
  current = dirname(current);
@@ -18,9 +18,12 @@ function findPackageRoot(startDir: string): string {
18
18
  return process.cwd();
19
19
  }
20
20
 
21
+ const packageRoot = findPackageRoot(__dirname);
22
+ console.log(`🏠 Package Root: ${packageRoot}`);
23
+
21
24
  function loadEnvironment() {
22
25
  const cwdEnv = join(process.cwd(), '.env');
23
- const rootEnv = join(findPackageRoot(__dirname), '.env');
26
+ const rootEnv = join(packageRoot, '.env');
24
27
 
25
28
  if (existsSync(cwdEnv)) {
26
29
  console.log(`📝 Loading environment from CWD: ${cwdEnv}`);
@@ -55,6 +58,7 @@ const cliArgs = parseArgs(process.argv.slice(2));
55
58
 
56
59
  export const config = {
57
60
  // Server
61
+ packageRoot,
58
62
  // Default port 3004 (RealTimeX Desktop uses 3001/3002)
59
63
  port: cliArgs.port || (process.env.PORT ? parseInt(process.env.PORT, 10) : 3004),
60
64
  noUi: cliArgs.noUi,
@@ -62,8 +66,8 @@ export const config = {
62
66
  isProduction: process.env.NODE_ENV === 'production',
63
67
 
64
68
  // Paths - Robust resolution for both TS source and compiled JS in dist/
65
- rootDir: process.cwd(),
66
- scriptsDir: join(process.cwd(), 'scripts'),
69
+ rootDir: packageRoot,
70
+ scriptsDir: join(packageRoot, 'scripts'),
67
71
 
68
72
  // Supabase
69
73
  supabase: {
@@ -62,18 +62,22 @@ function getDistPath() {
62
62
  if (process.env.ELECTRON_STATIC_PATH && existsSync(process.env.ELECTRON_STATIC_PATH)) {
63
63
  return process.env.ELECTRON_STATIC_PATH;
64
64
  }
65
- // 2. Try to find dist relative to this file
66
- // In dev: dist is at ../dist
67
- // In npx/dist: dist is at ../../dist
65
+ // 2. Try to find dist relative to packageRoot (from config)
66
+ // This is the most reliable way in compiled app
67
+ const fromRoot = join(config.rootDir || process.cwd(), 'dist');
68
+ if (existsSync(join(fromRoot, 'index.html'))) {
69
+ return fromRoot;
70
+ }
71
+ // 3. Try to find dist relative to this file
68
72
  let current = __dirname;
69
73
  for (let i = 0; i < 4; i++) {
70
74
  const potential = join(current, 'dist');
71
- if (existsSync(potential))
75
+ if (existsSync(join(potential, 'index.html')))
72
76
  return potential;
73
77
  current = path.dirname(current);
74
78
  }
75
- // 3. Fallback to current working directory
76
- return join(process.cwd(), 'dist');
79
+ // 4. Fallback to current working directory
80
+ return join(config.packageRoot || process.cwd(), 'dist');
77
81
  }
78
82
  const distPath = getDistPath();
79
83
  logger.info('Serving static assets', { path: distPath });
@@ -4,20 +4,22 @@ import path, { dirname, join } from 'path';
4
4
  import { existsSync } from 'fs';
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = dirname(__filename);
7
- // Robustly find package root (directory containing package.json)
7
+ // Robustly find package root (directory containing package.json and bin folder)
8
8
  function findPackageRoot(startDir) {
9
9
  let current = startDir;
10
10
  while (current !== path.parse(current).root) {
11
- if (existsSync(join(current, 'package.json'))) {
11
+ if (existsSync(join(current, 'package.json')) && existsSync(join(current, 'bin'))) {
12
12
  return current;
13
13
  }
14
14
  current = dirname(current);
15
15
  }
16
16
  return process.cwd();
17
17
  }
18
+ const packageRoot = findPackageRoot(__dirname);
19
+ console.log(`🏠 Package Root: ${packageRoot}`);
18
20
  function loadEnvironment() {
19
21
  const cwdEnv = join(process.cwd(), '.env');
20
- const rootEnv = join(findPackageRoot(__dirname), '.env');
22
+ const rootEnv = join(packageRoot, '.env');
21
23
  if (existsSync(cwdEnv)) {
22
24
  console.log(`📝 Loading environment from CWD: ${cwdEnv}`);
23
25
  dotenv.config({ path: cwdEnv, override: true });
@@ -47,14 +49,15 @@ function parseArgs(args) {
47
49
  const cliArgs = parseArgs(process.argv.slice(2));
48
50
  export const config = {
49
51
  // Server
52
+ packageRoot,
50
53
  // Default port 3004 (RealTimeX Desktop uses 3001/3002)
51
54
  port: cliArgs.port || (process.env.PORT ? parseInt(process.env.PORT, 10) : 3004),
52
55
  noUi: cliArgs.noUi,
53
56
  nodeEnv: process.env.NODE_ENV || 'development',
54
57
  isProduction: process.env.NODE_ENV === 'production',
55
58
  // Paths - Robust resolution for both TS source and compiled JS in dist/
56
- rootDir: process.cwd(),
57
- scriptsDir: join(process.cwd(), 'scripts'),
59
+ rootDir: packageRoot,
60
+ scriptsDir: join(packageRoot, 'scripts'),
58
61
  // Supabase
59
62
  supabase: {
60
63
  url: process.env.SUPABASE_URL || process.env.VITE_SUPABASE_URL || '',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realtimex/email-automator",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "type": "module",
5
5
  "main": "dist/api/server.js",
6
6
  "bin": {