@realtimex/email-automator 2.3.4 → 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 +11 -6
- package/api/src/config/index.ts +24 -10
- package/dist/api/server.js +10 -6
- package/dist/api/src/config/index.js +24 -9
- package/package.json +1 -1
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
|
|
78
|
-
//
|
|
79
|
-
|
|
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
|
-
//
|
|
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();
|
package/api/src/config/index.ts
CHANGED
|
@@ -6,25 +6,38 @@ 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);
|
|
17
17
|
}
|
|
18
|
-
return process.cwd();
|
|
18
|
+
return process.cwd();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const packageRoot = findPackageRoot(__dirname);
|
|
22
|
+
console.log(`🏠 Package Root: ${packageRoot}`);
|
|
23
|
+
|
|
24
|
+
function loadEnvironment() {
|
|
25
|
+
const cwdEnv = join(process.cwd(), '.env');
|
|
26
|
+
const rootEnv = join(packageRoot, '.env');
|
|
27
|
+
|
|
28
|
+
if (existsSync(cwdEnv)) {
|
|
29
|
+
console.log(`📝 Loading environment from CWD: ${cwdEnv}`);
|
|
30
|
+
dotenv.config({ path: cwdEnv, override: true });
|
|
31
|
+
} else if (existsSync(rootEnv)) {
|
|
32
|
+
console.log(`📝 Loading environment from Root: ${rootEnv}`);
|
|
33
|
+
dotenv.config({ path: rootEnv, override: true });
|
|
34
|
+
} else {
|
|
35
|
+
// Just run default dotenv config in case it's in a standard location
|
|
36
|
+
dotenv.config();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
22
39
|
|
|
23
|
-
|
|
24
|
-
dotenv.config({ path: join(process.cwd(), '.env') });
|
|
25
|
-
|
|
26
|
-
// 2. Fallback to package root
|
|
27
|
-
dotenv.config({ path: join(packageRoot, '.env') });
|
|
40
|
+
loadEnvironment();
|
|
28
41
|
|
|
29
42
|
function parseArgs(args: string[]): { port: number | null, noUi: boolean } {
|
|
30
43
|
const portIndex = args.indexOf('--port');
|
|
@@ -45,6 +58,7 @@ const cliArgs = parseArgs(process.argv.slice(2));
|
|
|
45
58
|
|
|
46
59
|
export const config = {
|
|
47
60
|
// Server
|
|
61
|
+
packageRoot,
|
|
48
62
|
// Default port 3004 (RealTimeX Desktop uses 3001/3002)
|
|
49
63
|
port: cliArgs.port || (process.env.PORT ? parseInt(process.env.PORT, 10) : 3004),
|
|
50
64
|
noUi: cliArgs.noUi,
|
|
@@ -52,8 +66,8 @@ export const config = {
|
|
|
52
66
|
isProduction: process.env.NODE_ENV === 'production',
|
|
53
67
|
|
|
54
68
|
// Paths - Robust resolution for both TS source and compiled JS in dist/
|
|
55
|
-
rootDir:
|
|
56
|
-
scriptsDir: join(
|
|
69
|
+
rootDir: packageRoot,
|
|
70
|
+
scriptsDir: join(packageRoot, 'scripts'),
|
|
57
71
|
|
|
58
72
|
// Supabase
|
|
59
73
|
supabase: {
|
package/dist/api/server.js
CHANGED
|
@@ -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
|
|
66
|
-
//
|
|
67
|
-
|
|
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
|
-
//
|
|
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,22 +4,36 @@ 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
|
-
return process.cwd();
|
|
16
|
+
return process.cwd();
|
|
17
17
|
}
|
|
18
18
|
const packageRoot = findPackageRoot(__dirname);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
console.log(`🏠 Package Root: ${packageRoot}`);
|
|
20
|
+
function loadEnvironment() {
|
|
21
|
+
const cwdEnv = join(process.cwd(), '.env');
|
|
22
|
+
const rootEnv = join(packageRoot, '.env');
|
|
23
|
+
if (existsSync(cwdEnv)) {
|
|
24
|
+
console.log(`📝 Loading environment from CWD: ${cwdEnv}`);
|
|
25
|
+
dotenv.config({ path: cwdEnv, override: true });
|
|
26
|
+
}
|
|
27
|
+
else if (existsSync(rootEnv)) {
|
|
28
|
+
console.log(`📝 Loading environment from Root: ${rootEnv}`);
|
|
29
|
+
dotenv.config({ path: rootEnv, override: true });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Just run default dotenv config in case it's in a standard location
|
|
33
|
+
dotenv.config();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
loadEnvironment();
|
|
23
37
|
function parseArgs(args) {
|
|
24
38
|
const portIndex = args.indexOf('--port');
|
|
25
39
|
let port = null;
|
|
@@ -35,14 +49,15 @@ function parseArgs(args) {
|
|
|
35
49
|
const cliArgs = parseArgs(process.argv.slice(2));
|
|
36
50
|
export const config = {
|
|
37
51
|
// Server
|
|
52
|
+
packageRoot,
|
|
38
53
|
// Default port 3004 (RealTimeX Desktop uses 3001/3002)
|
|
39
54
|
port: cliArgs.port || (process.env.PORT ? parseInt(process.env.PORT, 10) : 3004),
|
|
40
55
|
noUi: cliArgs.noUi,
|
|
41
56
|
nodeEnv: process.env.NODE_ENV || 'development',
|
|
42
57
|
isProduction: process.env.NODE_ENV === 'production',
|
|
43
58
|
// Paths - Robust resolution for both TS source and compiled JS in dist/
|
|
44
|
-
rootDir:
|
|
45
|
-
scriptsDir: join(
|
|
59
|
+
rootDir: packageRoot,
|
|
60
|
+
scriptsDir: join(packageRoot, 'scripts'),
|
|
46
61
|
// Supabase
|
|
47
62
|
supabase: {
|
|
48
63
|
url: process.env.SUPABASE_URL || process.env.VITE_SUPABASE_URL || '',
|