2015-02-10 19:41:24 +00:00
|
|
|
/**
|
|
|
|
* Serve plugins on the static server
|
|
|
|
*
|
2015-02-15 02:12:39 +00:00
|
|
|
* @copyright 2013, Ajax.org B.V.
|
2015-02-10 19:41:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
define(function(require, exports, module) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
main.consumes = ["Plugin", "connect.static"];
|
|
|
|
main.provides = ["c9.static.plugins"];
|
|
|
|
return main;
|
|
|
|
|
|
|
|
|
|
|
|
function main(options, imports, register) {
|
|
|
|
var Plugin = imports.Plugin;
|
|
|
|
var statics = imports["connect.static"];
|
|
|
|
var fs = require("fs");
|
|
|
|
|
|
|
|
var whitelist = options.whitelist;
|
|
|
|
var blacklist = options.blacklist;
|
2015-09-04 14:40:29 +00:00
|
|
|
var externalPlugins = options.externalPlugins || [];
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
/***** Initialization *****/
|
|
|
|
|
|
|
|
var plugin = new Plugin("Ajax.org", main.consumes);
|
|
|
|
|
|
|
|
var loaded = false;
|
|
|
|
function load(){
|
|
|
|
if (loaded) return false;
|
|
|
|
loaded = true;
|
|
|
|
|
|
|
|
var requirePaths = {
|
|
|
|
ace: "lib/ace/lib/ace",
|
|
|
|
ace_tree: "lib/ace_tree/lib/ace_tree",
|
|
|
|
treehugger: "lib/treehugger/lib/treehugger",
|
2015-06-26 06:44:46 +00:00
|
|
|
acorn: "lib/treehugger/lib/acorn",
|
2016-01-11 11:14:25 +00:00
|
|
|
jsonm: "lib/jsonm",
|
2015-02-10 19:41:24 +00:00
|
|
|
tern: "lib/tern",
|
2015-02-02 10:25:31 +00:00
|
|
|
tern_from_ts: "lib/tern_from_ts",
|
2015-02-10 19:41:24 +00:00
|
|
|
ui: "lib/ui",
|
|
|
|
c9: "lib/c9",
|
|
|
|
frontdoor: "lib/frontdoor",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (whitelist === "*") {
|
|
|
|
statics.addStatics([{
|
|
|
|
path: __dirname + "/../../node_modules",
|
|
|
|
mount: "/lib"
|
|
|
|
}]);
|
|
|
|
|
|
|
|
statics.addStatics([{
|
|
|
|
path: __dirname + "/../../plugins",
|
|
|
|
mount: "/plugins",
|
|
|
|
rjs: requirePaths
|
|
|
|
}]);
|
|
|
|
} else {
|
|
|
|
[
|
|
|
|
"ace_tree",
|
|
|
|
"acorn",
|
|
|
|
"tern",
|
2015-02-02 10:25:31 +00:00
|
|
|
"tern_from_ts",
|
2015-02-10 19:41:24 +00:00
|
|
|
"treehugger",
|
2016-01-11 11:14:25 +00:00
|
|
|
"jsonm",
|
2015-02-10 19:41:24 +00:00
|
|
|
"pivottable",
|
|
|
|
"architect",
|
|
|
|
"source-map",
|
|
|
|
"rusha",
|
|
|
|
"c9",
|
|
|
|
"ui",
|
|
|
|
"emmet",
|
|
|
|
"frontdoor",
|
|
|
|
"mocha", // TESTING
|
|
|
|
"chai", // TESTING
|
|
|
|
].forEach(function(name) {
|
|
|
|
statics.addStatics([{
|
|
|
|
path: __dirname + "/../../node_modules/" + name,
|
|
|
|
mount: "/lib/" + name
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
|
|
|
|
statics.addStatics([{
|
|
|
|
path: __dirname + "/../../node_modules/ace",
|
|
|
|
mount: "/lib/ace",
|
|
|
|
rjs: requirePaths
|
|
|
|
}]);
|
2015-09-04 14:40:29 +00:00
|
|
|
|
|
|
|
statics.addStatics(externalPlugins.map(function(plugin) {
|
2016-05-02 06:18:57 +00:00
|
|
|
if (typeof plugin == "string")
|
|
|
|
plugin = { path: plugin, mount: plugin};
|
2015-09-07 09:55:43 +00:00
|
|
|
return {
|
2016-05-02 06:18:57 +00:00
|
|
|
path: __dirname + "/../../node_modules/" + plugin.path,
|
|
|
|
mount: "/plugins/" + plugin.mount
|
2015-09-04 14:40:29 +00:00
|
|
|
};
|
|
|
|
}));
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
statics.addStatics(fs.readdirSync(__dirname + "/../")
|
|
|
|
.filter(function(path) {
|
|
|
|
if (path in blacklist)
|
|
|
|
return false;
|
|
|
|
else if (path in whitelist)
|
|
|
|
return true;
|
|
|
|
else if (path.indexOf("c9.ide.") === 0)
|
|
|
|
return true;
|
|
|
|
else if (path.indexOf("c9.account") === 0)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
.map(function(path) {
|
|
|
|
return {
|
|
|
|
path: __dirname + "/../../plugins/" + path,
|
|
|
|
mount: "/plugins/" + path
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
statics.addStatics([{
|
|
|
|
path: __dirname + "/www",
|
|
|
|
mount: "/"
|
|
|
|
}]);
|
|
|
|
|
|
|
|
statics.addStatics([{
|
|
|
|
path: __dirname + "/../../docs",
|
|
|
|
mount: "/docs"
|
|
|
|
}]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Lifecycle *****/
|
|
|
|
|
|
|
|
plugin.on("load", function(){
|
|
|
|
load();
|
|
|
|
});
|
|
|
|
plugin.on("unload", function(){
|
|
|
|
loaded = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
/***** Register and define API *****/
|
|
|
|
|
|
|
|
plugin.freezePublicAPI({});
|
|
|
|
|
|
|
|
register(null, {
|
|
|
|
"c9.static.plugins": plugin
|
|
|
|
});
|
|
|
|
}
|
2015-09-07 09:55:43 +00:00
|
|
|
});
|