smartnginx/ts/smartnginx.classes.nginxconfig.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2016-07-06 01:14:44 +00:00
import * as plugins from "./smartnginx.plugins";
2016-07-06 04:33:31 +00:00
import * as paths from "./smartnginx.paths";
import * as command from "./smartnginx.command";
2016-07-08 01:36:51 +00:00
import * as snippets from "./smartnginx.snippets"
2016-07-06 06:30:33 +00:00
import {NginxZone} from "./smartnginx.classes.nginxzone";
2016-07-06 04:33:31 +00:00
let allConfigs:NginxConfig[] = [];
2016-07-06 01:14:44 +00:00
export class NginxConfig {
2016-07-08 02:24:07 +00:00
zones:NginxZone[] = [];
2016-07-06 04:33:31 +00:00
isDeployed:boolean = false;
2016-07-06 01:14:44 +00:00
constructor(){
};
// interact with Zones
addZone(zoneArg:NginxZone){
2016-07-08 02:24:07 +00:00
this.zones.push(zoneArg);
2016-07-06 01:14:44 +00:00
}
listZones():NginxZone[] {
return this.zones;
};
removeZones(zoneArg:NginxZone){
}
// handle deployment of zones
2016-07-06 04:33:31 +00:00
deploy(nginxRestartArg:boolean = false){
2016-07-08 02:24:07 +00:00
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
2016-07-06 04:33:31 +00:00
for(let config of allConfigs){
config.isDeployed = false;
};
this.isDeployed = true;
for(let zone of this.zones){
zone.deploy();
2016-07-08 01:36:51 +00:00
};
plugins.smartfile.memory.toFsSync(
snippets.getBaseConfigString(),
plugins.path.join(paths.nginxConfigBase,"nginx.conf")
);
2016-07-06 04:33:31 +00:00
if(nginxRestartArg){
command.restart(this);
2016-07-08 02:24:07 +00:00
};
2016-07-06 01:14:44 +00:00
};
};