"use strict"; const plugins = require("./smartnginx.plugins"); const paths = require("./smartnginx.paths"); const command = require("./smartnginx.command"); const snippets = require("./smartnginx.snippets"); let allConfigs = []; class NginxConfig { constructor(optionsArg) { this.zones = []; this.isDeployed = false; this.cert = new plugins.cert.Cert({ cfEmail: optionsArg.cfEmail, cfKey: optionsArg.cfKey, sslDir: paths.nginxCertBase, gitOriginRepo: optionsArg.gitOriginRepo, testMode: optionsArg.testMode }); } ; // interact with Zones addZone(zoneArg) { this.zones.push(zoneArg); } listZones() { return this.zones; } ; removeZones(zoneArg) { } clean() { this.zones = []; } // handle deployment of zones deploy(nginxRestartArg = false) { let 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 (let config of allConfigs) { config.isDeployed = false; } ; this.isDeployed = true; // write base config plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), plugins.path.join(paths.nginxConfigBase, "nginx.conf")); // deploy zones let promiseArray = []; for (let zone of this.zones) { promiseArray.push(zone.deploy(this.cert)); } ; plugins.q.all(promiseArray) .then(() => { // restart nginx if (nginxRestartArg) { command.restart(this); } ; done.resolve(); }); return done.promise; } ; } exports.NginxConfig = NginxConfig; ; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELE1BQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsTUFBWSxP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