Begin making conf files

This commit is contained in:
MattIPv4
2020-05-08 17:58:38 +01:00
parent 627fc0cb7f
commit e6db3cea7b
6 changed files with 259 additions and 4 deletions

View File

@@ -0,0 +1,26 @@
import ConfigParser from '@webantic/nginx-config-parser';
const parser = new ConfigParser();
import { nginxFormat } from 'nginx-format';
import nginxConf from './nginx.conf';
const toConf = obj => {
// Convert the obj to nginx
const rawConf = nginxFormat(parser.toConf(obj));
const commentConf = rawConf
.replace(/((?:^|\n)(?:[^\S\r\n]*)#.+);($|\n)/g, '$1$2') // Remove semis on comments
.replace(/((?:^|\n)[^\S\r\n]*[^#\s].*[^\n])\n([^\S\r\n]*)#/g, '$1\n$2\n$2#') // Double linebreak before comment
.replace(/((?:^|\n)[^\S\r\n]*#.*\n[^\S\r\n]*#.*\n)([^\S\r\n]*)([^#\s])/g, '$1\n$2$3'); // Double linebreak after double comment
return commentConf;
}
export default (domains, global) => {
const files = {};
files['nginx.conf'] = toConf(nginxConf(domains, global));
return files;
}