forked from RamonGebben/figlefy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix-error.js
30 lines (28 loc) · 810 Bytes
/
fix-error.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
const fs = require('fs');
const LINE_NUMBER = 6;
const FILE_LOCATION = 'node_modules/hapi/lib/defaults.js'
const INJECT_FIX_STRING = `
var isWin = process.platform === "win32";
var isLinux = process.platform === "linux";
var isDarwin = process.platform === "darwin";
if (isDarwin || isLinux) {
Os.tmpDir = Os.tmpdir;
} else if (isWin) {
Os.tmpDir = os.tmpDir;
}
`
let data = fs.readFileSync(FILE_LOCATION)
if (data.includes(INJECT_FIX_STRING)) {
console.log("Skipping fix injection, already exists.")
} else {
data = data.toString().split("\n");
data.splice(LINE_NUMBER, 0, INJECT_FIX_STRING);
let text = data.join("\n");
fs.writeFile(FILE_LOCATION, text, (err) => {
if (err) {
return console.log(err);
} else {
return console.log('Injected fix successfully')
}
});
}