diff --git a/.gitignore b/.gitignore index 10f3928..534be16 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ coverage # npm install log npm-debug.log.* +package-lock.json diff --git a/bin/node-red-nodegen.js b/bin/node-red-nodegen.js index 2db0714..06e6719 100755 --- a/bin/node-red-nodegen.js +++ b/bin/node-red-nodegen.js @@ -145,11 +145,30 @@ if (argv.help || argv.h) { }); } else if (sourcePath.endsWith('.json') && !argv.wottd) { data.src = JSON.parse(fs.readFileSync(sourcePath)); - nodegen.swagger2node(data, options).then(function (result) { - console.log('Success: ' + result); - }).catch(function (error) { - console.log('Error: ' + error); - }); + // if it's a .json flow file with one function node in... + if (Array.isArray(data.src) && data.src[0].hasOwnProperty("type") && data.src[0].type == "function") { + var f = data.src[0]; + if (!f.name || f.name.length ==0) { console.log('Error: No function name supplied.'); return; } + data.name = f.name.toLowerCase(); + data.icon = f.icon; + data.info = f.info; + data.outputs = f.outputs; + data.inputLabels = f.inputLabels; + data.outputLabels = f.outputLabels; + data.src = Buffer.from(f.func); + nodegen.function2node(data, options).then(function (result) { + console.log('Success: ' + result); + }).catch(function (error) { + console.log('Error: ' + error); + }); + } + else { + nodegen.swagger2node(data, options).then(function (result) { + console.log('Success: ' + result); + }).catch(function (error) { + console.log('Error: ' + error); + }); + } } else if (sourcePath.endsWith('.yaml')) { data.src = yamljs.load(sourcePath); nodegen.swagger2node(data, options).then(function (result) { diff --git a/lib/nodegen.js b/lib/nodegen.js index 5a1684c..0606aff 100644 --- a/lib/nodegen.js +++ b/lib/nodegen.js @@ -39,7 +39,7 @@ function createCommonFiles(templateDirectory, data) { } } - var isStockIcon = data.icon && data.icon.match(/^(alert|arduino|arrow-in|batch|bluetooth|bridge-dash|bridge|cog|comment|db|debug|envelope|feed|file-in|file-out|file|function|hash|inject|join|leveldb|light|link-out|mongodb|mouse|node-changed|node-error|parser-csv|parser-html|parser-json|parser-xml|parser-yaml|range|redis|rpi|serial|sort|split|subflow|swap|switch|template|timer|trigger|twitter|watch|white-globe)\.png$/); + var isStockIcon = data.icon && (data.icon.match(/^(alert|arduino|arrow-in|batch|bluetooth|bridge-dash|bridge|cog|comment|db|debug|envelope|feed|file-in|file-out|file|function|hash|inject|join|leveldb|light|link-out|mongodb|mouse|node-changed|node-error|parser-csv|parser-html|parser-json|parser-xml|parser-yaml|range|redis|rpi|serial|sort|split|subflow|swap|switch|template|timer|trigger|twitter|watch|white-globe)\.png$/) || data.icon.match(/^(node-red|font-awesome)/)); if (!isStockIcon) { try { fs.mkdirSync(path.join(data.dst, data.module, 'icons')); @@ -143,6 +143,8 @@ function extractKeywords(keywordsStr) { } function function2node(data, options) { + // console.log("OPT",options); + // console.log("DATA",data); "use strict"; return when.promise(function (resolve, reject) { // Read meta data in js file @@ -181,7 +183,7 @@ function function2node(data, options) { } if (data.icon) { - if (!data.icon.match(/\.(png|gif)$/)) { + if (!data.icon.match(/\.(png|gif)$/) && !data.icon.match(/^(node-red|font-awesome)/)) { data.icon = data.icon + '.png'; } if (!data.icon.match(/^[a-zA-Z0-9\-\./]+$/)) { @@ -213,15 +215,22 @@ function function2node(data, options) { keywords: extractKeywords(data.keywords), category: data.category || 'function', icon: function () { - if (data.icon) { - return path.basename(data.icon); + if (data.icon ) { + if (!data.icon.match(/^(node-red|font-awesome)/)) { + return path.basename(data.icon); + } + else { return data.icon; } } else { return 'icon.png'; } }, color: data.color || '#C0DEED', func: jsStringEscape(data.src), - outputs: meta.outputs + outputs: meta.outputs || data.outputs, + inputLabels: JSON.stringify(data.inputLabels || []), + outputLabels: JSON.stringify(data.outputLabels || []), + nodeInfo: jsStringEscape(data.info || ""), + nodeRead: data.info || "" }; createCommonFiles(__dirname + '/../templates/function', data); diff --git a/templates/function/README.md.mustache b/templates/function/README.md.mustache index c1888f2..53a2d62 100644 --- a/templates/function/README.md.mustache +++ b/templates/function/README.md.mustache @@ -13,3 +13,6 @@ command in your Node-RED user directory, typically `~/.node-red` npm install {{&projectName}} +## Information + +{{&nodeRead}} \ No newline at end of file diff --git a/templates/function/node.html.mustache b/templates/function/node.html.mustache index 89d5955..299ea35 100644 --- a/templates/function/node.html.mustache +++ b/templates/function/node.html.mustache @@ -38,7 +38,13 @@ label: function() { return this.name || '{{&nodeName}}'; }, + labelStyle: function() { + return this.name?"node_label_italic":""; + }, + inputLabels: {{&inputLabels}}, + outputLabels: {{&outputLabels}}, icon: '{{&icon}}', - align: 'left' + align: 'left', + info: '{{nodeInfo}}' }); diff --git a/templates/function/package.json.mustache b/templates/function/package.json.mustache index f7c5741..4b685ac 100644 --- a/templates/function/package.json.mustache +++ b/templates/function/package.json.mustache @@ -17,9 +17,9 @@ {{/keywords}} ], "devDependencies": { - "mocha": "6.2.0", - "node-red": "1.0.3", - "node-red-node-test-helper": "0.2.3" + "mocha": "^6.2.0", + "node-red": "^1.0.4", + "node-red-node-test-helper": "^0.2.3" }, "license": "Apache-2.0" } diff --git a/templates/swagger/package.json.mustache b/templates/swagger/package.json.mustache index 2fc478b..d4ba9e4 100644 --- a/templates/swagger/package.json.mustache +++ b/templates/swagger/package.json.mustache @@ -18,13 +18,13 @@ ], "dependencies": { "q": "1.5.1", - "request": "2.88.0", + "request": "2.88.2", "file-type": "12.1.0" }, "devDependencies": { - "mocha": "6.2.0", - "node-red": "1.0.3", - "node-red-node-test-helper": "0.2.3" + "mocha": "^6.2.0", + "node-red": "^1.0.4", + "node-red-node-test-helper": "^0.2.3" }, "author": "{{&contactName}}", "license": "{{&licenseName}}" diff --git a/templates/webofthings/package.json.mustache b/templates/webofthings/package.json.mustache index 30ed0c0..e2149f8 100644 --- a/templates/webofthings/package.json.mustache +++ b/templates/webofthings/package.json.mustache @@ -18,14 +18,14 @@ ], "dependencies": { "https-proxy-agent": "^3.0.1", - "request": "^2.88.0", + "request": "^2.88.2", "ws": "^7.2.0", "url-template": "^2.0.8", "ajv": "^6.10.2", "node-coap-client": "^1.0.2" }, "devDependencies": { - "node-red": "^1.0.3", + "node-red": "^1.0.4", "node-red-node-test-helper": "^0.2.3" }, "license": "{{&licenseName}}",