-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathpluginManager.js
76 lines (57 loc) · 2.4 KB
/
pluginManager.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
/**
* Interactive Linter Copyright (c) 2015 Miguel Castillo.
*
* Licensed under MIT
*/
define(function(require, exports, module) {
"use strict";
var _ = brackets.getModule("thirdparty/lodash"),
FileSystem = brackets.getModule("filesystem/FileSystem"),
pluginLoader = require("pluginLoader"),
Promise = require("libs/js/spromise"),
pluginDirectory = module.uri.substring(0, module.uri.lastIndexOf("/")),
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
preferences = PreferencesManager.getExtensionPrefs("interactive-linter");
var webworker;
preferences.definePreference("webworker", "boolean", true).on("change", function() {
webworker = preferences.get("webworker");
});
/**
* pluginManager is the processor for loading up plugins in the plugins directory in
* make sure they are smoothly running in a worker thread.
*/
function pluginManager() {
return Promise.all([getPluginsMeta(pluginDirectory + "/plugins/default/threaded",'webworker'), getPluginsMeta(pluginDirectory + "/plugins/dev/threaded",'webworker'),getPluginsMeta(pluginDirectory + "/plugins/default/embedded",'embedded'), getPluginsMeta(pluginDirectory + "/plugins/dev/embedded",'embedded')])
.then(loadPlugins)
.then(pluginsLoaded);
}
function loadPlugins(plugins) {
plugins = _.filter(plugins, function(plugin) {
return plugin.directories.length !== 0;
});
return Promise.all(plugins.map(loadPlugin));
}
function loadPlugin(plugin) {
if (webworker && plugin.type === 'webworker') {
return pluginLoader.workerThreadPluginLoader(plugin);
}
else {
return pluginLoader.embeddedPluginLoader(plugin);
}
}
function pluginsLoaded(plugins) {
return _.extend.apply(_, plugins);
}
function getPluginsMeta(path,type) {
return new Promise(function(resolve) {
FileSystem.getDirectoryForPath(path).getContents(function(err, entries) {
resolve({
directories: _.filter(entries, 'isDirectory').map(function(dir) {return dir.name;}),
path: path,
type : type
});
});
});
}
return pluginManager;
});