File size: 1,362 Bytes
dc7ee79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
/**

 * Morphus CLI

 * Usage: node scripts/convert.js --input ./examples/page.html --output ./out/page.json

 */

import { program } from 'commander';
import { writeFileSync, mkdirSync } from 'fs';
import { dirname } from 'path';
import { convertHtmlFile } from '../src/pipeline/convert.js';

program
  .requiredOption('--input <path>', 'Path to input HTML file')
  .requiredOption('--output <path>', 'Path for output JSON (loaded by Figma plugin)')
  .option('--width <px>', 'Viewport width', '1440')
  .option('--height <px>', 'Viewport height', '900')
  .parse();

const opts = program.opts();

async function run() {
  console.log(`\nConverting ${opts.input}...`);

  const output = await convertHtmlFile(opts.input, {
    viewport: {
      width: parseInt(opts.width, 10),
      height: parseInt(opts.height, 10),
    },
  });

  mkdirSync(dirname(opts.output), { recursive: true });
  writeFileSync(opts.output, JSON.stringify(output, null, 2));

  for (const warning of output.warnings ?? []) {
    console.warn(`Warning: ${warning}`);
  }

  console.log(`\nDone. Output -> ${opts.output}`);
  console.log('Load this file in the Figma plugin, or use the plugin HTML flow with the local server.\n');
}

run().catch((err) => {
  console.error('Conversion failed:', err);
  process.exit(1);
});