dsh-activity-pane 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ // dsh-activity-pane 源码 watch:src/*.mjs 或 build 脚本变化时自动重建
2
+ // .dsh-plugin/client.js(原地写入,保留 profile 硬链接)。配合 DSH 的
3
+ // dsh-client-hmr:文件一变,浏览器即热装该插件,无需整页刷新或重启。
4
+ //
5
+ // 用法:node scripts/watch.mjs (或 pnpm dev:watch)
6
+ import { watch } from 'node:fs'
7
+ import { dirname, join } from 'node:path'
8
+ import { fileURLToPath } from 'node:url'
9
+ import { build } from './build-client.mjs'
10
+
11
+ const root = dirname(dirname(fileURLToPath(import.meta.url)))
12
+ const watched = [
13
+ join(root, 'src'),
14
+ join(root, 'scripts/build-client.mjs'),
15
+ ]
16
+ const DEBOUNCE_MS = 80
17
+ let timer = null
18
+
19
+ async function rebuild(reason) {
20
+ try {
21
+ await build()
22
+ console.log(
23
+ `[watch] ${new Date().toLocaleTimeString()} 重建 .dsh-plugin/client.js(${reason})`,
24
+ )
25
+ } catch (error) {
26
+ console.error(`[watch] 构建失败:${error?.message ?? error}`)
27
+ }
28
+ }
29
+
30
+ function schedule(reason) {
31
+ if (timer !== null) clearTimeout(timer)
32
+ timer = setTimeout(() => {
33
+ timer = null
34
+ rebuild(reason)
35
+ }, DEBOUNCE_MS)
36
+ }
37
+
38
+ for (const target of watched) {
39
+ watch(target, () => schedule('src 变化'))
40
+ }
41
+
42
+ console.log('[watch] 监视 src/ 与 scripts/build-client.mjs;Ctrl+C 退出')
43
+ await rebuild('启动')