#!/usr/bin/env node

// 
import commander = require("commander");
import React = require("react");
import * as Resolve from "resolve-module-path";
import { render } from ".";
const propsName = "props";
let componentModule;
commander
  .arguments("<component>")
  .action((component) => {
    componentModule = component;
  })
  .option("-p --" + propsName + " <type>", "Props")
  .parse(process.argv);
let props;
if (commander[propsName]) {
  props = JSON.parse(commander[propsName]);
} else {
  props = {};
}
if (!componentModule) {
  throw new Error("Component should be set as first argument, example t1.js");
}
// tslint:disable no-var-requires
let component = require(Resolve(componentModule, { basePath: process.cwd() }));
component = component.default ? component.default : component;
render(React.createElement(component, props));
