-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
84 lines (73 loc) · 2.4 KB
/
build.js
File metadata and controls
84 lines (73 loc) · 2.4 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
// Load environment variables from .env file
require('dotenv').config();
// Get environment variables with defaults
const MONITORING_ACCOUNT = process.env.MONITORING_ACCOUNT || '';
const MONITORING_PROFILE_ID = process.env.MONITORING_PROFILE_ID || 'guesty-onsite-monitoring';
// Parse DEBUG_ACCOUNT_IDS from JSON array string
const DEBUG_ACCOUNT_IDS_RAW = process.env.DEBUG_ACCOUNT_IDS || '[]';
const DEBUG_ACCOUNT_IDS = JSON.parse(DEBUG_ACCOUNT_IDS_RAW);
// Parse command line arguments
const args = process.argv.slice(2);
const integration = args[0]; // 'cloudbeds', 'mews', or 'guesty'
const watch = args.includes('--watch');
// Build configuration
const buildConfigs = {
cloudbeds: {
entryPoint: 'src/cloudbeds/klaviyo_hotel_tracking.js',
outfile: 'public/klaviyo_hotel_tracking_cloudbeds.js'
},
mews: {
entryPoint: 'src/mews/klaviyo_hotel_tracking.js',
outfile: 'public/klaviyo_hotel_tracking_mews.js'
},
guesty: {
entryPoint: 'src/guesty/klaviyo_hotel_tracking.js',
outfile: 'public/klaviyo_hotel_tracking_guesty.js'
}
};
async function build(config) {
const options = {
entryPoints: [config.entryPoint],
bundle: true,
outfile: config.outfile,
format: 'iife',
define: {
'process.env.MONITORING_ACCOUNT': JSON.stringify(MONITORING_ACCOUNT),
'process.env.MONITORING_PROFILE_ID': JSON.stringify(MONITORING_PROFILE_ID),
'process.env.DEBUG_ACCOUNT_IDS': JSON.stringify(DEBUG_ACCOUNT_IDS) // Injected as array
}
};
try {
if (watch) {
const context = await esbuild.context(options);
await context.watch();
console.log(`Watching ${config.entryPoint}...`);
} else {
await esbuild.build(options);
console.log(`Built ${config.outfile}`);
}
} catch (error) {
console.error(`Build failed for ${config.entryPoint}:`, error);
process.exit(1);
}
}
// Main execution
async function main() {
if (!integration) {
console.error('Usage: node build.js <integration> [--watch]');
console.error(' integration: cloudbeds, mews, or guesty');
process.exit(1);
}
const config = buildConfigs[integration];
if (!config) {
console.error(`Unknown integration: ${integration}`);
console.error('Valid options: cloudbeds, mews, guesty');
process.exit(1);
}
await build(config);
}
main();