diff --git a/package.json b/package.json index 7166d4d..b1fa6b6 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dependencies": { "@types/q": "*", "beautylog": "^5.0.13", - "cert": "0.0.13", + "cert": "0.0.15", "q": "^1.4.1", "shelljs": "^0.7.0", "smartfile": "^4.0.10", diff --git a/ts/smartnginx.classes.nginxconfig.ts b/ts/smartnginx.classes.nginxconfig.ts index 1814d4f..bae6a45 100644 --- a/ts/smartnginx.classes.nginxconfig.ts +++ b/ts/smartnginx.classes.nginxconfig.ts @@ -7,9 +7,15 @@ let allConfigs:NginxConfig[] = []; export class NginxConfig { zones:NginxZone[] = []; + cert:plugins.cert.Cert; // the Cert Instance from which the config gets its certificates isDeployed:boolean = false; - constructor(){ - + constructor(optionsArg:plugins.cert.CertConstructorOptions){ + this.cert = new plugins.cert.Cert({ + cfEmail:optionsArg.cfEmail, + cfKey:optionsArg.cfKey, + sslDir:optionsArg.sslDir, + gitOriginRepo:optionsArg.gitOriginRepo + }); }; // interact with Zones @@ -25,22 +31,34 @@ export class NginxConfig { // handle deployment of zones deploy(nginxRestartArg:boolean = 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; - for(let zone of this.zones){ - zone.deploy(); - }; + // write base config plugins.smartfile.memory.toFsSync( snippets.getBaseConfigString(), plugins.path.join(paths.nginxConfigBase,"nginx.conf") ); - if(nginxRestartArg){ - command.restart(this); + // 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; }; }; diff --git a/ts/smartnginx.classes.nginxzone.ts b/ts/smartnginx.classes.nginxzone.ts index 38e1ecb..f2a9894 100644 --- a/ts/smartnginx.classes.nginxzone.ts +++ b/ts/smartnginx.classes.nginxzone.ts @@ -22,8 +22,14 @@ export class NginxZone { this.destination = optionsArg.destination; this.configString = snippets.getZoneConfigString(optionsArg.zoneName,optionsArg.destination); }; - deploy(){ + deploy(certInstanceArg:plugins.cert.Cert){ + let done = plugins.q.defer(); let filePath = plugins.path.join(paths.nginxZoneBase,this.zoneName + ".conf"); + // writeConfig plugins.smartfile.memory.toFsSync(this.configString,filePath); + // get cert + certInstanceArg.getDomainCert(this.zoneName) + .then(done.resolve); + return done.promise; }; }; \ No newline at end of file diff --git a/ts/smartnginx.paths.ts b/ts/smartnginx.paths.ts index 02b1553..2e3ebad 100644 --- a/ts/smartnginx.paths.ts +++ b/ts/smartnginx.paths.ts @@ -1,5 +1,6 @@ import * as plugins from "./smartnginx.plugins" export let packageBase = plugins.path.join(__dirname,"../"); -export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig/"); -export let nginxZoneBase = plugins.path.join(nginxConfigBase,"zones"); \ No newline at end of file +export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig"); +export let nginxZoneBase = plugins.path.join(nginxConfigBase,"zones"); +export let nginxCertBase = plugins.path.join(nginxConfigBase,"cert"); \ No newline at end of file