Do some cleanup

This commit is contained in:
MattIPv4
2020-05-08 20:57:36 +01:00
parent c5b2459e9d
commit 4bd34dab39
3 changed files with 11 additions and 20 deletions

View File

@@ -1,22 +1,13 @@
import toConf from './to_conf';
import nginxConf from './nginx.conf';
const toConfig = obj => {
// Convert the obj to nginx
const rawConf = toConf(obj);
// Do some magic to comments
const commentConf = rawConf
.replace(/^([^\S\r\n]*[^#\s].*[^\n])\n([^\S\r\n]*)#/gm, '$1\n\n$2#') // Double linebreak before comment
.replace(/^([^\S\r\n]*#.*\n[^\S\r\n]*#.*\n)([^\S\r\n]*[^#\s])/gm, '$1\n$2') // Double linebreak after double comment
return commentConf;
}
// Convert the data to nginx conf and do some magic to comments
const toConfig = entriesOrObject => toConf(entriesOrObject)
.replace(/^([^\S\r\n]*[^#\s].*[^\n])\n([^\S\r\n]*)#/gm, '$1\n\n$2#') // Double linebreak before comment
.replace(/^([^\S\r\n]*#.*\n[^\S\r\n]*#.*\n)([^\S\r\n]*[^#\s])/gm, '$1\n$2'); // Double linebreak after double comment
export default (domains, global) => {
const files = {};
files['nginx.conf'] = toConfig(nginxConf(domains, global));
const files = [];
files.push(['nginx.conf', toConfig(nginxConf(domains, global))]);
return files;
}
};

View File

@@ -46,6 +46,6 @@ const recurse = (entriesOrObject, depth) => {
}
return retVal.replace(/\n\n\n/g, '\n\n');
}
};
export default entriesOrObject => recurse(entriesOrObject, 0);