"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TsTarget = void 0;
const tslib_1 = require("tslib");
/* eslint-disable no-param-reassign */
const typescript_1 = tslib_1.__importDefault(require("typescript"));
const path_1 = tslib_1.__importDefault(require("path"));
const core_1 = require("@il2js/core");
const GeneratorMethods_1 = require("./GeneratorMethods");
class TsTarget {
    constructor(assembly, version, types, api) {
        this.assembly = assembly;
        this.version = version;
        this.types = types;
        this.api = api;
    }
    async process(il2js, opts, progressCallback) {
        this.nodes = await GeneratorMethods_1.generateFileAsync(il2js, this.assembly, this.version, this.types, opts, progressCallback);
    }
    async write(options) {
        core_1.assert(this.nodes, ReferenceError);
        const printer = typescript_1.default.createPrinter({
            newLine: typescript_1.default.NewLineKind.LineFeed,
        });
        const indexFile = typescript_1.default.createSourceFile('index.ts', '', typescript_1.default.ScriptTarget.Latest, false, typescript_1.default.ScriptKind.TS);
        const output = this.nodes.map((node) => printer.printNode(typescript_1.default.EmitHint.Unspecified, node, indexFile)).join('\n');
        const targetFile = path_1.default.join(options.outputDir, options.entry);
        await this.api.writeFile(targetFile, output);
    }
}
exports.TsTarget = TsTarget;
TsTarget.targetName = 'typescript';
//# sourceMappingURL=TsTarget.js.map