-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
56 lines (47 loc) · 1.11 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
var path = require('path');
// confiuration for loading libflac.js:
//optimization variants:
var optVariant = {
default: '',
release: '',
dev: '.dev',
min: '.min'
};
//technology variants:
var tecVariant = {
default: '',
asmjs: '',
wasm: '.wasm'
};
var baseDir = path.resolve(__dirname, 'dist');
var baseName = 'libflac';
var ext = '.js';
// export factory method:
module.exports = function(impl){
var optv, optStr;
if(/\bdev\b/.test(impl)){
optv = optVariant['dev'];
optStr = 'dev';
} else if(/\bmin\b/.test(impl)){
optv = optVariant['min'];
optStr = 'min';
} else {
optv = optVariant['default'];
optStr = 'release';
}
var tecv, tecStr;
if(/\bwasm\b/.test(impl)){
tecv = tecVariant['wasm'];
tecStr = 'wasm';
} else {
tecv = tecVariant['default'];
tecStr = 'asmjs';
}
var libPath = baseDir + path.sep;
// set library directory
process.env.FLAC_SCRIPT_LOCATION = libPath;
// load library variant
var libInstance = require(libPath + baseName + optv + tecv + ext);
libInstance.variant = optStr + '.' + tecStr;
return libInstance;
}