#!/usr/bin/env node // Prints the image-edit request for one ghost mannequin shot. It does not call any API. // Usage: // node scripts/build-input.mjs --garment "olive green nylon bomber jacket" --image https://... \ // --details "olive colour, glossy-satin nylon, ribbed collar, cuffs and hem, silver open zip, sleeve zip pocket" \ // [--background "white (#FFFFFF)"] [--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 --garment "type and colour" --image https://... --details "what must be kept" [--background "white (#FFFFFF)"] [--square]' const flags = new Set(['square']) const known = new Set(['garment','image','details','background','square']) const options = {} const args = process.argv.slice(2) for (let index = 0; index < args.length; index += 1) { const key = args[index] if (!key.startsWith('--')) { console.error(`Unexpected argument: ${key}`) process.exit(1) } const name = key.slice(2) if (!known.has(name)) { console.error(`Unknown flag: ${key}`) console.error(usage) process.exit(1) } if (flags.has(name)) { options[name] = true continue } const value = args[index + 1] if (value === undefined || value.startsWith('--')) { console.error(`Flag ${key} needs a value.`) process.exit(1) } options[name] = value index += 1 } const { garment, image, details } = options if (!garment || !image || !details) { console.error(usage) process.exit(1) } if (!/^https:\/\//.test(image)) { console.error('The garment photo must be a public https URL.') 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('{{garment}}', () => garment) .replace('{{details}}', () => details) .replace('{{background}}', () => options.background || 'white (#FFFFFF)') .replace(/\s{2,}/g, ' ') const input = { ...settings.input, ...(options.square ? { image_size: settings.square_image_size } : {}), image_urls: [image], prompt, } console.log(JSON.stringify({ model: settings.model, input }, null, 2))