|
6 | 6 | // |
7 | 7 | // bun run assets/flagship.ts |
8 | 8 |
|
9 | | -import { spawnSync } from "node:child_process"; |
10 | | -import { existsSync, mkdirSync, writeFileSync } from "node:fs"; |
11 | | -import { join } from "node:path"; |
12 | | -import { FIXTURE_NOW } from "../src/tui/fixtures.ts"; |
13 | | -import { FONT, FONT_SIZE, MARGIN_FILL, THEMES, type ThemeName } from "./assets.config.ts"; |
| 9 | +import { spawnSync } from 'node:child_process' |
| 10 | +import { existsSync, mkdirSync, writeFileSync } from 'node:fs' |
| 11 | +import { join } from 'node:path' |
| 12 | +import { FIXTURE_NOW } from '../src/tui/fixtures.ts' |
| 13 | +import { FONT, FONT_SIZE, MARGIN_FILL, THEMES, type ThemeName } from './assets.config.ts' |
14 | 14 |
|
15 | | -const assetsDir = import.meta.dir; |
16 | | -const outDir = join(assetsDir, "generated"); |
17 | | -const tapeDir = join(assetsDir, "tapes"); |
18 | | -const tmpDir = join(assetsDir, ".tmp"); |
| 15 | +const assetsDir = import.meta.dir |
| 16 | +const outDir = join(assetsDir, 'generated') |
| 17 | +const tapeDir = join(assetsDir, 'tapes') |
| 18 | +const tmpDir = join(assetsDir, '.tmp') |
19 | 19 | for (const dir of [outDir, tapeDir, tmpDir]) { |
20 | | - mkdirSync(dir, { recursive: true }); |
| 20 | + mkdirSync(dir, { recursive: true }) |
21 | 21 | } |
22 | 22 |
|
23 | | -const vhs = existsSync("/opt/homebrew/bin/vhs") ? "/opt/homebrew/bin/vhs" : "vhs"; |
24 | | -const buildScript = join(assetsDir, "flagship", "build.sh"); |
| 23 | +const vhs = existsSync('/opt/homebrew/bin/vhs') ? '/opt/homebrew/bin/vhs' : 'vhs' |
| 24 | +const buildScript = join(assetsDir, 'flagship', 'build.sh') |
25 | 25 |
|
26 | 26 | // The whole terminal background must match the tokenmaxx theme, otherwise the mock |
27 | 27 | // panes (which don't paint their own background) show VHS's default and their |
28 | 28 | // theme-coloured text vanishes. Single-pane shots don't need this — tokenmaxx fills |
29 | 29 | // the frame — but the flagship's mock panes do. |
30 | | -const TERM_BG: Record<ThemeName, string> = { dark: "#0b0d10", light: "#fbfcfe" }; |
31 | | -const TERM_FG: Record<ThemeName, string> = { dark: "#e6e6e6", light: "#1c2430" }; |
| 30 | +const TERM_BG: Record<ThemeName, string> = { dark: '#0b0d10', light: '#fbfcfe' } |
| 31 | +const TERM_FG: Record<ThemeName, string> = { dark: '#e6e6e6', light: '#1c2430' } |
32 | 32 |
|
33 | 33 | function tape(theme: ThemeName, png: string, gif: string): string { |
34 | | - return [ |
35 | | - `Output "${gif}"`, |
36 | | - `Set Theme '{ "background": "${TERM_BG[theme]}", "foreground": "${TERM_FG[theme]}" }'`, |
37 | | - `Set FontFamily "${FONT}"`, |
38 | | - `Set FontSize ${FONT_SIZE - 1}`, |
39 | | - "Set LetterSpacing 0", |
40 | | - "Set Width 1560", |
41 | | - "Set Height 860", |
42 | | - "Set Padding 22", |
43 | | - "Set Margin 46", |
44 | | - `Set MarginFill "${MARGIN_FILL[theme]}"`, |
45 | | - "Set WindowBar Colorful", |
46 | | - "Set WindowBarSize 40", |
47 | | - "Set BorderRadius 12", |
48 | | - "Set TypingSpeed 1ms", |
49 | | - `Env TOKENMAXX_NOW "${FIXTURE_NOW}"`, |
50 | | - `Type "THEME=${theme} bash ${buildScript}"`, |
51 | | - "Enter", |
52 | | - "Sleep 9s", |
53 | | - `Screenshot "${png}"`, |
54 | | - "", |
55 | | - ].join("\n"); |
| 34 | + return [ |
| 35 | + `Output "${gif}"`, |
| 36 | + `Set Theme '{ "background": "${TERM_BG[theme]}", "foreground": "${TERM_FG[theme]}" }'`, |
| 37 | + `Set FontFamily "${FONT}"`, |
| 38 | + `Set FontSize ${FONT_SIZE - 1}`, |
| 39 | + 'Set LetterSpacing 0', |
| 40 | + 'Set Width 1560', |
| 41 | + 'Set Height 860', |
| 42 | + 'Set Padding 22', |
| 43 | + 'Set Margin 46', |
| 44 | + `Set MarginFill "${MARGIN_FILL[theme]}"`, |
| 45 | + 'Set WindowBar Colorful', |
| 46 | + 'Set WindowBarSize 40', |
| 47 | + 'Set BorderRadius 12', |
| 48 | + 'Set TypingSpeed 1ms', |
| 49 | + `Env TOKENMAXX_NOW "${FIXTURE_NOW}"`, |
| 50 | + `Type "THEME=${theme} bash ${buildScript}"`, |
| 51 | + 'Enter', |
| 52 | + 'Sleep 9s', |
| 53 | + `Screenshot "${png}"`, |
| 54 | + '' |
| 55 | + ].join('\n') |
56 | 56 | } |
57 | 57 |
|
58 | | -let ok = 0; |
59 | | -const failed: string[] = []; |
| 58 | +let ok = 0 |
| 59 | +const failed: string[] = [] |
60 | 60 | for (const theme of THEMES) { |
61 | | - const base = `flagship-${theme}`; |
62 | | - const png = join(outDir, `${base}.png`); |
63 | | - const gif = join(tmpDir, `${base}.gif`); |
64 | | - const tapePath = join(tapeDir, `${base}.tape`); |
65 | | - writeFileSync(tapePath, tape(theme, png, gif)); |
66 | | - spawnSync("rm", ["-f", png]); |
67 | | - let landed = false; |
68 | | - for (let attempt = 1; attempt <= 4 && !landed; attempt += 1) { |
69 | | - spawnSync(vhs, [tapePath], { stdio: "ignore" }); |
70 | | - // build.sh runs tmux inside VHS's own shell, but kill any stray session too. |
71 | | - spawnSync("tmux", ["kill-session", "-t", "fs"], { stdio: "ignore" }); |
72 | | - landed = existsSync(png); |
73 | | - if (!landed) { |
74 | | - Bun.sleepSync(1500); |
75 | | - } |
76 | | - } |
77 | | - if (landed) { |
78 | | - ok += 1; |
79 | | - console.log(` ok ${base}.png`); |
80 | | - } else { |
81 | | - failed.push(base); |
82 | | - console.log(` FAIL ${base}.png`); |
83 | | - } |
| 61 | + const base = `flagship-${theme}` |
| 62 | + const png = join(outDir, `${base}.png`) |
| 63 | + const gif = join(tmpDir, `${base}.gif`) |
| 64 | + const tapePath = join(tapeDir, `${base}.tape`) |
| 65 | + writeFileSync(tapePath, tape(theme, png, gif)) |
| 66 | + spawnSync('rm', ['-f', png]) |
| 67 | + let landed = false |
| 68 | + for (let attempt = 1; attempt <= 4 && !landed; attempt += 1) { |
| 69 | + spawnSync(vhs, [tapePath], { stdio: 'ignore' }) |
| 70 | + // build.sh runs tmux inside VHS's own shell, but kill any stray session too. |
| 71 | + spawnSync('tmux', ['kill-session', '-t', 'fs'], { stdio: 'ignore' }) |
| 72 | + landed = existsSync(png) |
| 73 | + if (!landed) { |
| 74 | + Bun.sleepSync(1500) |
| 75 | + } |
| 76 | + } |
| 77 | + if (landed) { |
| 78 | + ok += 1 |
| 79 | + console.log(` ok ${base}.png`) |
| 80 | + } else { |
| 81 | + failed.push(base) |
| 82 | + console.log(` FAIL ${base}.png`) |
| 83 | + } |
84 | 84 | } |
85 | 85 |
|
86 | 86 | console.log( |
87 | | - `\n${ok} rendered, ${failed.length} failed${failed.length ? `: ${failed.join(", ")}` : ""}`, |
88 | | -); |
89 | | -process.exitCode = failed.length > 0 ? 1 : 0; |
| 87 | + `\n${ok} rendered, ${failed.length} failed${failed.length ? `: ${failed.join(', ')}` : ''}` |
| 88 | +) |
| 89 | +process.exitCode = failed.length > 0 ? 1 : 0 |
0 commit comments