-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluaumin.js
37 lines (30 loc) · 962 Bytes
/
luaumin.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
const { spawnSync } = require('child_process');
const path = require('path');
function minifyLuau(source) {
const exePath = path.join(__dirname, 'bin', 'luaumin.exe');
try {
const base64LuaCode = Buffer.from(source).toString('base64');
const child = spawnSync(exePath, [], {
input: base64LuaCode,
encoding: "utf-8"
})
if (child.error) {
console.error('Error spawning child process:', child.error);
return null;
}
const minifiedOutput = JSON.parse(child.stdout.replace(/\s+/g, ' ').trim());
if (minifiedOutput.error) {
console.warn("Could not minify:", minifiedOutput.error)
return null
}
return atob(minifiedOutput.source);
} catch (error) {
console.error('Error executing .exe:', error);
throw error;
}
}
var luaumin = {
'version': '1.0.0',
'minify': minifyLuau
}
module.exports = luaumin