PulseCanvas / app · pulsecanvas.ai / assets / app-store / search-marketing-1.2 / render.mjs
| 1 | // Keep the approved search campaign, refreshing only real app captures. |
| 2 | import {fileURLToPath,pathToFileURL} from 'node:url'; |
| 3 | import {dirname,resolve,join} from 'node:path'; |
| 4 | import {mkdirSync,readFileSync,writeFileSync} from 'node:fs'; |
| 5 | import {createHash} from 'node:crypto'; |
| 6 | const {chromium}=await import(process.env.PLAYWRIGHT??'playwright'); |
| 7 | const here=dirname(fileURLToPath(import.meta.url)); |
| 8 | const sources=resolve(process.argv[2]),out=resolve(process.argv[3]); |
| 9 | mkdirSync(out,{recursive:true}); |
| 10 | const url=new URL(pathToFileURL(join(here,'layout.html'))); |
| 11 | url.searchParams.set('sources',pathToFileURL(sources).href); |
| 12 | url.searchParams.set('icon',pathToFileURL(resolve(here,'../../../mobile/Assets.xcassets/AppIcon.appiconset/AppIcon.png')).href); |
| 13 | const browser=await chromium.launch(); |
| 14 | const page=await browser.newPage({viewport:{width:3840,height:2560},deviceScaleFactor:1}); |
| 15 | const errors=[];page.on('pageerror',e=>errors.push(String(e))); |
| 16 | await page.goto(url.href); |
| 17 | await page.evaluate(()=>Promise.all([...document.images].map(i=>i.decode()))); |
| 18 | await page.evaluate(()=>document.fonts.ready); |
| 19 | await 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');}}); |
| 20 | if(errors.length)throw Error(errors.join('\n')); |
| 21 | const file='pulsecanvas-search-variety-1.2.png'; |
| 22 | await page.screenshot({path:join(out,file),omitBackground:false}); |
| 23 | await browser.close(); |
| 24 | const hash=p=>createHash('sha256').update(readFileSync(p)).digest('hex'); |
| 25 | writeFileSync(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'); |
| 26 | console.log(file); |