-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebuild.js
More file actions
57 lines (52 loc) · 1.83 KB
/
rebuild.js
File metadata and controls
57 lines (52 loc) · 1.83 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
const path = require('node:path')
const child = require('node:child_process')
function execute(cmd, callback, cwd = process.cwd()) {
console.log('Rebuilding better-sqlite3 for Electron...')
const items = cmd
const exe = items.shift()
const processor = child.spawn(exe, items, { cwd })
const collect = () => {
let str = ''
const print = () => {
const lines = str.split(/[\n|\r]/)
str = lines.pop()
let contents = lines.join('\r\n')
if (str === '') {
// 如果本来内容就是完整断句的,这里进行修正,表示结尾是正常断句的
contents += '\r\n'
}
callback(contents)
}
return (data) => {
str += data.toString()
print()
}
}
if (typeof callback === 'function') {
processor.stdout.on('data', collect())
processor.stderr.on('data', collect())
}
processor.on('exit', (code) => {
if (code === 0) {
console.log('Rebuild better-sqlite3 success.')
}
process.exit(code)
})
}
// If you prefer electron-rebuild:
// 👉 https://github.com/WiseLibs/better-sqlite3/blob/v8.5.2/docs/troubleshooting.md#electron
// 👉 https://stackoverflow.com/questions/46384591/node-was-compiled-against-a-different-node-js-version-using-node-module-versio/52796884#52796884
const better_sqlite3 = require.resolve('better-sqlite3')
const better_sqlite3_root = path.posix.join(
better_sqlite3.slice(0, better_sqlite3.lastIndexOf('node_modules')),
'node_modules/better-sqlite3',
)
const cmd = [
'win32' ? 'npm.cmd' : 'npm',
'run',
'build-release',
`--target=${process.versions.electron}`,
// https://github.com/electron/electron/blob/v26.1.0/docs/tutorial/using-native-node-modules.md#manually-building-for-electron
'--dist-url=https://electronjs.org/headers',
]
execute(cmd, contents => console.log(contents), better_sqlite3_root)