"use strict";
var ts = require("typescript");
var pathModule = require("path");
var fs = require("fs-extra");
var TSConfigParser = (function () {
    function TSConfigParser(filePath) {
        this.filePath = filePath;
        this.result = {};
        var content = fs.readFileSync(this.filePath, "utf8");
        console.log(content);
        this.sourceFile = ts.createSourceFile(this.filePath, content, ts.ScriptTarget.ES5, true);
        this.traverseAndParse();
    }
    TSConfigParser.prototype.getTemplatePath = function () {
        var basedir = pathModule.dirname(this.filePath) + "/";
        var templatePath = pathModule.resolve(basedir, this.result.Template || "template");
        return templatePath;
    };
    TSConfigParser.prototype.getOutputPath = function () {
        var basedir = pathModule.dirname(this.filePath) + "/";
        var outputPath = pathModule.resolve(basedir, this.result.Output || "R.d.ts");
        return outputPath;
    };
    TSConfigParser.prototype.getRootPath = function () {
        var basedir = pathModule.dirname(this.filePath) + "/";
        if (!this.result.Root)
            return basedir;
        var outputPath = pathModule.resolve(basedir, this.result.Root);
        return outputPath;
    };
    TSConfigParser.prototype.getStyleOutputPath = function () {
        if (!this.result.StyleOutput)
            return "";
        var basedir = pathModule.dirname(this.filePath) + "/";
        var styleOutputPath = pathModule.resolve(basedir, this.result.StyleOutput || "R.d.ts");
        return styleOutputPath;
    };
    TSConfigParser.prototype.traverseAndParse = function () {
        var _this = this;
        ts.forEachChild(this.sourceFile, function (child) {
            if (child.kind === ts.SyntaxKind.TypeAliasDeclaration) {
                var node = child;
                var name_1 = node.name;
                var type = node.type;
                var typeLiteral = type.literal;
                var nameString = name_1.text;
                if (typeLiteral.kind !== ts.SyntaxKind.StringLiteral) {
                    throw new Error("Invalid type declaration" + getSyntaxKindName(typeLiteral.kind));
                }
                var stringLiteral = typeLiteral;
                var contentString = stringLiteral.text;
                _this.result[nameString] = contentString;
            }
            else {
            }
        });
    };
    TSConfigParser.prototype.getDeclareName = function (node) {
        var name = null;
        ts.forEachChild(node, function (child) {
            if (child.kind === ts.SyntaxKind.Identifier) {
                name = child.text;
            }
        });
        return name;
    };
    return TSConfigParser;
}());
exports.TSConfigParser = TSConfigParser;
function getSyntaxKindName(kind) {
    for (var name_2 in ts.SyntaxKind) {
        if (ts.SyntaxKind[name_2] === kind) {
            return name_2;
        }
    }
    return "Unknown";
}
function getKindTree(node) {
    var tree = {
        name: getSyntaxKindName(node.kind),
        children: []
    };
    ts.forEachChild(node, function (child) {
        tree.children.push(getKindTree(child));
    });
    return tree;
}
function inspectKind(node) {
    var tree = getKindTree(node);
    console.log(JSON.stringify(tree, null, 2));
}
//# sourceMappingURL=tsConfigParser.js.map