okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
8820fa433
main
1#!/usr/bin/env node 2/** 3* The installer's pictures, drawn from the app's own design: the light surface and ink colours of the app (src/styles tokens), the 4* brand lockup and mark files, GT Walsheim Bold for the words (baked into the pictures, because NSIS cannot use a web font). 5* 6* node apps/desktop/scripts/make-installer-images.mjs [--out <folder>] [--preview <folder>] 7* 8* Writes sidebar.bmp (164x314, the welcome and finish pages) and header.bmp (150x57, the other pages) as 24-bit BMPs, and with 9* --preview the same as PNGs at 3x. 10*/ 11import { spawnSync } from 'node:child_process' ; 12import { existsSync , mkdirSync , readFileSync , writeFileSync } from 'node:fs' ; 13import { dirname , join , resolve } from 'node:path' ; 14import { fileURLToPath , pathToFileURL } from 'node:url' ; 15import { tmpdir } from 'node:os' ; 16 17const args = Object . fromEntries ( process . argv . slice ( 2 ). reduce (( acc , a , i , all ) => ( a . startsWith ( '--' ) ?[ ...acc , [ a . slice ( 2 ), all [ i + 1 ]]] :acc ), [])); 18const here = dirname ( fileURLToPath ( import . meta. url )); 19const host = resolve ( here , '../../host' ); 20const out = resolve ( args . out ?? join ( here , '../src-tauri/nsis' )); 21mkdirSync ( out , { recursive :true }); 22const { chromium} = await import ( pathToFileURL ( join ( host , 'node_modules/playwright-core/index.mjs' )). href ). catch (() => import ( 'playwright-core' )); 23const CHROME = process . env . CHROME ?? [ 'C:/Program Files/Google/Chrome/Application/chrome.exe' , '/usr/bin/google-chrome' ]. find ( existsSync ); 24const font = pathToFileURL ( join ( host , 'public/fonts/GTWalsheimPro-Bold.woff2' )). href ; 25const fontMedium = pathToFileURL ( join ( host , 'public/fonts/GTWalsheimPro-Medium.woff2' )). href ; 26const lockup = readFileSync ( join ( host , 'public/brand/strata-lockup-light.svg' ), 'utf8' ); 27const mark = readFileSync ( join ( host , 'public/brand/strata-mark-light.svg' ), 'utf8' ); 28 29// the app's light tokens 30const SURFACE = '#f9fafb' , INK = '#171b1e' , MUTED = '#5b646b' , ACCENT = '#10b981' , LINE = '#e3e8ea' ; 31const css = `@font-face{font-family:GT;font-weight:700;src:url( ${ font } )}@font-face{font-family:GT;font-weight:500;src:url( ${ fontMedium } )} 32*{box-sizing:border-box}body{margin:0;font-family:GT,'Segoe UI',sans-serif;color: ${ INK } ;background: ${ SURFACE } }` ; 33 34const pages = { 35sidebar :{ w :164 , h :314 , html :`<div style="width:164px;height:314px;padding:22px 18px;display:flex;flex-direction:column;background:linear-gradient(180deg,#f9fafb 0%,#eef6f2 100%);border-right:1px solid ${ LINE } "> 36<div style="height:26px"> ${ lockup . replace ( '<svg' , '<svg style="height:26px;width:auto;display:block"' )} </div> 37<div style="margin-top:auto"> 38<div style="font-weight:700;font-size:22px;line-height:1.12;letter-spacing:-.01em">State of<br>the art.<br>At home.</div> 39<div style="margin-top:10px;font-weight:500;font-size:11px;line-height:1.5;color: ${ MUTED } ">AI on your own computer.<br>Private. Fast. Easy.</div> 40<div style="margin-top:16px;height:3px;width:34px;border-radius:2px;background: ${ ACCENT } "></div> 41</div></div>` }, 42header :{ w :150 , h :57 , html :`<div style="width:150px;height:57px;display:flex;align-items:center;justify-content:flex-end;padding-right:12px;background: ${ SURFACE } "> ${ lockup . replace ( '<svg' , '<svg style="height:22px;width:auto;display:block"' )} </div>` }, 43}; 44 45const browser = await chromium . launch ({ executablePath :CHROME , headless :true }); 46const work = join ( tmpdir (), 'strata-installer-images' ); mkdirSync ( work , { recursive :true }); 47for ( const [ name , page ] of Object . entries ( pages )) { 48for ( const scale of [ 1 , 3 ]) { 49const file = join ( work , ` ${ name } .html` ); 50writeFileSync ( file , `<!doctype html><meta charset="utf-8"><style> ${ css } </style><body> ${ page . html } </body>` ); 51const tab = await browser . newPage ({ viewport :{ width :page . w , height :page . h }, deviceScaleFactor :scale }); 52await tab . goto ( pathToFileURL ( file ). href ); 53await tab . evaluate (() => document . fonts . ready ); 54await tab . waitForTimeout ( 200 ); 55const png = join ( work , ` ${ name } @ ${ scale } .png` ); 56await tab . screenshot ({ path :png , clip :{ x :0 , y :0 , width :page . w , height :page . h } }); 57await tab . close (); 58if ( scale === 3 && args . preview ) { mkdirSync ( resolve ( args . preview ), { recursive :true }); writeFileSync ( join ( resolve ( args . preview ), ` ${ name } .png` ), readFileSync ( png )); } 59} 60} 61await browser . close (); 62// 24-bit BMP, the format NSIS wants: render at 3x, shrink with a good filter 63const py = `import sys\nfrom PIL import Image\nfor name in ('sidebar','header'):\n im = Image.open(sys.argv[1] + '/' + name + '@3.png').convert('RGB')\n w, h = im.width // 3, im.height // 3\n im.resize((w, h), Image.LANCZOS).save(sys.argv[2] + '/' + name + '.bmp', 'BMP')\n` ; 64const done = spawnSync ( 'python' , [ '-c' , py , work , out ], { encoding :'utf8' }); 65if ( done . status !== 0 ) { console . error ( done . stderr ); process . exit ( 1 ); } 66console . log ( 'wrote' , join ( out , 'sidebar.bmp' ), join ( out , 'header.bmp' ));