"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.adScriptsToPackageJson = void 0;
const getOptionsKeys_1 = require("./helpers/getOptionsKeys");
function sortObjectByKeys(obj) {
    return Object.keys(obj)
        .sort()
        .reduce((result, key) => {
        result[key] = obj[key];
        return result;
    }, {});
}
const adScriptsToPackageJson = (_options) => {
    return (host, _context) => {
        if (host.exists("package.json") == false) {
            host.create("package.json", "{}");
        }
        const sourceText = host.read("package.json").toString("utf-8");
        const json = JSON.parse(sourceText);
        if (!json.scripts) {
            json.scripts = {};
        }
        let toInstallKeys = (0, getOptionsKeys_1.getOptionskeys)(_options, _context);
        for (const installKey of toInstallKeys) {
            if (installKey.scripts !== undefined) {
                Object.keys(installKey.scripts).forEach((key) => {
                    if (!json.scripts[key]) {
                        json.scripts[key] = installKey.scripts[key];
                    }
                });
            }
        }
        //json.scripts = sortObjectByKeys(json.scripts);
        host.overwrite("package.json", JSON.stringify(json, null, 2));
    };
};
exports.adScriptsToPackageJson = adScriptsToPackageJson;
//# sourceMappingURL=addScriptsToPackageJson.js.map