-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (41 loc) · 1.31 KB
/
index.js
File metadata and controls
50 lines (41 loc) · 1.31 KB
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
47
48
49
50
import { exec } from 'child_process';
import { promisify } from 'util';
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
import {spawn} from "node:child_process";
const execAsync = promisify(exec);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
function loadEnvFile(filePath) {
try {
const envConfig = fs.readFileSync(filePath, 'utf8').split('\n');
for (const line of envConfig) {
const [key, value] = line.split('=');
if (key && value) {
process.env[key.trim()] = value.trim();
}
}
console.log('Environment variables loaded successfully.');
} catch (error) {
console.error('Error loading .env file:', error);
}
}
async function run() {
try {
// Load environment variables
const envPath = path.join(__dirname, '.env');
loadEnvFile(envPath);
// Run compiled TypeScript
const child = spawn('node', ['build/main.js'], {
stdio: 'inherit',
env: process.env
});
child.on('close', (code) => {
console.log(`Child process exited with code ${code}`);
});
} catch (error) {
console.error('An error occurred:', error);
}
}
run();