-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathConfiguration.java.gen.js
More file actions
53 lines (42 loc) · 1.48 KB
/
Configuration.java.gen.js
File metadata and controls
53 lines (42 loc) · 1.48 KB
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
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
/*
Normally I'd avoid scripts to generate code as it makes it harder to reason and work/develop with. But in this case the Java class is too tedious and error-prone to do manually.
*/
const fs = require("fs");
const cfgRs = fs.readFileSync(`${__dirname}/../../../../../../../minify-html/src/cfg/mod.rs`, "utf8");
const opts = [];
for (const [_, snake] of cfgRs.matchAll(/^\s*pub ([a-zA-Z0-9_]+): bool,?\s*$/gm)) {
const pascal = snake.split("_").map((w) => `${w[0].toUpperCase()}${w.slice(1)}`).join("");
opts.push({snake, pascal});
}
const java = `
package in.wilsonl.minifyhtml;
// WARNING: Do not manually edit, use Configuration.java.gen.js.
/**
* Class representing minification configuration.
*/
public class Configuration {
${opts.map(o => `public final boolean ${o.snake};`).join("\n ")}
private Configuration(
${opts.map(o => `boolean ${o.snake}`).join(",\n ")}
) {
${opts.map(o => `this.${o.snake} = ${o.snake};`).join("\n ")}
}
/**
* Builder to help create configuration.
*/
public static class Builder {
${opts.map(o => `private boolean ${o.snake} = false;`).join("\n ")}
${opts.map(o => `public Builder set${o.pascal}(boolean v) {
this.${o.snake} = v;
return this;
}`).join("\n ")}
public Configuration build() {
return new Configuration(
${opts.map(o => `this.${o.snake}`).join(",\n ")}
);
}
}
}
`.trim();
fs.writeFileSync(`${__dirname}/Configuration.java`, java);