"use strict"; var plugins = require("./smartnginx.plugins"); var paths = require("./smartnginx.paths"); var command = require("./smartnginx.command"); var snippets = require("./smartnginx.snippets"); var allConfigs = []; var NginxConfig = (function () { function NginxConfig(optionsArg) { this.zones = []; this.isDeployed = false; this.cert = new plugins.cert.Cert({ cfEmail: optionsArg.cfEmail, cfKey: optionsArg.cfKey, sslDir: optionsArg.sslDir, gitOriginRepo: optionsArg.gitOriginRepo }); } ; // interact with Zones NginxConfig.prototype.addZone = function (zoneArg) { this.zones.push(zoneArg); }; NginxConfig.prototype.listZones = function () { return this.zones; }; ; NginxConfig.prototype.removeZones = function (zoneArg) { }; // handle deployment of zones NginxConfig.prototype.deploy = function (nginxRestartArg) { var _this = this; if (nginxRestartArg === void 0) { nginxRestartArg = false; } var done = plugins.q.defer(); plugins.smartfile.fs.removeSync(paths.nginxConfigBase); plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase); plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase); plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase); for (var _i = 0, allConfigs_1 = allConfigs; _i < allConfigs_1.length; _i++) { var config = allConfigs_1[_i]; config.isDeployed = false; } ; this.isDeployed = true; // write base config plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), plugins.path.join(paths.nginxConfigBase, "nginx.conf")); // deploy zones var promiseArray = []; for (var _a = 0, _b = this.zones; _a < _b.length; _a++) { var zone = _b[_a]; promiseArray.push(zone.deploy(this.cert)); } ; plugins.q.all(promiseArray) .then(function () { // restart nginx if (nginxRestartArg) { command.restart(_this); } ; done.resolve(); }); return done.promise; }; ; return NginxConfig; }()); exports.NginxConfig = NginxConfig; ; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZm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