Skip to content

Commit 91b2c12

Browse files
kazuhitoyokoiHiroyasuNishiyama
authored andcommitted
Add version check option (#76)
1 parent 8ba4820 commit 91b2c12

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

bin/node-red-nodegen.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
**/
1818

1919
var fs = require('fs');
20+
var path = require('path');
2021
var request = require('request');
2122
var yamljs = require('yamljs');
2223
var argv = require('minimist')(process.argv.slice(2));
@@ -32,7 +33,7 @@ var data = {
3233
prefix: argv.prefix || argv.p,
3334
name: argv.name || argv.n,
3435
module: argv.module,
35-
version: argv.version || argv.v,
36+
version: argv.version,
3637
keywords: argv.keywords || argv.k,
3738
category: argv.category || argv.c,
3839
dst: argv.output || argv.o || '.'
@@ -51,7 +52,8 @@ function help() {
5152
//' [--icon <png or gif file>]' +
5253
//' [--color <node color>]' +
5354
' [--tgz]' +
54-
' [--help]\n' +
55+
' [--help]' +
56+
' [-v]\n' +
5557
'\n' +
5658
'Description:'.bold + '\n' +
5759
' Node generator for Node-RED\n' +
@@ -72,11 +74,21 @@ function help() {
7274
//' --icon : png or gif file for node appearance (image size should be 10x20)\n';
7375
//' --color : color for node appearance (format: color hexadecimal numbers like "#A6BBCF")\n';
7476
' --tgz : Save node as tgz file\n' +
75-
' --help : Show help\n';
77+
' --help : Show help\n' +
78+
' -v : Show node generator version\n';
7679
console.log(helpText);
7780
}
7881

79-
if (!argv.h && !argv.help) {
82+
function version() {
83+
var packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')));
84+
console.log(packageJson.version);
85+
}
86+
87+
if (argv.help || argv.h) {
88+
help();
89+
} else if (argv.v) {
90+
version();
91+
} else {
8092
var sourcePath = argv._[0];
8193
if (sourcePath) {
8294
if (sourcePath.startsWith('http://') || sourcePath.startsWith('https://')) {
@@ -119,6 +131,4 @@ if (!argv.h && !argv.help) {
119131
} else {
120132
help();
121133
}
122-
} else {
123-
help();
124134
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-nodegen",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Node generator for Node-RED",
55
"homepage": "http://nodered.org",
66
"main": "./lib/nodegen.js",

0 commit comments

Comments
 (0)