-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_manifest.js
85 lines (73 loc) · 2.5 KB
/
update_manifest.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
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
var https = require('https');
var fs = require('fs');
var childProcess = require('child_process');
function runScript(scriptPath, callback) {
// keep track of whether callback has been invoked to prevent multiple invocations
var invoked = false;
var process = childProcess.fork(scriptPath);
// listen for errors as they may prevent the exit event from firing
process.on('error', function (err) {
if (invoked) return;
invoked = true;
if(callback) callback(err);
});
// execute the callback once the process has finished running
process.on('exit', function (code) {
if (invoked) return;
invoked = true;
var err = code === 0 ? null : new Error('exit code ' + code);
if(callback) callback(err);
});
}
function downloadScripts(){
return new Promise((resolve, reject)=>{
https.get("https://raw.githubusercontent.com/oeway/ImJoy/master/web/src/pluginParser.js", (response)=>{
if(response.statusCode == 200){
var file = fs.createWriteStream( './pluginParser.js');
var code = ''
response.on('data', (d) => {
code = code + d.toString()
});
response.on('end', () => {
code = code.replace('export function', 'function')
code = code + '\nexports.parseComponent = parseComponent;'
file.write(code);
file.close(()=>{
https.get("https://raw.githubusercontent.com/oeway/ImJoy/master/web/src/buildManifest.js", (response)=>{
if(response.statusCode == 200){
var code2 = ''
response.on('data', (d) => {
code2 = code2 + d.toString()
});
response.on('end', () => {
var file = fs.createWriteStream( './buildManifest.js');
file.write(code2);
file.close(resolve);
})
}
else{
reject(response.statusCode)
}
}).on('error', function(err) { // Handle errors
reject(err.message);
});
});
})
}
else{
reject(response.statusCode)
}
}).on('error', function(err) { // Handle errors
reject(err.message);
});
})
}
downloadScripts().then(()=>{
runScript('./buildManifest.js', ()=>{
fs.unlink('./pluginParser.js', ()=>{})
fs.unlink('./buildManifest.js', ()=>{})
})
}).catch((err)=>{
console.error(err)
runScript('./buildManifest.js')
})