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AQ;aACxB,CAAC,CAAA;YAEF,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport { CodeConnectJSON } from './figma_connect'\nimport { CodeConnectConfig } from './project'\nimport { parseRawFile } from './raw_templates'\n\ninterface BatchComponentEntry {\n url: string\n source?: string\n component?: string\n [key: string]: any\n}\n\ninterface BatchGroup {\n templateFile: string\n components: BatchComponentEntry[]\n}\n\n/**\n * Resolves and validates the template file path referenced by a batch group.\n * Returns the absolute path or throws a descriptive error.\n */\nfunction validateBatchTemplatePath(\n templateFile: string,\n batchDir: string,\n batchFilePath: string,\n): string {\n const templatePath = path.resolve(batchDir, templateFile)\n\n if (!fs.existsSync(templatePath)) {\n throw new Error(`Template file not found: ${templatePath} (referenced from ${batchFilePath})`)\n }\n\n if (!templatePath.endsWith('.figma.batch.ts') && !templatePath.endsWith('.figma.batch.js')) {\n throw new Error(\n `Template file must have a .figma.batch.ts or .figma.batch.js extension: ${templatePath}`,\n )\n }\n\n return templatePath\n}\n\n/**\n * Parses a `.figma.batch.json` file and produces CodeConnectJSON objects.\n *\n * For each component entry, delegates to `parseRawFile` with batch overrides\n * that prepend `window['__FIGMA_BATCH'] = ` to the template. The figma\n * runtime exposes this as `figma.batch`.\n */\nexport function parseBatchFile(\n filePath: string,\n label: string | undefined,\n config?: CodeConnectConfig,\n dir?: string,\n): CodeConnectJSON[] {\n const raw = fs.readFileSync(filePath, 'utf-8')\n let parsed: any\n try {\n parsed = JSON.parse(raw)\n } catch (e) {\n throw new Error(`Failed to parse JSON in ${filePath}: ${e}`)\n }\n\n // Support both single group (object) and multiple groups (array)\n const groups: BatchGroup[] = Array.isArray(parsed) ? parsed : [parsed]\n\n const results: CodeConnectJSON[] = []\n const batchDir = path.dirname(filePath)\n\n for (const group of groups) {\n if (!group.templateFile) {\n throw new Error(`Missing required field \"templateFile\" in ${filePath}`)\n }\n if (!Array.isArray(group.components) || group.components.length === 0) {\n throw new Error(`\"components\" must be a non-empty array in ${filePath}`)\n }\n\n const templatePath = validateBatchTemplatePath(group.templateFile, batchDir, filePath)\n\n for (let i = 0; i < group.components.length; i++) {\n const entry = group.components[i]\n\n if (!entry.url) {\n const entryName = entry.name || entry.component || `index ${i}`\n throw new Error(`Missing required field \"url\" in entry \"${entryName}\" in ${filePath}`)\n }\n\n const doc = parseRawFile(templatePath, label, config, dir, {\n url: entry.url,\n source: entry.source,\n component: entry.component,\n batchData: entry,\n batchFilePath: filePath,\n })\n\n results.push(doc)\n }\n }\n\n return results\n}\n"]}