Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ coverage

# npm install log
npm-debug.log.*
package-lock.json
29 changes: 24 additions & 5 deletions bin/node-red-nodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
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;
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) {
Expand Down
19 changes: 14 additions & 5 deletions lib/nodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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\-\./]+$/)) {
Expand Down Expand Up @@ -213,15 +215,22 @@ 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 || ""),
nodeRead: data.info || ""
};

createCommonFiles(__dirname + '/../templates/function', data);
Expand Down
3 changes: 3 additions & 0 deletions templates/function/README.md.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ command in your Node-RED user directory, typically `~/.node-red`

npm install {{&projectName}}

## Information

{{&nodeRead}}
8 changes: 7 additions & 1 deletion templates/function/node.html.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}'
});
</script>
6 changes: 3 additions & 3 deletions templates/function/package.json.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
{{/keywords}}
],
"devDependencies": {
"mocha": "6.2.0",
"node-red": "1.0.3",
"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"
}
8 changes: 4 additions & 4 deletions templates/swagger/package.json.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
],
"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-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}}"
Expand Down
4 changes: 2 additions & 2 deletions templates/webofthings/package.json.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand Down