rvlib-shipkit 2.18.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.
- package/CHANGELOG.md +31 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/asks/asks-queue.ts +63 -10
- 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_Asks.ts +3 -1
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_GlobalProcesses.ts +34 -11
- package/src/cli/cmd_Home.ts +41 -4
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Releases.ts +48 -0
- package/src/cli/cmd_Review.ts +161 -6
- package/src/cli/cmd_Secret.ts +4 -30
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +179 -3
- package/src/cli/cmd_Trailer.ts +15 -3
- 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 +8 -2
- package/src/collections/actions.ts +29 -1
- package/src/collections/collection-types.ts +10 -1
- package/src/collections/providers.ts +5 -2
- 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 +5 -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 +302 -5
- package/src/home/gui-app.ts +63 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-paths.ts +5 -1
- package/src/home/home-start.ts +14 -14
- package/src/home/lib-watch.ts +21 -11
- 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-daemon.ts +11 -2
- package/src/home/run-pm.ts +9 -1
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/home/supervise.ts +3 -1
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +130 -11
- 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 +180 -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 +66 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +66 -0
- package/src/releases/model.ts +267 -0
- package/src/releases/pictures.ts +89 -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 +7 -2
- package/src/review/model.ts +92 -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 +117 -19
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +57 -4
- package/src/review/trailer-model.ts +41 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +22 -13
- package/src/secrets/manager.ts +59 -0
- package/src/secrets/name.ts +2 -0
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/col-card.tsx +10 -0
- package/src/serve/hub-app/cols-svc.ts +37 -6
- 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 +40 -1
- package/src/serve/hub-app/home-st.ts +11 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +6 -0
- package/src/serve/hub-app/hub.css +1 -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/releases/releases-page.tsx +94 -0
- package/src/serve/hub-app/releases/releases-st.ts +69 -0
- package/src/serve/hub-app/releases.css +25 -0
- package/src/serve/hub-app/repo-sections.ts +15 -1
- package/src/serve/hub-app/repo-st.ts +56 -5
- package/src/serve/hub-app/review/clip-st.ts +31 -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 +62 -31
- package/src/serve/hub-app/review/trailer-st.ts +138 -26
- package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
- package/src/serve/hub-app/review.css +49 -6
- package/src/serve/hub-app/social/comms-page.tsx +55 -23
- package/src/serve/hub-app/social/identity-pictures.ts +112 -0
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +37 -3
- package/src/serve/hub-app/social/social-page.tsx +236 -82
- package/src/serve/hub-app/social/social-st.ts +79 -26
- 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 -4
- package/src/serve/hub-app/tree-build.ts +38 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +27 -3
- package/src/shipkit-files.ts +9 -7
- package/src/shot/shooter.ts +3 -3
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/discord-layout.ts +282 -0
- 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 +92 -0
- package/src/social/load.ts +105 -9
- package/src/social/md.ts +14 -6
- 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/discord.ts +3 -2
- package/src/social/publish/index.ts +31 -5
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +173 -0
- package/src/social/routes.ts +44 -9
- package/src/social/stage.ts +227 -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/stores/routes.ts +2 -2
- package/src/suite/judge-suites.ts +1 -1
- package/src/suite/suite-cli.ts +5 -5
- package/src/trailer/build.ts +90 -52
- package/src/trailer/draft.ts +28 -0
- package/src/trailer/footage.ts +4 -2
- package/src/trailer/grammar.ts +25 -13
- package/src/trailer/graph.ts +32 -9
- package/src/trailer/profile.ts +35 -0
- package/src/trailer/prune.ts +15 -10
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/stitch.ts +22 -10
- package/src/trailer/titles.ts +47 -2
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// check context, so a check reading units stays keyed on what it read.
|
|
4
4
|
import { basename, isAbsolute, join, relative } from 'path'
|
|
5
5
|
import type { CheckCtx } from '../core/check-ctx.ts'
|
|
6
|
+
import { LAYOUT } from '../core/layout.ts'
|
|
6
7
|
import type { RepoConfig } from '../repo-config.ts'
|
|
7
8
|
import type { TestsConfig } from '../suite/judge-suites.ts'
|
|
8
9
|
|
|
@@ -90,6 +91,9 @@ export type ReleaseUnit = {
|
|
|
90
91
|
version: string
|
|
91
92
|
/** absolute path to the versioned changelog */
|
|
92
93
|
changelog: string
|
|
94
|
+
/** the root unit's release files (`.shipkit/releases/`), absolute, when the folder exists: then its notes are those
|
|
95
|
+
* files and CHANGELOG.md is made from them (releases/model.ts); null for a sub-unit and for a repo without one */
|
|
96
|
+
releases: string | null
|
|
93
97
|
/** tag template, `{name}` and `{version}` unsubstituted — bump renders the NEXT tag from it */
|
|
94
98
|
tagTemplate: string
|
|
95
99
|
/** rendered tag for the current version */
|
|
@@ -168,6 +172,7 @@ export function resolveUnits(root: string, config: RepoConfig, io: UnitReader):
|
|
|
168
172
|
undeclaredFix: 'add `release: { npm: true }` to repo.config.ts to publish it',
|
|
169
173
|
githubRelease: rc.githubRelease ?? true,
|
|
170
174
|
tsconfigRel: rc.tsconfig,
|
|
175
|
+
releases: rc.releases === true,
|
|
171
176
|
checkFolderName: false,
|
|
172
177
|
io,
|
|
173
178
|
})
|
|
@@ -205,6 +210,7 @@ export function resolveUnits(root: string, config: RepoConfig, io: UnitReader):
|
|
|
205
210
|
undeclaredFix: 'add `npm: true` to this units[] entry to publish it',
|
|
206
211
|
githubRelease: decl.githubRelease ?? false,
|
|
207
212
|
tsconfigRel: decl.tsconfig,
|
|
213
|
+
releases: false,
|
|
208
214
|
// only the DEFAULT tag renders the package name into a git tag, so
|
|
209
215
|
// only there does the folder have to agree with it
|
|
210
216
|
checkFolderName: decl.tag == null,
|
|
@@ -229,6 +235,8 @@ function build(p: {
|
|
|
229
235
|
undeclaredFix: string
|
|
230
236
|
githubRelease: boolean
|
|
231
237
|
tsconfigRel: string | undefined
|
|
238
|
+
/** the root's notes are the release files (`release.releases`) */
|
|
239
|
+
releases: boolean
|
|
232
240
|
checkFolderName: boolean
|
|
233
241
|
io: UnitReader
|
|
234
242
|
}): { unit: ReleaseUnit } | { error: UnitError[] } {
|
|
@@ -265,6 +273,7 @@ function build(p: {
|
|
|
265
273
|
name,
|
|
266
274
|
version,
|
|
267
275
|
changelog: join(p.root, p.changelogRel),
|
|
276
|
+
releases: p.releases ? join(p.root, LAYOUT.releases) : null,
|
|
268
277
|
tagTemplate: p.tagTemplate,
|
|
269
278
|
tag: render(p.tagTemplate, { name, version }),
|
|
270
279
|
tagGlob: render(p.tagTemplate, { name, version: '*' }),
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// `sk releases add`: one change of next.md written by hand, or a card's change written again (wiki tools/shipkit/units.md,
|
|
2
|
+
// The release files). What a hand does not give is kept from the change it replaces; the repo's guard reads every word
|
|
3
|
+
// before the file holds it, and the write is committed by pathspec
|
|
4
|
+
import { itemOfRef, storeDir } from '../review/store.ts'
|
|
5
|
+
import { publicProblems } from '../social/unit.ts'
|
|
6
|
+
import { commitPaths } from '../social/writes.ts'
|
|
7
|
+
import { cardParts, versionsOf } from './from-card.ts'
|
|
8
|
+
import { changesOf, emptyRelease, NEXT, type Change, type ReleaseKind } from './model.ts'
|
|
9
|
+
import { keepPicture } from './pictures.ts'
|
|
10
|
+
import { addChange, readRelease, undeclaredReleases, writeRelease } from './store.ts'
|
|
11
|
+
|
|
12
|
+
export interface AddAsk {
|
|
13
|
+
category?: string
|
|
14
|
+
title?: string
|
|
15
|
+
text?: string
|
|
16
|
+
bullets?: string[]
|
|
17
|
+
image?: string
|
|
18
|
+
card?: string
|
|
19
|
+
commit?: string
|
|
20
|
+
kind?: string
|
|
21
|
+
heading?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const KINDS: readonly string[] = ['major', 'minor', 'patch']
|
|
25
|
+
|
|
26
|
+
async function guarded(root: string, what: string, texts: string[]): Promise<void> {
|
|
27
|
+
const problems = await publicProblems(root, { texts: texts.filter((t) => t.trim() !== '') })
|
|
28
|
+
if (problems.length > 0) throw new Error(`${what}: the repo's guard refuses it: ${problems.join('; ')}`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** next.md written with the ask: its kind and title, and one change; the file written */
|
|
32
|
+
export async function addByHand(root: string, a: AddAsk): Promise<string> {
|
|
33
|
+
if (a.kind !== undefined && !KINDS.includes(a.kind)) throw new Error(`--kind ${a.kind}: major, minor or patch`)
|
|
34
|
+
const change = a.category !== undefined || a.title !== undefined || a.card !== undefined
|
|
35
|
+
if (!change && a.kind === undefined && a.heading === undefined) throw new Error('nothing to write: a change (a category and a title, or --card), or --kind, or --release-title')
|
|
36
|
+
const why = await undeclaredReleases(root)
|
|
37
|
+
if (why) throw new Error(why)
|
|
38
|
+
let file: string | null = null
|
|
39
|
+
if (a.kind !== undefined || a.heading !== undefined) {
|
|
40
|
+
if (a.heading) await guarded(root, '--release-title', [a.heading])
|
|
41
|
+
const next = readRelease(root, NEXT) ?? emptyRelease()
|
|
42
|
+
file = writeRelease(root, { ...next, ...(a.kind ? { kind: a.kind as ReleaseKind } : {}), ...(a.heading !== undefined ? { title: a.heading.trim() } : {}) })
|
|
43
|
+
}
|
|
44
|
+
if (change) {
|
|
45
|
+
const x = a.card !== undefined ? itemOfRef(storeDir(root), a.card) : null
|
|
46
|
+
if (a.card !== undefined && !x) throw new Error(`--card ${a.card}: no such card`)
|
|
47
|
+
// the card's own line, when it has one, unless the hand names its own
|
|
48
|
+
const line = x ? versionsOf(storeDir(root), x).find((v) => v.changelog)?.changelog : undefined
|
|
49
|
+
const category = a.category ?? line?.category
|
|
50
|
+
const title = a.title ?? line?.line
|
|
51
|
+
if (category === undefined || title === undefined) throw new Error(x ? `--card ${a.card}: the card has no changelog line; name the category and the title` : 'a change by hand names its category and its title')
|
|
52
|
+
const next = readRelease(root, NEXT)
|
|
53
|
+
const given = x ? versionsOf(storeDir(root), x).at(-1)!.id : null
|
|
54
|
+
// the change of the same card, else of the same title: what the hand does not give, the card included, is kept
|
|
55
|
+
const all = next ? changesOf(next) : []
|
|
56
|
+
const had = (given != null ? all.find((ch) => ch.card === given) : undefined) ?? all.find((ch) => ch.title === title)
|
|
57
|
+
const c: Change = { title, text: a.text ?? had?.text ?? '', bullets: a.bullets ?? had?.bullets ?? [], picture: had?.picture ?? null, card: given ?? had?.card ?? null, commit: a.commit ?? x?.item.commit ?? had?.commit ?? null }
|
|
58
|
+
// the words first: a refused change uploads no picture
|
|
59
|
+
await guarded(root, `"${c.title}"`, [category, c.title, c.text, ...c.bullets])
|
|
60
|
+
if (a.image !== undefined) c.picture = { url: await keepPicture(root, a.image), alt: c.title }
|
|
61
|
+
else if (x) c.picture = (await cardParts(root, x, c.title)).picture ?? c.picture
|
|
62
|
+
file = addChange(root, category, c).file
|
|
63
|
+
}
|
|
64
|
+
commitPaths([file!], `releases: next.md takes ${a.title ?? a.card ?? 'its heading'}`)
|
|
65
|
+
return file!
|
|
66
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// the release files as tree rows (wiki tools/shipkit/units.md, The release files): one row a version under the
|
|
2
|
+
// Releases section, next first, then newest first, its count of changes in the slot. A file that does not parse is a
|
|
3
|
+
// red row: SK040 says why. Read on every tree build: a few small md files
|
|
4
|
+
import { RELEASES_COL, type Collection, type Instance } from '../collections/collection-types.ts'
|
|
5
|
+
import { LAYOUT } from '../core/layout.ts'
|
|
6
|
+
import { changesOf, fileOf, NEXT } from './model.ts'
|
|
7
|
+
import { hasReleases, readRelease, releaseVersions } from './store.ts'
|
|
8
|
+
|
|
9
|
+
export function releasesCollection(root: string): Collection | null {
|
|
10
|
+
if (!hasReleases(root)) return null
|
|
11
|
+
return {
|
|
12
|
+
id: RELEASES_COL,
|
|
13
|
+
title: 'releases',
|
|
14
|
+
kind: 'release',
|
|
15
|
+
media: 'text',
|
|
16
|
+
list: async () =>
|
|
17
|
+
releaseVersions(root).map((v, i): Instance => {
|
|
18
|
+
let n: number | null = null
|
|
19
|
+
try {
|
|
20
|
+
n = changesOf(readRelease(root, v)!).length
|
|
21
|
+
} catch {
|
|
22
|
+
n = null
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
id: `release:${v}`,
|
|
26
|
+
text: v === NEXT ? 'the next release, being filled' : `release ${v}`,
|
|
27
|
+
label: v,
|
|
28
|
+
order: i,
|
|
29
|
+
slot: n == null ? 'unreadable' : `${n} change${n === 1 ? '' : 's'}`,
|
|
30
|
+
type: 'release',
|
|
31
|
+
path: `${LAYOUT.releases}/${fileOf(v)}`,
|
|
32
|
+
state: n == null ? 'red' : 'idle',
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// a change written from a review card (wiki tools/shipkit/review.md, A change for the release): the card carries its
|
|
2
|
+
// public line (`--changelog "<category>: <line>"`), and the owner's approval adds it to next.md with the card's after picture,
|
|
3
|
+
// kept private in the Space. The card named is the thread's first version, so a later version approved again replaces
|
|
4
|
+
// its change instead of adding a second one
|
|
5
|
+
import { ensureLocal } from '../review/media-read.ts'
|
|
6
|
+
import { isApproved, verdictOf, type Item, type ReviewItem } from '../review/model.ts'
|
|
7
|
+
import { stageablesOf } from '../review/stage-card.ts'
|
|
8
|
+
import { readItem, storeDir } from '../review/store.ts'
|
|
9
|
+
import { commitPaths } from '../social/writes.ts'
|
|
10
|
+
import { NEXT, type Change } from './model.ts'
|
|
11
|
+
import { keepPicture } from './pictures.ts'
|
|
12
|
+
import { addChange, readRelease, undeclaredReleases } from './store.ts'
|
|
13
|
+
|
|
14
|
+
/** the versions of a card, newest first, following `supersedes` */
|
|
15
|
+
export function versionsOf(dir: string, x: ReviewItem): Item[] {
|
|
16
|
+
const out = [x.item]
|
|
17
|
+
for (let s = x.item.supersedes; s && out.length < 100; ) {
|
|
18
|
+
const prev = readItem(dir, s)
|
|
19
|
+
if (!prev) break
|
|
20
|
+
out.push(prev.item)
|
|
21
|
+
s = prev.item.supersedes
|
|
22
|
+
}
|
|
23
|
+
return out
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** the file that stands for the change: the after of a pair, else the first image or clip */
|
|
27
|
+
async function pictureOf(dir: string, i: Item): Promise<string | null> {
|
|
28
|
+
const pick = stageablesOf(i, 1).find((s) => s.side !== 'before' && s.side !== 'wipe')
|
|
29
|
+
return pick ? ensureLocal(dir, i.id, pick.file) : null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** what a card lends a change whatever its line: its newest version's picture kept private, the thread's first id, its
|
|
33
|
+
* commit */
|
|
34
|
+
export async function cardParts(root: string, x: ReviewItem, alt: string): Promise<Pick<Change, 'picture' | 'card' | 'commit'>> {
|
|
35
|
+
const dir = storeDir(root)
|
|
36
|
+
const file = await pictureOf(dir, x.item)
|
|
37
|
+
const url = file ? await keepPicture(root, file) : null
|
|
38
|
+
return { picture: url ? { url, alt } : null, card: versionsOf(dir, x).at(-1)!.id, commit: x.item.commit ?? null }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** the change a card adds to next: its line and its parts; null for a card with no changelog line */
|
|
42
|
+
export async function changeOfCard(root: string, x: ReviewItem): Promise<{ category: string; change: Change } | null> {
|
|
43
|
+
const line = versionsOf(storeDir(root), x).find((v) => v.changelog)?.changelog
|
|
44
|
+
if (!line) return null
|
|
45
|
+
return { category: line.category, change: { title: line.line, text: '', bullets: [], ...(await cardParts(root, x, line.line)) } }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** after the owner's verdict: an approved card with a changelog line goes into next.md, committed; the next.md path,
|
|
49
|
+
* or null when the verdict adds nothing. The description and bullets a hand wrote for that change stay. A repo that
|
|
50
|
+
* declares no release files throws, so the card's thread says why its line went nowhere */
|
|
51
|
+
export async function onVerdict(root: string, id: string): Promise<string | null> {
|
|
52
|
+
const x = readItem(storeDir(root), id)
|
|
53
|
+
if (!x || !isApproved(verdictOf(x)?.status ?? 'rejected')) return null
|
|
54
|
+
if (!versionsOf(storeDir(root), x).some((v) => v.changelog)) return null
|
|
55
|
+
const why = await undeclaredReleases(root)
|
|
56
|
+
if (why) throw new Error(why)
|
|
57
|
+
const c = await changeOfCard(root, x)
|
|
58
|
+
if (!c) return null
|
|
59
|
+
const had = readRelease(root, NEXT)
|
|
60
|
+
?.categories.flatMap((k) => k.changes)
|
|
61
|
+
.find((ch) => ch.card === c.change.card)
|
|
62
|
+
const change = had ? { ...c.change, text: had.text, bullets: had.bullets } : c.change
|
|
63
|
+
const { file } = addChange(root, c.category, change)
|
|
64
|
+
commitPaths([file], `releases: next takes the change of the card ${c.change.card}`)
|
|
65
|
+
return file
|
|
66
|
+
}
|
|
@@ -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(``)
|
|
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(` `)
|
|
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
|
+
}
|