mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
allow a node's icon to be set dynamically (#1490)
* create a proto type * Fixed some problems after reviewing
This commit is contained in:
committed by
Nick O'Leary
parent
cc88ebd2b9
commit
6d2389945b
@@ -24,6 +24,7 @@ var i18n;
|
||||
|
||||
var settings;
|
||||
var disableNodePathScan = false;
|
||||
var iconFileExtensions = [".png", ".gif"];
|
||||
|
||||
function init(runtime) {
|
||||
settings = runtime.settings;
|
||||
@@ -104,7 +105,8 @@ function getLocalNodeFiles(dir) {
|
||||
if (!/^(\..*|lib|icons|node_modules|test|locales)$/.test(fn)) {
|
||||
result = result.concat(getLocalNodeFiles(path.join(dir,fn)));
|
||||
} else if (fn === "icons") {
|
||||
events.emit("node-icon-dir",{name:'node-red',path:path.join(dir,fn)});
|
||||
var iconList = scanIconDir(path.join(dir,fn));
|
||||
events.emit("node-icon-dir",{name:'node-red',path:path.join(dir,fn),icons:iconList});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -197,7 +199,8 @@ function getModuleNodeFiles(module) {
|
||||
if (iconDirs.indexOf(iconDir) == -1) {
|
||||
try {
|
||||
fs.statSync(iconDir);
|
||||
events.emit("node-icon-dir",{name:pkg.name,path:iconDir});
|
||||
var iconList = scanIconDir(iconDir);
|
||||
events.emit("node-icon-dir",{name:pkg.name,path:iconDir,icons:iconList});
|
||||
iconDirs.push(iconDir);
|
||||
} catch(err) {
|
||||
}
|
||||
@@ -218,6 +221,10 @@ function getNodeFiles(disableNodePathScan) {
|
||||
// Find all of the nodes to load
|
||||
var nodeFiles = [];
|
||||
|
||||
var dir = path.resolve(__dirname + '/../../../../public/icons');
|
||||
var iconList = scanIconDir(dir);
|
||||
events.emit("node-icon-dir",{name:'node-red',path:dir,icons:iconList});
|
||||
|
||||
if (settings.coreNodesDir) {
|
||||
nodeFiles = getLocalNodeFiles(path.resolve(settings.coreNodesDir));
|
||||
var defaultLocalesPath = path.join(settings.coreNodesDir,"core","locales");
|
||||
@@ -302,6 +309,20 @@ function getModuleFiles(module) {
|
||||
return nodeList;
|
||||
}
|
||||
|
||||
function scanIconDir(dir) {
|
||||
var iconList = [];
|
||||
try {
|
||||
var files = fs.readdirSync(dir);
|
||||
files.forEach(function(file) {
|
||||
var stats = fs.statSync(path.join(dir, file));
|
||||
if (stats.isFile() && iconFileExtensions.indexOf(path.extname(file)) !== -1) {
|
||||
iconList.push(file);
|
||||
}
|
||||
});
|
||||
} catch(err) {
|
||||
}
|
||||
return iconList;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
|
||||
Reference in New Issue
Block a user