From ad190e49e4aea6dfcaa19017ce01d4a3e239cc41 Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Fri, 19 Jun 2020 21:16:17 +0900 Subject: [PATCH] Add example flow to function node template --- lib/nodegen.js | 14 ++++- .../function/examples/flow.json.mustache | 60 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 templates/function/examples/flow.json.mustache diff --git a/lib/nodegen.js b/lib/nodegen.js index 1318089..4a30f0b 100644 --- a/lib/nodegen.js +++ b/lib/nodegen.js @@ -104,6 +104,13 @@ function createCommonFiles(templateDirectory, data) { console.error(error); } } + try { + fs.mkdirSync(path.join(data.dst, data.module, 'examples')); + } catch (error) { + if (error.code !== 'EEXIST') { + console.error(error); + } + } try { fs.mkdirSync(path.join(data.dst, data.module, 'test')); } catch (error) { @@ -119,8 +126,6 @@ function createCommonFiles(templateDirectory, data) { console.error(error); } } - - } function runNpmPack(data) { @@ -253,6 +258,11 @@ function function2node(data, options) { var htmlSourceCode = mustache.render(htmlTemplate, params); fs.writeFileSync(path.join(data.dst, data.module, 'node.html'), htmlSourceCode); + // Create flow.json + var flowTemplate = fs.readFileSync(path.join(__dirname, '../templates/function/examples/flow.json.mustache'), 'utf-8'); + var flowSourceCode = mustache.render(flowTemplate, params); + fs.writeFileSync(path.join(data.dst, data.module, 'examples/flow.json'), flowSourceCode); + // Create node_spec.js var nodeSpecTemplate = fs.readFileSync(path.join(__dirname, '../templates/function/test/node_spec.js.mustache'), 'utf-8'); var nodeSpecSourceCode = mustache.render(nodeSpecTemplate, params); diff --git a/templates/function/examples/flow.json.mustache b/templates/function/examples/flow.json.mustache new file mode 100644 index 0000000..cd63bac --- /dev/null +++ b/templates/function/examples/flow.json.mustache @@ -0,0 +1,60 @@ +[ + { + "id": "786d9ce1.c1c3a4", + "type": "inject", + "z": "7b8f4430.ec912c", + "name": "", + "props": [ + { + "p": "payload" + }, + { + "p": "topic", + "vt": "str" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "", + "payloadType": "date", + "x": 0, + "y": 0, + "wires": [ + [ + "726f08b3.50bfd8" + ] + ] + }, + { + "id": "726f08b3.50bfd8", + "type": "{{&nodeName}}", + "z": "7b8f4430.ec912c", + "name": "", + "x": 200, + "y": 0, + "wires": [ + [ + "82d40348.2d47b" + ] + ] + }, + { + "id": "82d40348.2d47b", + "type": "debug", + "z": "7b8f4430.ec912c", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "false", + "statusVal": "", + "statusType": "auto", + "x": 400, + "y": 0, + "wires": [] + } +]