forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuckle_lto.js
55 lines (51 loc) · 1.2 KB
/
buckle_lto.js
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
54
55
//@ts-check
var fs = require("fs");
var pairs = [
["Config.bs_only", "true"],
["Clflags.native_code", "false"],
["Clflags.unsafe_string", "false"],
["Clflags.record_event_when_debug", "false"],
["Clflags.use_threads", "false"],
["Clflags.use_vmthreads", "false"],
["Clflags.no_implicit_current_dir", "true"],
["Clflags.strict_formats", "true"],
["Clflags.compile_only", "true"],
];
var regexp = RegExp(
`${pairs
.map((x) => {
let result = [];
result.push("!" + x[0]);
let xs = x[0].split(".");
if (xs.length === 2 && xs[1]) {
result.push("!" + xs[1]);
}
return result;
})
.reduce((x,y)=>x.concat(y))
.join("|")}`,
"g"
);
/**
*
* @param {string} s
*/
function transform(s) {
return s.replace(regexp, (s) => {
for (let [k, v] of pairs) {
if (s.includes(k.split(".")[1])) {
// "bs_only" instead of "Clflags.bs_only"
return v;
}
}
return s;
});
}
// transform('!Config.bs_only && Clflags.native && !Clflags.native')
var file = process.argv[2];
console.log(`POST-PROCESSING-FILE:`, file);
fs.writeFileSync(
file,
transform(fs.readFileSync(file, { encoding: "utf8" })),
{ encoding: "utf8" }
);