rvlib-shipkit 2.19.0 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/checks/SK040-release-words.check.ts +43 -0
- package/src/checks/SK041-annex-links.check.ts +28 -0
- package/src/checks/SK042-post-kinds.check.ts +73 -0
- package/src/cli/cmd_Annex.ts +179 -0
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +4 -3
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +84 -0
- package/src/cli/cmd_Review.ts +176 -12
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +151 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/family-pages.ts +2 -0
- package/src/cli/kit/index.ts +1 -1
- package/src/cli/kit/verb.ts +11 -3
- package/src/cli/registry.ts +7 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/collections/review.ts +23 -4
- package/src/commands/model.ts +36 -0
- package/src/commands/registry.ts +49 -0
- package/src/commands/routes.ts +59 -0
- package/src/commands/runner.ts +35 -0
- package/src/commands/runs.ts +112 -0
- package/src/core/app-icon.ts +4 -3
- package/src/core/icon-type.ts +8 -0
- package/src/core/jobs.ts +4 -3
- package/src/core/layout.ts +11 -2
- package/src/core/squircle.ts +95 -0
- package/src/home/daemon-jobs.ts +26 -2
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +337 -5
- package/src/home/gui-app.ts +64 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-start.ts +2 -2
- package/src/home/lib-watch.ts +21 -11
- package/src/home/pm-switch.ts +112 -0
- package/src/home/pm.ts +1 -1
- package/src/home/process-apps.ts +181 -0
- package/src/home/resources.ts +3 -3
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +121 -14
- package/src/identities/machine.ts +4 -3
- package/src/identities/rating.ts +33 -0
- package/src/identities/shown.ts +170 -0
- package/src/identities/steps.ts +5 -0
- package/src/media-store/purge.ts +15 -1
- package/src/media-store/remote.ts +22 -6
- package/src/messages/brief.ts +117 -0
- package/src/messages/collection.ts +40 -0
- package/src/messages/model.ts +171 -0
- package/src/messages/routes.ts +15 -0
- package/src/messages/score.ts +182 -0
- package/src/messages/tabs.ts +13 -0
- package/src/release/notes.ts +130 -0
- package/src/release/run-bump.ts +41 -18
- package/src/release/run-release.ts +22 -4
- package/src/release/run-releases.ts +17 -15
- package/src/release/unit-resolve.ts +9 -0
- package/src/releases/add.ts +94 -0
- package/src/releases/before.ts +31 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +151 -0
- package/src/releases/model.ts +327 -0
- package/src/releases/pictures.ts +110 -0
- package/src/releases/routes.ts +36 -0
- package/src/releases/store.ts +71 -0
- package/src/repo-config.ts +5 -0
- package/src/review/cells.ts +0 -11
- package/src/review/format.ts +10 -6
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +102 -3
- package/src/review/notes.ts +2 -48
- package/src/review/routes.ts +28 -10
- package/src/review/stage-card.ts +197 -0
- package/src/review/stage-routes.ts +123 -0
- package/src/review/store.ts +47 -1
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +76 -4
- package/src/review/trailer-model.ts +106 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +119 -13
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/commands/commands-page.tsx +122 -0
- package/src/serve/hub-app/commands/commands-st.ts +177 -0
- package/src/serve/hub-app/commands.css +24 -0
- package/src/serve/hub-app/hash-route.ts +59 -8
- package/src/serve/hub-app/home-st.ts +19 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +8 -0
- package/src/serve/hub-app/icons.tsx +5 -0
- package/src/serve/hub-app/identities-view.tsx +4 -1
- package/src/serve/hub-app/identities.css +1 -0
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +41 -10
- package/src/serve/hub-app/messages/messages-page.tsx +354 -0
- package/src/serve/hub-app/messages/messages-st.ts +74 -0
- package/src/serve/hub-app/messages.css +35 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +187 -0
- package/src/serve/hub-app/releases/releases-st.ts +111 -0
- package/src/serve/hub-app/releases.css +52 -0
- package/src/serve/hub-app/repo-sections.ts +16 -2
- package/src/serve/hub-app/repo-st.ts +66 -10
- package/src/serve/hub-app/review/clip-st.ts +34 -4
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/note-place.ts +31 -0
- package/src/serve/hub-app/review/review-cells.tsx +27 -3
- package/src/serve/hub-app/review/review-st.ts +77 -2
- package/src/serve/hub-app/review/review-thread.tsx +9 -31
- package/src/serve/hub-app/review/review-views.tsx +164 -58
- package/src/serve/hub-app/review/thread-st.ts +108 -41
- package/src/serve/hub-app/review/trailer-card.tsx +187 -0
- package/src/serve/hub-app/review/trailer-page.tsx +92 -36
- package/src/serve/hub-app/review/trailer-st.ts +306 -34
- package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +137 -6
- package/src/serve/hub-app/social/comms-page.tsx +65 -28
- package/src/serve/hub-app/social/identity-pictures.ts +46 -8
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +39 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +117 -27
- package/src/serve/hub-app/social/stage-popup.tsx +268 -0
- package/src/serve/hub-app/social/stage-st.ts +310 -0
- package/src/serve/hub-app/social/step-layout.ts +42 -0
- package/src/serve/hub-app/social.css +68 -1
- package/src/serve/hub-app/tree-build.ts +40 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +12 -2
- package/src/serve/project-gutter.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +15 -1
- package/src/shipkit-files.ts +9 -7
- package/src/shot/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +22 -12
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +54 -7
- package/src/social/drafts.ts +1 -1
- package/src/social/fit.ts +84 -0
- package/src/social/identity-words.ts +74 -0
- package/src/social/kind-pages.ts +41 -0
- package/src/social/kinds.ts +93 -0
- package/src/social/load.ts +125 -10
- package/src/social/media-limit.ts +63 -2
- package/src/social/presence.ts +1 -1
- package/src/social/publish/bluesky.ts +58 -19
- package/src/social/publish/index.ts +47 -6
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +277 -0
- package/src/social/routes.ts +44 -8
- package/src/social/stage.ts +246 -0
- package/src/social/strip.ts +85 -0
- package/src/social/text.ts +6 -2
- package/src/social/unit.ts +57 -1
- package/src/social/writes.ts +11 -0
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +72 -40
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +37 -6
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// an identity's public words and pictures through the guard of each repo that speaks as it (wiki
|
|
2
|
+
// tools/shipkit/social-identities.md, The guard on the rows): its profile rows and each account's own (a text, or the
|
|
3
|
+
// pictures a row names), its Discord server's name, roles, categories, channels and topics. The desk reads them with its
|
|
4
|
+
// repo's guard; a push to a venue reads them with the guard of every repo speaking as the identity, before any call
|
|
5
|
+
import { existsSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import type { Identity } from '../identities/identities.ts'
|
|
8
|
+
import { layoutOf } from './discord-layout.ts'
|
|
9
|
+
import { guardWith, type GuardInput, type SocialUnit } from './unit.ts'
|
|
10
|
+
|
|
11
|
+
/** one public word or picture of an identity, `where` its file and row as a problem line names them */
|
|
12
|
+
export type IdentityWord = { where: string; input: Partial<GuardInput> }
|
|
13
|
+
|
|
14
|
+
/** every row once (an account's row it inherits is the identity's), then the server's layout */
|
|
15
|
+
export function identityWords(i: Identity): IdentityWord[] {
|
|
16
|
+
const out: IdentityWord[] = []
|
|
17
|
+
const seen = new Set<string>()
|
|
18
|
+
const base = i.files ?? i.dir
|
|
19
|
+
const row = (file: string, r: { field: string; value: string; files: string[] }): void => {
|
|
20
|
+
const key = JSON.stringify([r.field, r.value])
|
|
21
|
+
if (seen.has(key)) return
|
|
22
|
+
seen.add(key)
|
|
23
|
+
const files = r.files.map((f) => join(base, f)).filter((f) => existsSync(f))
|
|
24
|
+
out.push({ where: `${file}: row ${r.field}`, input: r.files.length > 0 ? { files } : { texts: [r.value] } })
|
|
25
|
+
}
|
|
26
|
+
for (const r of i.rows) row(i.file, r)
|
|
27
|
+
for (const a of i.accounts) for (const r of a.rows) row(a.file, r)
|
|
28
|
+
const discord = i.accounts.find((a) => a.id === 'discord')
|
|
29
|
+
if (discord != null && existsSync(join(discord.dir, 'layout.md'))) {
|
|
30
|
+
// a layout that does not parse is the layout's own error line, said where it is read
|
|
31
|
+
const l = (() => {
|
|
32
|
+
try {
|
|
33
|
+
return layoutOf(discord)
|
|
34
|
+
} catch {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
})()
|
|
38
|
+
if (l != null) {
|
|
39
|
+
out.push({ where: `${l.file}: the server's name`, input: { texts: [l.name] } })
|
|
40
|
+
// a role's name shows beside each member it is given
|
|
41
|
+
for (const r of l.roles) out.push({ where: `${l.file}: role ${r.name}`, input: { texts: [r.name] } })
|
|
42
|
+
for (const c of l.categories) {
|
|
43
|
+
out.push({ where: `${l.file}: category ${c.name}`, input: { texts: [c.name] } })
|
|
44
|
+
for (const ch of c.channels) out.push({ where: `${l.file}: channel ${ch.name}`, input: { texts: [ch.name, ch.topic].filter((t) => t.trim() !== '') } })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** what the guards refuse of an identity's words, one line each, `<file>: row <field>: <problem>` */
|
|
52
|
+
export function identityProblems(units: readonly (SocialUnit | null)[], i: Identity): string[] {
|
|
53
|
+
const words = identityWords(i)
|
|
54
|
+
return [...new Set(units.flatMap((u) => words.flatMap((w) => guardWith(u, w.input).map((p) => `${w.where}: ${p}`))))]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** the social units of the house repos that speak as `id`: the guards a push of its words to a venue passes */
|
|
58
|
+
export async function speakersUnits(id: string, cwd = process.cwd()): Promise<SocialUnit[]> {
|
|
59
|
+
const { houseRepoRoots } = await import('./house.ts')
|
|
60
|
+
const { loadSocialUnit } = await import('./unit.ts')
|
|
61
|
+
const out: SocialUnit[] = []
|
|
62
|
+
for (const r of await houseRepoRoots(cwd)) {
|
|
63
|
+
if (r.speaksAs !== id) continue
|
|
64
|
+
const u = await loadSocialUnit(r.path)
|
|
65
|
+
if (u != null) out.push(u)
|
|
66
|
+
}
|
|
67
|
+
return out
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** the push of an identity's words to a venue, refused while a guard of a repo speaking as it names a problem */
|
|
71
|
+
export async function refuseUnguarded(i: Identity, cwd = process.cwd()): Promise<void> {
|
|
72
|
+
const problems = identityProblems(await speakersUnits(i.id, cwd), i)
|
|
73
|
+
if (problems.length > 0) throw new Error(`the guard of a repo speaking as ${i.id} refuses ${problems.length === 1 ? 'one of its words' : `${problems.length} of its words`}, so nothing is pushed:\n ${problems.join('\n ')}`)
|
|
74
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// every kind a repo's drafts take, with its rules page on the disk (wiki tools/shipkit/social.md, The kind): the shared
|
|
2
|
+
// ones' pages in the house wiki beside the house's identities folder, the project's in the repo. The desk links each
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { LAYOUT } from '../core/layout.ts'
|
|
6
|
+
import { KIND_FOR, kindPage, POST_KINDS, type OwnKind } from './kinds.ts'
|
|
7
|
+
|
|
8
|
+
/** a kind as the desk lists it: `page` its rules page, absolute, and `title` what that page's heading says it is for;
|
|
9
|
+
* both null where no page is on this machine */
|
|
10
|
+
export type DeskKind = { id: string; for: string; own: boolean; page: string | null; title: string | null }
|
|
11
|
+
|
|
12
|
+
/** the house wiki, from the identities folder the desk read: `<house>/wiki`; null outside a house */
|
|
13
|
+
function houseWiki(identitiesDir: string | null): string | null {
|
|
14
|
+
if (identitiesDir == null || !identitiesDir.endsWith(LAYOUT.identities)) return null
|
|
15
|
+
const wiki = join(identitiesDir.slice(0, -LAYOUT.identities.length), 'wiki')
|
|
16
|
+
return existsSync(wiki) ? wiki : null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** a page's heading, the words after its path: `# guides/x — a change a user can use` → `a change a user can use` */
|
|
20
|
+
function titleOf(abs: string): string | null {
|
|
21
|
+
const h = /^# (.+)$/m.exec(readFileSync(abs, 'utf8'))?.[1]?.trim()
|
|
22
|
+
if (h == null) return null
|
|
23
|
+
return /^\S+ — (.+)$/.exec(h)?.[1] ?? h
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** the line a unit kind whose rules page is no file gives */
|
|
27
|
+
export const ownPageMissing = (k: Pick<OwnKind, 'id' | 'page'>): string => `social unit: kind ${k.id} names its page ${k.page}, which is no file of the repo`
|
|
28
|
+
|
|
29
|
+
const at = (abs: string | null): { page: string | null; title: string | null } => (abs != null && existsSync(abs) ? { page: abs, title: titleOf(abs) } : { page: null, title: null })
|
|
30
|
+
|
|
31
|
+
/** the shared kinds then the unit's, each with its page; a unit kind whose page is no file is an error line */
|
|
32
|
+
export function deskKinds(root: string, identitiesDir: string | null, own: readonly OwnKind[], errors: string[]): DeskKind[] {
|
|
33
|
+
const wiki = houseWiki(identitiesDir)
|
|
34
|
+
const shared = POST_KINDS.map((k) => ({ id: k, for: KIND_FOR[k], own: false, ...at(wiki == null ? null : join(wiki, kindPage(k))) }))
|
|
35
|
+
const mine = own.map((k) => {
|
|
36
|
+
const p = at(join(root, k.page))
|
|
37
|
+
if (p.page == null) errors.push(ownPageMissing(k))
|
|
38
|
+
return { id: k.id, for: k.for, own: true, ...p }
|
|
39
|
+
})
|
|
40
|
+
return [...shared, ...mine]
|
|
41
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// what a post is for (wiki guides/post-kinds/index.md): the closed set of kinds a draft's `kind` takes, a project's
|
|
2
|
+
// own kinds from its social unit, the old words each kind replaces, and the one check the load and SK042 share. Pure:
|
|
3
|
+
// the unit module and the hub page import it
|
|
4
|
+
|
|
5
|
+
/** the shared kinds, in the order the desk lists them */
|
|
6
|
+
export const POST_KINDS = ['announcement', 'feature', 'iteration', 'showcase', 'release', 'trailer', 'throwback', 'custom'] as const
|
|
7
|
+
export type PostKind = (typeof POST_KINDS)[number]
|
|
8
|
+
|
|
9
|
+
/** what a post of each kind is for, one line */
|
|
10
|
+
export const KIND_FOR: Readonly<Record<PostKind, string>> = {
|
|
11
|
+
announcement: 'opens a place, or tells big news that is not a version',
|
|
12
|
+
feature: 'shows a change that a user can use now',
|
|
13
|
+
iteration: 'logs a step of the work, unfinished allowed',
|
|
14
|
+
showcase: 'shows the product as it is, with no news',
|
|
15
|
+
release: 'tells a version, from its release file',
|
|
16
|
+
trailer: 'shows a cut that was kept',
|
|
17
|
+
throwback: 'shows where the project started',
|
|
18
|
+
custom: 'fits no kind: the escape hatch, with its kindWhy',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** a shared kind's rules page, from the house wiki's root */
|
|
22
|
+
export const kindPage = (k: PostKind): string => `guides/post-kinds/post-kind-${k}.md`
|
|
23
|
+
|
|
24
|
+
/** the kind a staged draft takes from its source: a card logs a step of the work, a release tells a version. A card is
|
|
25
|
+
* never a `feature` by default: no fact the house keeps says its change reaches users, so that is picked by hand */
|
|
26
|
+
export const sourceKind = (s: { review: string } | { release: string }): PostKind => ('review' in s ? 'iteration' : 'release')
|
|
27
|
+
|
|
28
|
+
/** a kind a project declares in its social unit: its id, what a post of it is for, its rules page from the repo's root */
|
|
29
|
+
export interface OwnKind {
|
|
30
|
+
id: string
|
|
31
|
+
for: string
|
|
32
|
+
page: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** the words in use before the set closed, each with the kind it maps to by default; null: a text that stays on a
|
|
36
|
+
* venue, a profile row of the identity and no post kind */
|
|
37
|
+
export const OLD_KINDS: Readonly<Record<string, PostKind | null>> = {
|
|
38
|
+
hello: 'announcement',
|
|
39
|
+
welcome: 'announcement',
|
|
40
|
+
devlog: 'iteration',
|
|
41
|
+
wip: 'iteration',
|
|
42
|
+
look: 'iteration',
|
|
43
|
+
roundup: 'iteration',
|
|
44
|
+
people: 'showcase',
|
|
45
|
+
puzzle: 'showcase',
|
|
46
|
+
page: null,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const isPostKind = (k: string): k is PostKind => (POST_KINDS as readonly string[]).includes(k)
|
|
50
|
+
|
|
51
|
+
/** a front matter value as written, trimmed and out of one pair of quotes: `"feature"` is feature, `""` is empty */
|
|
52
|
+
const unquote = (v: string | undefined): string => (v ?? '').trim().replace(/^(["'])(.*)\1$/, '$2').trim()
|
|
53
|
+
|
|
54
|
+
/** a draft's kind and its `kindWhy`, read the one way the load and SK042 read them */
|
|
55
|
+
export const kindOfMeta = (meta: Readonly<Record<string, string | undefined>>): { kind: string; why: string } => ({ kind: unquote(meta['kind']), why: unquote(meta['kindWhy']) })
|
|
56
|
+
|
|
57
|
+
/** why a draft's kind is wrong, or null; `old`: a word of the old words table, which a gate only warns on */
|
|
58
|
+
export type KindProblem = { text: string; old: boolean }
|
|
59
|
+
|
|
60
|
+
const INDEX = 'wiki guides/post-kinds/index.md'
|
|
61
|
+
|
|
62
|
+
/** the kind a draft names, with its `kindWhy`, against the shared set and the project's own kinds */
|
|
63
|
+
export function kindProblem(kind: string, why: string, own: readonly Pick<OwnKind, 'id'>[]): KindProblem | null {
|
|
64
|
+
const k = kind.trim()
|
|
65
|
+
const set = [...POST_KINDS, ...own.map((o) => o.id)].join(', ')
|
|
66
|
+
if (k === '') return { text: `no kind: a draft names what it is for, one of ${set} (${INDEX})`, old: false }
|
|
67
|
+
if (k === 'custom') return why.trim() === '' ? { text: `kind custom names no kindWhy: one line on why no kind fits (wiki ${kindPage('custom')})`, old: false } : null
|
|
68
|
+
if (isPostKind(k) || own.some((o) => o.id === k)) return null
|
|
69
|
+
if (k in OLD_KINDS) {
|
|
70
|
+
const to = OLD_KINDS[k]
|
|
71
|
+
return to == null
|
|
72
|
+
? { text: `kind "${k}" is an old word and no post kind: a text that stays on a venue is a profile row of the identity (wiki tools/shipkit/social-identities.md)`, old: true }
|
|
73
|
+
: { text: `kind "${k}" is an old word: ${to} by default, or the kind its intent reads as (${INDEX}, The old words)`, old: true }
|
|
74
|
+
}
|
|
75
|
+
return { text: `kind "${k}" is not one of ${set}: a project's own kind is declared in its social unit's kinds (${INDEX})`, old: false }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const WORD = /^[a-z][a-z0-9-]*$/
|
|
79
|
+
const REL_MD = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$)).+\.md$/
|
|
80
|
+
|
|
81
|
+
/** why a unit's own kinds cannot be read, or null */
|
|
82
|
+
export function ownKindsProblem(kinds: readonly OwnKind[]): string | null {
|
|
83
|
+
const seen = new Set<string>()
|
|
84
|
+
for (const k of kinds) {
|
|
85
|
+
if (typeof k?.id !== 'string' || !WORD.test(k.id)) return `social: kind '${String(k?.id)}' is a lowercase word`
|
|
86
|
+
if (isPostKind(k.id)) return `social: kind '${k.id}' is a shared kind already: a project's kind takes a name of its own`
|
|
87
|
+
if (seen.has(k.id)) return `social: kind '${k.id}' twice`
|
|
88
|
+
seen.add(k.id)
|
|
89
|
+
if (typeof k.for !== 'string' || k.for.trim() === '') return `social: kind '${k.id}' says what a post of it is for (for)`
|
|
90
|
+
if (typeof k.page !== 'string' || !REL_MD.test(k.page)) return `social: kind '${k.id}' page is its rules page, a .md path from the repo's root`
|
|
91
|
+
}
|
|
92
|
+
return null
|
|
93
|
+
}
|
package/src/social/load.ts
CHANGED
|
@@ -2,17 +2,25 @@
|
|
|
2
2
|
// message, each platform's part handed to its speaker's account; the rhythm; the load's errors. Read from the disk as
|
|
3
3
|
// it is on every call: the desks and `sk social` never hold a stale copy
|
|
4
4
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
5
|
-
import { join, relative } from 'node:path'
|
|
5
|
+
import { join, relative, resolve, sep } from 'node:path'
|
|
6
6
|
import { LAYOUT } from '../core/layout.ts'
|
|
7
7
|
import { speakerOf, type Account, type Identities, type Identity } from '../identities/identities.ts'
|
|
8
|
+
import { isPostRating, POST_RATINGS, takes, type PostRating } from '../identities/rating.ts'
|
|
8
9
|
import { fileList, groupKeys, mediaNames, parseDraft, renderedTrailer, resolveMedia, tagList, topicList, type Topic } from './drafts.ts'
|
|
9
10
|
import { compose, fillLink, messageLength } from './compose.ts'
|
|
10
11
|
import { parseFrontmatter, table } from './md.ts'
|
|
11
12
|
import { type Family, familyOf, type Slot, slotOf, type WeeklySlot, weeklySlots } from './presence.ts'
|
|
12
13
|
import { purgedAt } from './media-facts.ts'
|
|
13
|
-
import {
|
|
14
|
+
import { identityProblems } from './identity-words.ts'
|
|
15
|
+
import { deskKinds, type DeskKind } from './kind-pages.ts'
|
|
16
|
+
import { kindOfMeta, kindProblem } from './kinds.ts'
|
|
17
|
+
import { heavyMedia, limitProblem, mbOf, MEDIA_MAX_BYTES } from './media-limit.ts'
|
|
14
18
|
import { pushFailure } from './push.ts'
|
|
15
|
-
import type
|
|
19
|
+
import { ceilingAt, hasLayout, landing, placesOf, type Landing } from './reach.ts'
|
|
20
|
+
import { guardWith, type SocialUnit } from './unit.ts'
|
|
21
|
+
|
|
22
|
+
/** a draft's `release:`, the release it was staged from: `<unit>@<version>` */
|
|
23
|
+
export const RELEASE_REF = /^[a-z0-9][a-z0-9-]*@\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/
|
|
16
24
|
|
|
17
25
|
/** a draft's folder name: the moment it was made, then its topic */
|
|
18
26
|
export const DRAFT_NAME = /^\d{8}-\d{6}-[a-z0-9-]+$/
|
|
@@ -32,6 +40,26 @@ function reviewOf(raw: string | undefined, file: string, errors: string[]): stri
|
|
|
32
40
|
return null
|
|
33
41
|
}
|
|
34
42
|
|
|
43
|
+
function releaseOf(raw: string | undefined, file: string, errors: string[]): string | null {
|
|
44
|
+
const v = raw?.trim() ?? ''
|
|
45
|
+
if (v === '') return null
|
|
46
|
+
if (RELEASE_REF.test(v)) return v
|
|
47
|
+
errors.push(`${file}: release "${v}" is not <unit>@<version>`)
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** a draft's `rating`: unset is safe, but an adult voice's draft names it, and a bad word or an unrated adult draft
|
|
52
|
+
* reads explicit, so it goes only where explicit is taken */
|
|
53
|
+
function ratingOf(raw: string | undefined, adult: boolean, who: string, file: string, errors: string[]): PostRating {
|
|
54
|
+
const v = raw?.trim() ?? ''
|
|
55
|
+
if (isPostRating(v)) return v
|
|
56
|
+
if (v !== '') errors.push(`${file}: rating "${v}" is not ${POST_RATINGS.join(', ')}`)
|
|
57
|
+
else if (adult) errors.push(`${file}: no rating: ${who} is an adult voice, so each draft names one (${POST_RATINGS.join(', ')})`)
|
|
58
|
+
else return 'safe'
|
|
59
|
+
return 'explicit'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
35
63
|
/** a media as the draft names it, and where it is on the disk: its folder, the repo, or anywhere */
|
|
36
64
|
export type Media = { name: string; path: string }
|
|
37
65
|
|
|
@@ -73,6 +101,10 @@ export type SocialPost = {
|
|
|
73
101
|
reply: string
|
|
74
102
|
/** its write page takes the text (`{text}`); else « Open » copies it first */
|
|
75
103
|
prefilled: boolean
|
|
104
|
+
/** its rating, its heading's own else the draft's: what a publisher labels it with */
|
|
105
|
+
rating: PostRating
|
|
106
|
+
/** why it may not go out: the repo's guard on its draft, or a place under its rating; empty, it may */
|
|
107
|
+
refused: string
|
|
76
108
|
}
|
|
77
109
|
|
|
78
110
|
/** a draft's post.md: a long article of the identity's site */
|
|
@@ -89,6 +121,10 @@ export type Draft = {
|
|
|
89
121
|
identity: string
|
|
90
122
|
title: string
|
|
91
123
|
kind: string
|
|
124
|
+
/** a `custom` draft's line on why no kind fits */
|
|
125
|
+
kindWhy: string
|
|
126
|
+
/** why its kind is wrong (kinds.ts kindProblem), an error line of the load too; null when it is right */
|
|
127
|
+
kindProblem: string | null
|
|
92
128
|
topics: Topic[]
|
|
93
129
|
slot: Slot | null
|
|
94
130
|
status: string
|
|
@@ -97,8 +133,16 @@ export type Draft = {
|
|
|
97
133
|
alt: string
|
|
98
134
|
posts: SocialPost[]
|
|
99
135
|
article: Article | null
|
|
100
|
-
/** the review card it was
|
|
136
|
+
/** the review card it was staged from, any id of its thread; null when none */
|
|
101
137
|
review: string | null
|
|
138
|
+
/** the release it was staged from, `<unit>@<version>`; null when none */
|
|
139
|
+
release: string | null
|
|
140
|
+
/** what it shows: safe, mild or explicit */
|
|
141
|
+
rating: PostRating
|
|
142
|
+
/** the repo's guard's problems with it, one line each: while one stands, nothing of it goes out */
|
|
143
|
+
guard: string[]
|
|
144
|
+
/** the accounts its group headings skip, no place of theirs taking its rating, and why */
|
|
145
|
+
skipped: { account: string; why: string }[]
|
|
102
146
|
}
|
|
103
147
|
|
|
104
148
|
/** an identity's account with the repo's messages to it */
|
|
@@ -114,7 +158,12 @@ export type Desk = {
|
|
|
114
158
|
weekly: WeeklySlot[]
|
|
115
159
|
/** the topics a draft may take: the unit's, else every one the drafts name */
|
|
116
160
|
topics: Topic[]
|
|
161
|
+
/** the kinds a draft may take: the shared set, then the unit's own, each with its rules page */
|
|
162
|
+
kinds: DeskKind[]
|
|
117
163
|
errors: string[]
|
|
164
|
+
/** what is wrong but stays until its repo moves it, one line each: a draft on an old kind word. Shown with the
|
|
165
|
+
* errors, never counted as one */
|
|
166
|
+
warnings: string[]
|
|
118
167
|
}
|
|
119
168
|
|
|
120
169
|
const read = (abs: string): string => readFileSync(abs, 'utf8')
|
|
@@ -175,6 +224,7 @@ function v2Left(root: string, errors: string[]): void {
|
|
|
175
224
|
/** the desk of a repo: every identity with its accounts, the repo's drafts on them, the newest first */
|
|
176
225
|
export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string | undefined; unit?: SocialUnit | null; now?: Date } = {}): Desk {
|
|
177
226
|
const errors = [...ids.errors]
|
|
227
|
+
const warnings: string[] = []
|
|
178
228
|
const unit = o.unit ?? null
|
|
179
229
|
const own = speakerOf(o.speaksAs, ids)
|
|
180
230
|
if (o.speaksAs != null && own == null) errors.push(`repo.config.ts: speaksAs '${o.speaksAs}' is no identity (${ids.identities.map((i) => i.id).join(', ') || 'none'})`)
|
|
@@ -229,7 +279,9 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
229
279
|
dir: ddir,
|
|
230
280
|
identity: speaker.id,
|
|
231
281
|
title: d.meta.title ?? '',
|
|
232
|
-
kind: d.meta.kind
|
|
282
|
+
kind: kindOfMeta(d.meta).kind,
|
|
283
|
+
kindWhy: kindOfMeta(d.meta).why,
|
|
284
|
+
kindProblem: null,
|
|
233
285
|
topics: topicList(d.meta.topics, file, errors, unit?.topics ?? null),
|
|
234
286
|
slot: slotOf(d.meta.slot, file, week, errors),
|
|
235
287
|
status: d.meta.status ?? 'draft',
|
|
@@ -239,7 +291,18 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
239
291
|
posts: [],
|
|
240
292
|
article: article(ddir, root, unit),
|
|
241
293
|
review: reviewOf(d.meta.review, file, errors),
|
|
294
|
+
release: releaseOf(d.meta.release, file, errors),
|
|
295
|
+
rating: ratingOf(d.meta.rating, speaker.adult, speaker.name, file, errors),
|
|
296
|
+
guard: [],
|
|
297
|
+
skipped: [],
|
|
298
|
+
}
|
|
299
|
+
const kp = kindProblem(draft.kind, draft.kindWhy, unit?.kinds ?? [])
|
|
300
|
+
if (kp != null) {
|
|
301
|
+
draft.kindProblem = kp.text
|
|
302
|
+
;(kp.old ? warnings : errors).push(`${file}: ${kp.text}`)
|
|
242
303
|
}
|
|
304
|
+
const landings = new Map<string, Landing[]>()
|
|
305
|
+
const placesFor = (a: DeskAccount): Landing[] => landings.get(a.id) ?? (landings.set(a.id, placesOf(a, errors)), landings.get(a.id)!)
|
|
243
306
|
const footerText = footerOf(accounts)
|
|
244
307
|
// each account heading's message, then a group heading's on every account of the group the draft gives no heading
|
|
245
308
|
const sends: { s: (typeof d.sections)[number]; a: DeskAccount; key: string; from: string }[] = []
|
|
@@ -259,14 +322,34 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
259
322
|
if (b) sends.push({ s, a: b, key, from: s.key })
|
|
260
323
|
}
|
|
261
324
|
for (const { s, a, key, from } of sends) {
|
|
262
|
-
// a place belongs to its account: a group's message lands on the account's own place
|
|
263
|
-
|
|
325
|
+
// a place belongs to its account: a group's message lands on the account's own place, or the first that
|
|
326
|
+
// takes the message's rating; an account's own heading names its place, which must take it. A heading's own
|
|
327
|
+
// `rating` is its message's (a release's nsfw picture on the venue that takes it), else the draft's
|
|
328
|
+
const rating = s.options.rating === undefined ? draft.rating : ratingOf(s.options.rating, false, speaker.name, `${file} ## ${s.key}`, errors)
|
|
329
|
+
const places = placesFor(a)
|
|
330
|
+
let place = s.options.place ?? ''
|
|
331
|
+
let refused = ''
|
|
332
|
+
if (from !== key) {
|
|
333
|
+
const l = landing(a, places, rating)
|
|
334
|
+
if ('skip' in l) {
|
|
335
|
+
draft.skipped.push({ account: a.id, why: l.skip })
|
|
336
|
+
continue
|
|
337
|
+
}
|
|
338
|
+
place = l.place
|
|
339
|
+
} else {
|
|
340
|
+
const ceiling = ceilingAt(a, places, place)
|
|
341
|
+
if (ceiling != null && !takes(ceiling, rating)) {
|
|
342
|
+
refused = `## ${key} goes to ${place || 'its profile'} on ${a.name}, which takes ${ceiling}, and ${s.options.rating === undefined ? 'the draft' : 'its message'} is ${rating}`
|
|
343
|
+
errors.push(`${file}: ${refused}`)
|
|
344
|
+
}
|
|
345
|
+
}
|
|
264
346
|
const footer = from.split('/')[0] === VERTICAL ? footerText : ''
|
|
265
347
|
const tags = tagList(s.options.tags)
|
|
266
348
|
const made = compose(a.id, { text: s.text, tags, footer }, { max: a.max, saturday })
|
|
267
349
|
const at = a.places.find((x) => x.id === place)
|
|
268
|
-
// a Discord place is a channel of
|
|
269
|
-
if (place !== '' &&
|
|
350
|
+
// a Discord place is a channel of its server's layout; with no layout, checked when the bot posts
|
|
351
|
+
if (place !== '' && !places.some((x) => x.id === place) && (a.id !== 'discord' || hasLayout(a)))
|
|
352
|
+
errors.push(`${file}: ## ${a.id} place "${place}" is no ${hasLayout(a) ? `channel of ${a.id}/layout.md` : `file of ${a.id}/places/`}`)
|
|
270
353
|
const title = s.options.title ?? ''
|
|
271
354
|
const write = at?.write || a.write
|
|
272
355
|
const post: SocialPost = {
|
|
@@ -294,11 +377,23 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
294
377
|
pin: s.options.pin === 'true',
|
|
295
378
|
from,
|
|
296
379
|
footer,
|
|
380
|
+
rating,
|
|
381
|
+
refused,
|
|
297
382
|
}
|
|
298
383
|
errors.push(...messageErrors(post, a))
|
|
384
|
+
if (post.media != null) {
|
|
385
|
+
const over = limitProblem(post.media.path, a.limits)
|
|
386
|
+
if (over != null) errors.push(`${file}: media "${post.media.name}" ${over} on ${a.name}: « fit » makes it a copy that fits`)
|
|
387
|
+
}
|
|
299
388
|
a.posts.push(post)
|
|
300
389
|
draft.posts.push(post)
|
|
301
390
|
}
|
|
391
|
+
// the repo's guard reads every public word and every media: while it names a problem, no message goes out
|
|
392
|
+
// a heading's own title (a Reddit or YouTube title) and its tags are public words too
|
|
393
|
+
const said = d.sections.flatMap((s) => [s.text, s.options.title ?? '', s.options.tags ?? ''])
|
|
394
|
+
draft.guard = guardWith(unit, { title: draft.title, alt: draft.alt, texts: [...new Set(said.filter((t) => t.trim() !== ''))], files: draft.media.map((m) => m.path) })
|
|
395
|
+
for (const g of draft.guard) errors.push(`${file}: ${g}`)
|
|
396
|
+
for (const p of draft.posts) if (draft.guard.length > 0) p.refused = `the repo's guard: ${draft.guard[0]}`
|
|
302
397
|
draft.posts.sort((x, y) => accounts.findIndex((a) => a.id === x.platform) - accounts.findIndex((a) => a.id === y.platform))
|
|
303
398
|
drafts.push(draft)
|
|
304
399
|
}
|
|
@@ -313,7 +408,10 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
313
408
|
} else if (i.id === own?.id && !a.posts.some((x) => x.slug === slug)) errors.push(`${a.file}: [[${ref}]] names no draft with a message to ${a.name} in this repo`)
|
|
314
409
|
}
|
|
315
410
|
const topics = unit?.topics ? [...unit.topics] : [...new Set(drafts.flatMap((d) => d.topics))].sort()
|
|
316
|
-
|
|
411
|
+
const kinds = deskKinds(root, ids.dir, unit?.kinds ?? [], errors)
|
|
412
|
+
// the rows and the server of the identity the repo speaks as are public words too: its guard reads them
|
|
413
|
+
if (own != null && unit?.guard != null) errors.push(...identityProblems([unit], own))
|
|
414
|
+
return { root, speaksAs: own?.id ?? null, identities, drafts, weekly: week, topics, kinds, errors, warnings }
|
|
317
415
|
}
|
|
318
416
|
|
|
319
417
|
/** one account of an identity, loud when absent */
|
|
@@ -324,6 +422,23 @@ export function accountOf(desk: Desk, identity: string, account: string): DeskAc
|
|
|
324
422
|
return a
|
|
325
423
|
}
|
|
326
424
|
|
|
425
|
+
/** a draft by what a command was given: its folder's name, its topic, or its path (relative to `cwd` or absolute, a
|
|
426
|
+
* trailing slash or its `draft.md` alike); a path outside the drafts folder is refused */
|
|
427
|
+
export function findDraft(desk: Desk, ref: string, cwd: string): Draft {
|
|
428
|
+
const where = `${LAYOUT.social}/drafts/`
|
|
429
|
+
let name = ref
|
|
430
|
+
if (ref.includes('/') || ref.endsWith('.md') || ref === '.') {
|
|
431
|
+
const parts = relative(draftsDir(desk.root), resolve(cwd, ref)).split(sep).filter((x) => x !== '')
|
|
432
|
+
if (parts.length === 2 && parts[1]!.endsWith('.md')) parts.pop()
|
|
433
|
+
if (parts.length !== 1 || parts[0] === '..') throw new Error(`${ref} is no draft of ${where}: a draft is a folder right under it`)
|
|
434
|
+
name = parts[0]!
|
|
435
|
+
}
|
|
436
|
+
const hits = desk.drafts.filter((x) => x.slug === name || x.slug.replace(/^\d{8}-\d{6}-/, '') === name)
|
|
437
|
+
if (hits.length > 1) throw new Error(`"${ref}" is the topic of ${hits.length} drafts: ${hits.map((x) => x.slug).join(', ')}; give its folder's name`)
|
|
438
|
+
if (hits[0] == null) throw new Error(`no draft "${ref}" in ${where}: give its folder's name, its topic or its path`)
|
|
439
|
+
return hits[0]
|
|
440
|
+
}
|
|
441
|
+
|
|
327
442
|
/** one message of a draft by its key, `<account>` or `<account>/<name>` */
|
|
328
443
|
export function draftPost(desk: Desk, slug: string, key: string): SocialPost {
|
|
329
444
|
const d = desk.drafts.find((x) => x.slug === slug)
|
|
@@ -1,14 +1,75 @@
|
|
|
1
1
|
// the size a committed draft media may take (wiki tools/shipkit/social.md, contract v3): GitHub refuses a file over
|
|
2
2
|
// 100 MB, so the desk's background push would fail with the commit already made. The desk's load reads the disk,
|
|
3
|
-
// SK036 the index at commit
|
|
4
|
-
import { statSync } from 'node:fs'
|
|
3
|
+
// SK036 the index at commit. A venue's own limits (an account's `limits:`) are checked per account it reaches
|
|
4
|
+
import { closeSync, openSync, readSync, statSync } from 'node:fs'
|
|
5
5
|
import { relative } from 'node:path'
|
|
6
6
|
import { gitBin } from '../core/git-bin.ts'
|
|
7
|
+
import type { MediaLimits } from '../identities/identities.ts'
|
|
7
8
|
|
|
8
9
|
export const MEDIA_MAX_BYTES = 95_000_000
|
|
9
10
|
|
|
10
11
|
export const mbOf = (n: number): string => `${Math.round(n / 1e6)} MB`
|
|
11
12
|
|
|
13
|
+
const VIDEO = /\.(mp4|m4v|mov|webm)$/i
|
|
14
|
+
const IMAGE = /\.(png|jpe?g|webp|gif)$/i
|
|
15
|
+
|
|
16
|
+
/** an mp4's length in seconds, read from its `mvhd` box (a few small reads, no ffprobe); null when it has none */
|
|
17
|
+
export function mp4Seconds(path: string): number | null {
|
|
18
|
+
let fd: number
|
|
19
|
+
try {
|
|
20
|
+
fd = openSync(path, 'r')
|
|
21
|
+
} catch {
|
|
22
|
+
return null
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const size = statSync(path).size
|
|
26
|
+
const head = Buffer.alloc(16)
|
|
27
|
+
const box = (at: number): { type: string; len: number; body: number } | null => {
|
|
28
|
+
if (at + 8 > size || readSync(fd, head, 0, 16, at) < 8) return null
|
|
29
|
+
let len = head.readUInt32BE(0)
|
|
30
|
+
let body = at + 8
|
|
31
|
+
if (len === 1) {
|
|
32
|
+
len = Number(head.readBigUInt64BE(8))
|
|
33
|
+
body = at + 16
|
|
34
|
+
} else if (len === 0) len = size - at
|
|
35
|
+
return len < 8 ? null : { type: head.toString('latin1', 4, 8), len, body }
|
|
36
|
+
}
|
|
37
|
+
const find = (from: number, to: number, type: string): { body: number; len: number; at: number } | null => {
|
|
38
|
+
for (let at = from; at < to; ) {
|
|
39
|
+
const b = box(at)
|
|
40
|
+
if (b == null) return null
|
|
41
|
+
if (b.type === type) return { body: b.body, len: b.len, at }
|
|
42
|
+
at += b.len
|
|
43
|
+
}
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
const moov = find(0, size, 'moov')
|
|
47
|
+
const mvhd = moov && find(moov.body, moov.at + moov.len, 'mvhd')
|
|
48
|
+
if (mvhd == null) return null
|
|
49
|
+
const m = Buffer.alloc(32)
|
|
50
|
+
readSync(fd, m, 0, 32, mvhd.body)
|
|
51
|
+
const v1 = m[0] === 1
|
|
52
|
+
const scale = v1 ? m.readUInt32BE(20) : m.readUInt32BE(12)
|
|
53
|
+
const dur = v1 ? Number(m.readBigUInt64BE(24)) : m.readUInt32BE(16)
|
|
54
|
+
return scale > 0 ? dur / scale : null
|
|
55
|
+
} finally {
|
|
56
|
+
closeSync(fd)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** why a media is over a venue's limits (« is 14 MB, over its 5 MB for an image »), or null; a file not on the disk
|
|
61
|
+
* (in the Space) or a kind the venue names no limit for passes */
|
|
62
|
+
export function limitProblem(path: string, l: MediaLimits): string | null {
|
|
63
|
+
const size = statSync(path, { throwIfNoEntry: false })?.size
|
|
64
|
+
if (size == null) return null
|
|
65
|
+
if (IMAGE.test(path) && l.imageBytes != null && size > l.imageBytes) return `is ${mbOf(size)}, over its ${mbOf(l.imageBytes)} for an image`
|
|
66
|
+
if (!VIDEO.test(path)) return null
|
|
67
|
+
if (l.videoBytes != null && size > l.videoBytes) return `is ${mbOf(size)}, over its ${mbOf(l.videoBytes)} for a video`
|
|
68
|
+
const s = l.videoSeconds != null && /\.(mp4|m4v|mov)$/i.test(path) ? mp4Seconds(path) : null
|
|
69
|
+
if (s != null && l.videoSeconds != null && s > l.videoSeconds + 0.05) return `is ${s.toFixed(1)} s, over its ${l.videoSeconds} s for a video`
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
|
|
12
73
|
/** the files of `paths` over the limit that git would commit: inside the repo and not ignored */
|
|
13
74
|
export function heavyMedia(root: string, paths: readonly string[]): { path: string; size: number }[] {
|
|
14
75
|
const big = [...new Set(paths)].flatMap((p) => {
|
package/src/social/presence.ts
CHANGED
|
@@ -216,7 +216,7 @@ export type Slot = { day: string; tag: string }
|
|
|
216
216
|
const SLOT_TAG = /^[a-z0-9-]+$/
|
|
217
217
|
const HOUR = /^(?:[01]\d|2[0-3]):[0-5]\d$/
|
|
218
218
|
|
|
219
|
-
const addDays = (day: string, n: number): string => new Date(dayMs(day) + n * 86_400_000).toISOString().slice(0, 10)
|
|
219
|
+
export const addDays = (day: string, n: number): string => new Date(dayMs(day) + n * 86_400_000).toISOString().slice(0, 10)
|
|
220
220
|
const isDay = (s: string): boolean => /^\d{4}-\d{2}-\d{2}$/.test(s) && !Number.isNaN(dayMs(s)) && addDays(s, 0) === s
|
|
221
221
|
const weekdayOf = (day: string): Weekday => WEEKDAYS[new Date(dayMs(day)).getUTCDay()]!
|
|
222
222
|
/** the Monday that opens a day's week */
|