UNPKG

@ralphwetzel/node-red-mcu-plugin

Version:

Plugin to integrate Node-RED MCU Edition into the Node-RED Editor

107 lines (92 loc) 2.85 kB
const resolvePackagePath = require('resolve-package-path'); const path = require("path"); class nodes_library { constructor() { this.nodes = {} } /* Examine node definition and extract type & module information * * @param node: node data object as generated by Node-REDs loadNodeConfig * (node_modules/@node-red/registry/lib/loader.js) */ register_node(node) { /* @ 20220812: var node = { type: "node", id: id, module: module, name: name, file: file, template: file.replace(/\.js$/,".html"), enabled: isEnabled, loaded:false, version: version, local: fileInfo.local, types: [], config: "", help: {} }; */ if (node.type !== "node") return; if (!node.types || node.types.length < 1) return; if (!node.module || !node.file) return; let pp = resolvePackagePath(node.module, node.file); if (!pp) return; pp = path.parse(pp).dir; for (let i=0; i<node.types.length; i+=1) { let type = node.types[i]; if (type in this.nodes) { this.nodes[type].module = node.module; this.nodes[type].path = pp; } else { this.nodes[type] = { module: node.module, path: pp, mcumode_type: null, file: node.file } } } } /* Register alternative node type for MCU mode * * @param standard_type (string) node type identifier * * @param mcu_type (string) node type identifier * * @return true if standard_type was registered */ register_mcumode_type(standard_type, mcumode_type) { if (standard_type in this.nodes) { this.nodes[standard_type].mcumode_type = mcumode_type; return true; } else { this.nodes[standard_type] = { mcumode_type: mcumode_type } return false; } } /* Get alternative node type for MCU mode * * @param standard_type (string) node type identifier * * @return mcumode_type (string) if standard_type was registered else null */ get_mcumode_type(standard_type) { if (standard_type in this.nodes) { return this.nodes[standard_type].mcumode_type; } else { return null; } } get_node(type) { if (type in this.nodes) { return this.nodes[type]; } return; } } module.exports = { library: nodes_library }