-
Notifications
You must be signed in to change notification settings - Fork 26
/
pluginWorker.js
103 lines (80 loc) · 2.21 KB
/
pluginWorker.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Interactive Linter Copyright (c) 2015 Miguel Castillo.
*
* Licensed under MIT
*/
importScripts("libs/js/require.js");
function PluginLoader(settings) {
"use strict";
var _self = this;
var data = settings.data;
var pluginRequire = requirejs.config({
"paths": {
"text": "../../../libs/js/text",
"libs": "../../../libs/js"
},
"baseUrl": data.baseUrl,
"packages": data.packages
});
_self.byName = {};
_self.byLanguage = {};
pluginRequire(data.packages, function() {
var _plugins = Array.prototype.slice.call(arguments),
_result = {},
plugin = null;
for (var iPlugin in _plugins) {
plugin = _plugins[iPlugin];
plugin.name = plugin.name || data.packages[iPlugin];
_self.byName[plugin.name] = plugin;
_self.byLanguage[plugin.language] = plugin;
_result[plugin.name] = {
"name": plugin.name,
"language": plugin.language,
"settingsFile": plugin.settingsFile
};
}
postMessage({
type: "ready",
data: _result
});
}, function (err) {
console.log(JSON.parse(JSON.stringify(err)));
});
}
PluginLoader.prototype.lint = function(data) {
var _self = this;
// Lint!
data = data.data;
var lintResult = _self.byName[data.name].lint(data.text, data.settings);
postMessage({
"type": "lint",
"data": {
result: lintResult
}
});
};
/**
* Only used for debugging purposes.
*/
var console = {
log: function(message) {
postMessage({
type: "debug",
message: message
});
}
};
onmessage = function(evt) {
var data = evt.data || {};
var method = PluginLoader.instance && PluginLoader.instance[data.type];
if (typeof method === "function") {
return method.apply(PluginLoader.instance, [data || {}]);
}
switch (data.type) {
case "init":
PluginLoader.instance = new PluginLoader(data);
break;
default:
throw new Error("Unknown message type: " + data.type);
}
};