"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FilePrinter = void 0;
const prettier_plugin_sort_imports_1 = __importDefault(require("@trivago/prettier-plugin-sort-imports"));
const import2_1 = __importDefault(require("import2"));
const prettier_1 = require("prettier");
const typescript_1 = __importDefault(require("typescript"));
var FilePrinter;
(function (FilePrinter) {
    FilePrinter.description = (node, comment) => {
        if (comment.length === 0)
            return node;
        typescript_1.default.addSyntheticLeadingComment(node, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, ["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"), true);
        return node;
    };
    FilePrinter.newLine = () => typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createIdentifier("\n"));
    FilePrinter.write = (props) => {
        var _a;
        const script = typescript_1.default
            .createPrinter({
            newLine: typescript_1.default.NewLineKind.LineFeed,
        })
            .printFile(typescript_1.default.factory.createSourceFile(props.statements, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EndOfFileToken), typescript_1.default.NodeFlags.None));
        return ((_a = props.top) !== null && _a !== void 0 ? _a : "") + script;
    };
    FilePrinter.beautify = (script) => __awaiter(this, void 0, void 0, function* () {
        try {
            return yield (0, prettier_1.format)(script, {
                parser: "typescript",
                plugins: [prettier_plugin_sort_imports_1.default, yield (0, import2_1.default)("prettier-plugin-jsdoc")],
                importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
                importOrderSeparation: true,
                importOrderSortSpecifiers: true,
                importOrderParserPlugins: ["decorators-legacy", "typescript", "jsx"],
            });
        }
        catch (_a) {
            return script;
        }
    });
})(FilePrinter || (exports.FilePrinter = FilePrinter = {}));
//# sourceMappingURL=FilePrinter.js.map