mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 21:03:47 -10:00
Compare commits
1
Commits
main
...
floor-kept
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78ef07a49c |
No files matched your search
@@ -4,7 +4,7 @@
|
|||||||
// stills a composition as it's saved (`raea check EDIT.tsx --quick`): three stills rendered with their manifest, and
|
// stills a composition as it's saved (`raea check EDIT.tsx --quick`): three stills rendered with their manifest, and
|
||||||
// the text rules and the person's text taste on them; what it can't see waits for the export's floor
|
// the text rules and the person's text taste on them; what it can't see waits for the export's floor
|
||||||
import { spawnSync } from "node:child_process"
|
import { spawnSync } from "node:child_process"
|
||||||
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs"
|
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs"
|
||||||
import os from "node:os"
|
import os from "node:os"
|
||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import { check, found } from "raea/check"
|
import { check, found } from "raea/check"
|
||||||
@@ -12,7 +12,7 @@ import type { FileFacts } from "../facts.ts"
|
|||||||
import { RAEA, stem } from "../media.ts"
|
import { RAEA, stem } from "../media.ts"
|
||||||
import { bookkeeping } from "./naming.ts"
|
import { bookkeeping } from "./naming.ts"
|
||||||
|
|
||||||
type Measured = { level: "error" | "warn" | "note"; says: string; fix?: string | null; frames?: [number, number] | null }
|
export type Measured = { level: "error" | "warn" | "note"; says: string; fix?: string | null; frames?: [number, number] | null }
|
||||||
|
|
||||||
/** raea's measure of a file, its findings as it wrote them (-o) */
|
/** raea's measure of a file, its findings as it wrote them (-o) */
|
||||||
function measure(args: string[], cwd: string): Measured[] {
|
function measure(args: string[], cwd: string): Measured[] {
|
||||||
@@ -27,12 +27,36 @@ function measure(args: string[], cwd: string): Measured[] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** a video's floor report, kept beside it */
|
||||||
|
export const FLOOR_EXT = "floor.json"
|
||||||
|
let version: string | undefined
|
||||||
|
const raeaVersion = () => (version ??= String(spawnSync(RAEA, ["--version"], { encoding: "utf8" }).stdout ?? "").trim())
|
||||||
|
const when = (f: string) => (existsSync(f) ? statSync(f).mtimeMs : 0)
|
||||||
|
|
||||||
|
/** A made video's floor findings: kept beside it (FILE.floor.json) and measured again only when the video or its
|
||||||
|
* manifest is newer, raea is another version, or the kept report holds an error. The measure took 26 s a cut and ran
|
||||||
|
* again on the same file at publish and at done (12-01). An error is always measured again, since what it names (a
|
||||||
|
* placeholder brand kit) can be put right without the video changing, and a kept error would hold a finished run. */
|
||||||
|
export function floorOf(abs: string, manifest: string | undefined, cwd: string, by: (args: string[], cwd: string) => Measured[] = measure): Measured[] {
|
||||||
|
const kept = `${stem(abs)}.${FLOOR_EXT}`
|
||||||
|
try {
|
||||||
|
const k = JSON.parse(readFileSync(kept, "utf8")) as { raea: string; findings: Measured[] }
|
||||||
|
const fresh = when(kept) >= when(abs) && (!manifest || when(kept) >= when(manifest))
|
||||||
|
if (fresh && k.raea === raeaVersion() && !k.findings.some((x) => x.level === "error")) return k.findings
|
||||||
|
} catch {}
|
||||||
|
const findings = by([abs, ...(manifest ? ["--manifest", manifest] : [])], cwd)
|
||||||
|
try {
|
||||||
|
writeFileSync(kept, `${JSON.stringify({ raea: raeaVersion(), findings })}\n`)
|
||||||
|
} catch {}
|
||||||
|
return findings
|
||||||
|
}
|
||||||
|
|
||||||
const say = (x: Measured) => found({ level: x.level, says: x.says, fix: x.fix ?? undefined, frames: x.frames ?? undefined })
|
const say = (x: Measured) => found({ level: x.level, says: x.says, fix: x.fix ?? undefined, frames: x.frames ?? undefined })
|
||||||
|
|
||||||
export const floorPack = check<FileFacts>({ id: "floor", text: "no clipped text, low contrast, freeze, flash or loudness out of range", over: "file", at: ["render", "publish", "done"] }, async (f) => {
|
export const floorPack = check<FileFacts>({ id: "floor", text: "no clipped text, low contrast, freeze, flash or loudness out of range", over: "file", at: ["render", "publish", "done"] }, async (f) => {
|
||||||
if (!f.made || f.kind !== "video" || bookkeeping(f.path)) return
|
if (!f.made || f.kind !== "video" || bookkeeping(f.path)) return
|
||||||
const m = [`${stem(f.abs)}.render.json`, `${stem(f.abs)}.manifest.json`].find(existsSync)
|
const m = [`${stem(f.abs)}.render.json`, `${stem(f.abs)}.manifest.json`].find(existsSync)
|
||||||
for (const x of measure([f.abs, ...(m ? ["--manifest", m] : [])], f.root)) say(x)
|
for (const x of floorOf(f.abs, m, f.root)) say(x)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const stillsPack = check<FileFacts>({ id: "stills", text: "a composition's stills: no clipped or cramped text, nothing out of the safe areas", over: "file", at: ["edit"], needs: "render" }, async (f) => {
|
export const stillsPack = check<FileFacts>({ id: "stills", text: "a composition's stills: no clipped or cramped text, nothing out of the safe areas", over: "file", at: ["edit"], needs: "render" }, async (f) => {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const NOT_WORK = new Set(["review", ".git", "node_modules", ".raea", "target", "
|
|||||||
/** what a check keeps beside a file it read (its report, its words, its scene): a reading of the work, not a change
|
/** what a check keeps beside a file it read (its report, its words, its scene): a reading of the work, not a change
|
||||||
* to it. A done check that heard a cut's words wrote them beside it, and the critic's verdict of a minute before read
|
* to it. A done check that heard a cut's words wrote them beside it, and the critic's verdict of a minute before read
|
||||||
* as older than the work (12-01) */
|
* as older than the work (12-01) */
|
||||||
const READING = /\.(check|words|scene)\.json$/
|
const READING = /\.(check|words|scene|floor)\.json$/
|
||||||
|
|
||||||
/** when the work last changed (ms): the newest file under dir, its own bookkeeping left out (a bounded walk) */
|
/** when the work last changed (ms): the newest file under dir, its own bookkeeping left out (a bounded walk) */
|
||||||
export function newest(dir: string): number | null {
|
export function newest(dir: string): number | null {
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// A made video's floor report is kept beside it and measured again only for cause (packs/floor.ts)
|
||||||
|
import { expect, test } from "bun:test"
|
||||||
|
import { mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs"
|
||||||
|
import { tmpdir } from "node:os"
|
||||||
|
import path from "node:path"
|
||||||
|
import { floorOf, type Measured } from "../src/packs/floor.ts"
|
||||||
|
|
||||||
|
test("a floor report is kept: measured once, again when the video is newer, and always while it holds an error", () => {
|
||||||
|
const d = mkdtempSync(path.join(tmpdir(), "raea-floor-kept-"))
|
||||||
|
const v = path.join(d, "a.mp4")
|
||||||
|
writeFileSync(v, "x")
|
||||||
|
let runs = 0
|
||||||
|
let out: Measured[] = [{ level: "warn", says: "quiet" }]
|
||||||
|
const by = () => (runs++, out)
|
||||||
|
expect(floorOf(v, undefined, d, by)).toEqual(out)
|
||||||
|
expect(floorOf(v, undefined, d, by)).toEqual(out)
|
||||||
|
expect(runs).toBe(1)
|
||||||
|
// the video made again
|
||||||
|
const later = new Date(Date.now() + 60_000)
|
||||||
|
utimesSync(v, later, later)
|
||||||
|
floorOf(v, undefined, d, by)
|
||||||
|
expect(runs).toBe(2)
|
||||||
|
utimesSync(path.join(d, "a.floor.json"), new Date(Date.now() + 120_000), new Date(Date.now() + 120_000))
|
||||||
|
floorOf(v, undefined, d, by)
|
||||||
|
expect(runs).toBe(2)
|
||||||
|
// an error isn't kept as an answer
|
||||||
|
utimesSync(v, new Date(Date.now() + 180_000), new Date(Date.now() + 180_000))
|
||||||
|
out = [{ level: "error", says: "a placeholder brand kit" }]
|
||||||
|
floorOf(v, undefined, d, by)
|
||||||
|
utimesSync(path.join(d, "a.floor.json"), new Date(Date.now() + 240_000), new Date(Date.now() + 240_000))
|
||||||
|
floorOf(v, undefined, d, by)
|
||||||
|
expect(runs).toBe(4)
|
||||||
|
rmSync(d, { recursive: true, force: true })
|
||||||
|
})
|
||||||
@@ -87,7 +87,7 @@ test("a reading kept beside a file isn't the work changing", () => {
|
|||||||
const cut = path.join(d, "out/cuts/a_b_c_v1_9x16.mp4")
|
const cut = path.join(d, "out/cuts/a_b_c_v1_9x16.mp4")
|
||||||
writeFileSync(cut, "x")
|
writeFileSync(cut, "x")
|
||||||
utimesSync(cut, 1000, 1000)
|
utimesSync(cut, 1000, 1000)
|
||||||
for (const ext of ["words.json", "scene.json", "check.json"]) writeFileSync(path.join(d, `out/cuts/a_b_c_v1_9x16.${ext}`), "{}")
|
for (const ext of ["words.json", "scene.json", "check.json", "floor.json"]) writeFileSync(path.join(d, `out/cuts/a_b_c_v1_9x16.${ext}`), "{}")
|
||||||
expect(newest(d)).toBe(1_000_000)
|
expect(newest(d)).toBe(1_000_000)
|
||||||
writeFileSync(path.join(d, "out/cuts/a_b_c_v1_9x16.render.json"), "{}")
|
writeFileSync(path.join(d, "out/cuts/a_b_c_v1_9x16.render.json"), "{}")
|
||||||
expect(newest(d)!).toBeGreaterThan(1_000_000)
|
expect(newest(d)!).toBeGreaterThan(1_000_000)
|
||||||
|
|||||||
Reference in new issue
Block a user