rvlib-shipkit 2.12.0 → 2.13.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 +48 -13
- package/README.md +1 -1
- package/package.json +4 -2
- package/src/agent-time/store.ts +2 -2
- package/src/check.ts +1 -1
- package/src/checks/SK001-package-json-shape.check.ts +4 -0
- package/src/checks/SK003-claude-md-shape.check.ts +1 -1
- package/src/checks/SK004-gitignore-policy.check.ts +27 -2
- package/src/checks/SK005-rvlib-versions.check.ts +1 -1
- package/src/checks/SK008-reviewer-agent.check.ts +2 -2
- package/src/checks/SK012-config-barrel-import.check.ts +1 -1
- package/src/checks/SK015-nested-repo.check.ts +1 -1
- package/src/checks/SK035-public-clean.check.ts +46 -0
- package/src/checks/SK036-draft-media-size.check.ts +28 -0
- package/src/cli/cmd_Backup.ts +152 -0
- package/src/cli/cmd_Ci.ts +8 -11
- package/src/cli/cmd_Drill.ts +145 -0
- package/src/cli/cmd_Home.ts +50 -3
- package/src/cli/cmd_Media.ts +7 -5
- package/src/cli/cmd_Review.ts +4 -2
- package/src/cli/cmd_Shot.ts +5 -2
- package/src/cli/cmd_Smoke.ts +4 -1
- package/src/cli/cmd_Social.ts +226 -0
- package/src/cli/cmd_Start.ts +1 -1
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_Trailer.ts +5 -2
- package/src/cli/cmd_Veille.ts +173 -0
- package/src/cli/family-pages.ts +3 -0
- package/src/cli/registry.ts +13 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +1 -49
- package/src/collections/checks.ts +2 -1
- package/src/collections/collection-types.ts +11 -2
- package/src/collections/providers.ts +4 -4
- package/src/collections/review.ts +2 -1
- package/src/collections/tests.ts +19 -8
- package/src/contracts/apply-contracts.ts +1 -3
- package/src/contracts/contract-manifests.ts +2 -3
- package/src/contracts/contract-types.ts +0 -1
- package/src/contracts/contracts-engine.ts +0 -3
- package/src/core/app-icon.ts +9 -3
- package/src/core/bun-builtins.ts +2 -2
- package/src/core/discover-checks.ts +37 -5
- package/src/core/fix-scope.ts +4 -2
- package/src/core/floor-resolve.ts +68 -48
- package/src/core/floor.ts +9 -0
- package/src/core/git-root.ts +24 -0
- package/src/core/last-good.ts +3 -1
- package/src/core/layout.ts +8 -0
- package/src/core/log-stamp.ts +36 -0
- package/src/core/loop-watch.ts +93 -0
- package/src/core/machine-link.ts +134 -0
- package/src/core/memory-watch.ts +41 -0
- package/src/core/one-way-in-policy.ts +27 -19
- package/src/core/run-ci.ts +6 -8
- package/src/core/run-fixers.ts +9 -9
- package/src/core/slots.ts +21 -0
- package/src/core/tree-rev.ts +60 -0
- package/src/core/unit-files.ts +42 -0
- package/src/drill/render.ts +140 -0
- package/src/drill/run.ts +269 -0
- package/src/fleet/scan-fleet.ts +6 -5
- package/src/home/daemon-jobs.ts +201 -0
- package/src/home/global-context.ts +34 -1
- package/src/home/home-routes.ts +22 -15
- package/src/home/hubs.ts +10 -3
- package/src/home/inbox-shape.ts +53 -4
- package/src/home/inbox.ts +16 -1
- package/src/home/lib-watch.ts +10 -3
- package/src/home/machine-stores.ts +15 -29
- package/src/home/run-daemon.ts +15 -18
- package/src/home/run-pm.ts +2 -0
- package/src/home/serve-daemon.ts +4 -3
- package/src/home/serve-web.ts +104 -1
- package/src/hooks/commit-message.ts +28 -19
- package/src/hooks/leak-guard.ts +10 -3
- package/src/hooks/run-hooks.ts +2 -6
- package/src/identities/identities.ts +334 -0
- package/src/identities/machine-route.ts +126 -0
- package/src/identities/machine.ts +62 -0
- package/src/init-repo.ts +1 -1
- package/src/ledger/check-stats.ts +10 -9
- package/src/ledger/gate-checks.ts +32 -1
- package/src/ledger/record-kept.ts +112 -0
- package/src/ledger/repo-view.ts +10 -0
- package/src/ledger/run-log.ts +17 -12
- package/src/ledger/run-timeline.ts +8 -4
- package/src/ledger/store.ts +7 -0
- package/src/ledger/suite-log.ts +17 -13
- package/src/media-kinds.ts +2 -1
- package/src/media-store/backup/daemon.ts +73 -0
- package/src/media-store/backup/keys.ts +25 -0
- package/src/media-store/backup/manifest.ts +193 -0
- package/src/media-store/backup/restore.ts +192 -0
- package/src/media-store/backup/run.ts +278 -0
- package/src/media-store/backup/secret.ts +86 -0
- package/src/media-store/backup/snapshot.ts +64 -0
- package/src/media-store/backup/sources.ts +199 -0
- package/src/media-store/daemon.ts +56 -70
- package/src/media-store/put.ts +4 -2
- package/src/media-store/space.ts +23 -4
- package/src/pages/forward.ts +35 -0
- package/src/pages/frame-client.ts +118 -0
- package/src/pages/routes.ts +29 -0
- package/src/pages/unit.ts +92 -0
- package/src/plan/planner.ts +12 -0
- package/src/plan/repo-source.ts +19 -5
- package/src/reflect/transcript.ts +35 -10
- package/src/release/public-clean.ts +301 -0
- package/src/release/published-here.ts +22 -0
- package/src/release/run-bump.ts +2 -1
- package/src/release/run-release.ts +4 -1
- package/src/repo-config.ts +53 -2
- package/src/review/http.ts +16 -2
- package/src/review/model.ts +15 -4
- package/src/review/notes.ts +77 -0
- package/src/review/project.ts +6 -38
- package/src/review/routes.ts +4 -12
- package/src/review/store.ts +41 -1
- package/src/review/trailer-media.ts +7 -4
- package/src/review/trailer-shots.ts +21 -4
- package/src/review/unit.ts +1 -1
- package/src/scaffold/files/agent-handoff.md +3 -0
- package/src/scaffold/files/agent-index.md +4 -12
- package/src/scaffold/project-scaffold.ts +5 -4
- package/src/serve/embed.ts +1 -1
- package/src/serve/hub-app/col-card.tsx +3 -17
- package/src/serve/hub-app/col-tables-view.tsx +2 -1
- package/src/serve/hub-app/cols-svc.ts +0 -13
- package/src/serve/hub-app/dock-st.ts +4 -2
- package/src/serve/hub-app/dock-view.tsx +2 -0
- package/src/serve/hub-app/frames-st.ts +35 -0
- package/src/serve/hub-app/hash-route.ts +64 -1
- package/src/serve/hub-app/home-st.ts +31 -7
- package/src/serve/hub-app/home-strip.css +9 -1
- package/src/serve/hub-app/home-strip.tsx +7 -6
- package/src/serve/hub-app/home.html +5 -0
- package/src/serve/hub-app/hub-app.tsx +49 -5
- package/src/serve/hub-app/hub.css +29 -11
- package/src/serve/hub-app/icons.tsx +16 -1
- package/src/serve/hub-app/identities-st.ts +210 -0
- package/src/serve/hub-app/identities-view.tsx +352 -0
- package/src/serve/hub-app/identities.css +48 -0
- package/src/serve/hub-app/identity-address.ts +52 -0
- package/src/serve/hub-app/inbox-st.ts +59 -6
- package/src/serve/hub-app/inbox-view.tsx +48 -6
- package/src/serve/hub-app/inbox.css +12 -1
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +10 -2
- package/src/serve/hub-app/list-walk.ts +89 -0
- package/src/serve/hub-app/machine-st.ts +12 -0
- package/src/serve/hub-app/media-view.tsx +2 -1
- package/src/serve/hub-app/pages-frames.tsx +134 -0
- package/src/serve/hub-app/pages-svc.ts +111 -0
- package/src/serve/hub-app/palette-st.ts +18 -3
- package/src/serve/hub-app/palette-view.tsx +9 -2
- package/src/serve/hub-app/planned-view.tsx +2 -1
- package/src/serve/hub-app/project-list.css +18 -14
- package/src/serve/hub-app/project-list.tsx +88 -49
- package/src/serve/hub-app/projects-svc.ts +33 -3
- package/src/serve/hub-app/repo-sections.ts +19 -2
- package/src/serve/hub-app/repo-st.ts +75 -19
- package/src/serve/hub-app/review/review-cells.tsx +3 -3
- package/src/serve/hub-app/review/review-kit.ts +30 -7
- package/src/serve/hub-app/review/review-page.tsx +1 -1
- package/src/serve/hub-app/review/review-st.ts +19 -8
- package/src/serve/hub-app/review/review-thread.tsx +11 -9
- package/src/serve/hub-app/review/review-views.tsx +84 -19
- package/src/serve/hub-app/review/thread-st.ts +1 -10
- package/src/serve/hub-app/review/trailer-page.tsx +2 -1
- package/src/serve/hub-app/review.css +17 -8
- package/src/serve/hub-app/site/site-part.tsx +173 -0
- package/src/serve/hub-app/site/site-st.ts +157 -0
- package/src/serve/hub-app/site.css +35 -0
- package/src/serve/hub-app/social/calendar.tsx +182 -0
- package/src/serve/hub-app/social/comms-page.tsx +306 -0
- package/src/serve/hub-app/social/kit.tsx +244 -0
- package/src/serve/hub-app/social/post-card.tsx +456 -0
- package/src/serve/hub-app/social/problems.tsx +60 -0
- package/src/serve/hub-app/social/social-model.ts +154 -0
- package/src/serve/hub-app/social/social-page.tsx +674 -0
- package/src/serve/hub-app/social/social-st.ts +986 -0
- package/src/serve/hub-app/social.css +289 -0
- package/src/serve/hub-app/stores/stores-page.tsx +311 -0
- package/src/serve/hub-app/stores/stores-st.ts +286 -0
- package/src/serve/hub-app/stores.css +54 -0
- package/src/serve/hub-app/timeline-geometry.ts +1 -1
- package/src/serve/hub-app/timeline-view.tsx +3 -2
- package/src/serve/hub-app/tree-build.ts +6 -0
- package/src/serve/hub-app/tree-row.tsx +27 -4
- package/src/serve/hub-app/tree-svc.ts +18 -49
- package/src/serve/hub-app/veille/veille-page.tsx +514 -0
- package/src/serve/hub-app/veille/veille-st.ts +443 -0
- package/src/serve/hub-app/veille.css +84 -0
- package/src/serve/hub-runtime.ts +14 -9
- package/src/serve/project-gutter-route.ts +44 -12
- package/src/serve/run-lanes.ts +7 -4
- package/src/serve/same-origin.ts +1 -1
- package/src/serve/serve-hub.ts +20 -12
- package/src/serve/tracked-watch.ts +24 -3
- package/src/serve/warm-cell.ts +5 -1
- package/src/shipkit-files.ts +15 -4
- package/src/shipkit.ts +0 -1
- package/src/shot/box.ts +162 -0
- package/src/shot/browser-slot.ts +62 -0
- package/src/shot/client.ts +43 -7
- package/src/shot/clip-encoder.ts +93 -12
- package/src/shot/film-box.ts +188 -0
- package/src/shot/shooter.ts +50 -15
- package/src/shot/shot-ask.ts +10 -2
- package/src/shot/stepped-clip.ts +5 -4
- package/src/site/desk.ts +242 -0
- package/src/site/routes.ts +66 -0
- package/src/site/unit.ts +62 -0
- package/src/social/brands.ts +22 -0
- package/src/social/compose.ts +97 -0
- package/src/social/desk-index.ts +123 -0
- package/src/social/desk-wire.ts +64 -0
- package/src/social/drafts.ts +183 -0
- package/src/social/house.ts +24 -0
- package/src/social/load.ts +319 -0
- package/src/social/md.ts +70 -0
- package/src/social/media-facts.ts +53 -0
- package/src/social/media-kind.ts +189 -0
- package/src/social/media-limit.ts +42 -0
- package/src/social/media-of.ts +30 -0
- package/src/social/migrate.ts +123 -0
- package/src/social/open.ts +17 -0
- package/src/social/post-url.ts +158 -0
- package/src/social/presence.ts +332 -0
- package/src/social/public-read.ts +53 -0
- package/src/social/publish/bluesky.ts +168 -0
- package/src/social/publish/discord.ts +76 -0
- package/src/social/publish/index.ts +24 -0
- package/src/social/publish/secret.ts +13 -0
- package/src/social/push.ts +31 -0
- package/src/social/richtext.ts +37 -0
- package/src/social/routes.ts +180 -0
- package/src/social/stats.ts +134 -0
- package/src/social/text.ts +267 -0
- package/src/social/tracker-route.ts +39 -0
- package/src/social/tracker.ts +255 -0
- package/src/social/unit.ts +53 -0
- package/src/social/writes.ts +130 -0
- package/src/start-repo.ts +14 -9
- package/src/stores/collection.ts +27 -0
- package/src/stores/desk.ts +336 -0
- package/src/stores/model.ts +187 -0
- package/src/stores/routes.ts +126 -0
- package/src/stores/unit.ts +57 -0
- package/src/suite/calibrate.ts +127 -0
- package/src/suite/core-counters.ts +91 -0
- package/src/suite/judge-suites.ts +94 -34
- package/src/suite/suite-cli.ts +44 -10
- package/src/suite/suite-cpu-preload.ts +34 -9
- package/src/trailer/adapter.ts +4 -0
- package/src/trailer/build.ts +42 -11
- package/src/trailer/ffmpeg.ts +11 -0
- package/src/trailer/footage.ts +30 -13
- package/src/trailer/grammar.ts +18 -2
- package/src/trailer/graph.ts +28 -6
- package/src/trailer/passage.ts +17 -5
- package/src/trailer/plan.ts +74 -3
- package/src/trailer/stitch.ts +67 -26
- package/src/trailer/url.ts +1 -1
- package/src/trailer/versions.ts +24 -0
- package/src/ts/gate-typecheck.ts +32 -0
- package/src/ts/typecheck-cli.ts +9 -11
- package/src/tui/tui-app.tsx +0 -1
- package/src/veille/asks.ts +155 -0
- package/src/veille/auto.ts +31 -0
- package/src/veille/batch.ts +27 -0
- package/src/veille/chrome.ts +127 -0
- package/src/veille/collection.ts +28 -0
- package/src/veille/desk.ts +242 -0
- package/src/veille/identity.ts +80 -0
- package/src/veille/import.ts +68 -0
- package/src/veille/log.ts +183 -0
- package/src/veille/platforms.ts +118 -0
- package/src/veille/reads.ts +66 -0
- package/src/veille/replied.ts +110 -0
- package/src/veille/routes.ts +185 -0
- package/src/veille/service.ts +81 -0
- package/src/veille/watch.ts +116 -0
- package/src/veille/worth.ts +46 -0
- package/src/wiki/scan-md.ts +18 -0
- package/src/collections/posts.ts +0 -142
- package/src/contracts/manifests/social.contract.ts +0 -20
- package/src/scaffold/files/agent-coding.md +0 -35
- package/src/ts/typecheck-cache.ts +0 -11
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// the desk on the wire (wiki build/shipkit/social.md, Routes): a message leaves out what its draft and its account
|
|
2
|
+
// already say (the draft's fields, its media by index, the write link its account fills), and an account's messages
|
|
3
|
+
// are not sent twice, they are its drafts' messages again. `deskOfWire` gives back the very desk `wireOf` was given
|
|
4
|
+
// (tests/social-desk.test.ts pins it). Pure, so the hub page imports it
|
|
5
|
+
import { fillLink } from './compose.ts'
|
|
6
|
+
import type { Desk, DeskAccount, DeskIdentity, Draft, Media, SocialPost } from './load.ts'
|
|
7
|
+
|
|
8
|
+
/** the fields every message of a draft shares with it */
|
|
9
|
+
const FROM_DRAFT = ['slug', 'identity', 'file', 'status', 'kind', 'angle', 'alt'] as const
|
|
10
|
+
type FromDraft = (typeof FROM_DRAFT)[number]
|
|
11
|
+
|
|
12
|
+
/** `media` a number: the index of the draft's media it is; `href` absent: the one its account's write page gives */
|
|
13
|
+
export type WirePost = Omit<SocialPost, FromDraft | 'media' | 'href'> & Partial<Pick<SocialPost, FromDraft | 'href'>> & { media: Media | number | null }
|
|
14
|
+
export type WireDraft = Omit<Draft, 'posts'> & { posts: WirePost[] }
|
|
15
|
+
export type WireAccount = Omit<DeskAccount, 'posts'>
|
|
16
|
+
export type WireIdentity = Omit<DeskIdentity, 'accounts'> & { accounts: WireAccount[] }
|
|
17
|
+
export type Wire<T extends Desk> = Omit<T, 'drafts' | 'identities'> & { drafts: WireDraft[]; identities: WireIdentity[] }
|
|
18
|
+
|
|
19
|
+
type Accounts = ReadonlyMap<string, Pick<DeskAccount, 'write' | 'places'>>
|
|
20
|
+
|
|
21
|
+
const accountsOf = (identities: readonly { id: string; accounts: readonly (Pick<DeskAccount, 'id' | 'write' | 'places'>)[] }[]): Map<string, Pick<DeskAccount, 'write' | 'places'>> =>
|
|
22
|
+
new Map(identities.flatMap((i) => i.accounts.map((a) => [`${i.id}/${a.id}`, a] as const)))
|
|
23
|
+
|
|
24
|
+
/** the write link a message gets from its account and place, as the load fills it */
|
|
25
|
+
function writeLink(p: Pick<SocialPost, 'place' | 'title' | 'text'>, a: Pick<DeskAccount, 'write' | 'places'> | undefined): string | null {
|
|
26
|
+
const write = a?.places.find((x) => x.id === p.place)?.write || a?.write || ''
|
|
27
|
+
return write === '' ? null : fillLink(write, { url: '', title: p.title, text: p.text })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function lean(p: SocialPost, d: Draft, accounts: Accounts): WirePost {
|
|
31
|
+
const out: Omit<Partial<SocialPost>, 'media'> & { media?: Media | number | null } = { ...p }
|
|
32
|
+
for (const k of FROM_DRAFT) if (p[k] === d[k]) delete out[k]
|
|
33
|
+
const at = p.media == null ? -1 : d.media.findIndex((m) => m.name === p.media!.name && m.path === p.media!.path)
|
|
34
|
+
if (at >= 0) out.media = at
|
|
35
|
+
if (p.href === writeLink(p, accounts.get(`${p.identity}/${p.platform}`))) delete out.href
|
|
36
|
+
return out as WirePost
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function wireOf<T extends Desk>(desk: T): Wire<T> {
|
|
40
|
+
const accounts = accountsOf(desk.identities)
|
|
41
|
+
return {
|
|
42
|
+
...desk,
|
|
43
|
+
identities: desk.identities.map((i) => ({ ...i, accounts: i.accounts.map(({ posts: _, ...a }) => a) })),
|
|
44
|
+
drafts: desk.drafts.map((d) => ({ ...d, posts: d.posts.map((p) => lean(p, d, accounts)) })),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function deskOfWire<T extends Desk>(w: Wire<T>): T {
|
|
49
|
+
const writes = accountsOf(w.identities)
|
|
50
|
+
const drafts: Draft[] = w.drafts.map((d) => {
|
|
51
|
+
const full: Draft = { ...d, posts: [] }
|
|
52
|
+
full.posts = d.posts.map(({ media, ...p }) => {
|
|
53
|
+
const post = { slug: d.slug, identity: d.identity, file: d.file, status: d.status, kind: d.kind, angle: d.angle, alt: d.alt, ...p, media: typeof media === 'number' ? (d.media[media] ?? null) : media } as SocialPost
|
|
54
|
+
if (!('href' in p)) post.href = writeLink(post, writes.get(`${post.identity}/${post.platform}`))
|
|
55
|
+
return post
|
|
56
|
+
})
|
|
57
|
+
return full
|
|
58
|
+
})
|
|
59
|
+
const identities: DeskIdentity[] = w.identities.map((i) => ({ ...i, accounts: i.accounts.map((a) => ({ ...a, posts: [] })) }))
|
|
60
|
+
const accounts = new Map(identities.flatMap((i) => i.accounts.map((a) => [`${i.id}/${a.id}`, a] as const)))
|
|
61
|
+
// the drafts newest first, each one's messages in its order: the order the load gave every account
|
|
62
|
+
for (const d of drafts) for (const p of d.posts) accounts.get(`${p.identity}/${p.platform}`)?.posts.push(p)
|
|
63
|
+
return { ...w, identities, drafts } as unknown as T
|
|
64
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// one draft, one message for every platform (wiki build/shipkit/social.md, contract v3): `drafts/<slug>/draft.md` read into its
|
|
2
|
+
// sections and its posted links, the one write (a platform's line of `## Posted`), and where a media name points
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
4
|
+
import { homedir } from 'node:os'
|
|
5
|
+
import { isAbsolute, join } from 'node:path'
|
|
6
|
+
import { TAG } from './compose.ts'
|
|
7
|
+
import { parseFrontmatter } from './md.ts'
|
|
8
|
+
|
|
9
|
+
/** the headings a draft holds besides its platforms */
|
|
10
|
+
const OWN = ['Angle', 'Posted'] as const
|
|
11
|
+
const OPTIONS = ['name', 'place', 'title', 'media', 'pin', 'outro', 'mark', 'tags'] as const
|
|
12
|
+
type Option = (typeof OPTIONS)[number]
|
|
13
|
+
/** the options whose value is one of a few words: a vertical's end and its watermark's corner, words a project reads */
|
|
14
|
+
const WORDS: Partial<Record<Option, readonly string[]>> = { outro: ['montage', 'short', 'none'], mark: ['left', 'right'] }
|
|
15
|
+
|
|
16
|
+
const HEADING = /^## (.+?)[ \t]*$/gm
|
|
17
|
+
const PLATFORM = /^([a-z0-9-]+)(?:\s*\((.*)\))?$/
|
|
18
|
+
const POSTED_LINE = /^- ([a-z0-9-]+(?:\/[a-z0-9-]+)?): (\S+)$/
|
|
19
|
+
|
|
20
|
+
/** `key` is the platform, or `<platform>/<name>` when the platform holds several messages */
|
|
21
|
+
type DraftSection = { platform: string; key: string; options: Partial<Record<Option, string>>; text: string }
|
|
22
|
+
|
|
23
|
+
type ParsedDraft = {
|
|
24
|
+
meta: Record<string, string>
|
|
25
|
+
angle: string
|
|
26
|
+
sections: DraftSection[]
|
|
27
|
+
/** a section's key → the URL he pasted */
|
|
28
|
+
posted: Map<string, string>
|
|
29
|
+
errors: string[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** a comma list, `a.png, b.mp4`; `none` is the empty list */
|
|
33
|
+
export const fileList = (v: string | undefined): string[] =>
|
|
34
|
+
v == null || v.trim() === 'none'
|
|
35
|
+
? []
|
|
36
|
+
: v
|
|
37
|
+
.split(',')
|
|
38
|
+
.map((x) => x.trim())
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
|
|
41
|
+
/** a topic is a word the project's unit names (its `topics`); with none, any word */
|
|
42
|
+
export type Topic = string
|
|
43
|
+
|
|
44
|
+
/** a draft's `topics`, `world, towns`, as a list; a word off the unit's list is an error at its file */
|
|
45
|
+
export function topicList(v: string | undefined, file: string, errors: string[], topics: readonly string[] | null): Topic[] {
|
|
46
|
+
const out: Topic[] = []
|
|
47
|
+
for (const t of fileList(v)) {
|
|
48
|
+
if (topics == null || topics.includes(t)) out.push(t)
|
|
49
|
+
else errors.push(`${file}: topic "${t}" is not one of ${topics.join(', ')}`)
|
|
50
|
+
}
|
|
51
|
+
return out
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** a heading's `tags`, `#a #b`, as a list */
|
|
55
|
+
export const tagList = (v: string | undefined): string[] => (v ?? '').split(/\s+/).filter(Boolean)
|
|
56
|
+
|
|
57
|
+
/** `place: public, title: Hello, world` → its keys; a comma splits only before a known key */
|
|
58
|
+
function options(raw: string, where: string, errors: string[]): Partial<Record<Option, string>> {
|
|
59
|
+
const out: Partial<Record<Option, string>> = {}
|
|
60
|
+
for (const part of raw.split(new RegExp(`,\\s*(?=(?:${OPTIONS.join('|')}):)`))) {
|
|
61
|
+
const i = part.indexOf(':')
|
|
62
|
+
const key = part.slice(0, i).trim()
|
|
63
|
+
if (i === -1 || !(OPTIONS as readonly string[]).includes(key)) {
|
|
64
|
+
errors.push(`${where}: "${part.trim()}" is not one of ${OPTIONS.map((o) => `${o}: …`).join(', ')}`)
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
const value = part.slice(i + 1).trim()
|
|
68
|
+
const words = WORDS[key as Option]
|
|
69
|
+
if (words != null && !words.includes(value)) errors.push(`${where}: ${key} "${value}" is not ${words.length > 1 ? `${words.slice(0, -1).join(', ')} or ${words.at(-1)}` : words[0]}`)
|
|
70
|
+
if (key === 'tags') for (const t of tagList(value)) if (!TAG.test(t)) errors.push(`${where}: tag "${t}" is not #word`)
|
|
71
|
+
out[key as Option] = value
|
|
72
|
+
}
|
|
73
|
+
return out
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `groups`: a group's word to its accounts (wiki build/shipkit/social.md, The accounts): a heading named for it goes to each, so their
|
|
77
|
+
* posted lines need no heading of their own */
|
|
78
|
+
export function parseDraft(raw: string, file: string, groups: ReadonlyMap<string, readonly string[]> = new Map()): ParsedDraft {
|
|
79
|
+
const { meta, body } = parseFrontmatter(raw)
|
|
80
|
+
const errors: string[] = []
|
|
81
|
+
const heads = [...body.matchAll(HEADING)]
|
|
82
|
+
const text = (k: number): string => body.slice(heads[k]!.index + heads[k]![0].length, heads[k + 1]?.index ?? body.length).trim()
|
|
83
|
+
const d: ParsedDraft = { meta, angle: '', sections: [], posted: new Map(), errors }
|
|
84
|
+
heads.forEach((h, k) => {
|
|
85
|
+
const name = h[1]!
|
|
86
|
+
if (name === 'Angle') d.angle = text(k)
|
|
87
|
+
else if (name === 'Posted')
|
|
88
|
+
for (const line of text(k).split('\n')) {
|
|
89
|
+
if (line.trim() === '') continue
|
|
90
|
+
const m = POSTED_LINE.exec(line.trim())
|
|
91
|
+
if (m == null) errors.push(`${file}: "${line}" under ## Posted is not "- <platform>[/<name>]: <url>"`)
|
|
92
|
+
else d.posted.set(m[1]!, m[2]!)
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const m = PLATFORM.exec(name)
|
|
96
|
+
if (m == null) {
|
|
97
|
+
errors.push(`${file}: "## ${name}" is neither ${OWN.join(', ')} nor a platform, "## <id> (<options>)"`)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
const opts = m[2] == null ? {} : options(m[2], `${file} ## ${m[1]}`, errors)
|
|
101
|
+
if (groups.has(m[1]!) && opts.place != null) errors.push(`${file}: ## ${m[1]} is a group: each account's own place holds, never place: …`)
|
|
102
|
+
const key = opts.name == null ? m[1]! : `${m[1]}/${opts.name}`
|
|
103
|
+
if (opts.name != null && !/^[a-z0-9-]+$/.test(opts.name)) errors.push(`${file}: ## ${m[1]} name "${opts.name}" is not kebab case`)
|
|
104
|
+
if (d.sections.some((s) => s.key === key)) errors.push(`${file}: ## ${key} twice (a repeated platform takes name: …)`)
|
|
105
|
+
d.sections.push({ platform: m[1]!, key, options: opts, text: text(k) })
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
for (const p of d.posted.keys()) if (!d.sections.some((s) => s.key === p || groupKeys(s, groups).includes(p))) errors.push(`${file}: posted on ${p}, but no ## ${p}`)
|
|
109
|
+
return d
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** the keys of a group heading's message on each account of the group, `<account>[/<name>]` each; none for an account's
|
|
113
|
+
* own heading */
|
|
114
|
+
export function groupKeys(s: DraftSection, groups: ReadonlyMap<string, readonly string[]>): string[] {
|
|
115
|
+
return (groups.get(s.platform) ?? []).map((a) => (s.options.name == null ? a : `${a}/${s.options.name}`))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** every media name a draft gives, its own then its platforms', each once */
|
|
119
|
+
export function mediaNames(d: ParsedDraft): string[] {
|
|
120
|
+
const out = fileList(d.meta.media)
|
|
121
|
+
for (const s of d.sections) for (const m of fileList(s.options.media)) if (!out.includes(m)) out.push(m)
|
|
122
|
+
return out
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** where a media name points: `/…` or `~/…` anywhere on the disk, else the draft's folder, else the repo's root; null
|
|
126
|
+
* when none holds it */
|
|
127
|
+
export function resolveMedia(name: string, dir: string, repo: string): string | null {
|
|
128
|
+
if (name.startsWith('~/')) return existsSync(join(homedir(), name.slice(2))) ? join(homedir(), name.slice(2)) : null
|
|
129
|
+
if (isAbsolute(name)) return existsSync(name) ? name : null
|
|
130
|
+
for (const base of [dir, repo]) if (existsSync(join(base, name))) return join(base, name)
|
|
131
|
+
return null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** a rendered trailer the draft makes and never commits (wiki build/shipkit/social.md, contract v3): its name says
|
|
135
|
+
* `-trailer.mp4` and its text names the command that writes it, `--out <its path from the repo's root>` */
|
|
136
|
+
export function renderedTrailer(name: string, raw: string, dirFromRepo: string): boolean {
|
|
137
|
+
return name.endsWith('-trailer.mp4') && raw.includes(`--out ${join(dirFromRepo, name)}`)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** a section's line of `## Posted` set, or removed when the URL is null; the section is added at the end when absent, and
|
|
141
|
+
* goes with its last line, so a link pasted then cleared gives the draft back as it was */
|
|
142
|
+
export function setPostedLine(raw: string, key: string, url: string | null): string {
|
|
143
|
+
const at = raw.search(/^## Posted[ \t]*$/m)
|
|
144
|
+
const head = at === -1 ? raw.trimEnd() : raw.slice(0, at).trimEnd()
|
|
145
|
+
const rest = at === -1 ? '' : raw.slice(at).replace(/^.*\n?/, '')
|
|
146
|
+
const end = rest.search(/^## /m)
|
|
147
|
+
const lines = (end === -1 ? rest : rest.slice(0, end)).split('\n').filter((l) => l.trim() !== '' && POSTED_LINE.exec(l.trim())?.[1] !== key)
|
|
148
|
+
if (url != null) lines.push(`- ${key}: ${url}`)
|
|
149
|
+
const tail = end === -1 ? '' : `\n\n${rest.slice(end).trimEnd()}`
|
|
150
|
+
if (lines.length === 0) return `${head}${tail}\n`
|
|
151
|
+
return `${head}\n\n## Posted\n\n${lines.join('\n')}\n${tail}${tail ? '\n' : ''}`
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** one heading's text replaced, and its `title` option when given (empty removes it); the heading is found by its key,
|
|
155
|
+
* `<platform or group>[/<name>]` */
|
|
156
|
+
export function setHeadingText(raw: string, key: string, text: string, title?: string, tags?: string): string {
|
|
157
|
+
const body = text.trim()
|
|
158
|
+
if (/^## /m.test(body)) throw new Error(`a text holds no "## " line: it would start a heading`)
|
|
159
|
+
const heads = [...raw.matchAll(HEADING)]
|
|
160
|
+
const k = heads.findIndex((h) => {
|
|
161
|
+
const m = PLATFORM.exec(h[1]!)
|
|
162
|
+
if (m == null) return false
|
|
163
|
+
const name = m[2] == null ? undefined : options(m[2], '', []).name
|
|
164
|
+
return (name == null ? m[1] : `${m[1]}/${name}`) === key
|
|
165
|
+
})
|
|
166
|
+
const h = heads[k]
|
|
167
|
+
if (h == null) throw new Error(`no ## ${key} in the draft`)
|
|
168
|
+
const m = PLATFORM.exec(h[1]!)!
|
|
169
|
+
let line = h[0]
|
|
170
|
+
if (title !== undefined || tags !== undefined) {
|
|
171
|
+
const opts = m[2] == null ? {} : options(m[2], '', [])
|
|
172
|
+
for (const [o, v] of [['title', title], ['tags', tags === undefined ? undefined : tagList(tags).join(' ')]] as const) {
|
|
173
|
+
if (v === undefined) continue
|
|
174
|
+
if (v.trim() === '') delete opts[o]
|
|
175
|
+
else opts[o] = v.trim()
|
|
176
|
+
}
|
|
177
|
+
const list = (Object.keys(opts) as Option[]).map((o) => `${o}: ${opts[o]}`)
|
|
178
|
+
line = `## ${m[1]}${list.length ? ` (${list.join(', ')})` : ''}`
|
|
179
|
+
}
|
|
180
|
+
const next = heads[k + 1]
|
|
181
|
+
const tail = next == null ? '\n' : `\n\n${raw.slice(next.index)}`
|
|
182
|
+
return `${raw.slice(0, h.index)}${line}\n\n${body}${tail}`
|
|
183
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// the house repos and who each speaks as, read from each repo.config.ts as text (never imported: a repo's config may
|
|
2
|
+
// need its own install), so `sk identities` lists every repo in a few ms
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { homedir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { houseRepos } from '../serve/project-gutter.ts'
|
|
7
|
+
|
|
8
|
+
export type HouseRepo = { name: string; path: string; speaksAs: string | undefined }
|
|
9
|
+
|
|
10
|
+
/** `speaksAs: '<id>'` of a config's text, undefined when it names none */
|
|
11
|
+
export const speaksAsOfText = (text: string): string | undefined => /^\s*speaksAs:\s*['"]([a-z0-9-]+)['"]/m.exec(text)?.[1]
|
|
12
|
+
|
|
13
|
+
export async function houseRepoRoots(cwd = process.cwd()): Promise<HouseRepo[]> {
|
|
14
|
+
const { repos } = houseRepos(cwd, homedir())
|
|
15
|
+
return repos.map((r) => {
|
|
16
|
+
let text = ''
|
|
17
|
+
try {
|
|
18
|
+
text = readFileSync(join(r.path, 'repo.config.ts'), 'utf8')
|
|
19
|
+
} catch {
|
|
20
|
+
text = ''
|
|
21
|
+
}
|
|
22
|
+
return { name: r.name, path: r.path, speaksAs: speaksAsOfText(text) }
|
|
23
|
+
})
|
|
24
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// a repo's social folder read with every identity (wiki build/shipkit/social.md, contract v3): its drafts, one folder a
|
|
2
|
+
// message, each platform's part handed to its speaker's account; the rhythm; the load's errors. Read from the disk as
|
|
3
|
+
// it is on every call: the desks and `sk social` never hold a stale copy
|
|
4
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
5
|
+
import { join, relative } from 'node:path'
|
|
6
|
+
import { LAYOUT } from '../core/layout.ts'
|
|
7
|
+
import { speakerOf, type Account, type Identities, type Identity } from '../identities/identities.ts'
|
|
8
|
+
import { fileList, groupKeys, mediaNames, parseDraft, renderedTrailer, resolveMedia, tagList, topicList, type Topic } from './drafts.ts'
|
|
9
|
+
import { compose, fillLink, messageLength } from './compose.ts'
|
|
10
|
+
import { parseFrontmatter, table } from './md.ts'
|
|
11
|
+
import { type Family, familyOf, type Slot, slotOf, type WeeklySlot, weeklySlots } from './presence.ts'
|
|
12
|
+
import { purgedAt } from './media-facts.ts'
|
|
13
|
+
import { heavyMedia, mbOf, MEDIA_MAX_BYTES } from './media-limit.ts'
|
|
14
|
+
import { pushFailure } from './push.ts'
|
|
15
|
+
import type { SocialUnit } from './unit.ts'
|
|
16
|
+
|
|
17
|
+
/** a draft's folder name: the moment it was made, then its topic */
|
|
18
|
+
export const DRAFT_NAME = /^\d{8}-\d{6}-[a-z0-9-]+$/
|
|
19
|
+
|
|
20
|
+
/** the files the social folder holds beside `drafts/` */
|
|
21
|
+
const FOLDER_FILES = new Set(['rhythm.md', 'README.md'])
|
|
22
|
+
|
|
23
|
+
export const draftsDir = (root: string): string => join(root, LAYOUT.social, 'drafts')
|
|
24
|
+
|
|
25
|
+
/** a media as the draft names it, and where it is on the disk: its folder, the repo, or anywhere */
|
|
26
|
+
export type Media = { name: string; path: string }
|
|
27
|
+
|
|
28
|
+
/** one account's part of a draft: what its card shows and what a publisher sends */
|
|
29
|
+
export type SocialPost = {
|
|
30
|
+
slug: string
|
|
31
|
+
/** the speaker's identity */
|
|
32
|
+
identity: string
|
|
33
|
+
platform: string
|
|
34
|
+
/** the account, or `<account>/<name>` for one of several messages there: its key under `## Posted` */
|
|
35
|
+
key: string
|
|
36
|
+
/** the message's name among several on one account; empty when alone */
|
|
37
|
+
name: string
|
|
38
|
+
/** the draft's file, from the repo's root */
|
|
39
|
+
file: string
|
|
40
|
+
status: string
|
|
41
|
+
/** the URL of its line under `## Posted`; empty, it waits */
|
|
42
|
+
posted: string
|
|
43
|
+
kind: string
|
|
44
|
+
title: string
|
|
45
|
+
angle: string
|
|
46
|
+
text: string
|
|
47
|
+
length: number
|
|
48
|
+
media: Media | null
|
|
49
|
+
alt: string
|
|
50
|
+
/** the place it goes to, a file of places/; empty, the account's own profile */
|
|
51
|
+
place: string
|
|
52
|
+
/** the account's write page, prefilled when it takes {text}; null when it names none */
|
|
53
|
+
href: string | null
|
|
54
|
+
pin: boolean
|
|
55
|
+
/** the key of the heading its text comes from: its own, or its group's (`short`, `short/<name>`) */
|
|
56
|
+
from: string
|
|
57
|
+
/** the links under a vertical message's text, counted and copied with it; empty elsewhere */
|
|
58
|
+
footer: string
|
|
59
|
+
/** the heading's own text, as he writes it; `text` is it composed for the account */
|
|
60
|
+
body: string
|
|
61
|
+
tags: string[]
|
|
62
|
+
/** X's links, out of its text: the first reply under the post; empty elsewhere */
|
|
63
|
+
reply: string
|
|
64
|
+
/** its write page takes the text (`{text}`); else « Open » copies it first */
|
|
65
|
+
prefilled: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** a draft's post.md: a long article of the identity's site */
|
|
69
|
+
export type Article = { title: string; description: string; date: string; draft: boolean; url: string; file: string }
|
|
70
|
+
|
|
71
|
+
export type Draft = {
|
|
72
|
+
slug: string
|
|
73
|
+
/** from the repo's root */
|
|
74
|
+
file: string
|
|
75
|
+
/** absolute */
|
|
76
|
+
path: string
|
|
77
|
+
dir: string
|
|
78
|
+
/** who speaks: its own `speaksAs`, else the repo's */
|
|
79
|
+
identity: string
|
|
80
|
+
title: string
|
|
81
|
+
kind: string
|
|
82
|
+
topics: Topic[]
|
|
83
|
+
slot: Slot | null
|
|
84
|
+
status: string
|
|
85
|
+
angle: string
|
|
86
|
+
media: Media[]
|
|
87
|
+
alt: string
|
|
88
|
+
posts: SocialPost[]
|
|
89
|
+
article: Article | null
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** an identity's account with the repo's messages to it */
|
|
93
|
+
export type DeskAccount = Account & { family: Family; posts: SocialPost[] }
|
|
94
|
+
export type DeskIdentity = Omit<Identity, 'accounts'> & { accounts: DeskAccount[] }
|
|
95
|
+
|
|
96
|
+
export type Desk = {
|
|
97
|
+
root: string
|
|
98
|
+
/** the repo's own identity, null when none resolves */
|
|
99
|
+
speaksAs: string | null
|
|
100
|
+
identities: DeskIdentity[]
|
|
101
|
+
drafts: Draft[]
|
|
102
|
+
weekly: WeeklySlot[]
|
|
103
|
+
/** the topics a draft may take: the unit's, else every one the drafts name */
|
|
104
|
+
topics: Topic[]
|
|
105
|
+
errors: string[]
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const read = (abs: string): string => readFileSync(abs, 'utf8')
|
|
109
|
+
|
|
110
|
+
/** the group whose messages need a compiled 9:16 video */
|
|
111
|
+
export const VERTICAL = 'vertical'
|
|
112
|
+
/** the name of a compiled vertical video */
|
|
113
|
+
export const VERTICAL_FILE = /-vertical\.mp4$/
|
|
114
|
+
|
|
115
|
+
/** what one message breaks on its account: a text past the account's max, a `## vertical` message without its video */
|
|
116
|
+
export function messageErrors(post: Pick<SocialPost, 'file' | 'from' | 'length' | 'media'>, a: Pick<Account, 'name' | 'max'>): string[] {
|
|
117
|
+
const out: string[] = []
|
|
118
|
+
if (a.max !== null && post.length > a.max) out.push(`${post.file}: ## ${post.from} is ${post.length} on ${a.name}, over its ${a.max}`)
|
|
119
|
+
if (post.from.split('/')[0] === VERTICAL && !VERTICAL_FILE.test(post.media?.name ?? ''))
|
|
120
|
+
out.push(`${post.file}: ## ${post.from} goes to ${a.name} without its vertical video (media: media/<name>-vertical.mp4)`)
|
|
121
|
+
return out
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** the vertical's footer: each online account with a `footer` label, in their order, `<label>: <profile>` */
|
|
125
|
+
export const footerOf = (accounts: readonly Pick<Account, 'footer' | 'live'>[]): string =>
|
|
126
|
+
accounts
|
|
127
|
+
.filter((a) => a.footer !== '' && a.live !== '')
|
|
128
|
+
.map((a) => `${a.footer}: ${a.live}`)
|
|
129
|
+
.join('\n')
|
|
130
|
+
|
|
131
|
+
function weekly(root: string, errors: string[]): WeeklySlot[] {
|
|
132
|
+
const abs = join(root, LAYOUT.social, 'rhythm.md')
|
|
133
|
+
return existsSync(abs) ? weeklySlots(table(parseFrontmatter(read(abs)).body, 'Slots'), relative(root, abs), errors) : []
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function article(dir: string, root: string, unit: SocialUnit | null): Article | null {
|
|
137
|
+
const abs = join(dir, 'post.md')
|
|
138
|
+
if (!existsSync(abs)) return null
|
|
139
|
+
const { meta } = parseFrontmatter(read(abs))
|
|
140
|
+
let url = ''
|
|
141
|
+
try {
|
|
142
|
+
url = unit?.article?.(dir).url ?? ''
|
|
143
|
+
} catch {
|
|
144
|
+
url = ''
|
|
145
|
+
}
|
|
146
|
+
return { title: meta.title ?? '', description: meta.description ?? '', date: meta.date ?? '', draft: meta.draft === 'true', url, file: relative(root, abs) }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** the v2 channel files left in the folder: each one an error naming the command that moves it */
|
|
150
|
+
function v2Left(root: string, errors: string[]): void {
|
|
151
|
+
const at = join(root, LAYOUT.social)
|
|
152
|
+
if (!existsSync(at)) return
|
|
153
|
+
for (const e of readdirSync(at)) {
|
|
154
|
+
if (e === 'drafts' || FOLDER_FILES.has(e) || e.startsWith('.')) continue
|
|
155
|
+
const abs = join(at, e)
|
|
156
|
+
if (statSync(abs).isDirectory() && readdirSync(abs).some((f) => f.endsWith('.md'))) errors.push(`${relative(root, abs)}/: a v2 channel folder; sk social migrate makes its posts drafts`)
|
|
157
|
+
else errors.push(`${relative(root, abs)}: the social folder holds drafts/, rhythm.md and README.md only`)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** the desk of a repo: every identity with its accounts, the repo's drafts on them, the newest first */
|
|
162
|
+
export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string | undefined; unit?: SocialUnit | null; now?: Date } = {}): Desk {
|
|
163
|
+
const errors = [...ids.errors]
|
|
164
|
+
const unit = o.unit ?? null
|
|
165
|
+
const own = speakerOf(o.speaksAs, ids)
|
|
166
|
+
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'})`)
|
|
167
|
+
const identities: DeskIdentity[] = ids.identities.map((i) => ({ ...i, accounts: i.accounts.map((a) => ({ ...a, family: familyOf(a), posts: [] })) }))
|
|
168
|
+
const pushed = pushFailure(root)
|
|
169
|
+
if (pushed != null) errors.push(pushed)
|
|
170
|
+
const week = weekly(root, errors)
|
|
171
|
+
v2Left(root, errors)
|
|
172
|
+
const dir = draftsDir(root)
|
|
173
|
+
const drafts: Draft[] = []
|
|
174
|
+
const named = new Set<string>()
|
|
175
|
+
// the Saturday tag joins on the Mac's Saturday
|
|
176
|
+
const saturday = (o.now ?? new Date()).getDay() === 6
|
|
177
|
+
for (const slug of existsSync(dir) ? readdirSync(dir).sort().reverse() : []) {
|
|
178
|
+
if (slug.startsWith('.')) continue
|
|
179
|
+
const ddir = join(dir, slug)
|
|
180
|
+
const abs = join(ddir, 'draft.md')
|
|
181
|
+
const file = relative(root, abs)
|
|
182
|
+
if (!DRAFT_NAME.test(slug) || !statSync(ddir).isDirectory()) {
|
|
183
|
+
errors.push(`${relative(root, ddir)}: a draft is a folder <YYYYMMDD-HHMMSS>-<topic>/ holding draft.md`)
|
|
184
|
+
continue
|
|
185
|
+
}
|
|
186
|
+
if (!existsSync(abs)) {
|
|
187
|
+
errors.push(`${relative(root, ddir)}: no draft.md`)
|
|
188
|
+
continue
|
|
189
|
+
}
|
|
190
|
+
const raw = read(abs)
|
|
191
|
+
const head = parseFrontmatter(raw).meta
|
|
192
|
+
const speaker = head.speaksAs ? ids.identities.find((i) => i.id === head.speaksAs) : own
|
|
193
|
+
if (speaker == null) {
|
|
194
|
+
errors.push(`${file}: ${head.speaksAs ? `speaksAs '${head.speaksAs}' is no identity` : 'no identity speaks for this repo'} (sk identities)`)
|
|
195
|
+
continue
|
|
196
|
+
}
|
|
197
|
+
named.add(speaker.id)
|
|
198
|
+
const accounts = identities.find((i) => i.id === speaker.id)!.accounts
|
|
199
|
+
const groups = new Map([...new Set(accounts.map((a) => a.group).filter((g) => g !== ''))].map((g) => [g, accounts.filter((a) => a.group === g).map((a) => a.id)]))
|
|
200
|
+
const d = parseDraft(raw, file, groups)
|
|
201
|
+
errors.push(...d.errors)
|
|
202
|
+
const media = new Map<string, Media>()
|
|
203
|
+
for (const name of mediaNames(d)) {
|
|
204
|
+
const path = resolveMedia(name, ddir, root) ?? (renderedTrailer(name, raw, relative(root, ddir)) ? join(ddir, name) : null) ?? purgedAt(root, ddir, name)
|
|
205
|
+
if (path == null) errors.push(`${file}: media "${name}" is in neither its folder, the repo, at that path, nor in the Space`)
|
|
206
|
+
else media.set(name, { name, path })
|
|
207
|
+
}
|
|
208
|
+
for (const h of heavyMedia(root, [...media.values()].map((m) => m.path))) errors.push(`${file}: media "${relative(ddir, h.path)}" is ${mbOf(h.size)}, over the ${mbOf(MEDIA_MAX_BYTES)} GitHub takes: shrink it, name it *-trailer.mp4 when its command renders it, or keep it with sk media put`)
|
|
209
|
+
const pick = (list: string | undefined): Media[] => fileList(list).flatMap((n) => media.get(n) ?? [])
|
|
210
|
+
const ownMedia = pick(d.meta.media)
|
|
211
|
+
const draft: Draft = {
|
|
212
|
+
slug,
|
|
213
|
+
file,
|
|
214
|
+
path: abs,
|
|
215
|
+
dir: ddir,
|
|
216
|
+
identity: speaker.id,
|
|
217
|
+
title: d.meta.title ?? '',
|
|
218
|
+
kind: d.meta.kind ?? '',
|
|
219
|
+
topics: topicList(d.meta.topics, file, errors, unit?.topics ?? null),
|
|
220
|
+
slot: slotOf(d.meta.slot, file, week, errors),
|
|
221
|
+
status: d.meta.status ?? 'draft',
|
|
222
|
+
angle: d.angle,
|
|
223
|
+
media: [...media.values()],
|
|
224
|
+
alt: d.meta.alt ?? '',
|
|
225
|
+
posts: [],
|
|
226
|
+
article: article(ddir, root, unit),
|
|
227
|
+
}
|
|
228
|
+
const footerText = footerOf(accounts)
|
|
229
|
+
// each account heading's message, then a group heading's on every account of the group the draft gives no heading
|
|
230
|
+
const sends: { s: (typeof d.sections)[number]; a: DeskAccount; key: string; from: string }[] = []
|
|
231
|
+
for (const s of d.sections) {
|
|
232
|
+
if (groups.has(s.platform)) continue
|
|
233
|
+
const a = accounts.find((x) => x.id === s.platform)
|
|
234
|
+
if (a == null) {
|
|
235
|
+
errors.push(`${file}: ## ${s.platform} names neither a group nor an account of ${speaker.name}`)
|
|
236
|
+
continue
|
|
237
|
+
}
|
|
238
|
+
sends.push({ s, a, key: s.key, from: s.key })
|
|
239
|
+
}
|
|
240
|
+
for (const s of d.sections)
|
|
241
|
+
for (const key of groupKeys(s, groups)) {
|
|
242
|
+
if (d.sections.some((x) => x.key === key)) continue
|
|
243
|
+
const b = accounts.find((x) => x.id === key.split('/')[0])
|
|
244
|
+
if (b) sends.push({ s, a: b, key, from: s.key })
|
|
245
|
+
}
|
|
246
|
+
for (const { s, a, key, from } of sends) {
|
|
247
|
+
// a place belongs to its account: a group's message lands on the account's own place
|
|
248
|
+
const place = from === key ? (s.options.place ?? '') : a.place
|
|
249
|
+
const footer = from.split('/')[0] === VERTICAL ? footerText : ''
|
|
250
|
+
const tags = tagList(s.options.tags)
|
|
251
|
+
const made = compose(a.id, { text: s.text, tags, footer }, { max: a.max, saturday })
|
|
252
|
+
const at = a.places.find((x) => x.id === place)
|
|
253
|
+
// a Discord place is a channel of the server, checked when the bot posts
|
|
254
|
+
if (place !== '' && at == null && a.id !== 'discord') errors.push(`${file}: ## ${a.id} place "${place}" is no file of ${a.id}/places/`)
|
|
255
|
+
const title = s.options.title ?? ''
|
|
256
|
+
const write = at?.write || a.write
|
|
257
|
+
const post: SocialPost = {
|
|
258
|
+
slug,
|
|
259
|
+
identity: speaker.id,
|
|
260
|
+
platform: a.id,
|
|
261
|
+
key,
|
|
262
|
+
name: s.options.name ?? '',
|
|
263
|
+
file,
|
|
264
|
+
status: draft.status,
|
|
265
|
+
posted: d.posted.get(key) ?? '',
|
|
266
|
+
kind: draft.kind,
|
|
267
|
+
title,
|
|
268
|
+
angle: d.angle,
|
|
269
|
+
text: made.text,
|
|
270
|
+
body: s.text,
|
|
271
|
+
tags,
|
|
272
|
+
reply: made.reply,
|
|
273
|
+
length: messageLength(a.id, made.text),
|
|
274
|
+
media: (s.options.media == null ? ownMedia : pick(s.options.media))[0] ?? null,
|
|
275
|
+
alt: draft.alt,
|
|
276
|
+
place,
|
|
277
|
+
href: write === '' ? null : fillLink(write, { url: '', title, text: made.text }),
|
|
278
|
+
prefilled: write.includes('{text}'),
|
|
279
|
+
pin: s.options.pin === 'true',
|
|
280
|
+
from,
|
|
281
|
+
footer,
|
|
282
|
+
}
|
|
283
|
+
errors.push(...messageErrors(post, a))
|
|
284
|
+
a.posts.push(post)
|
|
285
|
+
draft.posts.push(post)
|
|
286
|
+
}
|
|
287
|
+
draft.posts.sort((x, y) => accounts.findIndex((a) => a.id === x.platform) - accounts.findIndex((a) => a.id === y.platform))
|
|
288
|
+
drafts.push(draft)
|
|
289
|
+
}
|
|
290
|
+
// a step's [[row]] names a profile row; its [[draft:<slug>]] a draft, checked where the repo speaks as the account's
|
|
291
|
+
for (const i of identities)
|
|
292
|
+
for (const a of i.accounts)
|
|
293
|
+
for (const st of a.steps)
|
|
294
|
+
for (const [, ref] of st.text.matchAll(/\[\[([^\]]+)\]\]/g)) {
|
|
295
|
+
const slug = /^draft:(.+)$/.exec(ref!)?.[1]
|
|
296
|
+
if (slug == null) {
|
|
297
|
+
if (!a.rows.some((r) => r.field === ref)) errors.push(`${a.file}: [[${ref}]] names no profile row`)
|
|
298
|
+
} 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`)
|
|
299
|
+
}
|
|
300
|
+
const topics = unit?.topics ? [...unit.topics] : [...new Set(drafts.flatMap((d) => d.topics))].sort()
|
|
301
|
+
return { root, speaksAs: own?.id ?? null, identities, drafts, weekly: week, topics, errors }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** one account of an identity, loud when absent */
|
|
305
|
+
export function accountOf(desk: Desk, identity: string, account: string): DeskAccount {
|
|
306
|
+
const i = desk.identities.find((x) => x.id === identity)
|
|
307
|
+
const a = i?.accounts.find((x) => x.id === account)
|
|
308
|
+
if (a == null) throw new Error(i == null ? `no identity "${identity}"` : `no account "${account}" of ${i.name}`)
|
|
309
|
+
return a
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** one message of a draft by its key, `<account>` or `<account>/<name>` */
|
|
313
|
+
export function draftPost(desk: Desk, slug: string, key: string): SocialPost {
|
|
314
|
+
const d = desk.drafts.find((x) => x.slug === slug)
|
|
315
|
+
if (d == null) throw new Error(`no draft ${slug} in ${LAYOUT.social}/drafts/`)
|
|
316
|
+
const p = d.posts.find((x) => x.key === key)
|
|
317
|
+
if (p == null) throw new Error(`no message ## ${key} in ${d.file}`)
|
|
318
|
+
return p
|
|
319
|
+
}
|
package/src/social/md.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// the markdown shapes every social file is written in: `key: value` front matter, `## <name>` sections, the
|
|
2
|
+
// `| field | value |` tables of a profile
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
4
|
+
import { isAbsolute, join } from 'node:path'
|
|
5
|
+
|
|
6
|
+
/** `key: value` lines only, no nesting */
|
|
7
|
+
export function parseFrontmatter(raw: string): { meta: Record<string, string>; body: string } {
|
|
8
|
+
const m = raw.match(/^---\n([\s\S]*?)\n---\n?/)
|
|
9
|
+
if (m == null) return { meta: {}, body: raw }
|
|
10
|
+
const meta: Record<string, string> = {}
|
|
11
|
+
for (const line of m[1]!.split('\n')) {
|
|
12
|
+
const i = line.indexOf(':')
|
|
13
|
+
if (i === -1) continue
|
|
14
|
+
meta[line.slice(0, i).trim()] = line.slice(i + 1).trim()
|
|
15
|
+
}
|
|
16
|
+
return { meta, body: raw.slice(m[0].length) }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** a frontmatter key set in place, added at the end of the block when absent */
|
|
20
|
+
export function setMeta(raw: string, key: string, value: string): string {
|
|
21
|
+
const m = raw.match(/^---\n([\s\S]*?)\n---\n?/)
|
|
22
|
+
if (m == null) throw new Error(`no frontmatter to set ${key} in`)
|
|
23
|
+
const lines = m[1]!.split('\n')
|
|
24
|
+
const i = lines.findIndex((l) => l.startsWith(`${key}:`))
|
|
25
|
+
const line = value === '' ? `${key}:` : `${key}: ${value}`
|
|
26
|
+
if (i === -1) lines.push(line)
|
|
27
|
+
else lines[i] = line
|
|
28
|
+
return `---\n${lines.join('\n')}\n---\n${raw.slice(m[0].length)}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** a `## <name>` section of a contract post file, trimmed; `## Post` runs to `## Feedback` so a post may hold `##` headings */
|
|
32
|
+
export function section(body: string, name: string): string | null {
|
|
33
|
+
const start = body.search(new RegExp(`^## ${name}[ \\t]*$`, 'm'))
|
|
34
|
+
if (start === -1) return null
|
|
35
|
+
const rest = body.slice(start).replace(/^.*\n?/, '')
|
|
36
|
+
const end = name === 'Post' ? rest.search(/^## Feedback[ \t]*$/m) : rest.search(/^## /m)
|
|
37
|
+
return (end === -1 ? rest : rest.slice(0, end)).trim()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ProfileRow = {
|
|
41
|
+
field: string
|
|
42
|
+
value: string
|
|
43
|
+
/** the value names files under the identity's `files` folder, a comma between two: their paths there, the
|
|
44
|
+
* pictures to upload; empty, a text */
|
|
45
|
+
files: string[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** the rows of the `| field | value |` table of a `## Profile` (or another) section; `filesRoot` the folder a picture
|
|
49
|
+
* path is relative to, null when the rows name none */
|
|
50
|
+
export function rows(body: string, name = 'Profile', filesRoot: string | null = null): ProfileRow[] {
|
|
51
|
+
const out: ProfileRow[] = []
|
|
52
|
+
for (const line of (section(body, name) ?? '').split('\n')) {
|
|
53
|
+
const m = /^\|\s*(.+?)\s*\|\s*(.*?)\s*\|$/.exec(line.trim())
|
|
54
|
+
if (m == null || m[1] === 'field' || /^-+$/.test(m[1]!)) continue
|
|
55
|
+
const value = m[2]!
|
|
56
|
+
const parts = value.split(',').map((x) => x.trim())
|
|
57
|
+
const files = filesRoot != null && parts.every((x) => /\.\w+$/.test(x) && !isAbsolute(x) && existsSync(join(filesRoot, x))) ? parts : []
|
|
58
|
+
out.push({ field: m[1]!, value, files })
|
|
59
|
+
}
|
|
60
|
+
return out
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** the body rows of a markdown table in a section, each a list of its cells */
|
|
64
|
+
export function table(body: string, name: string): string[][] {
|
|
65
|
+
return (section(body, name) ?? '')
|
|
66
|
+
.split('\n')
|
|
67
|
+
.filter((l) => /^\|.*\|$/.test(l.trim()))
|
|
68
|
+
.map((l) => l.trim().slice(1, -1).split('|').map((c) => c.trim()))
|
|
69
|
+
.slice(2)
|
|
70
|
+
}
|