@realtimex/email-automator 2.3.3 → 2.3.4

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
@@ -1,8 +1,9 @@
1
1
  import express from 'express';
2
2
  import cors from 'cors';
3
- import path from 'path';
3
+ import path, { join } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
  import { spawn } from 'child_process';
6
+ import { existsSync } from 'fs';
6
7
  import { config, validateConfig } from './src/config/index.js';
7
8
  import { errorHandler } from './src/middleware/errorHandler.js';
8
9
  import { apiRateLimit } from './src/middleware/rateLimit.js';
@@ -66,8 +67,28 @@ app.use('/api', apiRateLimit);
66
67
  // API routes
67
68
  app.use('/api', routes);
68
69
 
69
- // Serve static files - robust resolution for compiled app and NPX
70
- const distPath = process.env.ELECTRON_STATIC_PATH || path.join(process.cwd(), 'dist');
70
+ // Robust resolution for static assets (dist folder)
71
+ function getDistPath() {
72
+ // 1. Check environment variable override
73
+ if (process.env.ELECTRON_STATIC_PATH && existsSync(process.env.ELECTRON_STATIC_PATH)) {
74
+ return process.env.ELECTRON_STATIC_PATH;
75
+ }
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
80
+ let current = __dirname;
81
+ for (let i = 0; i < 4; i++) {
82
+ const potential = join(current, 'dist');
83
+ if (existsSync(potential)) return potential;
84
+ current = path.dirname(current);
85
+ }
86
+
87
+ // 3. Fallback to current working directory
88
+ return join(process.cwd(), 'dist');
89
+ }
90
+
91
+ const distPath = getDistPath();
71
92
  logger.info('Serving static assets', { path: distPath });
72
93
  app.use(express.static(distPath));
73
94
 
@@ -1,16 +1,30 @@
1
1
  import dotenv from 'dotenv';
2
2
  import { fileURLToPath } from 'url';
3
3
  import path, { dirname, join } from 'path';
4
+ import { existsSync } from 'fs';
4
5
 
5
6
  const __filename = fileURLToPath(import.meta.url);
6
7
  const __dirname = dirname(__filename);
7
8
 
9
+ // Robustly find package root (directory containing package.json)
10
+ function findPackageRoot(startDir: string): string {
11
+ let current = startDir;
12
+ while (current !== path.parse(current).root) {
13
+ if (existsSync(join(current, 'package.json'))) {
14
+ return current;
15
+ }
16
+ current = dirname(current);
17
+ }
18
+ return process.cwd(); // Fallback
19
+ }
20
+
21
+ const packageRoot = findPackageRoot(__dirname);
22
+
8
23
  // 1. Try to load from current working directory (where npx is run)
9
24
  dotenv.config({ path: join(process.cwd(), '.env') });
10
25
 
11
- // 2. Fallback to package root (where the binary lives)
12
- // In dist/api/src/config/index.js, the root is 4 levels up
13
- dotenv.config({ path: join(__dirname, '..', '..', '..', '..', '.env') });
26
+ // 2. Fallback to package root
27
+ dotenv.config({ path: join(packageRoot, '.env') });
14
28
 
15
29
  function parseArgs(args: string[]): { port: number | null, noUi: boolean } {
16
30
  const portIndex = args.indexOf('--port');
@@ -1,7 +1,8 @@
1
1
  import express from 'express';
2
2
  import cors from 'cors';
3
- import path from 'path';
3
+ import path, { join } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
+ import { existsSync } from 'fs';
5
6
  import { config, validateConfig } from './src/config/index.js';
6
7
  import { errorHandler } from './src/middleware/errorHandler.js';
7
8
  import { apiRateLimit } from './src/middleware/rateLimit.js';
@@ -55,8 +56,26 @@ app.use((req, res, next) => {
55
56
  app.use('/api', apiRateLimit);
56
57
  // API routes
57
58
  app.use('/api', routes);
58
- // Serve static files - robust resolution for compiled app and NPX
59
- const distPath = process.env.ELECTRON_STATIC_PATH || path.join(process.cwd(), 'dist');
59
+ // Robust resolution for static assets (dist folder)
60
+ function getDistPath() {
61
+ // 1. Check environment variable override
62
+ if (process.env.ELECTRON_STATIC_PATH && existsSync(process.env.ELECTRON_STATIC_PATH)) {
63
+ return process.env.ELECTRON_STATIC_PATH;
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
68
+ let current = __dirname;
69
+ for (let i = 0; i < 4; i++) {
70
+ const potential = join(current, 'dist');
71
+ if (existsSync(potential))
72
+ return potential;
73
+ current = path.dirname(current);
74
+ }
75
+ // 3. Fallback to current working directory
76
+ return join(process.cwd(), 'dist');
77
+ }
78
+ const distPath = getDistPath();
60
79
  logger.info('Serving static assets', { path: distPath });
61
80
  app.use(express.static(distPath));
62
81
  // Handle client-side routing
@@ -1,13 +1,25 @@
1
1
  import dotenv from 'dotenv';
2
2
  import { fileURLToPath } from 'url';
3
- import { dirname, join } from 'path';
3
+ import path, { dirname, join } from 'path';
4
+ import { existsSync } from 'fs';
4
5
  const __filename = fileURLToPath(import.meta.url);
5
6
  const __dirname = dirname(__filename);
7
+ // Robustly find package root (directory containing package.json)
8
+ function findPackageRoot(startDir) {
9
+ let current = startDir;
10
+ while (current !== path.parse(current).root) {
11
+ if (existsSync(join(current, 'package.json'))) {
12
+ return current;
13
+ }
14
+ current = dirname(current);
15
+ }
16
+ return process.cwd(); // Fallback
17
+ }
18
+ const packageRoot = findPackageRoot(__dirname);
6
19
  // 1. Try to load from current working directory (where npx is run)
7
20
  dotenv.config({ path: join(process.cwd(), '.env') });
8
- // 2. Fallback to package root (where the binary lives)
9
- // In dist/api/src/config/index.js, the root is 4 levels up
10
- dotenv.config({ path: join(__dirname, '..', '..', '..', '..', '.env') });
21
+ // 2. Fallback to package root
22
+ dotenv.config({ path: join(packageRoot, '.env') });
11
23
  function parseArgs(args) {
12
24
  const portIndex = args.indexOf('--port');
13
25
  let port = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realtimex/email-automator",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "type": "module",
5
5
  "main": "dist/api/server.js",
6
6
  "bin": {