-
Notifications
You must be signed in to change notification settings - Fork 3
/
globalizeFS.js
29 lines (24 loc) · 904 Bytes
/
globalizeFS.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
const fs = require("fs");
const path = require("path");
const lovejs = path.resolve("love.js");
function globalizeFS(sourceCode)
{
const isGlobalizedChecker = "window.FS = null;";
if(sourceCode.substring(0, isGlobalizedChecker.length) == isGlobalizedChecker)
{
console.log("love.js FS globalization is up to date");
return sourceCode;
}
var syscallsIndex = sourceCode.indexOf("var SYSCALLS");
return "window.FS = null;" + sourceCode.substring(0, syscallsIndex) +
"if(window.FS == null)window.FS = FS;" + sourceCode.substring(syscallsIndex);
}
if(fs.existsSync(lovejs))
{
const source = String(fs.readFileSync(lovejs));
if(source == null)
throw new Error("Error occurred while reading file " + lovejs);
fs.writeFileSync(lovejs, globalizeFS(source));
}
else
throw new Error("File love.js not found");