-
-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathbundle.js
More file actions
47 lines (41 loc) · 1.63 KB
/
bundle.js
File metadata and controls
47 lines (41 loc) · 1.63 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
const watch = process.argv.includes('--watch');
const minify = process.argv.includes('--minify');
const success = watch ? 'Watch build succeeded' : 'Build succeeded';
const fs = require('fs');
const path = require('path');
// Replace telemetry token before building
function replaceTelemetryToken() {
const telemetryToken = process.env.TELEMETRY_TRACKING_TOKEN;
if (!telemetryToken) {
console.error('Error: TELEMETRY_TRACKING_TOKEN environment variable is not set');
process.exit(1);
}
const constantsPath = path.join(__dirname, '../src/constants.ts');
let constantsContent = fs.readFileSync(constantsPath, 'utf8');
// Replace the placeholder with the actual token
constantsContent = constantsContent.replace('<TELEMETRY_TRACKING_TOKEN>', telemetryToken);
fs.writeFileSync(constantsPath, constantsContent);
console.log('Telemetry token replaced successfully');
}
// Replace the token before building
replaceTelemetryToken();
require('esbuild')
.build({
entryPoints: ['src/extension.ts', 'src/language-server/main.ts'],
outdir: 'bundle',
bundle: true,
external: ['vscode', '@prisma/*'],
platform: 'node',
sourcemap: !minify,
minify,
})
.then(() => {
fs.cpSync('./src/res', 'bundle/res', { force: true, recursive: true });
fs.cpSync('./src/vscode/res', 'bundle/res', { force: true, recursive: true });
fs.cpSync('../language/syntaxes', 'bundle/syntaxes', { force: true, recursive: true });
})
.then(() => console.log(success))
.catch((err) => {
console.error(err);
process.exit(1);
});