-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (41 loc) · 1.27 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
const path = require('path');
const crypto = require('crypto');
const child_process = require('child_process');
module.exports = {
getCacheKey: function getCacheKey(src, filename, configStr) {
if (typeof configStr !== 'string') {
configStr = JSON.stringify(configStr);
}
return crypto
.createHash('md5')
.update(src)
.update(filename)
.update(configStr)
.digest('hex');
},
getConfig: function getConfig(filename, config) {
//console.log('getConfig', filename);
if (config.transformerConfig) {
return config.transformerConfig;
}
for (const transform of config.transform) {
const expr = new RegExp(transform[0]);
//console.log('match transform', expr, expr.test(filename));
if (expr.test(filename)) {
//console.log('matched transform', transform);
return transform[2] || {};
}
}
return {};
},
process: function process(src, filename, config/*, options*/) {
//console.log('cpp-to-wasm process');
const wasmConfig = this.getConfig(filename, config);
//console.log('config =', wasmConfig);
return child_process.execFileSync(
path.join(__dirname, 'cpp-wasm-build'),
[ filename, JSON.stringify(wasmConfig) ],
{ encoding: 'utf8' }
);
}
};