Allow icons to be bundled with nodes

This commit is contained in:
Nicholas O'Leary 2013-10-13 21:01:46 +01:00
parent bbe37dd944
commit 5e8e35e6fa
3 changed files with 31 additions and 1 deletions

View File

@ -241,8 +241,10 @@ module.exports.load = function() {
}
} else if (stats.isDirectory()) {
// Ignore /.dirs/ and /lib/
if (!/^(\..*|lib)$/.test(fn)) {
if (!/^(\..*|lib|icons)$/.test(fn)) {
loadNodes(dir+"/"+fn);
} else if (fn === "icons") {
events.emit("node-icon-dir",dir+"/"+fn);
}
}
});

View File

@ -18,6 +18,7 @@ var fs = require('fs');
var util = require('util');
var createUI = require("./ui");
var redNodes = require("./nodes");
//TODO: relocated user dir
var flowfile = '';
@ -74,6 +75,7 @@ function createServer(_server,settings) {
});
});
}
function start() {
console.log("\nWelcome to Node-RED\n===================\n");
util.log("[red] Loading palette nodes");

View File

@ -18,7 +18,17 @@ var util = require('util');
var crypto = require('crypto');
var fs = require("fs");
var app = express();
var events = require("./events");
var path = require("path");
var icon_paths = [path.resolve(__dirname + '/../public/icons')];
events.on("node-icon-dir",function(dir) {
icon_paths.push(path.resolve(dir));
});
// TODO: nothing here uses settings... so does this need to be a function?
function setupUI(settings) {
// Need to ensure the url ends with a '/' so the static serving works
@ -31,10 +41,26 @@ function setupUI(settings) {
}
});
app.get("/icons/:icon",function(req,res) {
for (var p in icon_paths) {
if (fs.existsSync(icon_paths[p]+'/'+req.params.icon)) {
res.sendfile(icon_paths[p]+'/'+req.params.icon);
return;
}
}
//TODO: create a default icon
res.sendfile(path.resolve(__dirname + '/../public/icons/arrow-in.png'));
});
app.use("/",express.static(__dirname + '/../public'));
return app;
}
module.exports = setupUI;