forked from fazibear/elixirscript-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (40 loc) · 1.02 KB
/
index.js
File metadata and controls
53 lines (40 loc) · 1.02 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
53
var exec = require("child_process").exec;
var loaderUtils = require("loader-utils");
function buildCommand(options) {
if (!options.inputFolder) {
throw "inputFolder required";
}
var args = ["elixirscript"];
if (options.inputFolder) {
var input = [];
if (Array.isArray(options.inputFolder)) {
input = options.inputFolder;
} else {
input = [options.inputFolder];
}
input = input.join(" ");
args.push(input);
}
var modules = options.jsModules.map(function(module) {
return "--js-module " + module.join(":");
});
args = args.concat(modules);
return args.join(" ");
}
module.exports = function(source) {
this.cacheable && this.cacheable();
var callback = this.async();
var options = Object.assign(
{},
{ jsModules: [] },
loaderUtils.getOptions(this) || {}
);
var cmd = buildCommand(options);
exec(cmd, function(error, stdout, stderr) {
if (error) {
callback(new Error(stdout), null);
} else {
callback(null, stdout);
}
});
};