Skip to content

Commit

Permalink
Add example flow to function node template
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuhitoyokoi committed Jun 19, 2020
1 parent 121e22e commit ad190e4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/nodegen.js
Expand Up @@ -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) {
Expand All @@ -119,8 +126,6 @@ function createCommonFiles(templateDirectory, data) {
console.error(error);
}
}


}

function runNpmPack(data) {
Expand Down Expand Up @@ -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);
Expand Down
60 changes: 60 additions & 0 deletions 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": []
}
]

0 comments on commit ad190e4

Please sign in to comment.