mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Update runtime apis to support multiple libraries
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
var fs = require('fs');
|
||||
var fspath = require('path');
|
||||
var when = require('when');
|
||||
|
||||
var runtime;
|
||||
|
||||
@@ -24,7 +23,7 @@ var exampleRoots = {};
|
||||
var exampleFlows = null;
|
||||
|
||||
function getFlowsFromPath(path) {
|
||||
return when.promise(function(resolve,reject) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
var result = {};
|
||||
fs.readdir(path,function(err,files) {
|
||||
var promises = [];
|
||||
@@ -37,11 +36,11 @@ function getFlowsFromPath(path) {
|
||||
promises.push(getFlowsFromPath(fullPath));
|
||||
} else if (/\.json$/.test(file)){
|
||||
validFiles.push(file);
|
||||
promises.push(when.resolve(file.split(".")[0]))
|
||||
promises.push(Promise.resolve(file.split(".")[0]))
|
||||
}
|
||||
})
|
||||
var i=0;
|
||||
when.all(promises).then(function(results) {
|
||||
Promise.all(promises).then(function(results) {
|
||||
results.forEach(function(r) {
|
||||
if (typeof r === 'string') {
|
||||
result.f = result.f||[];
|
||||
@@ -62,21 +61,20 @@ function getFlowsFromPath(path) {
|
||||
function addNodeExamplesDir(module,path) {
|
||||
exampleRoots[module] = path;
|
||||
return getFlowsFromPath(path).then(function(result) {
|
||||
exampleFlows = exampleFlows||{d:{}};
|
||||
exampleFlows.d[module] = result;
|
||||
exampleFlows = exampleFlows||{};
|
||||
exampleFlows[module] = result;
|
||||
});
|
||||
}
|
||||
function removeNodeExamplesDir(module) {
|
||||
delete exampleRoots[module];
|
||||
if (exampleFlows && exampleFlows.d) {
|
||||
delete exampleFlows.d[module];
|
||||
if (exampleFlows) {
|
||||
delete exampleFlows[module];
|
||||
}
|
||||
if (exampleFlows && Object.keys(exampleFlows.d).length === 0) {
|
||||
if (exampleFlows && Object.keys(exampleFlows).length === 0) {
|
||||
exampleFlows = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function init() {
|
||||
exampleRoots = {};
|
||||
exampleFlows = null;
|
||||
|
Reference in New Issue
Block a user