smartnginx/dist/smartnginx.classes.nginxconfig.js

68 lines
4.8 KiB
JavaScript
Raw Permalink Normal View History

2016-07-06 01:14:44 +00:00
"use strict";
2016-07-21 00:24:54 +00:00
const plugins = require("./smartnginx.plugins");
const paths = require("./smartnginx.paths");
const snippets = require("./smartnginx.snippets");
2016-07-24 23:54:36 +00:00
const smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
2016-07-21 00:24:54 +00:00
let allConfigs = [];
class NginxConfig {
constructor(optionsArg) {
2016-07-08 02:24:07 +00:00
this.zones = [];
2016-07-24 23:54:36 +00:00
this.nginxProcess = new smartnginx_classes_nginxprocess_1.NginxProcess(this);
2016-07-06 04:33:31 +00:00
this.isDeployed = false;
2016-07-12 21:20:08 +00:00
this.cert = new plugins.cert.Cert({
cfEmail: optionsArg.cfEmail,
cfKey: optionsArg.cfKey,
sslDir: paths.nginxCertBase,
gitOriginRepo: optionsArg.gitOriginRepo,
testMode: optionsArg.testMode
2016-07-12 21:20:08 +00:00
});
2016-07-06 01:14:44 +00:00
}
;
2016-07-06 01:33:39 +00:00
// interact with Zones
2016-07-21 00:24:54 +00:00
addZone(zoneArg) {
2016-07-08 02:24:07 +00:00
this.zones.push(zoneArg);
2016-07-21 00:24:54 +00:00
}
listZones() {
2016-07-06 01:33:39 +00:00
return this.zones;
2016-07-21 00:24:54 +00:00
}
2016-07-06 01:33:39 +00:00
;
2016-07-21 00:24:54 +00:00
removeZones(zoneArg) {
}
clean() {
this.zones = [];
}
2016-07-06 01:33:39 +00:00
// handle deployment of zones
2016-07-24 23:54:36 +00:00
deploy() {
2016-07-21 00:24:54 +00:00
let done = plugins.q.defer();
2016-07-08 02:24:07 +00:00
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
2016-07-12 21:20:08 +00:00
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
2016-07-21 00:24:54 +00:00
for (let config of allConfigs) {
2016-07-06 04:33:31 +00:00
config.isDeployed = false;
}
;
this.isDeployed = true;
2016-07-12 21:20:08 +00:00
// write base config
2016-07-24 23:54:36 +00:00
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
2016-07-12 21:20:08 +00:00
// deploy zones
2016-07-21 00:24:54 +00:00
let promiseArray = [];
for (let zone of this.zones) {
2016-07-24 23:54:36 +00:00
let zoneDeployedPromise = zone.deploy(this.cert);
zoneDeployedPromise.then(() => {
plugins.beautylog.info(`Zone ${zone.zoneName} deployed!`);
this.nginxProcess.reloadConfig();
});
promiseArray.push(zoneDeployedPromise);
2016-07-06 04:33:31 +00:00
}
2016-07-08 02:24:07 +00:00
;
2016-07-12 21:20:08 +00:00
plugins.q.all(promiseArray)
2016-07-21 00:24:54 +00:00
.then(() => {
2016-07-12 21:20:08 +00:00
done.resolve();
});
return done.promise;
2016-07-21 00:24:54 +00:00
}
2016-07-06 01:14:44 +00:00
;
2016-07-21 00:24:54 +00:00
}
2016-07-06 01:14:44 +00:00
exports.NginxConfig = NginxConfig;
;
2016-07-24 23:54:36 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELE1BQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsTUFBWSxRQUFRLFdBQU0sdUJBQXVCLENBQUMsQ0FBQTtBQUVsRCxrREFBNkIsbUNBQW1DLENBQUMsQ0FBQTtBQUNqRSxJQUFJLFVBQVUsR0FBa0IsRUFBRSxDQUFDO0FBRW5DO0lBS0ksW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