Branchwell

PulseCanvas / app · pulsecanvas.ai / assets / app-store / search-marketing-1.2 / render.mjs

1// Keep the approved search campaign, refreshing only real app captures.
2import {fileURLToPath,pathToFileURL} from 'node:url';
3import {dirname,resolve,join} from 'node:path';
4import {mkdirSync,readFileSync,writeFileSync} from 'node:fs';
5import {createHash} from 'node:crypto';
6const {chromium}=await import(process.env.PLAYWRIGHT??'playwright');
7const here=dirname(fileURLToPath(import.meta.url));
8const sources=resolve(process.argv[2]),out=resolve(process.argv[3]);
9mkdirSync(out,{recursive:true});
10const url=new URL(pathToFileURL(join(here,'layout.html')));
11url.searchParams.set('sources',pathToFileURL(sources).href);
12url.searchParams.set('icon',pathToFileURL(resolve(here,'../../../mobile/Assets.xcassets/AppIcon.appiconset/AppIcon.png')).href);
13const browser=await chromium.launch();
14const page=await browser.newPage({viewport:{width:3840,height:2560},deviceScaleFactor:1});
15const errors=[];page.on('pageerror',e=>errors.push(String(e)));
16await page.goto(url.href);
17await page.evaluate(()=>Promise.all([...document.images].map(i=>i.decode())));
18await page.evaluate(()=>document.fonts.ready);
19await page.evaluate(()=>{for(const image of document.images){if(!image.naturalWidth)throw Error('Missing capture');const r=image.getBoundingClientRect();if(r.bottom>innerHeight||r.right>innerWidth)throw Error('Device overflow');}});
20if(errors.length)throw Error(errors.join('\n'));
21const file='pulsecanvas-search-variety-1.2.png';
22await page.screenshot({path:join(out,file),omitBackground:false});
23await browser.close();
24const hash=p=>createHash('sha256').update(readFileSync(p)).digest('hex');
25writeFileSync(join(out,'manifest.json'),JSON.stringify({renderedAt:new Date().toISOString(),appVersion:'1.2',appBuild:'10',file,width:3840,height:2560,sha256:hash(join(out,file)),captures:['iphone-fullscreen-alternate.png','iphone-studio.png'].map(file=>({file,sha256:hash(join(sources,file))}))},null,2)+'\n');
26console.log(file);