const fs = require('fs');
const path = require('path');
const TJS = require("typescript-json-schema");

const inputFilename = process.argv[2];
const outputFilename = process.argv[3];
const fullTypeName = process.argv[4];
console.log('in: ', inputFilename);
console.log('fullTypeName: ', fullTypeName);
console.log('out: ', outputFilename);

// optionally pass argument to schema generator
var settings = {
    refs: true,
    aliasRefs: true,
    required: true,
    defaultProps: false,
    titles: false,
    noExtraProps: true
};
// optionally pass ts compiler options
var compilerOptions = {
    strictNullChecks: true,
    skipLibCheck: true,
    typeRoots: ["node_modules/@types"]

};
// optionally pass a base path
const layouts = path.resolve("./app/" + inputFilename);
var program = TJS.getProgramFromFiles([layouts], compilerOptions);
var schema = TJS.generateSchema(program, fullTypeName, settings);
if (schema) {
    fs.writeFileSync("./schemas/" + outputFilename, JSON.stringify(schema, null, 4));
}