#!/usr/bin/env node // Prints the image-edit request for the clean hero photo. It does not call any API. // Usage: node scripts/build-input.mjs --image https://... --product "over-ear headphones" // [--pose "floating at a slight three-quarter angle"] [--background "..."] [--share 75] import { readFileSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' const root = join(dirname(fileURLToPath(import.meta.url)), '..') const usage = 'Usage: node scripts/build-input.mjs --image https://... --product "name" [--pose "..."] [--background "..."] [--share 75]' const allowed = new Set(['image', 'product', 'pose', 'background', 'share']) const options = {} const args = process.argv.slice(2) for (let index = 0; index < args.length; index += 2) { const key = args[index] const value = args[index + 1] if (!key.startsWith('--') || !allowed.has(key.slice(2))) { console.error(`Unknown option "${key}".\n${usage}`) process.exit(1) } if (value === undefined || value.startsWith('--')) { console.error(`Option ${key} needs a value.\n${usage}`) process.exit(1) } options[key.slice(2)] = value } if (!options.image || !options.product) { console.error(usage) process.exit(1) } if (!/^(https:\/\/|data:image\/)/.test(options.image)) { console.error('The product photo must be a public https URL or a data:image/ URI.') process.exit(1) } const share = Number(options.share ?? 75) if (!(share >= 40 && share <= 80)) { console.error('--share must be between 40 and 80 (percent of the frame width the product fills).') process.exit(1) } const template = readFileSync(join(root, 'assets/prompt-template.md'), 'utf8').trim() const settings = JSON.parse(readFileSync(join(root, 'assets/generation-input.json'), 'utf8')) const prompt = template .replace('{{product}}', () => options.product) .replace('{{pose}}', () => options.pose ?? 'floating upright, seen from the front and turned about 25 degrees so that two sides of the product show, with a soft shadow far beneath') .replace('{{background}}', () => options.background ?? settings.default_background) .replace('{{share}}', () => String(share)) console.log(JSON.stringify({ model: settings.model, input: { ...settings.input, image_urls: [options.image], prompt } }, null, 2))