/** * Copyright 2015 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 when = require("when"); var fs = require("fs"); var path = require("path"); var localfilesystem = require("./localfilesystem"); var registry = require("./registry"); var settings; function init(_settings) { settings = _settings; localfilesystem.init(settings); } function load(defaultNodesDir,disableNodePathScan) { var nodeFiles = localfilesystem.getNodeFiles(defaultNodesDir,disableNodePathScan); return loadNodeFiles(nodeFiles); } function loadNodeFiles(nodeFiles) { var nodes = []; for (var module in nodeFiles) { /* istanbul ignore else */ if (nodeFiles.hasOwnProperty(module)) { if (!registry.getModuleInfo(module)) { for (var node in nodeFiles[module].nodes) { /* istanbul ignore else */ if (nodeFiles[module].nodes.hasOwnProperty(node)) { try { nodes.push(loadNodeConfig(nodeFiles[module].nodes[node])) } catch(err) { // } } } } } } return loadNodeSetList(nodes); } function loadNodeConfig(fileInfo) { var file = fileInfo.file; var module = fileInfo.module; var name = fileInfo.name; var version = fileInfo.version; var id = module + "/" + name; var info = registry.getNodeInfo(id); var isEnabled = true; if (info) { if (info.hasOwnProperty("loaded")) { throw new Error(file+" already loaded"); } isEnabled = info.enabled; } var node = { id: id, module: module, name: name, file: file, template: file.replace(/\.js$/,".html"), enabled: isEnabled, loaded:false }; try { var content = fs.readFileSync(node.template,'utf8'); var types = []; var regExp = /