-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilder.ts
43 lines (34 loc) · 1.15 KB
/
builder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import fs from 'fs';
type RemoteType = "domains" | "hosts";
const createRule = (type: RemoteType, remote: string, source: string) =>
`
{
"action": "deny",
"notes": "Sourced from ${source}",
"process": "any",
"remote-${type}": "${remote}"
}`;
const createTemplate = (type: RemoteType, name: string, description: string, remotes: string[], source: string, numberOfRules: number) => `{
"name": "${name}",
"description": "Last updated ${(new Date()).toUTCString()}. \\n\\n${description} \\n\\nContains ${numberOfRules} ${type}",
"rules": [
${remotes.map(u => createRule(type, u, source)).join(',')}
]
}`;
export const ruleSetBuilder = (type: RemoteType, name: string, description: string, source: string) => {
let domains: string[] = [];
let domainCount: number = 0;
const addDeniedDomain = (domain: string) => {
domains.push(domain);
domainCount++;
}
const build = (outputDest: string) => {
const writer = fs.createWriteStream(outputDest);
writer.write(createTemplate(type, name, description, domains, source, domainCount))
writer.close();
}
return {
addDeniedDomain,
build
}
}