forked from knewter/elixirscript-brunch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (52 loc) · 1.75 KB
/
index.js
File metadata and controls
70 lines (52 loc) · 1.75 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use strict";
var childProcess = require("child_process");
var path = require("path");
function ElixirScriptPlugin(config) {
var defaults = {
inputFolder: process.cwd(),
outputFolder: path.join(config.paths.public, "js"),
format: "umd",
jsModules: []
};
var elixirscriptConfig = config.plugins && config.plugins.elixirscript || {};
this.config = Object.assign({}, defaults, elixirscriptConfig);
}
// Tell Brunch we are indeed a plugin for it
ElixirScriptPlugin.prototype.brunchPlugin = true;
// We are a javascript compiler
ElixirScriptPlugin.prototype.type = "javascript";
// We handle .ex, .exs, and .exjs files
ElixirScriptPlugin.prototype.extension = "ex";
ElixirScriptPlugin.prototype.pattern = /\.ex(s|js)?/;
ElixirScriptPlugin.prototype.stripTrailingSlash = function(str) {
const separatedPath = str.split(path.sep);
path.join.apply(path, separatedPath);
};
ElixirScriptPlugin.prototype.compile = function(file, callback) {
return callback(null, "");
};
ElixirScriptPlugin.prototype.buildCommand = function() {
var args = ["elixirscript"];
if (this.config.inputFolder) {
var input = [];
if (Array.isArray(this.config.inputFolder)) {
input = this.config.inputFolder;
} else {
input = [this.config.inputFolder];
}
input = input.join(" ");
args.push(input);
}
args = args.concat(["-o", this.config.outputFolder]);
args = args.concat(["-f", this.config.format]);
var modules = this.config.jsModules.map(function(module) {
return "--js-module " + module.join(":");
});
args = args.concat(modules);
return args.join(" ");
};
ElixirScriptPlugin.prototype.onCompile = function() {
var command = this.buildCommand();
childProcess.execSync(command);
};
module.exports = ElixirScriptPlugin;