-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdev.ts
139 lines (105 loc) · 3.14 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os from 'os'
import { call, fexists, get_command, noprint, ramdisk, Remote } from 'xshell'
import { setup_vscode_settings, process_stdin } from 'xshell/development.js'
import { builder, fpd_out, fpd_root } from './builder.ts'
await setup_vscode_settings(fpd_root)
await builder.build(false)
async function stop () {
await builder.close()
remote?.disconnect()
}
async function recompile () {
await builder.run()
// 自动重新加载 vscode
if (fp_vscode)
await reload_vscode(fp_vscode)
}
process_stdin(
async key => {
switch (key) {
case 'r':
try {
await recompile()
} catch (error) {
console.log(error)
console.log('重新编译失败,请尝试按 x 退出后再启动')
}
break
case 'x':
await stop()
process.exit()
case 'i':
console.log(info)
break
}
},
stop
)
let remote: Remote
if (ramdisk) {
remote = new Remote({
url: 'ws://localhost',
keeper: {
func: 'register',
args: ['ddb.ext'],
},
funcs: {
async recompile () {
await recompile()
return [ ]
},
async exit () {
await stop()
process.exit()
}
}
})
await remote.connect()
}
const args = [
'--extensionDevelopmentPath', fpd_out,
`${fpd_root}${ramdisk ? 'test' : 'workspace'}/`
]
const info =
'可以使用下面的命令手动启动调试\n' +
get_command('code.exe', args).blue + '\n'
console.log(
'\n' +
'extension 开发服务器启动成功\n'.green +
'尝试自动启动 vscode 调试插件,也' + info +
'终端快捷键:\n' +
'r: 重新编译,编译后会自动重新加载窗口,手动重新加载可用 ctrl + shift + p 选 reload window\n' +
'i: 打印调试命令\n' +
'x: 退出开发服务器\n'
)
/** 启动成功的 vscode 路径 */
let fp_vscode: string
// --- 尝试启动 vscode / cursor
for (const fp of [
// `C:/Users/${os.userInfo().username}/AppData/Local/Programs/cursor/Cursor.exe`,
'C:/Program Files/Microsoft VS Code/Code.exe' as const,
`C:/Users/${os.userInfo().username}/AppData/Local/Programs/Microsoft VS Code/Code.exe`,
])
if (fexists(fp, noprint)) {
try {
console.log('启动 vscode 成功'.green)
await reload_vscode(fp)
fp_vscode = fp
} catch (error) {
console.log('启动 vscode 失败,请手动启动:', error)
}
break
}
async function reload_vscode (fp: string) {
// 使用 launch 也无法控制 vscode 的子进程,算了
// 如果已有启动的进程,会自动 reload
await call(fp, args, {
cwd: fpd_root,
stdout: false,
window: true,
print: {
command: true,
code: false
}
})
}