From e3a7ad74a7c08f0f6ec6637d1c349c2120e6cd0e Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 28 Feb 2020 16:06:41 +0000 Subject: [PATCH 1/5] bump templates to node-red 1.0.4 and minor updates to some other libs --- .gitignore | 1 + package.json | 8 ++++---- templates/function/package.json.mustache | 2 +- templates/swagger/package.json.mustache | 4 ++-- templates/webofthings/package.json.mustache | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) 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/package.json b/package.json index f12bc84..95decd8 100644 --- a/package.json +++ b/package.json @@ -79,15 +79,15 @@ ], "dependencies": { "ajv": "6.10.2", - "cldr": "5.5.3", + "cldr": "5.5.4", "colors": "1.4.0", - "csv-string": "3.1.7", + "csv-string": "3.1.8", "javascript-obfuscator": "0.18.6", "jimp": "0.2.28", "js-string-escape": "1.0.1", "minimist": "1.2.0", "mustache": "3.1.0", - "request": "2.88.0", + "request": "2.88.2", "swagger-js-codegen-formdata": "0.15.5", "when": "3.7.8", "yamljs": "0.3.0" @@ -99,7 +99,7 @@ "grunt-shell": "3.0.1", "grunt-simple-mocha": "0.4.1", "istanbul": "0.4.5", - "node-red": "1.0.3", + "node-red": "1.0.4", "node-red-node-test-helper": "0.2.3", "q": "1.5.1", "should": "13.2.3", diff --git a/templates/function/package.json.mustache b/templates/function/package.json.mustache index f7c5741..6cf4ca4 100644 --- a/templates/function/package.json.mustache +++ b/templates/function/package.json.mustache @@ -18,7 +18,7 @@ ], "devDependencies": { "mocha": "6.2.0", - "node-red": "1.0.3", + "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..d5339de 100644 --- a/templates/swagger/package.json.mustache +++ b/templates/swagger/package.json.mustache @@ -18,12 +18,12 @@ ], "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": "1.0.4", "node-red-node-test-helper": "0.2.3" }, "author": "{{&contactName}}", 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}}", From 502292903f746bbe8cf5bc4d5fe54541c1baf2ca Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 28 Feb 2020 16:07:33 +0000 Subject: [PATCH 2/5] Add support for .json file of function node to be converted. (icon support needs more work...) --- bin/node-red-nodegen.js | 29 ++++++++++++++++++++++----- lib/nodegen.js | 18 ++++++++++++----- templates/function/node.html.mustache | 8 +++++++- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/bin/node-red-nodegen.js b/bin/node-red-nodegen.js index 2db0714..4776522 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]; + data.name = f.name.toLowerCase(); + data.icon = f.icon; + data.info = f.info; + data.inputs = f.inputs; + 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..b97a3cc 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,21 @@ 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 || "") }; createCommonFiles(__dirname + '/../templates/function', data); 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}}' }); From 0400b225a957d05daebe40914e2e65901fc37bbe Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 28 Feb 2020 17:00:06 +0000 Subject: [PATCH 3/5] throw error if function not named --- bin/node-red-nodegen.js | 1 + templates/function/package.json.mustache | 6 +++--- templates/swagger/package.json.mustache | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/node-red-nodegen.js b/bin/node-red-nodegen.js index 4776522..814bc05 100755 --- a/bin/node-red-nodegen.js +++ b/bin/node-red-nodegen.js @@ -148,6 +148,7 @@ if (argv.help || argv.h) { // 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; diff --git a/templates/function/package.json.mustache b/templates/function/package.json.mustache index 6cf4ca4..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.4", - "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 d5339de..d4ba9e4 100644 --- a/templates/swagger/package.json.mustache +++ b/templates/swagger/package.json.mustache @@ -22,9 +22,9 @@ "file-type": "12.1.0" }, "devDependencies": { - "mocha": "6.2.0", - "node-red": "1.0.4", - "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}}" From 569f2cb38ffdaca2aa56349fd6601fb1a26535f4 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 28 Feb 2020 17:01:47 +0000 Subject: [PATCH 4/5] no need for inputs variable --- bin/node-red-nodegen.js | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/node-red-nodegen.js b/bin/node-red-nodegen.js index 814bc05..06e6719 100755 --- a/bin/node-red-nodegen.js +++ b/bin/node-red-nodegen.js @@ -152,7 +152,6 @@ if (argv.help || argv.h) { data.name = f.name.toLowerCase(); data.icon = f.icon; data.info = f.info; - data.inputs = f.inputs; data.outputs = f.outputs; data.inputLabels = f.inputLabels; data.outputLabels = f.outputLabels; From 4449112bade64ad8f2329e8c4a82b3c2e6cfa1b5 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Sun, 1 Mar 2020 15:07:57 +0000 Subject: [PATCH 5/5] Add the extra info to README as well as sidebar. --- lib/nodegen.js | 3 ++- templates/function/README.md.mustache | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/nodegen.js b/lib/nodegen.js index b97a3cc..0606aff 100644 --- a/lib/nodegen.js +++ b/lib/nodegen.js @@ -229,7 +229,8 @@ function function2node(data, options) { outputs: meta.outputs || data.outputs, inputLabels: JSON.stringify(data.inputLabels || []), outputLabels: JSON.stringify(data.outputLabels || []), - nodeInfo: jsStringEscape(data.info || "") + 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