PulseCanvas / app · pulsecanvas.ai / assets / app-store / mobile-marketing-1.2 / render.mjs
| 1 | // Real 1.2 simulator captures, approved mobile marketing templates. |
| 2 | import { fileURLToPath, pathToFileURL } from 'node:url'; |
| 3 | import { dirname, join, resolve } 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 captures=resolve(process.argv[2]);const output=resolve(process.argv[3]); |
| 9 | const release=join(output,'release/en-US');mkdirSync(release,{recursive:true}); |
| 10 | const url=new URL(pathToFileURL(join(here,'layouts.html'))); |
| 11 | url.searchParams.set('sources',pathToFileURL(captures).href); |
| 12 | url.searchParams.set('icon',pathToFileURL(resolve(here,'../../../mobile/Assets.xcassets/AppIcon.appiconset/AppIcon.png')).href); |
| 13 | const hash=p=>createHash('sha256').update(readFileSync(p)).digest('hex'); |
| 14 | const browser=await chromium.launch();const errors=[];const slides=[];const sources=[]; |
| 15 | for(const [device,[width,height]] of Object.entries({iphone:[1320,2868],ipad:[2752,2064]})){ |
| 16 | if(process.argv[4] && process.argv[4]!==device)continue; |
| 17 | const page=await browser.newPage({viewport:{width,height},deviceScaleFactor:1}); |
| 18 | page.on('pageerror',e=>errors.push(String(e)));url.searchParams.set('device',device); |
| 19 | for(const [i,name] of ['music','studio','style','radio','export','free'].entries()){ |
| 20 | url.searchParams.set('slide',i+1);url.searchParams.delete('review'); |
| 21 | await page.goto(url.href);await page.evaluate(()=>Promise.all([...document.images].map(i=>i.decode())));await page.evaluate(()=>document.fonts.ready); |
| 22 | await page.evaluate(()=>{for(const e of document.querySelectorAll('.callout')){const s=getComputedStyle(e),r=e.getBoundingClientRect();if(new Set([s.paddingTop,s.paddingRight,s.paddingBottom,s.paddingLeft]).size!==1)throw Error('Unequal callout padding');if(r.left<0||r.right>innerWidth||r.bottom>innerHeight)throw Error('Callout outside canvas');}}); |
| 23 | if(device==='iphone' && await page.locator('.octagon').count())throw Error('Decorative outline remains behind iPhone'); |
| 24 | const file=`${device}-${String(i+1).padStart(2,'0')}-${name}.png`;const path=join(release,file); |
| 25 | await page.screenshot({path,clip:{x:0,y:0,width,height},omitBackground:false}); |
| 26 | slides.push({file,width,height,bytes:readFileSync(path).length,sha256:hash(path)});console.log(file); |
| 27 | } |
| 28 | url.searchParams.delete('slide');url.searchParams.set('review','1');await page.setViewportSize({width:2400,height:1800});await page.goto(url.href); |
| 29 | await page.evaluate(()=>Promise.all([...document.images].map(i=>i.decode())));await page.locator('#overview').screenshot({path:join(output,device+'-contact-sheet.png')}); |
| 30 | for(const name of ['studio','fullscreen','style','radio','library','export',...['studio','style','radio','export'].map(k=>'callout-'+k)]){const file=device+'-'+name+'.png';sources.push({file,sha256:hash(join(captures,file))});} |
| 31 | await page.close(); |
| 32 | } |
| 33 | await browser.close();if(errors.length)throw Error(errors.join('\n')); |
| 34 | writeFileSync(join(output,'manifest.json'),JSON.stringify({appVersion:'1.2',appBuild:'10',renderedAt:new Date().toISOString(),sources,slides},null,2)+'\n'); |