-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.js
More file actions
67 lines (61 loc) · 1.74 KB
/
Copy pathesbuild.js
File metadata and controls
67 lines (61 loc) · 1.74 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
const esbuild = require('esbuild')
const fs = require('fs')
const path = require('path')
function loadEnvFile() {
const env = {}
const envPath = path.resolve(__dirname, '.env')
if (fs.existsSync(envPath)) {
const lines = fs.readFileSync(envPath, 'utf-8').split(/\r?\n/)
for (const line of lines) {
const trimmed = line.trim()
if (!trimmed || trimmed.startsWith('#')) {
continue
}
const match = trimmed.match(/^([\w.-]+)\s*=\s*(.*)$/)
if (match) {
let value = match[2].trim()
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
) {
value = value.slice(1, -1)
}
env[match[1]] = value
}
}
}
return env
}
const fileEnv = loadEnvFile()
const umamiUrl = process.env.UMAMI_URL || fileEnv.UMAMI_URL || ''
const umamiWebsiteId = process.env.UMAMI_WEBSITE_ID || fileEnv.UMAMI_WEBSITE_ID || ''
const isWatch = process.argv.includes('--watch')
const isProduction = process.argv.includes('--production')
async function main() {
const ctx = await esbuild.context({
entryPoints: ['./src/extension.ts'],
bundle: true,
outfile: 'dist/extension.js',
external: ['vscode'],
format: 'cjs',
platform: 'node',
sourcemap: !isProduction,
minify: isProduction,
define: {
'process.env.UMAMI_URL': JSON.stringify(umamiUrl),
'process.env.UMAMI_WEBSITE_ID': JSON.stringify(umamiWebsiteId),
},
})
if (isWatch) {
await ctx.watch()
console.log('[esbuild] Watching for changes...')
} else {
await ctx.rebuild()
await ctx.dispose()
console.log('[esbuild] Build complete.')
}
}
main().catch((err) => {
console.error(err)
process.exit(1)
})