fix(core): update

This commit is contained in:
2019-01-09 12:15:28 +01:00
parent 1049920efd
commit ede884930e
12 changed files with 316 additions and 142 deletions

View File

@ -3,20 +3,20 @@ import * as paths from './smartnginx.paths';
import * as snippets from './smartnginx.snippets';
import { NginxHost } from './smartnginx.classes.nginxhost';
import { NginxProcess } from './smartnginx.classes.nginxprocess';
import { CertHandler } from './smartnginx.classes.certhandler';
let allConfigs: SmartNginx[] = [];
import { IHostConfig } from './interfaces/hostconfig';
/**
* main class that manages a NginxInstance
*/
export class SmartNginx {
certHandler = new CertHandler();
hosts: NginxHost[] = [];
nginxProcess: NginxProcess = new NginxProcess(this);
isDeployed: boolean = false;
constructor() {
};
public logger: plugins.smartlog.Smartlog;
private hosts = new plugins.lik.Objectmap<NginxHost>();
public nginxProcess: NginxProcess = new NginxProcess(this);
constructor(optionsArg: { logger?: plugins.smartlog.Smartlog }) {
optionsArg.logger
? (this.logger = optionsArg.logger)
: (this.logger = plugins.smartlog.defaultLogger);
}
// ===================
// interact with Hosts
@ -26,61 +26,57 @@ export class SmartNginx {
* add a host
* @param nginxHostArg
*/
addHost(hostNameArg: string, destinationIp: string): NginxHost {
const nginxHost = new NginxHost(this, {
hostName: hostNameArg,
destination: destinationIp
})
this.hosts.push(nginxHost);
public addHost(optionsArg: IHostConfig): NginxHost {
const nginxHost = new NginxHost(this, optionsArg);
this.hosts.add(nginxHost);
return nginxHost;
}
getNginxHostByHostName(hostNameArg: string): NginxHost {
/**
* Gets a NginxHost by hostname
* @param hostNameArg
*/
public getNginxHostByHostName(hostNameArg: string): NginxHost {
return this.hosts.find(nginxHost => {
return nginxHost.hostName === hostNameArg;
})
});
}
/**
* listHosts
*/
listHosts(): NginxHost[] {
return this.hosts;
public listHosts(): NginxHost[] {
return this.hosts.getArray();
}
/**
* remove a Host
* @param nginxHostArg
*/
removeHost(nginxHostArg: NginxHost) {}
public removeHost(nginxHostArg: NginxHost) {
this.hosts.remove(nginxHostArg);
}
/**
* clean all hosts
*/
clean() {
this.hosts = [];
public wipeHosts() {
this.hosts.wipe();
}
/**
* deploy the current stack and restart nginx
*/
async deploy() {
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;
public async deploy() {
// write base config
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigDirPath);
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
// deploy hosts
let promiseArray = [];
for (let host of this.hosts) {
plugins.smartfile.fs.ensureEmptyDirSync(paths.nginxHostDirPath);
for (const host of this.hosts.getArray()) {
await host.deploy();
plugins.smartlog.defaultLogger.log('info', `Host ${host.hostName} deployed!`);
this.nginxProcess.reloadConfig();
};
this.logger.log('info', `Host ${host.hostName} deployed!`);
}
this.nginxProcess.reloadConfig();
}
}