mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Move exec and events components to util module
The exec and events components are common components that are used by both runtime and registry. It makes sense to move them into the util package. This also adds some docs to the registry module
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var fs = require('fs');
|
||||
var fs = require('fs-extra');
|
||||
var fspath = require('path');
|
||||
|
||||
var runtime;
|
||||
@@ -22,38 +22,34 @@ var runtime;
|
||||
var exampleRoots = {};
|
||||
var exampleFlows = null;
|
||||
|
||||
function getFlowsFromPath(path) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
var result = {};
|
||||
fs.readdir(path,function(err,files) {
|
||||
var promises = [];
|
||||
var validFiles = [];
|
||||
files.forEach(function(file) {
|
||||
var fullPath = fspath.join(path,file);
|
||||
var stats = fs.lstatSync(fullPath);
|
||||
if (stats.isDirectory()) {
|
||||
validFiles.push(file);
|
||||
promises.push(getFlowsFromPath(fullPath));
|
||||
} else if (/\.json$/.test(file)){
|
||||
validFiles.push(file);
|
||||
promises.push(Promise.resolve(file.split(".")[0]))
|
||||
}
|
||||
})
|
||||
var i=0;
|
||||
Promise.all(promises).then(function(results) {
|
||||
results.forEach(function(r) {
|
||||
if (typeof r === 'string') {
|
||||
result.f = result.f||[];
|
||||
result.f.push(r);
|
||||
} else {
|
||||
result.d = result.d||{};
|
||||
result.d[validFiles[i]] = r;
|
||||
}
|
||||
i++;
|
||||
})
|
||||
resolve(result);
|
||||
})
|
||||
});
|
||||
async function getFlowsFromPath(path) {
|
||||
var result = {};
|
||||
var validFiles = [];
|
||||
return fs.readdir(path).then(files => {
|
||||
var promises = [];
|
||||
files.forEach(function(file) {
|
||||
var fullPath = fspath.join(path,file);
|
||||
var stats = fs.lstatSync(fullPath);
|
||||
if (stats.isDirectory()) {
|
||||
validFiles.push(file);
|
||||
promises.push(getFlowsFromPath(fullPath));
|
||||
} else if (/\.json$/.test(file)){
|
||||
validFiles.push(file);
|
||||
promises.push(Promise.resolve(file.split(".")[0]))
|
||||
}
|
||||
})
|
||||
return Promise.all(promises)
|
||||
}).then(results => {
|
||||
results.forEach(function(r,i) {
|
||||
if (typeof r === 'string') {
|
||||
result.f = result.f||[];
|
||||
result.f.push(r);
|
||||
} else {
|
||||
result.d = result.d||{};
|
||||
result.d[validFiles[i]] = r;
|
||||
}
|
||||
})
|
||||
return result;
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user