| 38 | }, |
| 39 | }, |
| 40 | async run({ args }) { |
| 41 | const format = args.format as string; |
| 42 | |
| 43 | // Validate --format against closed enum |
| 44 | if (!FORMATS.includes(format as ExportFormat)) { |
| 45 | console.error(JSON.stringify({ |
| 46 | error: `Invalid format "${format}". Valid formats: ${FORMATS.join(', ')}`, |
| 47 | })); |
| 48 | process.exitCode = 1; |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | const content = await readInput(args.file); |
| 53 | const report = lint(content); |
| 54 | |
| 55 | if (format === 'css-tailwind') { |
| 56 | const handler = new TailwindV4EmitterHandler(); |
| 57 | const result = handler.execute(report.designSystem); |
| 58 | |
| 59 | if (!result.success) { |
| 60 | console.error(JSON.stringify({ error: result.error.message })); |
| 61 | process.exitCode = 1; |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | console.log(serializeTailwindV4(result.data.theme)); |
| 66 | } else if (format === 'json-tailwind' || format === 'tailwind') { |
| 67 | const handler = new TailwindEmitterHandler(); |
| 68 | const result = handler.execute(report.designSystem); |
| 69 | |
| 70 | if (!result.success) { |
| 71 | console.error(JSON.stringify({ error: result.error.message })); |
| 72 | process.exitCode = 1; |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | console.log(JSON.stringify(result.data, null, 2)); |
| 77 | } else if (format === 'dtcg') { |
| 78 | const handler = new DtcgEmitterHandler(); |
| 79 | const result = handler.execute(report.designSystem); |
| 80 | |
| 81 | if (!result.success) { |
| 82 | console.error(JSON.stringify({ error: result.error.message })); |
| 83 | process.exitCode = 1; |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | console.log(JSON.stringify(result.data, null, 2)); |
| 88 | } |
| 89 | |
| 90 | process.exitCode = report.summary.errors > 0 ? 1 : 0; |
| 91 | }, |
| 92 | }); |