const { program } = require('commander');
const { createServer } = require('../lib/servers/snapshot-view-server');
const fs = require('fs');
const path = require('path');
const open = require('open');
const getPort = require('get-port');

program
  .description('An interactive application to preview Webf snapshot images.')
  .requiredOption('-s, --source <source_dir>', 'the integration snapshots source directory.')
program.parse(process.argv);

let source = program.source;

if (!path.isAbsolute(source)) {
  source = path.join(process.cwd(), source);
}

(async () => {
  const PORT = await getPort({port: 3300});
  const server = createServer(source, PORT);

  open(`http://127.0.0.1:${PORT}/snapshot-view`);
})();
