#!/usr/bin/env node // Prints the image-edit request for one packaging mockup. It does not call any API. // Usage: node scripts/build-input.mjs --art https://... --package "a tall rectangular tea carton" \ // --art-description "deep green panel, cream border, ..." --texts "'Mori Tea' and 'Roasted green tea'" \ // [--material "matte uncoated paper"] [--side "plain matching deep green"] [--setting "..."] [--shape landscape|portrait|square] 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 --art https://... --package "..." --art-description "..." --texts "..." [--material "..."] [--side "..."] [--setting "..."] [--shape landscape|portrait|square]' const allowed = new Set(['art', 'package', 'art-description', 'texts', 'material', 'side', 'setting', 'shape']) 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 } for (const required of ['art', 'package', 'art-description', 'texts']) { if (!options[required]) { console.error(`Missing --${required}.\n${usage}`) process.exit(1) } } if (!/^(https:\/\/|data:image\/)/.test(options.art)) { console.error('The art must be a public https URL or a data:image/ URI.') process.exit(1) } const shape = options.shape ?? 'landscape' if (!['landscape', 'portrait', 'square'].includes(shape)) { console.error('--shape must be landscape, portrait or square.') 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('{{package}}', () => options.package) .replace('{{setting}}', () => options.setting ?? settings.default_setting) .replace('{{art}}', () => options['art-description']) .replace('{{texts}}', () => options.texts) .replace('{{side}}', () => options.side ?? 'plain, in the main colour of the art') .replace('{{material}}', () => options.material ?? 'matte uncoated paper with a fine texture') const size = shape === 'portrait' ? settings.portrait_image_size : shape === 'square' ? settings.square_image_size : settings.input.image_size console.log(JSON.stringify({ model: settings.model, input: { ...settings.input, image_size: size, image_urls: [options.art], prompt } }, null, 2))