-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.mjs
105 lines (93 loc) · 3.09 KB
/
rollup.config.mjs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { readdirSync } from "fs";
import terser from "@rollup/plugin-terser";
import { yourFunction } from "rollup-plugin-your-function";
const toInitCap = str => {
if (str === "uuencode") {
return "UUencode";
}
if (str === "leb-128") {
return "LEB128";
}
return str
.at(0)
.toUpperCase()
.concat(
str.slice(1))
.replaceAll(/-./g, (s) => s
.at(1)
.toUpperCase()
);
}
const converters = new Array();
const bytesOnly = process.argv.includes("BYTES_ONLY");
const makeConverter = (inputFile, srcDir, distDir, useGroupDir, t=terser()) => {
const filename = inputFile.replace(/\.js$/, "");
const modName = toInitCap(filename);
const groupDir = (useGroupDir) ? `${modName}/`: "";
const converter = {
input: `${srcDir}${inputFile}`,
output: [
{
format: "iife",
name: modName,
file: `${distDir}${groupDir}${filename}.iife.js`
},
{
format: "iife",
name: modName,
file: `${distDir}${groupDir}${filename}.iife.min.js`,
plugins: [t]
},
{
format: "es",
name: modName,
file: `${distDir}${groupDir}${filename}.esm.js`
},
{
format: "es",
name: modName,
file: `${distDir}${groupDir}${filename}.esm.min.js`,
plugins: [t]
},
]
};
if (bytesOnly) {
converter.plugins = [
yourFunction({
include: "**/utils.js",
fn: source => {
const code = source
.replace(
/DEFAULT_INPUT_HANDLER ?= ?SmartInput/,
"DEFAULT_INPUT_HANDLER = BytesInput"
)
.replace(
/DEFAULT_OUTPUT_HANDLER ?= ?SmartOutput/,
"DEFAULT_OUTPUT_HANDLER = BytesOutput"
);
return code;
}
})
]
}
converters.push(converter);
}
// allow only the main license for base-ex class
const selectiveTerser = terser({
format: {
comments: (_, comment) => {
const text = comment.value;
const type = comment.type;
return (
type === "comment2" &&
!(/BaseEx\|\w+/).test(text) &&
(/@license/i).test(text)
);
}
}
});
makeConverter("base-ex.js", "src/", "dist/", false, selectiveTerser);
readdirSync("./src/converters").forEach(inputFile => {
makeConverter(inputFile, "src/converters/", "dist/converters/", true)
});
export default converters;