1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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()) { } else if (stats.isDirectory()) {
// Ignore /.dirs/ and /lib/ // Ignore /.dirs/ and /lib/
if (!/^(\..*|lib)$/.test(fn)) { if (!/^(\..*|lib|icons)$/.test(fn)) {
loadNodes(dir+"/"+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 util = require('util');
var createUI = require("./ui"); var createUI = require("./ui");
var redNodes = require("./nodes"); var redNodes = require("./nodes");
//TODO: relocated user dir //TODO: relocated user dir
var flowfile = ''; var flowfile = '';
@ -74,6 +75,7 @@ function createServer(_server,settings) {
}); });
}); });
} }
function start() { function start() {
console.log("\nWelcome to Node-RED\n===================\n"); console.log("\nWelcome to Node-RED\n===================\n");
util.log("[red] Loading palette nodes"); util.log("[red] Loading palette nodes");

View File

@ -18,7 +18,17 @@ var util = require('util');
var crypto = require('crypto'); var crypto = require('crypto');
var fs = require("fs"); var fs = require("fs");
var app = express(); 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) { function setupUI(settings) {
// Need to ensure the url ends with a '/' so the static serving works // 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')); app.use("/",express.static(__dirname + '/../public'));
return app; return app;
} }
module.exports = setupUI; module.exports = setupUI;