-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
61 lines (52 loc) · 1.49 KB
/
build.ts
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
import { existsSync, watch } from 'node:fs'
import { copyFile, mkdir } from 'node:fs/promises'
import { resolve } from 'node:path'
const isDev = Bun.env.NODE_ENV === 'development'
const PLUGIN_DIR = Bun.env.OBSIDIAN_PLUGIN_DIR
async function builder() {
if (!PLUGIN_DIR) {
throw new Error('OBSIDIAN_PLUGIN_DIR not defined')
}
const t0 = Bun.nanoseconds()
const res = await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
sourcemap: isDev ? 'external' : 'none',
minify: !isDev,
target: 'node',
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
],
})
if (res.success) {
const id = require('./manifest.json').id
const testPath = resolve(PLUGIN_DIR, id)
if (!existsSync(testPath)) {
await mkdir(testPath)
}
copyFile('./dist/index.js', resolve(testPath, 'main.js'))
copyFile('./manifest.json', resolve(testPath, 'manifest.json'))
copyFile('./styles.css', resolve(testPath, 'styles.css'))
copyFile('./.hotreload', resolve(testPath, '.hotreload'))
const t1 = Bun.nanoseconds()
console.log(`Build success. (${(t1 - t0) / 1000000}ms)`)
} else {
const t1 = Bun.nanoseconds()
console.error(`Build failed. (${t1 - t0}ms)`)
console.error(res.logs)
}
}
builder()
watch('./src', { recursive: true }, builder)