rvlib-shipkit 2.19.0 → 2.21.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.
- package/CHANGELOG.md +32 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/checks/SK040-release-words.check.ts +43 -0
- package/src/checks/SK041-annex-links.check.ts +28 -0
- package/src/checks/SK042-post-kinds.check.ts +73 -0
- package/src/cli/cmd_Annex.ts +179 -0
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +4 -3
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +84 -0
- package/src/cli/cmd_Review.ts +176 -12
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +151 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/family-pages.ts +2 -0
- package/src/cli/kit/index.ts +1 -1
- package/src/cli/kit/verb.ts +11 -3
- package/src/cli/registry.ts +7 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/collections/review.ts +23 -4
- package/src/commands/model.ts +36 -0
- package/src/commands/registry.ts +49 -0
- package/src/commands/routes.ts +59 -0
- package/src/commands/runner.ts +35 -0
- package/src/commands/runs.ts +112 -0
- package/src/core/app-icon.ts +4 -3
- package/src/core/icon-type.ts +8 -0
- package/src/core/jobs.ts +4 -3
- package/src/core/layout.ts +11 -2
- package/src/core/squircle.ts +95 -0
- package/src/home/daemon-jobs.ts +26 -2
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +337 -5
- package/src/home/gui-app.ts +64 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-start.ts +2 -2
- package/src/home/lib-watch.ts +21 -11
- package/src/home/pm-switch.ts +112 -0
- package/src/home/pm.ts +1 -1
- package/src/home/process-apps.ts +181 -0
- package/src/home/resources.ts +3 -3
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +121 -14
- package/src/identities/machine.ts +4 -3
- package/src/identities/rating.ts +33 -0
- package/src/identities/shown.ts +170 -0
- package/src/identities/steps.ts +5 -0
- package/src/media-store/purge.ts +15 -1
- package/src/media-store/remote.ts +22 -6
- package/src/messages/brief.ts +117 -0
- package/src/messages/collection.ts +40 -0
- package/src/messages/model.ts +171 -0
- package/src/messages/routes.ts +15 -0
- package/src/messages/score.ts +182 -0
- package/src/messages/tabs.ts +13 -0
- package/src/release/notes.ts +130 -0
- package/src/release/run-bump.ts +41 -18
- package/src/release/run-release.ts +22 -4
- package/src/release/run-releases.ts +17 -15
- package/src/release/unit-resolve.ts +9 -0
- package/src/releases/add.ts +94 -0
- package/src/releases/before.ts +31 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +151 -0
- package/src/releases/model.ts +327 -0
- package/src/releases/pictures.ts +110 -0
- package/src/releases/routes.ts +36 -0
- package/src/releases/store.ts +71 -0
- package/src/repo-config.ts +5 -0
- package/src/review/cells.ts +0 -11
- package/src/review/format.ts +10 -6
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +102 -3
- package/src/review/notes.ts +2 -48
- package/src/review/routes.ts +28 -10
- package/src/review/stage-card.ts +197 -0
- package/src/review/stage-routes.ts +123 -0
- package/src/review/store.ts +47 -1
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +76 -4
- package/src/review/trailer-model.ts +106 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +119 -13
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/commands/commands-page.tsx +122 -0
- package/src/serve/hub-app/commands/commands-st.ts +177 -0
- package/src/serve/hub-app/commands.css +24 -0
- package/src/serve/hub-app/hash-route.ts +59 -8
- package/src/serve/hub-app/home-st.ts +19 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +8 -0
- package/src/serve/hub-app/icons.tsx +5 -0
- package/src/serve/hub-app/identities-view.tsx +4 -1
- package/src/serve/hub-app/identities.css +1 -0
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +41 -10
- package/src/serve/hub-app/messages/messages-page.tsx +354 -0
- package/src/serve/hub-app/messages/messages-st.ts +74 -0
- package/src/serve/hub-app/messages.css +35 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +187 -0
- package/src/serve/hub-app/releases/releases-st.ts +111 -0
- package/src/serve/hub-app/releases.css +52 -0
- package/src/serve/hub-app/repo-sections.ts +16 -2
- package/src/serve/hub-app/repo-st.ts +66 -10
- package/src/serve/hub-app/review/clip-st.ts +34 -4
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/note-place.ts +31 -0
- package/src/serve/hub-app/review/review-cells.tsx +27 -3
- package/src/serve/hub-app/review/review-st.ts +77 -2
- package/src/serve/hub-app/review/review-thread.tsx +9 -31
- package/src/serve/hub-app/review/review-views.tsx +164 -58
- package/src/serve/hub-app/review/thread-st.ts +108 -41
- package/src/serve/hub-app/review/trailer-card.tsx +187 -0
- package/src/serve/hub-app/review/trailer-page.tsx +92 -36
- package/src/serve/hub-app/review/trailer-st.ts +306 -34
- package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +137 -6
- package/src/serve/hub-app/social/comms-page.tsx +65 -28
- package/src/serve/hub-app/social/identity-pictures.ts +46 -8
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +39 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +117 -27
- package/src/serve/hub-app/social/stage-popup.tsx +268 -0
- package/src/serve/hub-app/social/stage-st.ts +310 -0
- package/src/serve/hub-app/social/step-layout.ts +42 -0
- package/src/serve/hub-app/social.css +68 -1
- package/src/serve/hub-app/tree-build.ts +40 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +12 -2
- package/src/serve/project-gutter.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +15 -1
- package/src/shipkit-files.ts +9 -7
- package/src/shot/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +22 -12
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +54 -7
- package/src/social/drafts.ts +1 -1
- package/src/social/fit.ts +84 -0
- package/src/social/identity-words.ts +74 -0
- package/src/social/kind-pages.ts +41 -0
- package/src/social/kinds.ts +93 -0
- package/src/social/load.ts +125 -10
- package/src/social/media-limit.ts +63 -2
- package/src/social/presence.ts +1 -1
- package/src/social/publish/bluesky.ts +58 -19
- package/src/social/publish/index.ts +47 -6
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +277 -0
- package/src/social/routes.ts +44 -8
- package/src/social/stage.ts +246 -0
- package/src/social/strip.ts +85 -0
- package/src/social/text.ts +6 -2
- package/src/social/unit.ts +57 -1
- package/src/social/writes.ts +11 -0
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +72 -40
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +37 -6
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// the page's hot reload socket kept across a restart of the web. Bun's client
|
|
2
|
+
// reloads the whole page when its socket comes back, whatever moved, so a web
|
|
3
|
+
// restart for its own server code reloaded a page whose code had not changed.
|
|
4
|
+
// This script runs in the page's head before Bun's client, and hands that
|
|
5
|
+
// client one socket that never drops: under it, the real socket reconnects,
|
|
6
|
+
// says when it last heard the web (`since`), and the web answers whether a
|
|
7
|
+
// file of the page's bundle moved since then (serve-web.ts), and stamps the
|
|
8
|
+
// head it serves. Nothing moved: the client's subscriptions are sent again and
|
|
9
|
+
// it never sees the gap. A file moved, another head, or another dev server
|
|
10
|
+
// version: the client gets its version message
|
|
11
|
+
// and reloads the page, which is the reload that means something.
|
|
12
|
+
//
|
|
13
|
+
// the one constraint a reader breaks first: `keepHmr` ships as its own source
|
|
14
|
+
// text (hmrKeepScript), so it closes over nothing and imports nothing.
|
|
15
|
+
|
|
16
|
+
/** the text frames the web sends on the hot reload socket: its time, the stamp of the head it serves (its own code
|
|
17
|
+
* puts it there, so its edit reaches no page file), then whether the page moved while it was away */
|
|
18
|
+
export const HMR_WORDS = { beat: 't:', head: 'head:', fresh: 'page:fresh', moved: 'page:moved' } as const
|
|
19
|
+
/** how often the web stamps each hot reload socket with its time */
|
|
20
|
+
export const HMR_BEAT_MS = 2_000
|
|
21
|
+
/** a dropped socket tries again after `firstMs`, the wait doubling up to `maxMs` */
|
|
22
|
+
export const HMR_RETRY = { firstMs: 1_000, maxMs: 8_000 }
|
|
23
|
+
|
|
24
|
+
type Win = { WebSocket: typeof WebSocket; location: { href: string }; setTimeout: (f: () => void, ms: number) => unknown }
|
|
25
|
+
type Words = typeof HMR_WORDS
|
|
26
|
+
|
|
27
|
+
/** installs the kept socket on `win`: a socket to `/_bun/hmr` is a kept one, every other socket is native */
|
|
28
|
+
export function keepHmr(win: Win, words: Words, retry: typeof HMR_RETRY): void {
|
|
29
|
+
const Native = win.WebSocket
|
|
30
|
+
/** Bun's version message, the first a socket gets */
|
|
31
|
+
const VERSION = 86
|
|
32
|
+
function Keep(this: Record<string, unknown>, url: string): void {
|
|
33
|
+
const self = this
|
|
34
|
+
let ws: WebSocket
|
|
35
|
+
let closed = false
|
|
36
|
+
let heard = 0
|
|
37
|
+
/** the stamp a socket that came back said, the page's own once that web finds it current */
|
|
38
|
+
let waiting = 0
|
|
39
|
+
let version: string | null = null
|
|
40
|
+
let again = false
|
|
41
|
+
let verdict: string | null = null
|
|
42
|
+
/** the stamp of the head the web served this page with, and of the head the web now serves */
|
|
43
|
+
let loadedHead: string | null = null
|
|
44
|
+
let headNow: string | null = null
|
|
45
|
+
let wait = retry.firstMs
|
|
46
|
+
/** the client's subscriptions and its last route, sent again on a socket that came back */
|
|
47
|
+
const subs = new Map<string, string>()
|
|
48
|
+
self.readyState = 0
|
|
49
|
+
self.binaryType = 'arraybuffer'
|
|
50
|
+
self.url = url
|
|
51
|
+
const tell = (k: 'onopen' | 'onmessage' | 'onclose', e: Event): void => {
|
|
52
|
+
const f = self[k]
|
|
53
|
+
if (typeof f === 'function') f.call(self, e)
|
|
54
|
+
}
|
|
55
|
+
function connect(): void {
|
|
56
|
+
if (closed) return
|
|
57
|
+
const u = new URL(url, win.location.href)
|
|
58
|
+
if (again) u.searchParams.set('since', String(heard))
|
|
59
|
+
ws = new Native(u.href)
|
|
60
|
+
ws.binaryType = 'arraybuffer'
|
|
61
|
+
ws.onopen = (e) => {
|
|
62
|
+
wait = retry.firstMs
|
|
63
|
+
if (again) return
|
|
64
|
+
self.readyState = 1
|
|
65
|
+
tell('onopen', e)
|
|
66
|
+
}
|
|
67
|
+
ws.onmessage = (e) => {
|
|
68
|
+
if (typeof e.data === 'string') {
|
|
69
|
+
// a stamp counts only once the page is current on this socket: a web that drops before its
|
|
70
|
+
// version message never makes a missed edit look seen
|
|
71
|
+
if (e.data.startsWith(words.beat)) {
|
|
72
|
+
const t = Number(e.data.slice(words.beat.length)) || 0
|
|
73
|
+
if (again) waiting = t
|
|
74
|
+
else heard = t || heard
|
|
75
|
+
} else if (e.data.startsWith(words.head)) {
|
|
76
|
+
const h = e.data.slice(words.head.length)
|
|
77
|
+
if (!again) loadedHead ??= h
|
|
78
|
+
headNow = h
|
|
79
|
+
} else if (e.data === words.fresh || e.data === words.moved) verdict = e.data
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
const b = new Uint8Array(e.data as ArrayBuffer)
|
|
83
|
+
if (b[0] === VERSION) {
|
|
84
|
+
const v = new TextDecoder().decode(b.subarray(1))
|
|
85
|
+
if (again && verdict === words.fresh && v === version && headNow === loadedHead) {
|
|
86
|
+
again = false
|
|
87
|
+
heard = waiting || heard
|
|
88
|
+
for (const m of subs.values()) ws.send(m)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
version ??= v
|
|
92
|
+
}
|
|
93
|
+
tell('onmessage', e)
|
|
94
|
+
}
|
|
95
|
+
ws.onerror = (e) => { e.preventDefault() }
|
|
96
|
+
ws.onclose = (e) => {
|
|
97
|
+
// closed by the client, or a first socket that never opened: the client's own to retry
|
|
98
|
+
if (closed || self.readyState !== 1) {
|
|
99
|
+
closed = true
|
|
100
|
+
self.readyState = 3
|
|
101
|
+
tell('onclose', e)
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
again = true
|
|
105
|
+
verdict = null
|
|
106
|
+
headNow = null
|
|
107
|
+
waiting = 0
|
|
108
|
+
win.setTimeout(connect, wait)
|
|
109
|
+
wait = Math.min(wait * 2, retry.maxMs)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
self.send = (m: string | BufferSource): void => {
|
|
113
|
+
if (typeof m === 'string' && (m[0] === 's' || m[0] === 'n')) subs.set(m[0] === 'n' ? 'n' : m, m)
|
|
114
|
+
if (ws.readyState === 1 && !again) ws.send(m)
|
|
115
|
+
}
|
|
116
|
+
self.close = (): void => {
|
|
117
|
+
closed = true
|
|
118
|
+
ws.close()
|
|
119
|
+
}
|
|
120
|
+
connect()
|
|
121
|
+
}
|
|
122
|
+
function Socket(url: string | URL, protocols?: string | string[]): object {
|
|
123
|
+
const u = new URL(String(url), win.location.href)
|
|
124
|
+
if (u.pathname === '/_bun/hmr' && protocols === undefined) return new (Keep as unknown as new (url: string) => object)(u.href)
|
|
125
|
+
return protocols === undefined ? new Native(url) : new Native(url, protocols)
|
|
126
|
+
}
|
|
127
|
+
Socket.prototype = Native.prototype
|
|
128
|
+
Object.assign(Socket, { CONNECTING: 0, OPEN: 1, CLOSING: 2, CLOSED: 3 })
|
|
129
|
+
win.WebSocket = Socket as unknown as typeof WebSocket
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** the script the web puts in the page's head, before Bun's client runs */
|
|
133
|
+
export const hmrKeepScript = (retry = HMR_RETRY): string => `<script>(${keepHmr.toString()})(window, ${JSON.stringify(HMR_WORDS)}, ${JSON.stringify(retry)})</script>`
|
|
134
|
+
export const HMR_KEEP_SCRIPT = hmrKeepScript()
|
package/src/home/home-start.ts
CHANGED
|
@@ -109,8 +109,8 @@ export async function openWindow(url: string, o: { root?: string | null; version
|
|
|
109
109
|
return chromeWindow(url)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
/** a global process's own app: built
|
|
113
|
-
*
|
|
112
|
+
/** a global process's own app: built in ~/Applications when missing or
|
|
113
|
+
* stale, then opened with no url, so a running copy comes to
|
|
114
114
|
* the front instead of stacking windows. Where no app can be built, a
|
|
115
115
|
* Chrome app window on its url */
|
|
116
116
|
export async function openProcessApp(d: WrapperOf, o: { version: string; warn?: (l: string) => void }): Promise<string[]> {
|
package/src/home/lib-watch.ts
CHANGED
|
@@ -21,26 +21,34 @@ const CODE = /\.(ts|tsx|js|jsx|json|css|html)$/
|
|
|
21
21
|
const LOADER: Record<string, 'ts' | 'tsx' | 'js' | 'jsx'> = { '.ts': 'ts', '.tsx': 'tsx', '.js': 'js', '.jsx': 'jsx' }
|
|
22
22
|
const TRY = ['', '.ts', '.tsx', '.js', '/index.ts', '/index.tsx']
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
/** how libGraph reads the tree: the disk, or a test's files */
|
|
25
|
+
export type TreeIo = { exists: (f: string) => boolean; read: (f: string) => string }
|
|
26
|
+
const DISK: TreeIo = { exists: existsSync, read: (f) => readFileSync(f, 'utf8') }
|
|
27
|
+
|
|
28
|
+
function resolveRel(from: string, spec: string, io: TreeIo): string | null {
|
|
25
29
|
const base = resolve(dirname(from), spec)
|
|
26
|
-
for (const s of TRY) if (
|
|
30
|
+
for (const s of TRY) if (io.exists(base + s) && extname(base + s) !== '') return base + s
|
|
27
31
|
return null
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/** every lib file `entry` reaches through its relative imports, type only
|
|
31
|
-
* imports left out (an edit there changes no running code).
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
+
* imports left out (an edit there changes no running code). An imported
|
|
36
|
+
* html page is left out too: Bun's dev server watches the page and every
|
|
37
|
+
* file of its bundle, and hot swaps an edit into the open page, so no role
|
|
38
|
+
* restarts for it. With `bundles`, the files of the page's bundle: an html
|
|
39
|
+
* page followed into the scripts and styles it names */
|
|
40
|
+
export function libGraph(entry: string, o: { bundles?: boolean; io?: TreeIo } = {}): Set<string> {
|
|
41
|
+
const io = o.io ?? DISK
|
|
35
42
|
const out = new Set<string>()
|
|
36
43
|
const todo = [resolve(entry)]
|
|
37
44
|
while (todo.length > 0) {
|
|
38
45
|
const f = todo.pop()!
|
|
39
46
|
if (out.has(f)) continue
|
|
40
|
-
out.add(f)
|
|
41
47
|
const ext = extname(f)
|
|
48
|
+
if (ext === '.html' && o.bundles !== true) continue
|
|
49
|
+
out.add(f)
|
|
42
50
|
let text: string
|
|
43
|
-
try { text =
|
|
51
|
+
try { text = io.read(f) } catch { continue }
|
|
44
52
|
const specs: string[] = []
|
|
45
53
|
if (LOADER[ext] != null) {
|
|
46
54
|
try {
|
|
@@ -51,13 +59,16 @@ export function libGraph(entry: string, o: { bundles?: boolean } = {}): Set<stri
|
|
|
51
59
|
}
|
|
52
60
|
for (const s of specs) {
|
|
53
61
|
if (!s.startsWith('.')) continue
|
|
54
|
-
const r = resolveRel(f, s)
|
|
62
|
+
const r = resolveRel(f, s, io)
|
|
55
63
|
if (r != null) todo.push(r)
|
|
56
64
|
}
|
|
57
65
|
}
|
|
58
66
|
return out
|
|
59
67
|
}
|
|
60
68
|
|
|
69
|
+
/** the files a role restarts on: what its runner module runs */
|
|
70
|
+
export const roleGraph = (entry: string): Set<string> => libGraph(entry)
|
|
71
|
+
|
|
61
72
|
/** a burst of saves is one change once no write came for this long: an agent saves file after file, and each
|
|
62
73
|
* restart rescans every house repo */
|
|
63
74
|
export const SETTLE_MS = 5_000
|
|
@@ -148,7 +159,6 @@ export function reloadOnOwnCode(o: {
|
|
|
148
159
|
role: 'pm' | 'daemon' | 'web'
|
|
149
160
|
/** the role's runner module: its graph is what the role reloads on */
|
|
150
161
|
entry: string
|
|
151
|
-
bundles?: boolean
|
|
152
162
|
busy?: () => boolean
|
|
153
163
|
before: () => void
|
|
154
164
|
keep?: boolean
|
|
@@ -156,7 +166,7 @@ export function reloadOnOwnCode(o: {
|
|
|
156
166
|
}): { stop: () => void; files: number } {
|
|
157
167
|
const onCopy = copyStamp(OWN_LIB) != null
|
|
158
168
|
const tree = homeLib()
|
|
159
|
-
const graph =
|
|
169
|
+
const graph = roleGraph(onCopy ? join(tree, relative(OWN_LIB, o.entry)) : o.entry)
|
|
160
170
|
const lib = new LibWatch(tree, { only: onCopy ? undefined : graph })
|
|
161
171
|
if (lib.error != null) o.io.printErr(`WARN no watch on the shipkit source (${lib.error}), so an edit of the ${o.role} needs a restart of it`)
|
|
162
172
|
const probe = new TreeProbe(() => probeLoad(tree, bootEntries(tree, o.role)), () => `${lib.seq}|${versionAt(tree)}`)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// a global process, or one of pm's own roles, switched through the running pm
|
|
2
|
+
// and followed until its probe settles it. Lib code, not a command: the daemon
|
|
3
|
+
// reaches it (a take starts the dev server it films), so it never lives in
|
|
4
|
+
// src/cli/, which no role's graph may hold (home/lib-watch.ts).
|
|
5
|
+
import { pmUrl } from './home-paths.ts'
|
|
6
|
+
import { ROLES, type PmAnswer, type Role } from './pm.ts'
|
|
7
|
+
import type { ResourceView } from './resources.ts'
|
|
8
|
+
|
|
9
|
+
/** pm's status answer, or null when it does not answer */
|
|
10
|
+
export async function askPm(url = pmUrl()): Promise<PmAnswer | null> {
|
|
11
|
+
try {
|
|
12
|
+
const r = await fetch(`${url}/api/pm/status.json`, { signal: AbortSignal.timeout(1_500) })
|
|
13
|
+
if (!r.ok) return null
|
|
14
|
+
const j = (await r.json()) as PmAnswer
|
|
15
|
+
return j.pm === 'shipkit-pm' ? j : null
|
|
16
|
+
} catch {
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type SwitchAct = 'start' | 'stop' | 'restart'
|
|
22
|
+
|
|
23
|
+
/** what a switch follows, the same on a global process and on one of pm's own roles (the daemon, the web) */
|
|
24
|
+
export type SwitchView = Pick<ResourceView, 'status' | 'pid' | 'want' | 'note' | 'tail'>
|
|
25
|
+
|
|
26
|
+
export type SwitchDeps = {
|
|
27
|
+
/** pm's answer to the switch: null when it took it, else why not */
|
|
28
|
+
post: (id: string, act: SwitchAct | 'open' | 'chrome' | 'app') => Promise<string | null>
|
|
29
|
+
/** the process as pm sees it now, null when pm does not answer */
|
|
30
|
+
view: (id: string) => Promise<SwitchView | null>
|
|
31
|
+
sleep: (ms: number) => Promise<void>
|
|
32
|
+
now: () => number
|
|
33
|
+
log: (line: string) => void
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** the longest a switch is followed: a bring-up polls its health for minutes */
|
|
37
|
+
export const SWITCH_WAIT_MS = 10 * 60_000
|
|
38
|
+
const SWITCH_POLL_MS = 1_000
|
|
39
|
+
/** how long the state the switch left counts as pm not having acted yet */
|
|
40
|
+
export const SWITCH_GRACE_MS = 30_000
|
|
41
|
+
|
|
42
|
+
/** flip a global process, or one of pm's own roles, through pm, then follow
|
|
43
|
+
* pm's state until its probe settles it: 0 once it is up (or down for stop),
|
|
44
|
+
* 1 otherwise. A restart is up only on a new pid: the old one still answers
|
|
45
|
+
* until pm stops it (pm stops the web after its answer is out). The
|
|
46
|
+
* launcher's exit code proves nothing, pm's probe does */
|
|
47
|
+
export async function switchProcess(id: string, act: SwitchAct, d: SwitchDeps, waitMs = SWITCH_WAIT_MS): Promise<number> {
|
|
48
|
+
const before = act === 'restart' ? ((await d.view(id))?.pid ?? null) : null
|
|
49
|
+
const refused = await d.post(id, act)
|
|
50
|
+
if (refused != null) {
|
|
51
|
+
d.log(`FAIL ${act} ${id}: ${refused}`)
|
|
52
|
+
return 1
|
|
53
|
+
}
|
|
54
|
+
const want = act === 'stop' ? 'down' : 'up'
|
|
55
|
+
const start = d.now()
|
|
56
|
+
const end = start + waitMs
|
|
57
|
+
let said = ''
|
|
58
|
+
for (;;) {
|
|
59
|
+
const v = await d.view(id)
|
|
60
|
+
if (v == null) {
|
|
61
|
+
d.log(`FAIL pm stopped answering while ${id} was switched ${want}: shipkit gp`)
|
|
62
|
+
return 1
|
|
63
|
+
}
|
|
64
|
+
if (v.status !== said) {
|
|
65
|
+
said = v.status
|
|
66
|
+
d.log(`${id}: ${v.status}`)
|
|
67
|
+
}
|
|
68
|
+
// the state it is leaving, read just after the switch, is pm not there yet
|
|
69
|
+
const graced = d.now() - start < SWITCH_GRACE_MS
|
|
70
|
+
const leaving = v.status === (want === 'up' ? 'down' : 'up') && graced
|
|
71
|
+
const old = before != null && v.pid === before
|
|
72
|
+
const moving = v.status === 'starting' || v.status === 'stopping' || v.want !== want || leaving || (old && graced)
|
|
73
|
+
if (!moving) {
|
|
74
|
+
if (old && v.status === 'up') {
|
|
75
|
+
d.log(`FAIL ${id} still runs pid ${before} ${Math.round(SWITCH_GRACE_MS / 1000)}s after the restart: pm did not restart it`)
|
|
76
|
+
return 1
|
|
77
|
+
}
|
|
78
|
+
if (v.status === want) return 0
|
|
79
|
+
d.log(`FAIL ${id} is ${v.status}, not ${want}${v.note == null ? '' : `: ${v.note}`}`)
|
|
80
|
+
for (const l of v.tail.slice(-10)) d.log(` log: ${l}`)
|
|
81
|
+
return 1
|
|
82
|
+
}
|
|
83
|
+
if (d.now() >= end) {
|
|
84
|
+
d.log(`FAIL ${id} still ${v.status} after ${Math.round(waitMs / 1000)}s: shipkit gp shows where it stands`)
|
|
85
|
+
return 1
|
|
86
|
+
}
|
|
87
|
+
await d.sleep(SWITCH_POLL_MS)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const isRole = (id: string): id is Role => (ROLES as string[]).includes(id)
|
|
92
|
+
|
|
93
|
+
/** the switch against the running pm: pm's own roles (the daemon, the web) through its child api, every other id a
|
|
94
|
+
* global process */
|
|
95
|
+
export const pmSwitchDeps = (log: (line: string) => void, url = pmUrl()): SwitchDeps => ({
|
|
96
|
+
post: async (id, act) => {
|
|
97
|
+
try {
|
|
98
|
+
const r = await fetch(`${url}/api/pm/${isRole(id) ? 'child' : 'resource'}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id, act }), signal: AbortSignal.timeout(5_000) })
|
|
99
|
+
return r.ok ? null : await r.text()
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return `pm does not answer on ${url} (${(e as Error).message}): shipkit pm install`
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
view: async (id) => {
|
|
105
|
+
const a = await askPm(url)
|
|
106
|
+
if (a == null) return null
|
|
107
|
+
return (isRole(id) ? a.children.find((c) => c.id === id) : a.resources.find((r) => r.id === id)) ?? null
|
|
108
|
+
},
|
|
109
|
+
sleep: (ms) => Bun.sleep(ms),
|
|
110
|
+
now: () => Date.now(),
|
|
111
|
+
log,
|
|
112
|
+
})
|
package/src/home/pm.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { existsSync } from 'fs'
|
|
11
11
|
import { join } from 'path'
|
|
12
12
|
import { LIB_VERSION } from '../core/lib-version.ts'
|
|
13
|
-
import { iconImageType } from '../
|
|
13
|
+
import { iconImageType } from '../core/icon-type.ts'
|
|
14
14
|
import { sameOrigin } from '../serve/same-origin.ts'
|
|
15
15
|
import { readBeat } from './beat.ts'
|
|
16
16
|
import { childBeat, childLog, childPid, daemonPort, homePort, pmLog, pmPort } from './home-paths.ts'
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// every global process with a url as its own macOS app in ~/Applications,
|
|
2
|
+
// named by its `app` (else its label), where Spotlight and Launchpad find it.
|
|
3
|
+
// The daemon's `apps` job (home/daemon-jobs.ts) builds what is missing or
|
|
4
|
+
// stale through home/gui-app.ts, and removes the apps of a process renamed or
|
|
5
|
+
// gone. A repo's `.shipkit/wrapper/` holds no app: any shipkit bundle there is removed too.
|
|
6
|
+
//
|
|
7
|
+
// the one constraint a reader breaks first: the sweep removes only a bundle
|
|
8
|
+
// shipkit built (shipkitBundleOf), never another app of the folder, and
|
|
9
|
+
// nothing at all when a unit file did not load: its processes would look gone.
|
|
10
|
+
import { createHash } from 'crypto'
|
|
11
|
+
import { existsSync, readdirSync, readFileSync, rmdirSync, rmSync, statSync } from 'fs'
|
|
12
|
+
import { homedir } from 'os'
|
|
13
|
+
import { join } from 'path'
|
|
14
|
+
import { fileURLToPath } from 'url'
|
|
15
|
+
import { repoUnitFiles } from '../core/discover-checks.ts'
|
|
16
|
+
import { LAYOUT } from '../core/layout.ts'
|
|
17
|
+
import { yieldLoop } from '../core/loop-watch.ts'
|
|
18
|
+
import { machineGet } from '../core/machine-db.ts'
|
|
19
|
+
import { homeRepo, houseRepos } from '../serve/project-gutter.ts'
|
|
20
|
+
|
|
21
|
+
/** the one source every app's window is compiled from */
|
|
22
|
+
export const GUI_SOURCE = fileURLToPath(new URL('./gui-app/ShipkitGui.swift', import.meta.url))
|
|
23
|
+
|
|
24
|
+
/** where every app shipkit builds lands: Spotlight indexes it, and skips a dot folder or a symlink */
|
|
25
|
+
export const appsDir = (home = homedir()): string => process.env.SHIPKIT_APPS_DIR ?? join(home, 'Applications')
|
|
26
|
+
|
|
27
|
+
/** every process app's bundle id starts so: the sweep removes nothing else */
|
|
28
|
+
export const WRAPPER_PREFIX = 'dev.shipkit.app.'
|
|
29
|
+
export const wrapperBundleId = (id: string): string => `${WRAPPER_PREFIX}${id.replace(/[^A-Za-z0-9-]+/g, '-')}`
|
|
30
|
+
|
|
31
|
+
type Named = { label: string; app?: string | null }
|
|
32
|
+
export const appNameOf = (d: Named): string => d.app ?? d.label
|
|
33
|
+
export const wrapperPath = (d: Named, dir = appsDir()): string => join(dir, `${appNameOf(d).replace(/[/:]+/g, '-')}.app`)
|
|
34
|
+
|
|
35
|
+
/** the bundle id of a process app shipkit built (its id under WRAPPER_PREFIX
|
|
36
|
+
* and its build stamp), or null for any other app */
|
|
37
|
+
export function shipkitBundleOf(app: string): string | null {
|
|
38
|
+
const plist = join(app, 'Contents', 'Info.plist')
|
|
39
|
+
if (!existsSync(plist) || !existsSync(join(app, 'Contents', 'Resources', 'stamp'))) return null
|
|
40
|
+
let text: string
|
|
41
|
+
try { text = readFileSync(plist, 'utf8') } catch { return null }
|
|
42
|
+
const id = /<key>CFBundleIdentifier<\/key>\s*<string>([^<]*)<\/string>/.exec(text)?.[1] ?? null
|
|
43
|
+
return id?.startsWith(WRAPPER_PREFIX) ? id : null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** a process as its app needs it (WrapperOf in gui-app.ts) */
|
|
47
|
+
export type AppOf = Named & { id: string; url: string | null; icon: string | null; root: string }
|
|
48
|
+
|
|
49
|
+
/** the apps the processes want, one a name. The folder is case blind, so
|
|
50
|
+
* two names that differ by case are one: the second process gets no app */
|
|
51
|
+
export function plannedApps<T extends AppOf>(processes: T[], dir: string, reserved: string[] = []): { want: { d: T; path: string }[]; errors: string[] } {
|
|
52
|
+
const taken = new Map<string, string>(reserved.map((p) => [p.toLowerCase(), 'another app']))
|
|
53
|
+
const want: { d: T; path: string }[] = []
|
|
54
|
+
const errors: string[] = []
|
|
55
|
+
for (const d of processes) {
|
|
56
|
+
if (d.url == null) continue
|
|
57
|
+
const path = wrapperPath(d, dir)
|
|
58
|
+
const by = taken.get(path.toLowerCase())
|
|
59
|
+
if (by != null) {
|
|
60
|
+
errors.push(`${d.id}: its app name '${appNameOf(d)}' is ${by}'s too, so it gets no app: give it its own (app: in its unit file)`)
|
|
61
|
+
continue
|
|
62
|
+
}
|
|
63
|
+
taken.set(path.toLowerCase(), d.id)
|
|
64
|
+
want.push({ d, path })
|
|
65
|
+
}
|
|
66
|
+
return { want, errors }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** the bundles shipkit built in these folders that no process wants */
|
|
70
|
+
export function staleApps(dirs: string[], keep: string[]): string[] {
|
|
71
|
+
const kept = new Set(keep.map((p) => p.toLowerCase()))
|
|
72
|
+
const out: string[] = []
|
|
73
|
+
for (const dir of dirs) {
|
|
74
|
+
let names: string[]
|
|
75
|
+
try { names = readdirSync(dir) } catch { continue }
|
|
76
|
+
for (const name of names.sort()) {
|
|
77
|
+
const p = join(dir, name)
|
|
78
|
+
if (name.endsWith('.app') && !kept.has(p.toLowerCase()) && shipkitBundleOf(p) != null) out.push(p)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return out
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const LSREGISTER = '/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister'
|
|
85
|
+
|
|
86
|
+
/** removes a bundle, and tells launch services it is gone, so Launchpad drops it */
|
|
87
|
+
const removeReal = (app: string): void => {
|
|
88
|
+
rmSync(app, { recursive: true, force: true })
|
|
89
|
+
if (existsSync(LSREGISTER)) Bun.spawnSync([LSREGISTER, '-u', app], { stdout: 'ignore', stderr: 'ignore' })
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type AppsTickIo = {
|
|
93
|
+
processes: AppOf[]
|
|
94
|
+
/** the scan's errors: a unit file that did not load stops the sweep */
|
|
95
|
+
scanErrors: string[]
|
|
96
|
+
/** the house repos: each one's `.shipkit/wrapper/` is swept */
|
|
97
|
+
repos: string[]
|
|
98
|
+
dir: string
|
|
99
|
+
/** builds one app (gui-app.ts ensureWrapperApp); null: none can be built here */
|
|
100
|
+
build: ((d: AppOf, dir: string) => Promise<{ app: string; rebuilt: boolean }>) | null
|
|
101
|
+
/** paths in `dir` no process may take (the shipkit app) */
|
|
102
|
+
reserved?: string[]
|
|
103
|
+
remove?: (app: string) => void
|
|
104
|
+
print: (l: string) => void
|
|
105
|
+
printErr: (l: string) => void
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** one pass: build what is missing or stale, then remove the stale */
|
|
109
|
+
export async function appsTick(o: AppsTickIo): Promise<{ built: string[]; removed: string[] }> {
|
|
110
|
+
const { want, errors } = plannedApps(o.processes, o.dir, o.reserved)
|
|
111
|
+
for (const e of errors) o.printErr(`WARN ${e}`)
|
|
112
|
+
const built: string[] = []
|
|
113
|
+
if (o.build == null) o.printErr('WARN no app built: this machine has no swiftc and iconutil, or is not macOS')
|
|
114
|
+
else {
|
|
115
|
+
for (const { d } of want) {
|
|
116
|
+
try {
|
|
117
|
+
const r = await o.build(d, o.dir)
|
|
118
|
+
if (r.rebuilt) built.push(r.app)
|
|
119
|
+
} catch (e) {
|
|
120
|
+
o.printErr(`WARN the app of ${d.id} was not built: ${(e as Error).message}`)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const app of built) o.print(`ok: built ${app}`)
|
|
125
|
+
if (o.scanErrors.length > 0) {
|
|
126
|
+
o.printErr(`WARN no stale app removed: a unit file did not load, so its processes look gone (${o.scanErrors[0]})`)
|
|
127
|
+
return { built, removed: [] }
|
|
128
|
+
}
|
|
129
|
+
const homes = o.repos.map((r) => join(r, LAYOUT.wrapper))
|
|
130
|
+
const removed = staleApps([o.dir, ...homes], want.map((w) => w.path))
|
|
131
|
+
for (const app of removed) {
|
|
132
|
+
;(o.remove ?? removeReal)(app)
|
|
133
|
+
o.print(`ok: removed ${app}, no process has it`)
|
|
134
|
+
}
|
|
135
|
+
for (const home of homes) {
|
|
136
|
+
try { if (readdirSync(home).length === 0) rmdirSync(home) } catch { /* absent */ }
|
|
137
|
+
}
|
|
138
|
+
return { built, removed }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** how often the daemon looks whether the apps' sources moved */
|
|
142
|
+
export const APPS_EVERY_MS = 60_000
|
|
143
|
+
/** the stamp of the last pass (machine db), and when */
|
|
144
|
+
export const APPS_DONE = 'process-apps-done'
|
|
145
|
+
/** a pass at least this often: an icon or a colour is not in the stamp */
|
|
146
|
+
export const APPS_MAX_MS = 6 * 3600_000
|
|
147
|
+
|
|
148
|
+
const statOf = (f: string | null): string => {
|
|
149
|
+
if (f == null) return '-'
|
|
150
|
+
try {
|
|
151
|
+
const st = statSync(f)
|
|
152
|
+
return `${st.mtimeMs}:${st.size}`
|
|
153
|
+
} catch {
|
|
154
|
+
return '-'
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** the outside of what the apps are made of, a stat each: every repo's unit
|
|
159
|
+
* files and wrapper folder, the window's source, the names in the apps
|
|
160
|
+
* folder (an app deleted by hand comes back). Null off macOS or with no house */
|
|
161
|
+
export async function appsSourcesStamp(root: string, home: string = homedir(), platform = process.platform): Promise<string | null> {
|
|
162
|
+
if (platform !== 'darwin') return null
|
|
163
|
+
const h = houseRepos(homeRepo(root), home)
|
|
164
|
+
if (h.index == null) return null
|
|
165
|
+
let names: string[] = []
|
|
166
|
+
try { names = readdirSync(appsDir(home)).filter((n) => n.endsWith('.app')).sort() } catch { /* no folder yet */ }
|
|
167
|
+
const parts = [statOf(GUI_SOURCE), names.join('|')]
|
|
168
|
+
for (const r of h.repos) {
|
|
169
|
+
await yieldLoop()
|
|
170
|
+
parts.push(r.path, String(existsSync(join(r.path, LAYOUT.wrapper))))
|
|
171
|
+
for (const f of repoUnitFiles(r.path)) parts.push(f, statOf(f))
|
|
172
|
+
}
|
|
173
|
+
return createHash('sha256').update(parts.join('\n')).digest('hex').slice(0, 16)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** a pass is due when the stamp moved since the last one, or that one is old */
|
|
177
|
+
export function appsDue(now: number, stamp: string | null): boolean {
|
|
178
|
+
if (stamp == null) return false
|
|
179
|
+
const done = machineGet<{ stamp: string; at: number }>(APPS_DONE)
|
|
180
|
+
return done == null || done.stamp !== stamp || now - done.at >= APPS_MAX_MS
|
|
181
|
+
}
|
package/src/home/resources.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// declared once in a repo's `<name>.shipkit.ts` as `globalProcess({...})`
|
|
3
3
|
// (shipkit-files.ts) and owned by pm: a switch, a restart, its log, its
|
|
4
4
|
// action buttons, and its url opened in the default browser, in Chrome, or
|
|
5
|
-
// as its own app (home/
|
|
5
|
+
// as its own app (home/process-apps.ts keeps it in ~/Applications).
|
|
6
6
|
//
|
|
7
7
|
// two kinds: with no `down`, the command IS the service, supervised like a
|
|
8
8
|
// hub (restarted on a crash, signalled on stop). With `down`, the command is
|
|
@@ -13,7 +13,7 @@ import { homedir } from 'os'
|
|
|
13
13
|
import { dirname, join } from 'path'
|
|
14
14
|
import { fileURLToPath } from 'url'
|
|
15
15
|
import type { GlobalProcessDecl } from './global-units.ts'
|
|
16
|
-
import { iconImageType } from '../
|
|
16
|
+
import { iconImageType } from '../core/icon-type.ts'
|
|
17
17
|
import { Proc, realDeps, tailLines, type ProcStatus, type SuperviseDeps } from './supervise.ts'
|
|
18
18
|
import { resourceLog, resourcePid } from './home-paths.ts'
|
|
19
19
|
import { groupOf, localPort, portHolders } from '../core/port-holders.ts'
|
|
@@ -101,7 +101,7 @@ const openApp: OpenApp = async (d, log) => {
|
|
|
101
101
|
mkdirSync(dirname(log), { recursive: true })
|
|
102
102
|
const fd = openSync(log, 'a')
|
|
103
103
|
try {
|
|
104
|
-
const spec = { id: d.id, label: d.label, url: d.url, icon: d.icon, root: d.root }
|
|
104
|
+
const spec = { id: d.id, label: d.label, app: d.app, url: d.url, icon: d.icon, root: d.root }
|
|
105
105
|
return await Bun.spawn([process.execPath, OPEN_APP, '--process', JSON.stringify(spec)], { stdio: ['ignore', fd, fd] }).exited
|
|
106
106
|
} finally {
|
|
107
107
|
closeSync(fd)
|
package/src/home/run-web.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
// `shipkit web`: the page on the home port, in front of the daemon and pm. It
|
|
2
2
|
// loads no repo and no config, so it starts in a moment and a daemon restart
|
|
3
3
|
// never moves it: the page stays up and says the daemon is down. An edit of
|
|
4
|
-
// its
|
|
4
|
+
// its server code restarts it in place (lib-watch.ts), the open page kept
|
|
5
|
+
// (hmr-keep.ts); an edit of the page is Bun's hot reload's, never a restart.
|
|
5
6
|
import homePage from '../serve/hub-app/home.html'
|
|
6
7
|
import { fileURLToPath } from 'url'
|
|
7
8
|
import { startBeat } from './beat.ts'
|
|
8
9
|
import { childBeat, daemonPort, daemonUrl, homeDir, homePort, homeUp, pmUrl } from './home-paths.ts'
|
|
9
|
-
import { reloadOnOwnCode } from './lib-watch.ts'
|
|
10
|
+
import { libGraph, reloadOnOwnCode } from './lib-watch.ts'
|
|
10
11
|
import { serveWeb } from './serve-web.ts'
|
|
11
12
|
import type { HomeIo } from './run-daemon.ts'
|
|
12
13
|
|
|
14
|
+
const PAGE_FILE = fileURLToPath(new URL('../serve/hub-app/home.html', import.meta.url))
|
|
15
|
+
|
|
13
16
|
export async function runWeb(io: HomeIo, o: { port?: number } = {}): Promise<number> {
|
|
14
17
|
const port = o.port ?? homePort()
|
|
15
18
|
try {
|
|
16
|
-
const web = serveWeb({ port, daemon: daemonUrl(daemonPort()), pm: pmUrl(), page: homePage })
|
|
19
|
+
const web = serveWeb({ port, daemon: daemonUrl(daemonPort()), pm: pmUrl(), page: homePage, pageFiles: () => libGraph(PAGE_FILE, { bundles: true }) })
|
|
17
20
|
const beat = startBeat(childBeat(homeDir(), 'web'))
|
|
18
|
-
const code = reloadOnOwnCode({ role: 'web', entry: fileURLToPath(import.meta.url),
|
|
21
|
+
const code = reloadOnOwnCode({ role: 'web', entry: fileURLToPath(import.meta.url), before: () => { beat(); web.stop() }, io })
|
|
19
22
|
io.print(`home → http://localhost:${web.server.port} (the daemon: ${daemonUrl()}, pm: ${pmUrl()}), reloads on ${code.files} lib files`)
|
|
20
23
|
for (const sig of ['SIGINT', 'SIGTERM'] as const)
|
|
21
24
|
process.on(sig, () => {
|