mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Allow module to provide resources and automatically expose them
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
**/
|
||||
|
||||
//var UglifyJS = require("uglify-js");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
var library = require("./library");
|
||||
const {events} = require("@node-red/util")
|
||||
@@ -680,7 +680,6 @@ function getNodeIconPath(module,icon) {
|
||||
|
||||
function getNodeIcons() {
|
||||
var iconList = {};
|
||||
|
||||
for (var module in moduleConfigs) {
|
||||
if (moduleConfigs.hasOwnProperty(module)) {
|
||||
if (moduleConfigs[module].icons) {
|
||||
@@ -692,6 +691,21 @@ function getNodeIcons() {
|
||||
return iconList;
|
||||
}
|
||||
|
||||
function getModuleResource(module, resourcePath) {
|
||||
let mod = moduleConfigs[module];
|
||||
if (mod && mod.resources) {
|
||||
let basePath = mod.resources.path;
|
||||
let fullPath = path.join(basePath,resourcePath);
|
||||
if (/^\.\./.test(path.relative(basePath,fullPath))) {
|
||||
return null;
|
||||
}
|
||||
if (fs.existsSync(fullPath)) {
|
||||
return fullPath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var registry = module.exports = {
|
||||
init: init,
|
||||
load: load,
|
||||
@@ -722,6 +736,8 @@ var registry = module.exports = {
|
||||
|
||||
getNodeIconPath: getNodeIconPath,
|
||||
getNodeIcons: getNodeIcons,
|
||||
getModuleResource: getModuleResource,
|
||||
|
||||
/**
|
||||
* Gets all of the node template configs
|
||||
* @return all of the node templates in a single string
|
||||
|
Reference in New Issue
Block a user