mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Functionality to get installed module info from the cli
This commit is contained in:
parent
266a644ca6
commit
3e24601518
@ -19,6 +19,7 @@ var util = require('util');
|
|||||||
|
|
||||||
var ui = require("./ui");
|
var ui = require("./ui");
|
||||||
var nodes = require("./nodes");
|
var nodes = require("./nodes");
|
||||||
|
var modules = require("./modules");
|
||||||
var flows = require("./flows");
|
var flows = require("./flows");
|
||||||
var library = require("./library");
|
var library = require("./library");
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ var settings = require("../settings");
|
|||||||
var errorHandler = function(err,req,res,next) {
|
var errorHandler = function(err,req,res,next) {
|
||||||
//TODO: standardize json response
|
//TODO: standardize json response
|
||||||
res.send(400,err.toString());
|
res.send(400,err.toString());
|
||||||
}
|
};
|
||||||
|
|
||||||
function init(adminApp) {
|
function init(adminApp) {
|
||||||
|
|
||||||
@ -55,6 +56,10 @@ function init(adminApp) {
|
|||||||
adminApp.put("/nodes/:id",nodes.put);
|
adminApp.put("/nodes/:id",nodes.put);
|
||||||
adminApp.delete("/nodes/:id",nodes.delete);
|
adminApp.delete("/nodes/:id",nodes.delete);
|
||||||
|
|
||||||
|
// Modules
|
||||||
|
adminApp.get("/modules",modules.getAll);
|
||||||
|
adminApp.get("/modules/:id",modules.get);
|
||||||
|
|
||||||
// Library
|
// Library
|
||||||
adminApp.post(new RegExp("/library/flows\/(.*)"),library.post);
|
adminApp.post(new RegExp("/library/flows\/(.*)"),library.post);
|
||||||
adminApp.get("/library/flows",library.getAll);
|
adminApp.get("/library/flows",library.getAll);
|
||||||
@ -67,4 +72,4 @@ function init(adminApp) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: init
|
init: init
|
||||||
}
|
};
|
||||||
|
32
red/api/modules.js
Normal file
32
red/api/modules.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2014 IBM Corp.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
**/
|
||||||
|
|
||||||
|
var redNodes = require("../nodes");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAll: function(req,res) {
|
||||||
|
res.json(redNodes.getModuleList());
|
||||||
|
},
|
||||||
|
get: function(req,res) {
|
||||||
|
var id = req.params.id;
|
||||||
|
var result = redNodes.getModule(id);
|
||||||
|
if (result) {
|
||||||
|
res.send(result);
|
||||||
|
} else {
|
||||||
|
res.send(404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@ -114,7 +114,9 @@ module.exports = {
|
|||||||
getType: registry.get,
|
getType: registry.get,
|
||||||
getNodeInfo: registry.getNodeInfo,
|
getNodeInfo: registry.getNodeInfo,
|
||||||
getNodeModuleInfo: registry.getNodeModuleInfo,
|
getNodeModuleInfo: registry.getNodeModuleInfo,
|
||||||
|
getModule: registry.getModule,
|
||||||
getNodeList: registry.getNodeList,
|
getNodeList: registry.getNodeList,
|
||||||
|
getModuleList: registry.getModuleList,
|
||||||
getNodeConfigs: registry.getNodeConfigs,
|
getNodeConfigs: registry.getNodeConfigs,
|
||||||
getNodeConfig: registry.getNodeConfig,
|
getNodeConfig: registry.getNodeConfig,
|
||||||
clearRegistry: registry.clear,
|
clearRegistry: registry.clear,
|
||||||
@ -130,5 +132,5 @@ module.exports = {
|
|||||||
addCredentials: credentials.add,
|
addCredentials: credentials.add,
|
||||||
getCredentials: credentials.get,
|
getCredentials: credentials.get,
|
||||||
deleteCredentials: credentials.delete
|
deleteCredentials: credentials.delete
|
||||||
}
|
};
|
||||||
|
|
||||||
|
@ -159,11 +159,39 @@ var registry = (function() {
|
|||||||
var list = [];
|
var list = [];
|
||||||
for (var id in nodeConfigs) {
|
for (var id in nodeConfigs) {
|
||||||
if (nodeConfigs.hasOwnProperty(id)) {
|
if (nodeConfigs.hasOwnProperty(id)) {
|
||||||
list.push(filterNodeInfo(nodeConfigs[id]))
|
list.push(filterNodeInfo(nodeConfigs[id]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
},
|
},
|
||||||
|
getModuleList: function() {
|
||||||
|
var list = [];
|
||||||
|
for (var module in nodeModules) {
|
||||||
|
if (nodeModules.hasOwnProperty(module)) {
|
||||||
|
var nodes = nodeModules[module].nodes;
|
||||||
|
var m = {
|
||||||
|
name: module,
|
||||||
|
nodes: []
|
||||||
|
};
|
||||||
|
for (var i = 0; i < nodes.length; ++i) {
|
||||||
|
m.nodes.push(filterNodeInfo(nodeConfigs[nodes[i]]));
|
||||||
|
}
|
||||||
|
list.push(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
},
|
||||||
|
getModule: function(module) {
|
||||||
|
var nodes = nodeModules[module].nodes;
|
||||||
|
var m = {
|
||||||
|
name: module,
|
||||||
|
nodes: []
|
||||||
|
};
|
||||||
|
for (var i = 0; i < nodes.length; ++i) {
|
||||||
|
m.nodes.push(filterNodeInfo(nodeConfigs[nodes[i]]));
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
},
|
||||||
registerNodeConstructor: function(type,constructor) {
|
registerNodeConstructor: function(type,constructor) {
|
||||||
if (nodeConstructors[type]) {
|
if (nodeConstructors[type]) {
|
||||||
throw new Error(type+" already registered");
|
throw new Error(type+" already registered");
|
||||||
@ -243,7 +271,12 @@ var registry = (function() {
|
|||||||
if (!settings.available()) {
|
if (!settings.available()) {
|
||||||
throw new Error("Settings unavailable");
|
throw new Error("Settings unavailable");
|
||||||
}
|
}
|
||||||
var config = nodeConfigs[id];
|
var config;
|
||||||
|
if (nodeTypeToId[id]) {
|
||||||
|
config = nodeConfigs[nodeTypeToId[id]];
|
||||||
|
} else {
|
||||||
|
config = nodeConfigs[id];
|
||||||
|
}
|
||||||
if (config) {
|
if (config) {
|
||||||
delete config.err;
|
delete config.err;
|
||||||
config.enabled = true;
|
config.enabled = true;
|
||||||
@ -263,7 +296,12 @@ var registry = (function() {
|
|||||||
if (!settings.available()) {
|
if (!settings.available()) {
|
||||||
throw new Error("Settings unavailable");
|
throw new Error("Settings unavailable");
|
||||||
}
|
}
|
||||||
var config = nodeConfigs[id];
|
var config;
|
||||||
|
if (nodeTypeToId[id]) {
|
||||||
|
config = nodeConfigs[nodeTypeToId[id]];
|
||||||
|
} else {
|
||||||
|
config = nodeConfigs[id];
|
||||||
|
}
|
||||||
if (config) {
|
if (config) {
|
||||||
// TODO: persist setting
|
// TODO: persist setting
|
||||||
config.enabled = false;
|
config.enabled = false;
|
||||||
@ -679,7 +717,9 @@ module.exports = {
|
|||||||
get: registry.getNodeConstructor,
|
get: registry.getNodeConstructor,
|
||||||
getNodeInfo: registry.getNodeInfo,
|
getNodeInfo: registry.getNodeInfo,
|
||||||
getNodeModuleInfo: registry.getModuleInfo,
|
getNodeModuleInfo: registry.getModuleInfo,
|
||||||
|
getModule: registry.getModule,
|
||||||
getNodeList: registry.getNodeList,
|
getNodeList: registry.getNodeList,
|
||||||
|
getModuleList: registry.getModuleList,
|
||||||
getNodeConfigs: registry.getAllNodeConfigs,
|
getNodeConfigs: registry.getAllNodeConfigs,
|
||||||
getNodeConfig: registry.getNodeConfig,
|
getNodeConfig: registry.getNodeConfig,
|
||||||
addNode: addNode,
|
addNode: addNode,
|
||||||
|
Loading…
Reference in New Issue
Block a user