-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
56 lines (45 loc) · 1.06 KB
/
index.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
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Sol Bekic / s-ol.nu
*/
const loader_utils = require('loader-utils');
const child_process = require('child_process');
const Readable = require('stream').Readable;
module.exports = function(content) {
const callback = this.async();
this.cacheable && this.cacheable();
const options = Object.assign(
{},
{ moonc: 'moonc' },
loader_utils.getOptions(this)
);
const job = child_process.spawn(
options.moonc,
['--'],
{ encoding: 'utf8', windows_hide: true }
);
job.stdin.write(content);
job.stdin.end();
let done;
job.on('error', function (err) {
done = true;
callback(err);
});
let data = '';
let error = '';
job.stdout.on('data', function (d) {
data += d.toString();
});
job.stderr.on('data', function (d) {
error += d.toString();
});
job.on('close', function (code) {
if (done)
return;
if (code === 0)
callback(null, data);
else
callback(new Error(error));
});
}
module.exports.seperable = true;