-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·52 lines (46 loc) · 1.39 KB
/
index.js
File metadata and controls
executable file
·52 lines (46 loc) · 1.39 KB
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
'use strict';
const path = require('path');
const spawn = require('child_process').spawn;
const promisify = require("es6-promisify");
const mkdirp=promisify(require("mkdirp"));
const extract = promisify(require('extract-zip'));
function runForgeflower(inputDir,outputDir,showProgress)
{
var forgeflowerProcess=spawn('java', [
'-jar',
path.join(__dirname,"forgeflower.jar"),
inputDir,
outputDir],
{
stdio: 'pipe'
});
forgeflowerProcess.stdout.setEncoding('utf8');
forgeflowerProcess.stderr.setEncoding('utf8');
var buffer = "";
forgeflowerProcess.stdout.on('data', onData);
forgeflowerProcess.stderr.on('data', onData);
function onData(data) {
buffer += data;
var lines = buffer.split("\n");
var len = lines.length - 1;
for(var i = 0; i < len; ++i) {
if(showProgress) console.log(lines[i]);
}
buffer = lines[lines.length - 1];
}
return new Promise((resolve)=> {
forgeflowerProcess.on('exit', function() {
resolve();
});
});
}
module.exports=function(inputJar,outputDir,showProgress)
{
var compiledDir=path.join(outputDir,"compiled");
var decompiledDir=path.join(outputDir,"decompiled");
return mkdirp(compiledDir)
.then(() => mkdirp(decompiledDir))
.then(() => extract(inputJar, {dir: compiledDir}))
.then(() => runForgeflower(compiledDir, decompiledDir,showProgress))
.then(() => decompiledDir);
};