mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Allow icons to be bundled with nodes
This commit is contained in:
		@@ -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);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
        });
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								red/ui.js
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								red/ui.js
									
									
									
									
									
								
							@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user