-
Notifications
You must be signed in to change notification settings - Fork 2
/
dev.ts
91 lines (66 loc) · 1.81 KB
/
dev.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
import { fmkdir, Remote, type RemoteReconnectingOptions } from 'xshell'
import { fpd_out, copy_files, webpack, ramdisk } from './webpack.js'
await fmkdir(fpd_out)
await Promise.all([
copy_files(),
webpack.run(false)
])
let remote: Remote
// 监听终端快捷键
// https://stackoverflow.com/a/12506613/7609214
let { stdin } = process
stdin.setRawMode(true)
stdin.resume()
stdin.setEncoding('utf-8')
// on any data into stdin
stdin.on('data', async function (key: any) {
// ctrl-c ( end of text )
if (key === '\u0003')
process.exit()
// write the key to stdout all normal like
console.log(key)
switch (key) {
case 'r':
await webpack.run(false)
break
case 'x':
remote?.disconnect()
await webpack.close()
process.exit()
break
}
})
if (ramdisk) {
const reconnecting_options: RemoteReconnectingOptions = {
func: 'register',
args: ['ddb.gfn'],
on_error (error: Error) {
console.log(error.message)
}
}
remote = new Remote({
url: 'ws://localhost',
funcs: {
async recompile () {
await webpack.run(false)
return [ ]
},
async exit () {
remote.disconnect()
await webpack.close()
process.exit()
}
},
on_error (error) {
console.log(error.message)
remote.start_reconnecting({ ...reconnecting_options, first_delay: 1000 })
}
})
remote.start_reconnecting(reconnecting_options)
}
console.log(
'编译器已启动,快捷键:\n' +
'r: 重新编译\n' +
'x: 退出编译器'
)