Lumen & Gesso / website / scripts / backfill-pair-frames.mjs
| 1 | #!/usr/bin/env node |
| 2 | // One-off: add frameId + matteId to every TransformPair entry in |
| 3 | // app/data/transformPairs.ts, inferred from the medium string. Idempotent — |
| 4 | // skips pairs that already carry frameId. |
| 5 | // |
| 6 | // Lookup table is per-pair-id (the `n:` field). Frame mapping rationale: |
| 7 | // - "ivory frame" / "white frame" → 'white' |
| 8 | // - "gilt frame" / "gold frame" → 'gold' |
| 9 | // - "walnut frame" → 'walnut' |
| 10 | // - "oak frame" → 'oak' |
| 11 | // - "matte black frame" / "black frame" → 'black' |
| 12 | // Matte choices favour 'warmwhite' for gold + walnut frames (warm-on-warm), |
| 13 | // 'snowwhite' for cool/neutral frames, and a few overrides per style. |
| 14 | |
| 15 | import fs from 'node:fs'; |
| 16 | import path from 'node:path'; |
| 17 | import { fileURLToPath } from 'node:url'; |
| 18 | |
| 19 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 20 | const FILE = path.resolve(__dirname, '..', 'app/data/transformPairs.ts'); |
| 21 | |
| 22 | const FRAME_MATTE = { |
| 23 | '01': { frame: 'white', matte: 'warmwhite' }, // Teddy — impasto, ivory |
| 24 | '02': { frame: 'white', matte: 'warmwhite' }, // Otto — landscape oil, ivory |
| 25 | '03': { frame: 'white', matte: 'snowwhite' }, // Pepper — pop art, ivory |
| 26 | '04': { frame: 'white', matte: 'snowwhite' }, // Cooper — vector, ivory |
| 27 | '05': { frame: 'white', matte: 'snowwhite' }, // Bowie — pop art, ivory |
| 28 | '06': { frame: 'walnut', matte: 'snowwhite' }, // Koda — named portrait |
| 29 | '07': { frame: 'white', matte: 'snowwhite' }, // Maple — watercolor, ivory |
| 30 | '08': { frame: 'white', matte: 'snowwhite' }, // Juno — line drawing, ivory |
| 31 | '09': { frame: 'white', matte: 'snowwhite' }, // Clover — watercolor, ivory (was Henry — royal, retired) |
| 32 | '10': { frame: 'white', matte: 'warmwhite' }, // Otis — cubist, ivory |
| 33 | '11': { frame: 'white', matte: 'warmwhite' }, // Sakura — ukiyo-e, ivory |
| 34 | '12': { frame: 'gold', matte: 'warmwhite' }, // Tenzin — thangka, gilt |
| 35 | '13': { frame: 'white', matte: 'snowwhite' }, // Sable — charcoal, ivory |
| 36 | '14': { frame: 'white', matte: 'snowwhite' }, // Marlow — watercolor, white |
| 37 | '15': { frame: 'white', matte: 'snowwhite' }, // Mortimer — vector, ivory (was Major — royal, retired) |
| 38 | '16': { frame: 'white', matte: 'snowwhite' }, // Clover — charcoal, white |
| 39 | '17': { frame: 'walnut', matte: 'warmwhite' }, // Wren — ukiyo-e, walnut |
| 40 | '18': { frame: 'black', matte: 'snowwhite' }, // Hamlet — pop art, matte black |
| 41 | '19': { frame: 'oak', matte: 'snowwhite' }, // Mortimer — vector, oak |
| 42 | '20': { frame: 'walnut', matte: 'warmwhite' }, // Quill — mixed-media, walnut |
| 43 | '21': { frame: 'white', matte: 'snowwhite' }, // Clover — watercolor, white |
| 44 | '22': { frame: 'black', matte: 'snowwhite' }, // Major — line drawing, black |
| 45 | '23': { frame: 'oak', matte: 'snowwhite' }, // Marlow — cubist, oak |
| 46 | '24': { frame: 'gold', matte: 'warmwhite' }, // Mortimer — thangka, gold |
| 47 | '25': { frame: 'walnut', matte: 'warmwhite' }, // Hamlet — modern portrait, walnut |
| 48 | '26': { frame: 'oak', matte: 'snowwhite' }, // Murph — risograph |
| 49 | '27': { frame: 'walnut', matte: 'snowwhite' }, // Suki — risograph |
| 50 | '28': { frame: 'white', matte: 'snowwhite' }, // Chip — risograph |
| 51 | '29': { frame: 'walnut', matte: 'warmwhite' }, // Frank — at home |
| 52 | '30': { frame: 'oak', matte: 'warmwhite' }, // Marmalade — at home |
| 53 | '31': { frame: 'walnut', matte: 'warmwhite' }, // Popcorn — at home |
| 54 | '32': { frame: 'black', matte: 'black' }, // Rex — neo-expressionist |
| 55 | '33': { frame: 'black', matte: 'snowwhite' }, // Iggy — neo-expressionist |
| 56 | '34': { frame: 'black', matte: 'black' }, // Capy — neo-expressionist |
| 57 | }; |
| 58 | |
| 59 | let content = fs.readFileSync(FILE, 'utf8'); |
| 60 | let changed = 0; |
| 61 | let skipped = 0; |
| 62 | |
| 63 | // Match each pair object — from `n: 'NN',` up to (but not including) the |
| 64 | // `tilt:` line. We insert frameId/matteId right before `tilt:`. |
| 65 | content = content.replace( |
| 66 | /(\n {4}n: '(\d{2})',\n)([\s\S]*?)( {4}tilt: )/g, |
| 67 | (match, header, n, body, tiltLine) => { |
| 68 | const fm = FRAME_MATTE[n]; |
| 69 | if (!fm) { |
| 70 | console.warn(` no frame/matte entry for n='${n}' — skipping`); |
| 71 | skipped++; |
| 72 | return match; |
| 73 | } |
| 74 | if (/frameId:/.test(body)) { |
| 75 | skipped++; |
| 76 | return match; |
| 77 | } |
| 78 | changed++; |
| 79 | const insertion = ` frameId: '${fm.frame}',\n matteId: '${fm.matte}',\n`; |
| 80 | return header + body + insertion + tiltLine; |
| 81 | }, |
| 82 | ); |
| 83 | |
| 84 | fs.writeFileSync(FILE, content); |
| 85 | console.log(`Done. ${changed} pairs updated, ${skipped} pairs skipped (already had frameId or no entry).`); |