File tree Expand file tree Collapse file tree 1 file changed +25
-12
lines changed
Expand file tree Collapse file tree 1 file changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -36,21 +36,34 @@ configuration in a reasonably well-defined order:
3636 - Groups
3737
3838```
39- const flow = parseFlow(exampleFlow);
39+ const fs = require("fs");
40+ const FlowParser = require("@node-red/flow-parser");
4041
41- flow.walk(obj => {
42- if (obj.type === 'tab') {
43- // A flow object
44- } else if (obj.type === 'subflow') {
45- // A subflow definition
46- } else if (obj.type === 'group') {
47- // A group object
48- } else if (obj.constructor.name === 'NRConfigNode') {
49- // A config node
50- } else {
51- // A flow node
42+ // Load the flow json from a local file and parse to an object
43+ const exampleFlow = JSON.parse(fs.readFileSync("flows.json", "utf-8"));
44+
45+ const flow = FlowParser.parseFlow(exampleFlow);
46+
47+ flow.walk(function(obj) {
48+ switch(obj.TYPE) {
49+ case FlowParser.types.Flow:
50+ // A flow object
51+ break;
52+ case FlowParser.types.Subflow:
53+ // A subflow definition
54+ break;
55+ case FlowParser.types.Group:
56+ // A group object
57+ break;
58+ case FlowParser.types.ConfigNode:
59+ // A config node
60+ break;
61+ case FlowParser.types.Node:
62+ // A flow node
63+ break;
5264 }
5365})
66+
5467```
5568
5669** TODO:** Add a better way to distinguish the object types
You can’t perform that action at this time.
0 commit comments