From ff819d74178e0f416a6e1fed6ea0d4018ecd795b Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Mon, 28 Mar 2022 18:48:47 +0900 Subject: [PATCH 1/5] Change subflow file to formatted JSON --- samples/qrcode.json | 67 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/samples/qrcode.json b/samples/qrcode.json index fde6ee2..d0daa8e 100644 --- a/samples/qrcode.json +++ b/samples/qrcode.json @@ -1 +1,66 @@ -[{"id":"921a4b1d.07bb68","type":"subflow","name":"QRcode","info":"","category":"","in":[{"x":140,"y":120,"wires":[{"id":"e563f491.e443f8"}]}],"out":[{"x":380,"y":120,"wires":[{"id":"e563f491.e443f8","port":0}]}],"env":[],"meta":{"module":"node-red-contrib-qrcode","type":"qrcode","version":"0.1.0","author":"hiroyasu.nishiyama.uq@hitachi.com","desc":"Node-RED node for converting string to QRcode","keywords":"Node-RED, subflow, QRcode","license":"Apache-2.0"},"color":"#87A980","icon":"font-awesome/fa-qrcode"},{"id":"e563f491.e443f8","type":"function","z":"921a4b1d.07bb68","name":"","func":"qrcode.toString(msg.payload, (err,str) => {\n if (err) {\n node.error(err);\n return;\n }\n node.send({payload: str});\n});","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"qrcode","module":"qrcode"}],"x":260,"y":120,"wires":[[]]}] \ No newline at end of file +[ + { + "id": "921a4b1d.07bb68", + "type": "subflow", + "name": "QRcode", + "info": "", + "category": "", + "in": [ + { + "x": 140, + "y": 120, + "wires": [ + { + "id": "e563f491.e443f8" + } + ] + } + ], + "out": [ + { + "x": 380, + "y": 120, + "wires": [ + { + "id": "e563f491.e443f8", + "port": 0 + } + ] + } + ], + "env": [], + "meta": { + "module": "node-red-contrib-qrcode", + "type": "qrcode", + "version": "0.1.0", + "author": "hiroyasu.nishiyama.uq@hitachi.com", + "desc": "Node-RED node for converting string to QRcode", + "keywords": "Node-RED, subflow, QRcode", + "license": "Apache-2.0" + }, + "color": "#87A980", + "icon": "font-awesome/fa-qrcode" + }, + { + "id": "e563f491.e443f8", + "type": "function", + "z": "921a4b1d.07bb68", + "name": "", + "func": "qrcode.toString(msg.payload, (err,str) => {\n if (err) {\n node.error(err);\n return;\n }\n node.send({payload: str});\n});", + "outputs": 1, + "noerr": 0, + "initialize": "", + "finalize": "", + "libs": [ + { + "var": "qrcode", + "module": "qrcode" + } + ], + "x": 260, + "y": 120, + "wires": [ + [] + ] + } +] From 04230bafd82fd2d95a801d2a0d615821d8a3c4f0 Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Mon, 28 Mar 2022 18:50:17 +0900 Subject: [PATCH 2/5] Add node information into subflow file --- samples/qrcode.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/qrcode.json b/samples/qrcode.json index d0daa8e..44bdd89 100644 --- a/samples/qrcode.json +++ b/samples/qrcode.json @@ -3,7 +3,7 @@ "id": "921a4b1d.07bb68", "type": "subflow", "name": "QRcode", - "info": "", + "info": "This node generates a QR code from the text data in the `msg.payload`. The QR code in the outputted `msg.payload` is text data (not image data) described by text which consists of black rectangles and white spaces. Therefore, you can use the debug node to see the QR code.\n\n### Inputs\n- `payload` - _string_\n\n Text data which is converted to QR code\n\n### Outputs\n- `payload` - _string_\n\n Text data which contains QR code\n\n**Note**: This node uses the [node-qrcode](https://www.npmjs.com/package/qrcode) module to generate QR codes.", "category": "", "in": [ { @@ -63,4 +63,4 @@ [] ] } -] +] \ No newline at end of file From 3955106d80f0488a319e54ddd872f9de82d13bcd Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Mon, 28 Mar 2022 18:56:06 +0900 Subject: [PATCH 3/5] Output subflow information to README.md --- lib/subflow/index.js | 2 ++ templates/subflow/README.md.mustache | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/subflow/index.js b/lib/subflow/index.js index b53b8f1..8eab738 100644 --- a/lib/subflow/index.js +++ b/lib/subflow/index.js @@ -79,6 +79,7 @@ module.exports = async function(data, options) { if (!data.license || (data.license === "")) { data.license = "unknown"; } + data.info = meta.info; var params = { nodeName: data.name, @@ -88,6 +89,7 @@ module.exports = async function(data, options) { category: data.category || "subflow", description: data.desc, licenseName: data.license, + nodeRead: sf.info || "" }; // Make directory diff --git a/templates/subflow/README.md.mustache b/templates/subflow/README.md.mustache index 0ee221f..cae8709 100644 --- a/templates/subflow/README.md.mustache +++ b/templates/subflow/README.md.mustache @@ -3,10 +3,12 @@ {{&description}} -Install -------- +## Install Run the following command in your Node-RED user directory - typically `~/.node-red` npm install {{&projectName}} +## Information + +{{&nodeRead}} From 90b9ba61e64ed209ab0730c401ce8f60ada5ae43 Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Mon, 28 Mar 2022 19:10:29 +0900 Subject: [PATCH 4/5] Use encoding code when the option specified only --- lib/subflow/index.js | 3 ++- templates/subflow/package.json.mustache | 33 ++++++++++++++----------- templates/subflow/subflow.js.mustache | 10 +++++--- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/lib/subflow/index.js b/lib/subflow/index.js index 8eab738..8a3d0a4 100644 --- a/lib/subflow/index.js +++ b/lib/subflow/index.js @@ -89,7 +89,8 @@ module.exports = async function(data, options) { category: data.category || "subflow", description: data.desc, licenseName: data.license, - nodeRead: sf.info || "" + nodeRead: sf.info || "", + encoding: options.encoding }; // Make directory diff --git a/templates/subflow/package.json.mustache b/templates/subflow/package.json.mustache index 4c86ef6..9902cc9 100644 --- a/templates/subflow/package.json.mustache +++ b/templates/subflow/package.json.mustache @@ -1,18 +1,21 @@ { - "name": "{{&projectName}}", - "version": "{{&projectVersion}}", - "description": "Node-RED node for {{&nodeName}}", - "node-red": { - "nodes": { - "{{&nodeName}}": "subflow.js" - } - }, - "keywords": [ - {{#keywords}} - "{{name}}"{{^last}}, {{/last}} - {{/keywords}} - ], - "dependencies": { - "crypto-js": "4.1.1" + "name": "{{&projectName}}", + "version": "{{&projectVersion}}", + "description": "Node-RED node for {{&nodeName}}", + "keywords": [ + {{#keywords}} + "{{name}}"{{^last}}, {{/last}} + {{/keywords}} + ], + "node-red": { + "nodes": { + "{{&nodeName}}": "subflow.js" } + }, + {{#encoding}} + "dependencies": { + "crypto-js": "4.1.1" + }, + {{/encoding}} + "license": "{{&licenseName}}" } diff --git a/templates/subflow/subflow.js.mustache b/templates/subflow/subflow.js.mustache index 669f264..4a6dd58 100644 --- a/templates/subflow/subflow.js.mustache +++ b/templates/subflow/subflow.js.mustache @@ -1,11 +1,11 @@ -module.exports = function(RED) { +module.exports = function (RED) { const fs = require('fs'); const path = require("path"); - const crypt = require("crypto-js"); - const file = path.join(__dirname, "subflow.json"); const text = fs.readFileSync(file); const flow = JSON.parse(text); + {{#encoding}} + const crypt = require("crypto-js"); function getDecoder(encoding) { var settings = RED.settings; @@ -63,4 +63,8 @@ module.exports = function(RED) { } RED.nodes.registerSubflow(convFlow(flow)); + {{/encoding}} + {{^encoding}} + RED.nodes.registerSubflow(flow); + {{/encoding}} } From 0bcbfd80c0dfe9f439c56a48b97b7260f651047f Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Mon, 28 Mar 2022 19:15:50 +0900 Subject: [PATCH 5/5] Bump for 0.2.2 --- README.md | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 51c7616..af99b32 100644 --- a/README.md +++ b/README.md @@ -93,12 +93,12 @@ You may need to run this with `sudo`, or from within an Administrator command sh ## Documentation -- [Use cases](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index.md#use-cases) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index_ja.md#use-cases)) -- [How to use Node generator](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index.md#how-to-use-node-generator) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index_ja.md#how-to-use-node-generator)) -- [Generated files which node package contains](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index.md#generated-files-which-node-package-contains) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index_ja.md#generated-files-which-node-package-contains)) -- [How to create a node from OpenAPI document](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index.md#how-to-create-a-node-from-openapi-document) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index_ja.md#how-to-create-a-node-from-openapi-document)) -- [How to create a node from function node](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index.md#how-to-create-a-node-from-function-node) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index_ja.md#how-to-create-a-node-from-function-node)) -- [How to create a node from subflow](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index.md#how-to-create-a-node-from-subflow) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index_ja.md#how-to-create-a-node-from-subflow)) -- [How to create a node from WoT Thing Description](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index.md#how-to-create-a-node-from-wot-thing-description) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.1/docs/index_ja.md#how-to-create-a-node-from-wot-thing-description)) +- [Use cases](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index.md#use-cases) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index_ja.md#use-cases)) +- [How to use Node generator](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index.md#how-to-use-node-generator) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index_ja.md#how-to-use-node-generator)) +- [Generated files which node package contains](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index.md#generated-files-which-node-package-contains) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index_ja.md#generated-files-which-node-package-contains)) +- [How to create a node from OpenAPI document](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index.md#how-to-create-a-node-from-openapi-document) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index_ja.md#how-to-create-a-node-from-openapi-document)) +- [How to create a node from function node](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index.md#how-to-create-a-node-from-function-node) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index_ja.md#how-to-create-a-node-from-function-node)) +- [How to create a node from subflow](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index.md#how-to-create-a-node-from-subflow) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index_ja.md#how-to-create-a-node-from-subflow)) +- [How to create a node from WoT Thing Description](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index.md#how-to-create-a-node-from-wot-thing-description) ([Japanese](https://github.com/node-red/node-red-nodegen/blob/0.2.2/docs/index_ja.md#how-to-create-a-node-from-wot-thing-description)) Note: Currently node generator supports GET and POST methods using JSON format without authentication. diff --git a/package.json b/package.json index 347627e..18b4bd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-nodegen", - "version": "0.2.1", + "version": "0.2.2", "description": "Node generator for Node-RED", "homepage": "http://nodered.org", "main": "./lib/nodegen.js",