rvlib-shipkit 2.21.0 → 2.22.1
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 +23 -0
- package/package.json +1 -1
- package/src/asks/asks-queue.ts +8 -7
- package/src/assets/kits/identity-kit.ts +158 -2
- package/src/cli/cmd_Bump.ts +3 -3
- package/src/cli/cmd_Rec.ts +349 -0
- package/src/cli/cmd_Releases.ts +4 -1
- package/src/cli/cmd_Secret.ts +10 -3
- package/src/cli/cmd_Sign.ts +24 -0
- package/src/cli/cmd_Social.ts +44 -1
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +4 -0
- package/src/core/agent-spawn.ts +4 -17
- package/src/core/code-lines.ts +49 -0
- package/src/core/discover-checks.ts +27 -3
- package/src/core/hard-reset.ts +34 -0
- package/src/core/raw-access.ts +3 -13
- package/src/core/throwaway-worktree.ts +72 -0
- package/src/home/app-sign.ts +98 -0
- package/src/home/gui-app.ts +31 -12
- package/src/home/home-routes.ts +6 -0
- package/src/home/serve-web.ts +1 -1
- package/src/identities/identities.ts +6 -0
- package/src/media-kinds.ts +5 -3
- package/src/media-store/forget.ts +54 -0
- package/src/media-store/put.ts +4 -3
- package/src/media-store/space.ts +63 -24
- package/src/recordings/delete.ts +19 -0
- package/src/recordings/edit.ts +231 -0
- package/src/recordings/load.ts +37 -0
- package/src/recordings/marks-draw.ts +111 -0
- package/src/recordings/marks-png.ts +25 -0
- package/src/recordings/marks.ts +138 -0
- package/src/recordings/media-kind.ts +67 -0
- package/src/recordings/model.ts +170 -0
- package/src/recordings/open.ts +33 -0
- package/src/recordings/place.ts +89 -0
- package/src/recordings/presets.ts +99 -0
- package/src/recordings/recorder-app/Capture.swift +510 -0
- package/src/recordings/recorder-app/Clip.swift +162 -0
- package/src/recordings/recorder-app/Editor.swift +39 -0
- package/src/recordings/recorder-app/Tray.swift +298 -0
- package/src/recordings/recorder-app/main.swift +862 -0
- package/src/recordings/recorder-app.ts +46 -0
- package/src/recordings/recorder.shipkit.ts +11 -0
- package/src/recordings/routes.ts +140 -0
- package/src/recordings/run-recorder.ts +40 -0
- package/src/recordings/share.ts +107 -0
- package/src/recordings/take.ts +146 -0
- package/src/recordings/view.ts +40 -0
- package/src/release/gate-checkout.ts +74 -0
- package/src/release/release-scope.ts +35 -26
- package/src/release/run-bump.ts +79 -37
- package/src/release/run-release.ts +67 -53
- package/src/releases/add.ts +7 -2
- package/src/releases/from-card.ts +3 -3
- package/src/releases/model.ts +29 -7
- package/src/repo-config.ts +7 -3
- package/src/review/trailer-desk.ts +1 -0
- package/src/review/trailer-model.ts +2 -0
- package/src/secrets/manager.ts +18 -1
- package/src/serve/hub-app/home-st.ts +15 -5
- package/src/serve/hub-app/home.html +1 -0
- package/src/serve/hub-app/hub-app.tsx +6 -1
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/palette-st.ts +1 -0
- package/src/serve/hub-app/project-list.tsx +1 -0
- package/src/serve/hub-app/projects-svc.ts +1 -1
- package/src/serve/hub-app/recordings-st.ts +641 -0
- package/src/serve/hub-app/recordings-view.tsx +504 -0
- package/src/serve/hub-app/recordings.css +82 -0
- package/src/serve/hub-app/repo-st.ts +1 -1
- package/src/serve/hub-app/review/trailer-page.tsx +1 -0
- package/src/serve/hub-app/review/trailer-st.ts +16 -0
- package/src/serve/hub-app/review/trailer-timeline.tsx +3 -0
- package/src/serve/hub-app/review.css +2 -0
- package/src/serve/hub-app/social/post-card.tsx +31 -3
- package/src/serve/hub-app/social/social-model.ts +4 -0
- package/src/serve/hub-app/social/social-st.ts +12 -0
- package/src/serve/hub-app/social.css +4 -0
- package/src/shipkit.ts +2 -2
- package/src/shot/box.ts +23 -17
- package/src/shot/browser-slot.ts +13 -3
- package/src/shot/film-box.ts +193 -117
- package/src/shot/shooter.ts +5 -3
- package/src/smoke/run-smoke.ts +8 -6
- package/src/social/compose.ts +14 -0
- package/src/social/drafts.ts +1 -1
- package/src/social/load.ts +16 -2
- package/src/social/publish/index.ts +3 -1
- package/src/social/publish/secret.ts +12 -4
- package/src/social/release-card.ts +69 -0
- package/src/social/release-stage.ts +49 -10
- package/src/social/routes.ts +5 -0
- package/src/social/stage.ts +9 -5
- package/src/trailer/build.ts +24 -0
- package/src/trailer/ffmpeg.ts +8 -0
- package/src/trailer/grammar.ts +9 -2
- package/src/trailer/look.ts +7 -0
- package/src/veille/chrome.ts +6 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// one recording on the disk (wiki tools/shipkit/recordings.md, A recording): `<root>/<repo>/<id>/` holds `raw.<ext>`
|
|
2
|
+
// (the take, never changed), `edit.txt` and `out.<ext>` (the export of that edit), `poster.webp` and `meta.json`, its
|
|
3
|
+
// facts and the sha of each media file. The id is the take's time and never moves; the name is what a trailer, a link
|
|
4
|
+
// and the hub say, unique in its repo
|
|
5
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { mediaDb } from '../media-store/db.ts'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import { mediaKey } from '../media-store/content.ts'
|
|
9
|
+
import type { MediaFact } from '../media-store/fact.ts'
|
|
10
|
+
import { recordingRoots, repoDir } from './place.ts'
|
|
11
|
+
|
|
12
|
+
export type RecMeta = {
|
|
13
|
+
id: string
|
|
14
|
+
name: string
|
|
15
|
+
/** the repo's name, its folder under the root */
|
|
16
|
+
repo: string
|
|
17
|
+
still: boolean
|
|
18
|
+
/** ISO time of the take */
|
|
19
|
+
created: string
|
|
20
|
+
preset?: string
|
|
21
|
+
width: number
|
|
22
|
+
height: number
|
|
23
|
+
/** 0 for a still */
|
|
24
|
+
seconds: number
|
|
25
|
+
audio: boolean
|
|
26
|
+
/** `raw.mp4` or `raw.png` */
|
|
27
|
+
raw: string
|
|
28
|
+
/** the media files and their content, by name: raw, out, poster */
|
|
29
|
+
files: Record<string, MediaFact>
|
|
30
|
+
/** the permanent URL of its public copy, once published */
|
|
31
|
+
publicUrl?: string
|
|
32
|
+
/** every Space key it had that its files no longer name (an export, a poster or a public copy replaced): a delete
|
|
33
|
+
* takes them too, so a link copied before an export dies with the rest */
|
|
34
|
+
former?: string[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type Recording = RecMeta & { dir: string; root: string }
|
|
38
|
+
|
|
39
|
+
export const META = 'meta.json'
|
|
40
|
+
export const EDIT = 'edit.txt'
|
|
41
|
+
export const POSTER = 'poster.webp'
|
|
42
|
+
export const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/
|
|
43
|
+
|
|
44
|
+
export const outOf = (m: Pick<RecMeta, 'raw'>): string => m.raw.replace(/^raw\./, 'out.')
|
|
45
|
+
|
|
46
|
+
/** a Space key the meta is about to stop naming, kept in `former` */
|
|
47
|
+
export function retireKey(m: RecMeta, key: string): void {
|
|
48
|
+
const f = new Set(m.former ?? [])
|
|
49
|
+
f.add(key)
|
|
50
|
+
m.former = [...f]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** the file `name`'s key kept in `former` before its fact is replaced or dropped */
|
|
54
|
+
export function retire(m: RecMeta, name: string): void {
|
|
55
|
+
const f = m.files[name]
|
|
56
|
+
if (f) retireKey(m, mediaKey('recording', f, name))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** the file a reader plays: the export of the edit when it is there and current, else the take */
|
|
60
|
+
export function currentFile(r: Recording): string {
|
|
61
|
+
const out = join(r.dir, outOf(r))
|
|
62
|
+
return existsSync(join(r.dir, EDIT)) && (existsSync(out) || r.files[outOf(r)]) ? outOf(r) : r.raw
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** a take's id from its time: `20261109-191230` */
|
|
66
|
+
export function idOf(at: Date): string {
|
|
67
|
+
const p = (n: number): string => String(n).padStart(2, '0')
|
|
68
|
+
return `${at.getFullYear()}${p(at.getMonth() + 1)}${p(at.getDate())}-${p(at.getHours())}${p(at.getMinutes())}${p(at.getSeconds())}`
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function readMeta(dir: string): RecMeta | null {
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(readFileSync(join(dir, META), 'utf8')) as RecMeta
|
|
74
|
+
} catch {
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** written beside, then renamed: a reader never sees half a file */
|
|
80
|
+
export function writeMeta(dir: string, m: RecMeta): void {
|
|
81
|
+
const tmp = join(dir, `.${META}.tmp`)
|
|
82
|
+
writeFileSync(tmp, `${JSON.stringify(m, null, 2)}\n`)
|
|
83
|
+
renameSync(tmp, join(dir, META))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const dirs = (p: string): string[] => {
|
|
87
|
+
try {
|
|
88
|
+
return readdirSync(p, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith('.')).map((e) => e.name)
|
|
89
|
+
} catch {
|
|
90
|
+
return []
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** every recording of one repo folder */
|
|
95
|
+
export function recordingsIn(root: string, repoFolder: string): Recording[] {
|
|
96
|
+
const out: Recording[] = []
|
|
97
|
+
for (const id of dirs(repoFolder)) {
|
|
98
|
+
const dir = join(repoFolder, id)
|
|
99
|
+
const m = readMeta(dir)
|
|
100
|
+
if (m) out.push({ ...m, dir, root })
|
|
101
|
+
}
|
|
102
|
+
return out
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** every recording of every root, of one repo or all, newest first */
|
|
106
|
+
export async function listRecordings(o: { repo?: string } = {}): Promise<Recording[]> {
|
|
107
|
+
const out: Recording[] = []
|
|
108
|
+
for (const root of await recordingRoots()) {
|
|
109
|
+
const repos = o.repo === undefined ? dirs(root) : [o.repo]
|
|
110
|
+
for (const repo of repos) out.push(...recordingsIn(root, repoDir(root, repo)))
|
|
111
|
+
}
|
|
112
|
+
return out.sort((a, b) => b.created.localeCompare(a.created) || b.id.localeCompare(a.id))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** a recording by `<name>`, `<id>`, or `<repo>/<name>`; `repo` is where a bare name looks first */
|
|
116
|
+
export async function findRecording(ref: string, o: { repo?: string } = {}): Promise<Recording> {
|
|
117
|
+
const at = ref.indexOf('/')
|
|
118
|
+
const repo = at > 0 ? ref.slice(0, at) : o.repo
|
|
119
|
+
const word = at > 0 ? ref.slice(at + 1) : ref
|
|
120
|
+
const all = await listRecordings(repo === undefined ? {} : { repo })
|
|
121
|
+
const hits = all.filter((r) => r.name === word || r.id === word)
|
|
122
|
+
if (hits.length === 1) return hits[0]!
|
|
123
|
+
if (hits.length > 1) throw new Error(`${ref}: ${hits.length} recordings answer to it (${hits.map((r) => `${r.repo}/${r.name}`).join(', ')}); name the repo`)
|
|
124
|
+
throw new Error(`${ref}: no recording of that name${repo ? ` in ${repo}` : ''} (sk rec ls lists them)`)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** the name given, checked free in the repo folder */
|
|
128
|
+
export function checkName(repoFolder: string, name: string, self?: string): void {
|
|
129
|
+
if (!NAME.test(name)) throw new Error(`${name}: a name is lowercase letters, digits and dashes`)
|
|
130
|
+
for (const id of dirs(repoFolder)) {
|
|
131
|
+
if (id === self) continue
|
|
132
|
+
const m = readMeta(join(repoFolder, id))
|
|
133
|
+
if (m && (m.name === name || m.id === name)) throw new Error(`${name}: ${m.repo} already has a recording of that name`)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function rename(r: Recording, name: string): Recording {
|
|
138
|
+
checkName(join(r.root, r.repo), name, r.id)
|
|
139
|
+
const m = readMeta(r.dir)
|
|
140
|
+
if (!m) throw new Error(`${r.dir}: no ${META}`)
|
|
141
|
+
m.name = name
|
|
142
|
+
writeMeta(r.dir, m)
|
|
143
|
+
return { ...m, dir: r.dir, root: r.root }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** the take filed under another repo (or `unassigned`) on its own root: its folder moved, its meta and its media
|
|
147
|
+
* index rows following, so the upload, the purge and a delete still find every file */
|
|
148
|
+
export function moveRecording(r: Recording, repo: string): Recording {
|
|
149
|
+
if (!NAME.test(repo)) throw new Error(`${repo}: a repo is lowercase letters, digits and dashes`)
|
|
150
|
+
if (repo === r.repo) return r
|
|
151
|
+
const folder = join(r.root, repo)
|
|
152
|
+
mkdirSync(folder, { recursive: true })
|
|
153
|
+
checkName(folder, r.name)
|
|
154
|
+
const to = join(folder, r.id)
|
|
155
|
+
if (existsSync(to)) throw new Error(`${repo} already has a take ${r.id}`)
|
|
156
|
+
renameSync(r.dir, to)
|
|
157
|
+
const m = readMeta(to)!
|
|
158
|
+
m.repo = repo
|
|
159
|
+
writeMeta(to, m)
|
|
160
|
+
const db = mediaDb()
|
|
161
|
+
db?.query('update files set store = ? where store = ? and item = ?').run(folder, join(r.root, r.repo), r.id)
|
|
162
|
+
return { ...m, dir: to, root: r.root }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** the newest mtime of what a person touches: the meta and the edit */
|
|
166
|
+
export const usedAt = (dir: string): number | undefined => {
|
|
167
|
+
const t = [META, EDIT].map((n) => statSync(join(dir, n), { throwIfNoEntry: false })?.mtimeMs ?? 0)
|
|
168
|
+
const m = Math.max(...t)
|
|
169
|
+
return m > 0 ? m : undefined
|
|
170
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// the recordings' doors to the rest of the Mac: the hub's editor opened on a take, the recorder app asked to record
|
|
2
|
+
// through its url scheme, a folder sent to the Trash
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { homeUrl } from '../home/home-paths.ts'
|
|
5
|
+
import type { Recording } from './model.ts'
|
|
6
|
+
import { recordingAddress } from './view.ts'
|
|
7
|
+
import type { RecPreset } from './presets.ts'
|
|
8
|
+
|
|
9
|
+
export const RECORDER_SCHEME = 'shipkit-recorder'
|
|
10
|
+
|
|
11
|
+
/** the editor in a shipkit window, its own short process like every window the home opens */
|
|
12
|
+
export async function openEditor(r: Recording): Promise<void> {
|
|
13
|
+
const url = `${homeUrl()}${recordingAddress(r)}`
|
|
14
|
+
const p = Bun.spawn([process.execPath, join(import.meta.dir, '..', 'home', 'open-app.ts'), url], { stdout: 'ignore', stderr: 'pipe' })
|
|
15
|
+
if ((await p.exited) !== 0) throw new Error(`the editor did not open: ${(await new Response(p.stderr).text()).trim()}`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** the url that asks the app to record: a preset by id, or a whole preset of its own (a trailer's shot) */
|
|
19
|
+
export function recorderUrl(o: { preset?: string; spec?: RecPreset; repo?: string; name?: string; replace?: string }): string {
|
|
20
|
+
const q = new URLSearchParams()
|
|
21
|
+
if (o.preset) q.set('preset', o.preset)
|
|
22
|
+
if (o.spec) q.set('spec', JSON.stringify(o.spec))
|
|
23
|
+
if (o.repo) q.set('repo', o.repo)
|
|
24
|
+
if (o.name) q.set('name', o.name)
|
|
25
|
+
if (o.replace) q.set('replace', o.replace)
|
|
26
|
+
return `${RECORDER_SCHEME}://record?${q.toString()}`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** a folder to the Trash through the Finder: it works across drives, and it can be put back */
|
|
30
|
+
export async function trash(dir: string): Promise<void> {
|
|
31
|
+
const p = Bun.spawn(['osascript', '-e', 'on run argv', '-e', 'tell application "Finder" to delete (POSIX file (item 1 of argv) as alias)', '-e', 'end run', dir], { stdout: 'ignore', stderr: 'pipe' })
|
|
32
|
+
if ((await p.exited) !== 0) throw new Error(`the Trash refused ${dir}: ${(await new Response(p.stderr).text()).trim()}`)
|
|
33
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// where the recordings live (wiki tools/shipkit/recordings.md, Where takes live): the house config's `recorder.dir`
|
|
2
|
+
// (an external drive), else the machine's home dir. A dir under `/Volumes/<drive>` counts only while that drive is
|
|
3
|
+
// mounted: `/Volumes` is root's, so an unplugged drive is never a phantom folder we write into. Then the home dir holds
|
|
4
|
+
// the take, said loud, and both roots stay listed so nothing recorded on the road is lost
|
|
5
|
+
import { existsSync, mkdirSync } from 'node:fs'
|
|
6
|
+
import { basename, join, resolve, sep } from 'node:path'
|
|
7
|
+
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
8
|
+
import { homeDir } from '../home/home-paths.ts'
|
|
9
|
+
|
|
10
|
+
/** the folder of the takes no repo owns yet: where every take goes unless one is picked */
|
|
11
|
+
export const UNASSIGNED = 'unassigned'
|
|
12
|
+
|
|
13
|
+
/** a folder in place of the house config's `recorder.dir`, for one process (a test's temp folder) */
|
|
14
|
+
export const RECORDINGS_ENV = 'SHIPKIT_RECORDINGS'
|
|
15
|
+
|
|
16
|
+
/** the machine's own fallback: the Mac's disk, under the shipkit home dir */
|
|
17
|
+
export const fallbackDir = (): string => join(homeDir(), 'recordings')
|
|
18
|
+
|
|
19
|
+
/** the drive a path sits on when it is an external one (`/Volumes/<drive>`), null on the system disk */
|
|
20
|
+
export function driveOf(path: string): string | null {
|
|
21
|
+
const parts = resolve(path).split(sep)
|
|
22
|
+
return parts[1] === 'Volumes' && parts[2] ? `/Volumes/${parts[2]}` : null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** the configured dir can take a file now: its drive mounted, or no drive to wait for */
|
|
26
|
+
export function usable(dir: string): boolean {
|
|
27
|
+
const drive = driveOf(dir)
|
|
28
|
+
return drive === null || existsSync(drive)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let held: Promise<string | null> | null = null
|
|
32
|
+
|
|
33
|
+
/** the house config's `recorder.dir`, or the env's; null when neither names one */
|
|
34
|
+
export function configuredDir(): Promise<string | null> {
|
|
35
|
+
held ??= (async (): Promise<string | null> => {
|
|
36
|
+
const env = process.env[RECORDINGS_ENV]
|
|
37
|
+
if (env !== undefined) return env === '' ? null : env
|
|
38
|
+
const { houseRoot } = await import('../home/home-start.ts')
|
|
39
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
40
|
+
const house = houseRoot(process.cwd())
|
|
41
|
+
return house ? ((await loadRepoConfig(house)).recorder?.dir ?? null) : null
|
|
42
|
+
})()
|
|
43
|
+
return held
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** a test's own dir in place of the machine's; undefined reads it again */
|
|
47
|
+
export function useRecordingsDir(dir: string | null | undefined): void {
|
|
48
|
+
held = dir === undefined ? null : Promise.resolve(dir)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const KNOWN = 'recordings-roots'
|
|
52
|
+
|
|
53
|
+
/** every root a take was ever written to, the media store's sync read of where recordings sit: a root holds a take
|
|
54
|
+
* only once a write named it here, so the list is never short of one */
|
|
55
|
+
export function knownRoots(): string[] {
|
|
56
|
+
const env = process.env[RECORDINGS_ENV]
|
|
57
|
+
const own = env !== undefined && env !== '' ? [resolve(env)] : (machineGet<string[]>(KNOWN) ?? [])
|
|
58
|
+
return [...new Set([...own, resolve(fallbackDir())])]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function rememberRoot(root: string): void {
|
|
62
|
+
if (process.env[RECORDINGS_ENV] !== undefined) return
|
|
63
|
+
const had = machineGet<string[]>(KNOWN) ?? []
|
|
64
|
+
if (!had.includes(resolve(root))) machineSet(KNOWN, [...had, resolve(root)])
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** every root a recording may sit in, the configured one first: all are read, only a usable one is written */
|
|
68
|
+
export async function recordingRoots(): Promise<string[]> {
|
|
69
|
+
const dir = await configuredDir()
|
|
70
|
+
return [...new Set([...(dir === null ? [] : [resolve(dir)]), ...knownRoots()])]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** the root a new take goes to, and the warning when it is not the configured one */
|
|
74
|
+
export async function writeRoot(): Promise<{ root: string; warn: string | null }> {
|
|
75
|
+
const dir = await configuredDir()
|
|
76
|
+
if (dir === null) return { root: fallbackDir(), warn: null }
|
|
77
|
+
if (usable(dir)) return { root: dir, warn: null }
|
|
78
|
+
return { root: fallbackDir(), warn: `WARN recordings: ${driveOf(dir)} is not mounted, so this take stays on the Mac's disk (${fallbackDir()})` }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** a repo's folder under a root: its name, the same on every root */
|
|
82
|
+
export const repoDir = (root: string, repo: string): string => join(root, basename(repo))
|
|
83
|
+
|
|
84
|
+
/** the folder made when absent; refused under an unmounted drive */
|
|
85
|
+
export function ensureDir(dir: string): string {
|
|
86
|
+
if (!usable(dir)) throw new Error(`${dir}: ${driveOf(dir)} is not mounted`)
|
|
87
|
+
mkdirSync(dir, { recursive: true })
|
|
88
|
+
return dir
|
|
89
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// the recorder's presets (wiki tools/shipkit/recordings.md, Presets): each one is a hotkey, what it shoots, its
|
|
2
|
+
// options and what runs after. Data only: the shipkit app reads them through `sk rec presets --json` and records,
|
|
3
|
+
// `sk rec import` files the take and runs `after`. The house config's presets replace the built-in ones by name, a
|
|
4
|
+
// repo's own join them under its name
|
|
5
|
+
import { basename } from 'node:path'
|
|
6
|
+
|
|
7
|
+
/** what a preset shoots: `select` the crosshair (a click takes a window, a drag an area; a video's choice is adjusted,
|
|
8
|
+
* its handles resizing the window itself), `region` the same with areas only, `freeze` the crosshair on the screen
|
|
9
|
+
* under the pointer frozen the instant the hotkey is pressed (a screenshot only), `pick` the system's picker, `screen`
|
|
10
|
+
* the screen under the pointer, or one app's window (its name or a word of its title), resized to `size` first */
|
|
11
|
+
export type RecShoot = 'select' | 'pick' | 'region' | 'freeze' | 'screen' | { window: string; size?: string }
|
|
12
|
+
|
|
13
|
+
export const AFTERS = ['upload', 'copy-link', 'copy-public-link', 'copy-file', 'copy-markdown', 'open-editor', 'reveal'] as const
|
|
14
|
+
/** a step run after the take is filed, in order: `copy-link` is a private link (7 days), `copy-public-link` a
|
|
15
|
+
* permanent one anyone opens, `copy-file` puts the file itself on the clipboard (a paste attaches it) */
|
|
16
|
+
export type RecAfter = (typeof AFTERS)[number]
|
|
17
|
+
|
|
18
|
+
export type RecPreset = {
|
|
19
|
+
/** the global hotkey, `alt+shift+r`, or several: modifiers (cmd, ctrl, alt, shift) and one key each */
|
|
20
|
+
key?: string | string[]
|
|
21
|
+
/** the menu's words; the preset's name when none */
|
|
22
|
+
label?: string
|
|
23
|
+
shoot: RecShoot
|
|
24
|
+
/** a screenshot, not a video */
|
|
25
|
+
still?: boolean
|
|
26
|
+
mic?: boolean
|
|
27
|
+
/** the sound the Mac plays (apps, games) */
|
|
28
|
+
systemAudio?: boolean
|
|
29
|
+
/** a ring on every click */
|
|
30
|
+
clicks?: boolean
|
|
31
|
+
/** the pointer in the frame (on unless false) */
|
|
32
|
+
cursor?: boolean
|
|
33
|
+
/** seconds of countdown before it starts */
|
|
34
|
+
countdown?: number
|
|
35
|
+
/** stops on its own after this long */
|
|
36
|
+
seconds?: number
|
|
37
|
+
/** the frames per second of a video (30 unless set) */
|
|
38
|
+
fps?: number
|
|
39
|
+
after?: RecAfter[]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type RecorderConfig = {
|
|
43
|
+
/** the folder every take goes to, a folder per repo inside (house config only): an external drive's folder is
|
|
44
|
+
* used while the drive is mounted, else the Mac's disk takes the take, said loud */
|
|
45
|
+
dir?: string
|
|
46
|
+
presets?: Record<string, RecPreset>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** what ships when the house names none: a video and a screenshot, each a window or an area, and a screenshot taken
|
|
50
|
+
* on the screen as it was the instant its hotkey was pressed */
|
|
51
|
+
export const BUILTIN_PRESETS: Record<string, RecPreset> = {
|
|
52
|
+
video: { key: 'alt+shift+r', label: 'Video', shoot: 'select', mic: true, clicks: true, after: ['upload', 'copy-link'] },
|
|
53
|
+
still: { key: 'alt+shift+s', label: 'Screenshot', shoot: 'select', still: true, after: ['copy-file', 'upload', 'open-editor'] },
|
|
54
|
+
instant: { key: 'alt+shift+i', label: 'Screenshot, frozen', shoot: 'freeze', still: true, after: ['copy-file', 'upload', 'open-editor'] },
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** one preset as the app and the hub read it: its id (`video`, or `<repo>/<name>` for a repo's own), its source, and
|
|
58
|
+
* its hotkeys as a list */
|
|
59
|
+
export type NamedPreset = RecPreset & { id: string; from: 'shipkit' | 'house' | string; keys: string[] }
|
|
60
|
+
|
|
61
|
+
/** a preset's hotkeys, none, one or several, as a list */
|
|
62
|
+
export const keysOf = (p: Pick<RecPreset, 'key'>): string[] => (p.key === undefined ? [] : typeof p.key === 'string' ? [p.key] : p.key)
|
|
63
|
+
|
|
64
|
+
const KEY = /^((cmd|ctrl|alt|shift)\+)+([a-z0-9]|f\d{1,2}|space)$/
|
|
65
|
+
const SIZE = /^\d{2,5}x\d{2,5}$/
|
|
66
|
+
|
|
67
|
+
/** the reasons a preset is wrong, empty when it is fine */
|
|
68
|
+
export function presetProblems(id: string, p: RecPreset): string[] {
|
|
69
|
+
const out: string[] = []
|
|
70
|
+
for (const k of keysOf(p)) if (!KEY.test(k)) out.push(`${id}: key ${k}: modifiers (cmd, ctrl, alt, shift) then one key, like alt+shift+r`)
|
|
71
|
+
const s = p.shoot
|
|
72
|
+
if (typeof s === 'string' ? !['select', 'pick', 'region', 'freeze', 'screen'].includes(s) : typeof s?.window !== 'string' || s.window === '') out.push(`${id}: shoot is select, pick, region, freeze, screen or { window: '<app>' }`)
|
|
73
|
+
if (s === 'freeze' && !p.still) out.push(`${id}: shoot freeze takes a screenshot: still: true`)
|
|
74
|
+
if (typeof s === 'object' && s?.size !== undefined && !SIZE.test(s.size)) out.push(`${id}: size ${s.size}: WIDTHxHEIGHT, like 1920x1080`)
|
|
75
|
+
for (const a of p.after ?? []) if (!(AFTERS as readonly string[]).includes(a)) out.push(`${id}: after ${a}: one of ${AFTERS.join(', ')}`)
|
|
76
|
+
if (p.still && (p.seconds !== undefined || p.systemAudio || p.mic)) out.push(`${id}: a still has no seconds, mic or sound`)
|
|
77
|
+
if (p.seconds !== undefined && !(p.seconds > 0)) out.push(`${id}: seconds must be above 0`)
|
|
78
|
+
if (p.countdown !== undefined && !(p.countdown >= 0 && p.countdown <= 10)) out.push(`${id}: countdown is 0 to 10 seconds`)
|
|
79
|
+
if (p.fps !== undefined && !(p.fps >= 1 && p.fps <= 120)) out.push(`${id}: fps is 1 to 120`)
|
|
80
|
+
return out
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** the presets of the menu: the house's (or the built-in ones), then each repo's own as `<repo>/<name>`; a hotkey
|
|
84
|
+
* two presets claim is a problem */
|
|
85
|
+
export function mergePresets(house: RecorderConfig | undefined, repos: { root: string; recorder: RecorderConfig | undefined }[]): { presets: NamedPreset[]; problems: string[] } {
|
|
86
|
+
const presets: NamedPreset[] = []
|
|
87
|
+
const base = house?.presets ?? BUILTIN_PRESETS
|
|
88
|
+
for (const [id, p] of Object.entries(base)) presets.push({ ...p, id, from: house?.presets ? 'house' : 'shipkit', keys: keysOf(p) })
|
|
89
|
+
for (const r of repos) for (const [n, p] of Object.entries(r.recorder?.presets ?? {})) presets.push({ ...p, id: `${basename(r.root)}/${n}`, from: basename(r.root), keys: keysOf(p) })
|
|
90
|
+
const problems = presets.flatMap((p) => presetProblems(p.id, p))
|
|
91
|
+
const keys = new Map<string, string>()
|
|
92
|
+
for (const p of presets)
|
|
93
|
+
for (const k of p.keys) {
|
|
94
|
+
const had = keys.get(k)
|
|
95
|
+
if (had) problems.push(`${p.id}: key ${k} is already ${had}'s`)
|
|
96
|
+
else keys.set(k, p.id)
|
|
97
|
+
}
|
|
98
|
+
return { presets, problems }
|
|
99
|
+
}
|