"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const JSON5 = require("json5");
const fs = require("mz/fs");
const writeFileAtomic = require("write-file-atomic");
const writeYamlFile = require("write-yaml-file");
const YAML_FORMAT = {
    noCompatMode: true,
    noRefs: true,
};
async function writeProjectManifest(filePath, manifest, opts) {
    var _a;
    const fileType = filePath.substr(filePath.lastIndexOf('.') + 1).toLowerCase();
    if (fileType === 'yaml') {
        return writeYamlFile(filePath, manifest, YAML_FORMAT);
    }
    await fs.mkdir(path.dirname(filePath), { recursive: true });
    const trailingNewline = (opts === null || opts === void 0 ? void 0 : opts.insertFinalNewline) === false ? '' : '\n';
    const json = (fileType === 'json5' ? JSON5 : JSON)
        .stringify(manifest, null, (_a = opts === null || opts === void 0 ? void 0 : opts.indent) !== null && _a !== void 0 ? _a : '\t');
    return writeFileAtomic(filePath, `${json}${trailingNewline}`);
}
exports.default = writeProjectManifest;
//# sourceMappingURL=index.js.map