Update runtime apis to support multiple libraries

This commit is contained in:
Nick O'Leary
2019-04-25 11:32:09 +01:00
parent 5e43a02cd3
commit b581e33611
15 changed files with 553 additions and 713 deletions

View File

@@ -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;