smartnginx/dist/smartnginx.classes.nginxconfig.js

71 lines
4.9 KiB
JavaScript

"use strict";
const plugins = require("./smartnginx.plugins");
const paths = require("./smartnginx.paths");
const snippets = require("./smartnginx.snippets");
const smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
let allConfigs = [];
/**
* main class that manages a NginxInstance
*/
class NginxConfig {
constructor(optionsArg) {
this.hosts = [];
this.nginxProcess = new smartnginx_classes_nginxprocess_1.NginxProcess(this);
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 Hosts
addHost(nginxHostArg) {
this.hosts.push(nginxHostArg);
}
listHosts() {
return this.hosts;
}
;
removeHost(nginxHostArg) {
}
clean() {
this.hosts = [];
}
// handle deployment of hosts
deploy() {
let done = plugins.q.defer();
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
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(), paths.nginxConfFile);
// deploy hosts
let promiseArray = [];
for (let host of this.hosts) {
let hostDeployedPromise = host.deploy(this.cert);
hostDeployedPromise.then(() => {
plugins.beautylog.info(`Host ${host.hostName} deployed!`);
this.nginxProcess.reloadConfig();
});
promiseArray.push(hostDeployedPromise);
}
;
plugins.q.all(promiseArray)
.then(() => {
done.resolve();
});
return done.promise;
}
;
}
exports.NginxConfig = NginxConfig;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21h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