-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsetup.ts
More file actions
59 lines (48 loc) · 1.7 KB
/
setup.ts
File metadata and controls
59 lines (48 loc) · 1.7 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
51
52
53
54
55
56
57
58
59
import 'dotenv/config';
import { execSync } from 'child_process';
import { config } from 'dotenv';
import path from 'path';
/**
* Setup for the liblab.ai builder
*/
const runSetup = async (): Promise<void> => {
try {
execSync('tsx ./scripts/setup.ts', { stdio: 'inherit' });
reloadEnvFile();
try {
const telemetryModule = await import('~/lib/telemetry/telemetry-manager');
const telemetry = await telemetryModule.getTelemetry();
await telemetry.trackTelemetryEvent({ eventType: telemetryModule.TelemetryEventType.SETUP_SUCCESS });
} catch (telemetryError) {
console.warn('Failed to track setup success:', (telemetryError as Error).message);
}
} catch (error) {
await trackSetupError(error);
process.exit(1);
}
};
runSetup();
function reloadEnvFile() {
const envPath = path.resolve(process.cwd(), '.env');
config({ path: envPath });
}
async function trackSetupError(error: any) {
try {
const telemetryModule = await import('~/lib/telemetry/telemetry-manager');
const errorUtilsModule = await import('~/lib/telemetry/error-utils');
const telemetry = await telemetryModule.getTelemetry();
const errorInfo = errorUtilsModule.normalizeError(error);
await telemetry.trackTelemetryEvent({
eventType: telemetryModule.TelemetryEventType.SETUP_ERROR,
properties: {
errorMessage: errorInfo.message,
error: errorInfo,
},
});
telemetry.shutdown();
// Leave some time for telemetry to flush the event before the process exits
await new Promise((resolve) => setTimeout(resolve, 2000));
} catch (telemetryError) {
console.warn('Failed to track setup error:', (telemetryError as Error).message);
}
}