rvlib-shipkit 2.19.0 → 2.20.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.
Files changed (158) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/annex/annex.ts +227 -0
  4. package/src/annex/offload.ts +279 -0
  5. package/src/checks/SK040-release-words.check.ts +43 -0
  6. package/src/checks/SK041-annex-links.check.ts +28 -0
  7. package/src/checks/SK042-post-kinds.check.ts +73 -0
  8. package/src/cli/cmd_Annex.ts +179 -0
  9. package/src/cli/cmd_Commands.ts +4 -1
  10. package/src/cli/cmd_Home.ts +3 -2
  11. package/src/cli/cmd_Messages.ts +155 -0
  12. package/src/cli/cmd_Releases.ts +48 -0
  13. package/src/cli/cmd_Review.ts +161 -6
  14. package/src/cli/cmd_Shot.ts +4 -4
  15. package/src/cli/cmd_Social.ts +143 -6
  16. package/src/cli/family-pages.ts +2 -0
  17. package/src/cli/kit/index.ts +1 -1
  18. package/src/cli/kit/verb.ts +11 -3
  19. package/src/cli/registry.ts +6 -1
  20. package/src/collections/collection-types.ts +8 -1
  21. package/src/collections/providers.ts +4 -1
  22. package/src/commands/model.ts +36 -0
  23. package/src/commands/registry.ts +49 -0
  24. package/src/commands/routes.ts +59 -0
  25. package/src/commands/runner.ts +35 -0
  26. package/src/commands/runs.ts +112 -0
  27. package/src/core/app-icon.ts +4 -3
  28. package/src/core/icon-type.ts +8 -0
  29. package/src/core/jobs.ts +4 -3
  30. package/src/core/layout.ts +5 -2
  31. package/src/core/squircle.ts +95 -0
  32. package/src/home/daemon-jobs.ts +26 -2
  33. package/src/home/global-units.ts +3 -0
  34. package/src/home/gui-app/ShipkitGui.swift +302 -5
  35. package/src/home/gui-app.ts +63 -33
  36. package/src/home/hmr-keep.ts +134 -0
  37. package/src/home/home-start.ts +2 -2
  38. package/src/home/lib-watch.ts +21 -11
  39. package/src/home/pm.ts +1 -1
  40. package/src/home/process-apps.ts +181 -0
  41. package/src/home/resources.ts +3 -3
  42. package/src/home/run-web.ts +7 -4
  43. package/src/home/serve-web.ts +64 -14
  44. package/src/identities/collection.ts +49 -0
  45. package/src/identities/identities.ts +110 -8
  46. package/src/identities/machine.ts +4 -3
  47. package/src/identities/rating.ts +33 -0
  48. package/src/identities/shown.ts +170 -0
  49. package/src/identities/steps.ts +5 -0
  50. package/src/media-store/purge.ts +15 -1
  51. package/src/media-store/remote.ts +22 -6
  52. package/src/messages/brief.ts +117 -0
  53. package/src/messages/collection.ts +40 -0
  54. package/src/messages/model.ts +171 -0
  55. package/src/messages/routes.ts +15 -0
  56. package/src/messages/score.ts +180 -0
  57. package/src/messages/tabs.ts +13 -0
  58. package/src/release/notes.ts +130 -0
  59. package/src/release/run-bump.ts +41 -18
  60. package/src/release/run-release.ts +22 -4
  61. package/src/release/run-releases.ts +17 -15
  62. package/src/release/unit-resolve.ts +9 -0
  63. package/src/releases/add.ts +66 -0
  64. package/src/releases/collection.ts +36 -0
  65. package/src/releases/from-card.ts +66 -0
  66. package/src/releases/model.ts +267 -0
  67. package/src/releases/pictures.ts +89 -0
  68. package/src/releases/routes.ts +36 -0
  69. package/src/releases/store.ts +71 -0
  70. package/src/repo-config.ts +5 -0
  71. package/src/review/cells.ts +0 -11
  72. package/src/review/format.ts +10 -6
  73. package/src/review/model.ts +92 -3
  74. package/src/review/notes.ts +2 -48
  75. package/src/review/routes.ts +28 -10
  76. package/src/review/stage-card.ts +197 -0
  77. package/src/review/stage-routes.ts +123 -0
  78. package/src/review/store.ts +36 -0
  79. package/src/review/trailer-card.ts +99 -0
  80. package/src/review/trailer-desk.ts +57 -4
  81. package/src/review/trailer-model.ts +41 -7
  82. package/src/review/trailer-notes.ts +45 -0
  83. package/src/review/trailer-routes.ts +22 -13
  84. package/src/serve/hub-app/app-bridge.ts +71 -0
  85. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  86. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  87. package/src/serve/hub-app/commands.css +24 -0
  88. package/src/serve/hub-app/hash-route.ts +40 -1
  89. package/src/serve/hub-app/home-st.ts +11 -2
  90. package/src/serve/hub-app/home.html +3 -0
  91. package/src/serve/hub-app/hub-app.tsx +6 -0
  92. package/src/serve/hub-app/icons.tsx +5 -0
  93. package/src/serve/hub-app/identities-view.tsx +4 -1
  94. package/src/serve/hub-app/identities.css +1 -0
  95. package/src/serve/hub-app/index.html +3 -0
  96. package/src/serve/hub-app/keys.ts +2 -2
  97. package/src/serve/hub-app/machine-st.ts +41 -10
  98. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  99. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  100. package/src/serve/hub-app/messages.css +35 -0
  101. package/src/serve/hub-app/releases/releases-page.tsx +94 -0
  102. package/src/serve/hub-app/releases/releases-st.ts +69 -0
  103. package/src/serve/hub-app/releases.css +25 -0
  104. package/src/serve/hub-app/repo-sections.ts +15 -1
  105. package/src/serve/hub-app/repo-st.ts +56 -5
  106. package/src/serve/hub-app/review/clip-st.ts +31 -3
  107. package/src/serve/hub-app/review/note-place.ts +31 -0
  108. package/src/serve/hub-app/review/review-cells.tsx +27 -3
  109. package/src/serve/hub-app/review/review-st.ts +77 -2
  110. package/src/serve/hub-app/review/review-thread.tsx +9 -31
  111. package/src/serve/hub-app/review/review-views.tsx +164 -58
  112. package/src/serve/hub-app/review/thread-st.ts +108 -41
  113. package/src/serve/hub-app/review/trailer-card.tsx +187 -0
  114. package/src/serve/hub-app/review/trailer-page.tsx +62 -31
  115. package/src/serve/hub-app/review/trailer-st.ts +138 -26
  116. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
  117. package/src/serve/hub-app/review.css +49 -6
  118. package/src/serve/hub-app/social/comms-page.tsx +55 -23
  119. package/src/serve/hub-app/social/identity-pictures.ts +46 -8
  120. package/src/serve/hub-app/social/kit.tsx +9 -6
  121. package/src/serve/hub-app/social/post-card.tsx +10 -2
  122. package/src/serve/hub-app/social/social-model.ts +37 -3
  123. package/src/serve/hub-app/social/social-page.tsx +179 -65
  124. package/src/serve/hub-app/social/social-st.ts +79 -26
  125. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  126. package/src/serve/hub-app/social/stage-st.ts +310 -0
  127. package/src/serve/hub-app/social/step-layout.ts +42 -0
  128. package/src/serve/hub-app/social.css +60 -1
  129. package/src/serve/hub-app/tree-build.ts +38 -1
  130. package/src/serve/hub-app/tree-svc.ts +10 -3
  131. package/src/serve/project-gutter-route.ts +4 -2
  132. package/src/serve/same-origin.ts +24 -1
  133. package/src/serve/serve-hub.ts +15 -1
  134. package/src/shipkit-files.ts +9 -7
  135. package/src/shot/shooter.ts +3 -3
  136. package/src/shot/shot-ask.ts +14 -3
  137. package/src/shot/shot.shipkit.ts +1 -1
  138. package/src/social/discord-layout.ts +48 -5
  139. package/src/social/fit.ts +84 -0
  140. package/src/social/identity-words.ts +74 -0
  141. package/src/social/kind-pages.ts +41 -0
  142. package/src/social/kinds.ts +92 -0
  143. package/src/social/load.ts +105 -9
  144. package/src/social/media-limit.ts +63 -2
  145. package/src/social/presence.ts +1 -1
  146. package/src/social/publish/bluesky.ts +58 -19
  147. package/src/social/publish/index.ts +31 -5
  148. package/src/social/reach.ts +49 -0
  149. package/src/social/release-stage.ts +173 -0
  150. package/src/social/routes.ts +42 -7
  151. package/src/social/stage.ts +227 -0
  152. package/src/social/strip.ts +85 -0
  153. package/src/social/text.ts +6 -2
  154. package/src/social/unit.ts +57 -1
  155. package/src/social/writes.ts +11 -0
  156. package/src/trailer/build.ts +15 -2
  157. package/src/trailer/grammar.ts +14 -4
  158. package/src/trailer/public-words.ts +41 -0
@@ -0,0 +1,267 @@
1
+ // a release as one markdown file (wiki tools/shipkit/units.md, The release files): `# <version>: <title>`, its date,
2
+ // `## <category>`, `### <change>`, its description, its picture, its bullets, the card it came from in a hidden
3
+ // comment. `next.md` is the version being filled. No fs: store.ts reads the files, the hub page imports this too.
4
+ // A picture is `space:<key>` (private, signed for the hub) until the release makes it a public URL
5
+
6
+ export const NEXT = 'next'
7
+
8
+ export type ReleaseKind = 'major' | 'minor' | 'patch'
9
+
10
+ export interface Picture {
11
+ /** `space:<key>` while private, the public URL once released */
12
+ url: string
13
+ alt: string
14
+ }
15
+
16
+ export interface Change {
17
+ title: string
18
+ /** its description, markdown, empty when the title says it all */
19
+ text: string
20
+ picture: Picture | null
21
+ bullets: string[]
22
+ /** the review card it came from, and the commit that card shows */
23
+ card: string | null
24
+ commit: string | null
25
+ }
26
+
27
+ export interface Category {
28
+ name: string
29
+ changes: Change[]
30
+ }
31
+
32
+ export interface Release {
33
+ /** `next`, or X.Y.Z once released */
34
+ version: string
35
+ /** what kind of release next is, `# next (minor)`; null on a released file or when unsaid */
36
+ kind: ReleaseKind | null
37
+ title: string
38
+ /** YYYY-MM-DD, null on next */
39
+ date: string | null
40
+ categories: Category[]
41
+ }
42
+
43
+ export const SPACE = 'space:'
44
+ export const isPrivate = (p: Picture): boolean => p.url.startsWith(SPACE)
45
+ export const spaceKey = (p: Picture): string | null => (isPrivate(p) ? p.url.slice(SPACE.length) : null)
46
+
47
+ /** where the hub serves a private picture, its key after it */
48
+ export const PICTURE_ROUTE = '/api/releases/picture/'
49
+ /** the hub path a picture shows by: a private one through the hub, a public one as it is */
50
+ export const pictureRoute = (url: string): string => (url.startsWith(SPACE) ? `${PICTURE_ROUTE}${encodeURIComponent(url.slice(SPACE.length))}` : url)
51
+
52
+ const VERSION = /^\d+\.\d+\.\d+$/
53
+ const HEAD = /^# (next|\d+\.\d+\.\d+)(?: \((major|minor|patch)\))?(?:: (.*))?$/
54
+ const DATE = /^\d{4}-\d{2}-\d{2}$/
55
+ const PICTURE = /^!\[([^\]]*)\]\((\S+)\)$/
56
+ const MARK = /^<!--\s*(?:card:\s*(\S+))?\s*(?:commit:\s*([0-9a-f]{7,40}))?\s*-->$/
57
+ const BULLET = /^[-*] (.*)$/
58
+
59
+ export const isVersion = (v: string): boolean => v === NEXT || VERSION.test(v)
60
+ export const fileOf = (version: string): string => `${version}.md`
61
+
62
+ export const emptyRelease = (): Release => ({ version: NEXT, kind: null, title: '', date: null, categories: [] })
63
+
64
+ /** a release file read into its parts; a line out of place throws naming it */
65
+ export function parseRelease(md: string, name = 'release'): Release {
66
+ const at = (i: number, why: string): Error => new Error(`${name}:${i + 1}: ${why}`)
67
+ let r: Release | null = null
68
+ let cat: Category | null = null
69
+ let ch: Change | null = null
70
+ let comment = false
71
+ let text: string[] = []
72
+ const close = (): void => {
73
+ if (ch) ch.text = text.join('\n').trim()
74
+ text = []
75
+ }
76
+ for (const [i, raw] of md.split('\n').entries()) {
77
+ const line = raw.trimEnd()
78
+ if (comment) {
79
+ comment = !line.includes('-->')
80
+ continue
81
+ }
82
+ if (r == null) {
83
+ if (line === '') continue
84
+ // a file comment before the heading says what the file is for, never a public word
85
+ if (line.startsWith('<!--')) {
86
+ comment = !line.includes('-->')
87
+ continue
88
+ }
89
+ const h = HEAD.exec(line)
90
+ if (!h) throw at(i, `the file opens on "# <version>: <title>" or "# next (<kind>): <title>", not: ${line}`)
91
+ if (h[1] !== NEXT && h[2]) throw at(i, 'a released version says no kind: only next does')
92
+ r = { version: h[1]!, kind: (h[2] as ReleaseKind | undefined) ?? null, title: (h[3] ?? '').trim(), date: null, categories: [] }
93
+ continue
94
+ }
95
+ if (line.startsWith('## ')) {
96
+ close()
97
+ ch = null
98
+ cat = { name: line.slice(3).trim(), changes: [] }
99
+ r.categories.push(cat)
100
+ continue
101
+ }
102
+ if (line.startsWith('### ')) {
103
+ if (!cat) throw at(i, `a change sits under a "## <category>": ${line}`)
104
+ close()
105
+ ch = { title: line.slice(4).trim(), text: '', picture: null, bullets: [], card: null, commit: null }
106
+ cat.changes.push(ch)
107
+ continue
108
+ }
109
+ if (line.startsWith('#')) throw at(i, `one "# " heading a file, then "## <category>" and "### <change>": ${line}`)
110
+ if (!cat) {
111
+ if (line === '') continue
112
+ if (DATE.test(line) && r.date == null && r.version !== NEXT) {
113
+ r.date = line
114
+ continue
115
+ }
116
+ throw at(i, `before the first "## <category>" only the date line of a released version: ${line}`)
117
+ }
118
+ if (!ch) {
119
+ if (line === '') continue
120
+ throw at(i, `under "## ${cat.name}" every line belongs to a "### <change>": ${line}`)
121
+ }
122
+ const m = MARK.exec(line)
123
+ if (m && (m[1] || m[2])) {
124
+ ch.card = m[1] ?? ch.card
125
+ ch.commit = m[2] ?? ch.commit
126
+ continue
127
+ }
128
+ if (line.startsWith('<!--')) throw at(i, `a hidden line of a change is "<!-- card: <id> commit: <sha> -->": ${line}`)
129
+ const p = PICTURE.exec(line)
130
+ if (p) {
131
+ if (ch.picture) throw at(i, `"${ch.title}" has one picture`)
132
+ ch.picture = { alt: p[1]!.trim(), url: p[2]! }
133
+ continue
134
+ }
135
+ const b = BULLET.exec(line)
136
+ if (b) {
137
+ ch.bullets.push(b[1]!.trim())
138
+ continue
139
+ }
140
+ if (ch.bullets.length > 0 && line !== '') throw at(i, `"${ch.title}": its description comes before its bullets: ${line}`)
141
+ text.push(line)
142
+ }
143
+ close()
144
+ if (r == null) throw new Error(`${name}: empty, it opens on "# <version>: <title>"`)
145
+ if (r.version !== NEXT && r.date == null) throw new Error(`${name}: a released version carries its date on the line under its heading`)
146
+ return r
147
+ }
148
+
149
+ /** the file's text, in the one order the parser reads: heading, date, then each category and its changes */
150
+ export function renderRelease(r: Release): string {
151
+ const kind = r.kind && r.version === NEXT ? ` (${r.kind})` : ''
152
+ const out = [`# ${r.version}${kind}${r.title ? `: ${r.title}` : ''}`]
153
+ if (r.date) out.push(r.date)
154
+ for (const c of r.categories) {
155
+ out.push('', `## ${c.name}`)
156
+ for (const ch of c.changes) {
157
+ out.push('', `### ${ch.title}`)
158
+ if (ch.card || ch.commit) out.push(`<!--${ch.card ? ` card: ${ch.card}` : ''}${ch.commit ? ` commit: ${ch.commit}` : ''} -->`)
159
+ if (ch.text) out.push(ch.text)
160
+ if (ch.picture) out.push(`![${ch.picture.alt}](${ch.picture.url})`)
161
+ for (const b of ch.bullets) out.push(`- ${b}`)
162
+ }
163
+ }
164
+ return `${out.join('\n')}\n`
165
+ }
166
+
167
+ /** next with one change added under its category: the change of the same card, else of the same title in that
168
+ * category, replaced in place (a card's category can move); a new category goes last */
169
+ export function upsertChange(r: Release, category: string, change: Change): Release {
170
+ const name = category.trim()
171
+ if (name === '') throw new Error('a change needs its category')
172
+ if (change.title.trim() === '') throw new Error('a change needs its title')
173
+ const same = (c: Category, x: Change): boolean => (change.card != null && x.card === change.card) || (c.name === name && x.title === change.title)
174
+ const cats = r.categories.map((c) => ({ ...c, changes: [...c.changes] }))
175
+ let placed = false
176
+ for (const c of cats) {
177
+ const i = c.changes.findIndex((x) => same(c, x))
178
+ if (i === -1) continue
179
+ if (c.name === name && !placed) {
180
+ c.changes[i] = change
181
+ placed = true
182
+ } else c.changes.splice(i, 1)
183
+ }
184
+ if (!placed) {
185
+ let c = cats.find((x) => x.name === name)
186
+ if (!c) cats.push((c = { name, changes: [] }))
187
+ c.changes.push(change)
188
+ }
189
+ return { ...r, categories: cats.filter((c) => c.changes.length > 0) }
190
+ }
191
+
192
+ export const changesOf = (r: Release): Change[] => r.categories.flatMap((c) => c.changes)
193
+
194
+ /** a card id's words: its slug, made from the card's title, which a public repo's file carries in its hidden comment */
195
+ const cardWords = (id: string | null): string => (id ?? '').replace(/^\d{8}-\d{6}-?/, '').replace(/-/g, ' ')
196
+
197
+ /** every word of a release that a stranger reads, each a text the repo's guard runs on. The card ids' slugs only when
198
+ * the file itself is public (a declared public repo): the notes, the post and the page never show the hidden comment */
199
+ export const publicTexts = (r: Release, o: { fileIsPublic?: boolean } = {}): string[] =>
200
+ [r.title, ...r.categories.flatMap((c) => [c.name, ...c.changes.flatMap((ch) => [ch.title, ch.text, ch.picture?.alt ?? '', ...ch.bullets, o.fileIsPublic ? cardWords(ch.card) : ''])])].filter((t) => t.trim() !== '')
201
+
202
+ /** next named as a version, dated */
203
+ export function promoted(r: Release, version: string, date: string): Release {
204
+ if (r.version !== NEXT) throw new Error(`${r.version} is released already: only next becomes a version`)
205
+ if (!VERSION.test(version)) throw new Error(`${version}: a release is X.Y.Z`)
206
+ if (changesOf(r).length === 0) throw new Error(`${fileOf(NEXT)} holds no change: write what changed, then bump`)
207
+ return { ...r, version, kind: null, date }
208
+ }
209
+
210
+ const newer = (a: string, b: string): number => {
211
+ const [x, y] = [a.split('.').map(Number), b.split('.').map(Number)]
212
+ return y[0]! - x[0]! || y[1]! - x[1]! || y[2]! - x[2]!
213
+ }
214
+
215
+ /** versions newest first, next on top */
216
+ export const byVersion = (a: string, b: string): number => (a === NEXT ? -1 : b === NEXT ? 1 : newer(a, b))
217
+
218
+ /** one release as notes: each category a `### `, each change a bullet of its title and description, its picture, its
219
+ * own bullets under it. A GitHub release, the staged post and CHANGELOG.md read this */
220
+ export function notesOf(r: Release): string {
221
+ const out: string[] = []
222
+ for (const c of r.categories) {
223
+ out.push(`### ${c.name}`, '')
224
+ for (const ch of c.changes) {
225
+ out.push(`- **${ch.title}**${ch.text ? `: ${ch.text.replace(/\s*\n\s*/g, ' ')}` : ''}`)
226
+ if (ch.picture && !isPrivate(ch.picture)) out.push(` ![${ch.picture.alt}](${ch.picture.url})`)
227
+ for (const b of ch.bullets) out.push(` - ${b}`)
228
+ }
229
+ out.push('')
230
+ }
231
+ return out.join('\n').trim()
232
+ }
233
+
234
+ const OLD_SECTION = /^##\s*\[?(\d+\.\d+\.\d+)\]?/
235
+
236
+ /** the `## <version>` sections of a CHANGELOG, each its version and its text */
237
+ function sectionsOf(changelog: string): { version: string; text: string }[] {
238
+ const out: { version: string; text: string }[] = []
239
+ let cur: { version: string; lines: string[] } | null = null
240
+ const close = (): void => void (cur && out.push({ version: cur.version, text: cur.lines.join('\n').trim() }))
241
+ for (const line of changelog.split('\n')) {
242
+ if (line.startsWith('## ')) {
243
+ close()
244
+ const m = OLD_SECTION.exec(line)
245
+ cur = m ? { version: m[1]!, lines: [line] } : null
246
+ continue
247
+ }
248
+ cur?.lines.push(line)
249
+ }
250
+ close()
251
+ return out
252
+ }
253
+
254
+ /** CHANGELOG.md for a unit that publishes to npm, made from its release files: never edited by hand. Every section of
255
+ * the CHANGELOG `before` whose version has no release file is kept as it was written, so the history from before the
256
+ * release files stays; an Unreleased section is not kept (notes.ts refuses a bump while it holds notes) */
257
+ export function changelogOf(releases: readonly Release[], before = ''): string {
258
+ const done = releases.filter((r) => r.version !== NEXT)
259
+ const have = new Set(done.map((r) => r.version))
260
+ const sections = [
261
+ ...done.map((r) => ({ version: r.version, text: `## ${r.version} (${r.date})${r.title ? `: ${r.title}` : ''}\n\n${notesOf(r)}` })),
262
+ ...sectionsOf(before).filter((s) => !have.has(s.version)),
263
+ ].sort((a, b) => byVersion(a.version, b.version))
264
+ const out = ['# Changelog', '', '<!-- made from .shipkit/releases/ by sk bump: edit those files, never this one -->']
265
+ for (const s of sections) out.push('', s.text)
266
+ return `${out.join('\n')}\n`
267
+ }
@@ -0,0 +1,89 @@
1
+ // a change's picture in the Space (wiki tools/shipkit/units.md, The release files): kept PRIVATE when the change is
2
+ // written, by its content, its metadata stripped, a copy in the scratch so the hub and the release read it with no
3
+ // download; made public only when its version ships, after the repo's guard read its bytes. A public URL is out for good
4
+ // once fetched, so nothing unreleased ever gets one
5
+ import { copyFileSync, existsSync, mkdirSync, renameSync, writeFileSync } from 'node:fs'
6
+ import { extname, join } from 'node:path'
7
+ import { LAYOUT } from '../core/layout.ts'
8
+ import { shaOf, shaOfKey } from '../media-store/content.ts'
9
+ import { linkMedia, putMedia } from '../media-store/put.ts'
10
+ import { stripCopy } from '../social/strip.ts'
11
+ import { guardWith, type SocialUnit } from '../social/unit.ts'
12
+ import { isPrivate, SPACE, spaceKey, type Release } from './model.ts'
13
+
14
+ /** the media store's label of every release picture, private and public */
15
+ export const RELEASE_KIND = 'release'
16
+
17
+ const STRIPPED = new Set(['.png', '.jpg', '.jpeg', '.webp', '.mp4', '.mov', '.webm'])
18
+
19
+ /** the scratch copy of the pictures, by their sha: never tracked, made again from the Space when gone */
20
+ export const picturesDir = (root: string): string => join(root, LAYOUT.tmp, 'releases')
21
+
22
+ const copyOf = (root: string, sha: string, ext: string): string => join(picturesDir(root), `${sha}${ext}`)
23
+
24
+ /** a file kept as a release picture: stripped, copied by its sha, up to the Space private; its `space:<key>` url */
25
+ export async function keepPicture(root: string, file: string): Promise<string> {
26
+ const ext = extname(file).toLowerCase()
27
+ if (!STRIPPED.has(ext)) throw new Error(`${file}: a release picture is a png, jpg, webp or a clip (mp4, mov, webm)`)
28
+ mkdirSync(picturesDir(root), { recursive: true })
29
+ const tmp = join(picturesDir(root), `.in-${process.pid}${ext}`)
30
+ stripCopy(file, tmp)
31
+ const at = copyOf(root, await shaOf(tmp), ext)
32
+ renameSync(tmp, at)
33
+ const p = await putMedia(at, { kind: RELEASE_KIND })
34
+ return `${SPACE}${p.key}`
35
+ }
36
+
37
+ /** the local file of a kept picture: its scratch copy, else fetched back from the Space into it */
38
+ export async function pictureFile(root: string, key: string): Promise<string> {
39
+ const sha = shaOfKey(key)
40
+ if (sha == null) throw new Error(`${key}: no key of the media store`)
41
+ const at = copyOf(root, sha, extname(key))
42
+ if (existsSync(at)) return at
43
+ const link = await linkMedia(key, { seconds: 300 })
44
+ const r = await fetch(link.url)
45
+ if (!r.ok) throw new Error(`${key}: the Space answered ${r.status}`)
46
+ mkdirSync(picturesDir(root), { recursive: true })
47
+ writeFileSync(at, Buffer.from(await r.arrayBuffer()))
48
+ return at
49
+ }
50
+
51
+ /** a signed link for the hub to show a private picture, or its public URL as it is */
52
+ export async function shownUrl(url: string): Promise<string> {
53
+ const key = url.startsWith(SPACE) ? url.slice(SPACE.length) : null
54
+ return key == null ? url : (await linkMedia(key, { seconds: 3600 })).url
55
+ }
56
+
57
+ /** every private picture of a release made public, each after the repo's guard read its bytes: the release with its
58
+ * public URLs. A refusal throws naming the change, and nothing is made public before every picture passed */
59
+ export async function publishPictures(root: string, r: Release, unit: SocialUnit | null): Promise<{ release: Release; published: number }> {
60
+ const todo = r.categories.flatMap((c) => c.changes).filter((ch) => ch.picture && isPrivate(ch.picture))
61
+ const files = new Map<string, string>()
62
+ for (const ch of todo) {
63
+ const key = spaceKey(ch.picture!)!
64
+ const file = await pictureFile(root, key)
65
+ const problems = guardWith(unit, { title: ch.title, alt: ch.picture!.alt, files: [file] })
66
+ if (problems.length > 0) throw new Error(`"${ch.title}": the repo's guard refuses its picture: ${problems.join('; ')}`)
67
+ files.set(key, file)
68
+ }
69
+ const urls = new Map<string, string>()
70
+ for (const [key, file] of files) {
71
+ // the public copy is put from its own name, so its index row never takes the private one's place
72
+ const pub = join(picturesDir(root), `public-${shaOfKey(key)}${extname(key)}`)
73
+ copyFileSync(file, pub)
74
+ const p = await putMedia(pub, { kind: RELEASE_KIND, public: true })
75
+ if (!p.url) throw new Error(`${key}: the Space gave no public URL`)
76
+ urls.set(key, p.url)
77
+ }
78
+ const release: Release = {
79
+ ...r,
80
+ categories: r.categories.map((c) => ({
81
+ ...c,
82
+ changes: c.changes.map((ch) => {
83
+ const key = ch.picture ? spaceKey(ch.picture) : null
84
+ return key && urls.has(key) ? { ...ch, picture: { ...ch.picture!, url: urls.get(key)! } } : ch
85
+ }),
86
+ })),
87
+ }
88
+ return { release, published: urls.size }
89
+ }
@@ -0,0 +1,36 @@
1
+ // the releases page's routes (wiki tools/shipkit/units.md, The release files): every release file read fresh, and a
2
+ // private picture shown from its scratch copy, else through a signed link of the Space. Read only: the files are
3
+ // written by an approval, `sk releases add` or a hand
4
+ import { existsSync } from 'node:fs'
5
+ import { extname, join } from 'node:path'
6
+ import { shaOfKey } from '../media-store/content.ts'
7
+ import { bad, NO_STORE, ranged } from '../review/http.ts'
8
+ import { PICTURE_ROUTE, type Release } from './model.ts'
9
+ import { picturesDir, shownUrl } from './pictures.ts'
10
+ import { readReleases } from './store.ts'
11
+
12
+ /** what the page reads: every release, next first, and each file that does not parse */
13
+ export interface ReleasesView {
14
+ releases: Release[]
15
+ errors: string[]
16
+ }
17
+
18
+ /** the releases routes of the repo at `root`; null for any other path */
19
+ export async function releasesRoutes(root: string, req: Request, path: string): Promise<Response | null> {
20
+ if (path !== '/api/releases' && !path.startsWith('/api/releases/')) return null
21
+ if (req.method !== 'GET') return bad(`releases: no route ${req.method} ${path}`, 404)
22
+ try {
23
+ if (path === '/api/releases') return Response.json(readReleases(root) satisfies ReleasesView, { headers: NO_STORE })
24
+ if (path.startsWith(PICTURE_ROUTE)) {
25
+ const key = decodeURIComponent(path.slice(PICTURE_ROUTE.length))
26
+ const sha = shaOfKey(key)
27
+ if (sha == null || !key.startsWith('release/')) return bad(`${key}: no release picture`, 404)
28
+ const local = join(picturesDir(root), `${sha}${extname(key)}`)
29
+ if (existsSync(local)) return ranged(req, local)
30
+ return Response.redirect(await shownUrl(`space:${key}`), 302)
31
+ }
32
+ return bad(`releases: no route ${path}`, 404)
33
+ } catch (e) {
34
+ return bad(e, 500)
35
+ }
36
+ }
@@ -0,0 +1,71 @@
1
+ // the release files on the disk (wiki tools/shipkit/units.md, The release files): `.shipkit/releases/next.md` and one
2
+ // `<version>.md` a released version, read, written, and a change added to next. Pictures: pictures.ts
3
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from 'node:fs'
4
+ import { join } from 'node:path'
5
+ import { atomicWrite } from '../core/locked-write.ts'
6
+ import { LAYOUT } from '../core/layout.ts'
7
+ import { byVersion, emptyRelease, fileOf, NEXT, parseRelease, renderRelease, upsertChange, type Change, type Release } from './model.ts'
8
+
9
+ const FILE = /^(next|\d+\.\d+\.\d+)\.md$/
10
+
11
+ export const releasesDir = (root: string): string => join(root, LAYOUT.releases)
12
+
13
+ /** why this repo keeps no release files, null when it declares them (`release: { releases: true }`): declared, never
14
+ * inferred, so a card's approval never starts a folder that would take over the repo's CHANGELOG */
15
+ export async function undeclaredReleases(root: string): Promise<string | null> {
16
+ const { loadRepoConfig } = await import('../repo-config.ts')
17
+ const c = await loadRepoConfig(root)
18
+ return c.release?.releases === true ? null : `${c.name ?? 'this repo'} keeps no release files: add \`release: { releases: true }\` to repo.config.ts first (wiki tools/shipkit/units.md, The release files)`
19
+ }
20
+ export const hasReleases = (root: string): boolean => existsSync(releasesDir(root))
21
+ export const releaseFile = (root: string, version: string): string => join(releasesDir(root), fileOf(version))
22
+
23
+ /** the versions the folder holds a file for, next first, then newest first */
24
+ export function releaseVersions(root: string): string[] {
25
+ const dir = releasesDir(root)
26
+ if (!existsSync(dir)) return []
27
+ return readdirSync(dir)
28
+ .map((f) => FILE.exec(f)?.[1])
29
+ .filter((v): v is string => v != null)
30
+ .sort(byVersion)
31
+ }
32
+
33
+ /** one release file, parsed; null when there is none */
34
+ export function readRelease(root: string, version: string): Release | null {
35
+ const f = releaseFile(root, version)
36
+ if (!existsSync(f)) return null
37
+ const r = parseRelease(readFileSync(f, 'utf8'), `${LAYOUT.releases}/${fileOf(version)}`)
38
+ if (r.version !== version) throw new Error(`${LAYOUT.releases}/${fileOf(version)} opens on "# ${r.version}": a file is named after its version`)
39
+ return r
40
+ }
41
+
42
+ /** every release file, each parsed, and the ones that do not parse as one error each */
43
+ export function readReleases(root: string): { releases: Release[]; errors: string[] } {
44
+ const releases: Release[] = []
45
+ const errors: string[] = []
46
+ for (const v of releaseVersions(root)) {
47
+ try {
48
+ releases.push(readRelease(root, v)!)
49
+ } catch (e) {
50
+ errors.push((e as Error).message)
51
+ }
52
+ }
53
+ return { releases, errors }
54
+ }
55
+
56
+ /** a release written as its file; the absolute path */
57
+ export function writeRelease(root: string, r: Release): string {
58
+ mkdirSync(releasesDir(root), { recursive: true })
59
+ const f = releaseFile(root, r.version)
60
+ atomicWrite(f, renderRelease(r))
61
+ return f
62
+ }
63
+
64
+ export const removeRelease = (root: string, version: string): void => rmSync(releaseFile(root, version), { force: true })
65
+
66
+ /** one change added to next, or put in place of the one of the same card (else of the same title in its category);
67
+ * next.md is made when there is none */
68
+ export function addChange(root: string, category: string, change: Change): { release: Release; file: string } {
69
+ const release = upsertChange(readRelease(root, NEXT) ?? emptyRelease(), category, change)
70
+ return { release, file: writeRelease(root, release) }
71
+ }
@@ -76,6 +76,11 @@ export type ServeConfig = {
76
76
  * media store (review cards, trailer cuts...), read only in the house
77
77
  * config; its key pair read through `credsReadCommand` */
78
78
  mediaSpace?: import('./media-store/space.ts').MediaSpace
79
+ /** folders on external drives for the machine's heavy files, never a db,
80
+ * in order, read only in the house config: the purge moves media there,
81
+ * `sk annex offload` moves scratch there behind a symlink. Present only
82
+ * while `sk annex init` marked the root (wiki tools/shipkit/annex.md) */
83
+ annexes?: import('./annex/annex.ts').AnnexSpec[]
79
84
  /** the secret whose value is a Cloudflare API token, read through
80
85
  * `credsReadCommand`, only in the house config: the site desk asks Pages
81
86
  * for a site's last production deployment with it */
@@ -10,7 +10,6 @@ import {
10
10
  moveOf,
11
11
  partyOf,
12
12
  reworkOf,
13
- isPostSubject,
14
13
  stateOf,
15
14
  STATUS_LABEL,
16
15
  thumbFileOf,
@@ -139,8 +138,6 @@ export interface ThreadView {
139
138
  /** the media files a view names that the store no longer holds, `<item id>/<name>`: the page says so in place of a
140
139
  * broken player (the routes fill it, the model never reads the disk) */
141
140
  missing: string[]
142
- /** the posts he asked from this card (« 📣 post »), oldest first, each with where it stands */
143
- posts: { id: string; state: ItemState }[]
144
141
  /** the social drafts naming this card in their `review:`, oldest first (the routes fill it, the model never reads the disk) */
145
142
  drafts: { slug: string; title: string }[]
146
143
  cells: Cell[]
@@ -305,13 +302,6 @@ export function threadOfId(id: string, threads: readonly Thread[]): Thread | nul
305
302
  return holding.sort((a, b) => b.head.item.created.localeCompare(a.head.item.created))[0] ?? null
306
303
  }
307
304
 
308
- /** the post requests naming one of these items as their card */
309
- const postsOf = (ids: ReadonlySet<string>, items: readonly ReviewItem[], followed: ReadonlySet<string>): ThreadView['posts'] =>
310
- items
311
- .filter((x) => isPostSubject(x.item.subject) && ids.has(x.item.subject.card))
312
- .sort((a, b) => a.item.created.localeCompare(b.item.created))
313
- .map((x) => ({ id: x.item.id, state: stateOf(x, followed.has(x.item.id)) }))
314
-
315
305
  /** one thread for the per card api; `asked` the id the caller named (an old version opens at its cell) */
316
306
  export function threadView(t: Thread, items: readonly ReviewItem[], threads: readonly Thread[], asked: string, now = new Date()): ThreadView {
317
307
  const h = t.head
@@ -342,7 +332,6 @@ export function threadView(t: Thread, items: readonly ReviewItem[], threads: rea
342
332
  .filter((x) => unreadBy(x, 'owner').length > 0)
343
333
  .map((x) => x.item.id),
344
334
  missing: [],
345
- posts: postsOf(new Set(idsOf(t)), items, followed),
346
335
  drafts: [],
347
336
  cells: cellsOf(t, items),
348
337
  }
@@ -14,8 +14,10 @@ const PLAIN: Say = { spec: NO_SPEC, more: () => [] }
14
14
 
15
15
  const flat = (t: string): string => t.replace(/\s+/g, ' ').trim()
16
16
 
17
- /** a rectangle's clip time, ` at 1.25 s`; nothing on an image */
18
- const atText = (t: number | undefined): string => (t === undefined ? '' : ` at ${t.toFixed(2)} s`)
17
+ /** a rectangle's clip time, ` at 1.25 s`, and on a trailer card's frame its shot, ` (shot dress +1.20 s)`; nothing on
18
+ * an image */
19
+ const atText = (t: number | undefined, shot?: Rect['shot']): string =>
20
+ (t === undefined ? '' : ` at ${t.toFixed(2)} s`) + (shot ? ` (shot ${shot.name} +${shot.time.toFixed(2)} s)` : '')
19
21
 
20
22
  /** each reaction to one view or tile: its place by label, its status, its comment */
21
23
  const reactionTexts = (x: ReviewItem): string[] =>
@@ -33,7 +35,7 @@ export function line(x: ReviewItem): string {
33
35
  if (!f) return x.item.id
34
36
  const views = x.item.views
35
37
  const many = views.length > 1
36
- const rects = f.rects.map((q, i) => `#${i + 1}${many || q.tile !== undefined ? ` ${placeText(q, views)}` : ''}${q.side ? ` ${q.side}` : ''}${atText(q.t)} ${flat(q.comment) || '(no comment)'}`)
38
+ const rects = f.rects.map((q, i) => `#${i + 1}${many || q.tile !== undefined ? ` ${placeText(q, views)}` : ''}${q.side ? ` ${q.side}` : ''}${atText(q.t, q.shot)} ${flat(q.comment) || '(no comment)'}`)
37
39
  const pick = pickText(x)
38
40
  const parts = [...(pick ? [pick] : []), ...reactionTexts(x), ...rects]
39
41
  return `${x.item.id} ${f.status} "${x.item.title}": ${flat(f.comment) || '(no overall comment)'}${parts.length ? ` | ${parts.join(' | ')}` : ''}`
@@ -145,12 +147,14 @@ export function detail(x: ReviewItem, dir: string, full = false, followed = fals
145
147
  const views = r.views
146
148
  f.rects.forEach((q, i) => {
147
149
  const v = views[q.view ?? 0] ?? views[0]
148
- const size = v && !isGallery(v) ? v.size : { w: 0, h: 0 }
150
+ // a trailer card's rectangles sit on the cut's frame, not on the strip its view keeps
151
+ const frame = (q.view ?? 0) === 0 ? r.trailer?.size : undefined
152
+ const size = frame ? { w: frame[0], h: frame[1] } : v && !isGallery(v) ? v.size : { w: 0, h: 0 }
149
153
  const on = views.length > 1 ? ` ${placeText(q, views)}` : ''
150
- const side = v && !isGallery(v) && isPair(v.files) ? ` ${q.side ?? '?'}` : ''
154
+ const side = (v && !isGallery(v) && isPair(v.files)) || q.side ? ` ${q.side ?? '?'}` : ''
151
155
  const norm = `${q.x.toFixed(3)},${q.y.toFixed(3)} ${q.w.toFixed(3)}x${q.h.toFixed(3)}`
152
156
  const pix = `${px(q.x, size.w)},${px(q.y, size.h)} ${px(q.w, size.w)}x${px(q.h, size.h)} px`
153
- out.push(` #${i + 1}${on}${side} ${norm} (${pix})${atText(q.t)}: ${q.comment || '(no comment)'}`)
157
+ out.push(` #${i + 1}${on}${side} ${norm} (${pix})${atText(q.t, q.shot)}: ${q.comment || '(no comment)'}`)
154
158
  })
155
159
  const files = views.flatMap((v) => (isGallery(v) ? v.gallery.map((t) => t.file) : Object.values(v.files)))
156
160
  out.push(` files: ${files.map((n) => `${dir}/${r.id}/${n}`).join(' ')}`, ...replies)