-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.js
67 lines (54 loc) · 1.17 KB
/
loader.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
const { execSync } = require('child_process');
const { spawn } = require('child_process');
const { readFileSync } = require('fs');
const { join, dirname } = require('path');
function spawnKonanc({ isDebug, cwd }) {
console.log("🚍 Starting to compile");
const bin = 'konanc';
const args = [
'-target',
'wasm32',
cwd,
'-o',
'dist/program'
];
const options = {
cwd,
env: {
PATH: process.env['PATH']
}
};
return new Promise((resolve, reject) => {
const p = spawn(bin, args, options);
console.log("⚙️ Compiling");
let stdout = '';
let stderr = '';
p.stdout.on('data', (d) => {
stdout += d;
});
p.stderr.on('data', (d) => {
stderr += d;
});
p.on('close', (code) => {
if (code === 0) {
console.log("✅ Compiled");
resolve();
} else {
reject(stderr);
}
});
});
}
module.exports = function() {
this.cacheable();
const callback = this.async();
const cwd = dirname(this.resourcePath);
spawnKonanc({
isDebug: this.debug,
cwd
}).then(() => {
callback(null, "");
})
.catch(callback);
}
module.exports.raw = true;