Skip to content

Commit ece2c05

Browse files
authored
Pr issue6 (#11)
* fix: issue #6 search * chore: release testing and settings done * chore: fix missed grunt checks * chore: changes to focus on issue #6
1 parent 93554fd commit ece2c05

File tree

6 files changed

+85
-38
lines changed

6 files changed

+85
-38
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ matrix:
44
include:
55
- node_js: 8
66
- node_js: 10
7+
- node_js: 12
78
before_install:
89
- npm i -g npm
910
script:

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# Node-RED Command Line Tool
1+
# Node-RED Admin
2+
3+
The Node-RED admin command line interface.
24

35
[![Build Status](https://travis-ci.org/node-red/node-red-admin.svg?branch=master)](https://travis-ci.org/node-red/node-red-admin) [![Coverage Status](https://coveralls.io/repos/node-red/node-red-admin/badge.svg?branch=master)](https://coveralls.io/r/node-red/node-red-admin?branch=master)
46

57

6-
Install this globally to make the `node-red-admin` command available on
7-
your path:
8+
A command line tool for Node-RED administrations.
9+
10+
Install this globally to make the `node-red-admin` command available on your path:
811

912
npm install -g node-red-admin
1013

@@ -22,13 +25,14 @@ You may also need to add `--unsafe-perm` to the command if you hit permissions e
2225
Node-RED command-line client
2326

2427
Commands:
25-
target - Set or view the target URL
26-
login - Log user in to the targetted Node-RED admin api
27-
list - List all of the installed nodes
28-
info - Display more information about the module or node
29-
enable - Enable the specified module or node set
28+
target - Set or view the target URL and port like http://localhost:1880
29+
login - Log user in to the target of the Node-RED admin API
30+
list - List all of the installed nodes
31+
info - Display more information about the module or node
32+
enable - Enable the specified module or node set
3033
disable - Disable the specified module or node set
31-
search - Search NPM for Node-RED modules relating to the search-term given
34+
search - Search NPM for Node-RED modules by matching name, description or keywords with the term
3235
install - Install the module from NPM
33-
remove - Remove the NPM module
36+
remove - Remove the NPM module
37+
hash-pw - creates a hash to use for Node-RED settings like "adminAuth"
3438

lib/commands/search.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,45 @@
1515
**/
1616

1717
var httpRequest = require("request");
18-
1918
var when = require("when");
19+
var defaultUrl = 'https://registry.npmjs.org/-/v1/search?text=keywords:node-red';
2020

2121
function command(argv,result) {
2222
var module = argv._[1];
23+
2324
if (!module) {
2425
return result.help(command);
2526
}
2627

2728
var options = {
2829
method: "GET",
29-
url: 'https://registry.npmjs.org/-/_view/byKeyword?startkey=["node-red"]&endkey=["node-red",{}]&group_level=3',
30+
url: defaultUrl,
3031
headers: {
3132
'Accept': 'application/json',
3233
}
3334
};
35+
3436
return when.promise(function(resolve) {
37+
options.url = defaultUrl + '+' + module;
3538
httpRequest.get(options, function(error, response, body) {
3639
if (!error && response.statusCode == 200) {
37-
var info = (JSON.parse(body)).rows;
40+
var objectsInfo = (JSON.parse(body));
3841
var filter = new RegExp(module);
3942
var found = false;
40-
for (var i = 0; i < info.length; i++) {
41-
var n = info[i];
42-
if (!filter || filter.test(n.key[1]) || filter.test(n.key[2])) {
43-
result.log(n.key[1].cyan.bold + (" - " + n.key[2]).grey);
44-
found = true;
43+
result.log('total: ' + objectsInfo.total + ' objects: ' + objectsInfo.objects.length + ' found');
44+
var objectsEntry = {};
45+
for (var i = 0; i < objectsInfo.objects.length; i++) {
46+
objectsEntry = objectsInfo.objects[i];
47+
if(objectsEntry && objectsEntry.package) {
48+
result.log(objectsEntry.package.name);
49+
if (!filter ||
50+
filter.test(objectsEntry.package.name) ||
51+
filter.test(objectsEntry.package.description) ||
52+
filter.test(objectsEntry.package.keywords)) {
53+
54+
result.log((objectsEntry.package.name).cyan.bold + (" - " + objectsEntry.package.keywords).grey);
55+
found = true;
56+
}
4557
}
4658
}
4759
if (!found) {

node-red-admin.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ function help() {
4444
"Description:".bold + "\n" +
4545
" Node-RED command-line client\n\n" +
4646
"Commands:\n".bold +
47-
" target\n" +
48-
" login\n" +
49-
" list\n" +
50-
" info\n" +
51-
" enable\n" +
52-
" disable\n" +
53-
" search\n" +
54-
" install\n" +
55-
" remove\n" +
56-
" hash-pw\n"
47+
" target (Set or view the target URL and port like http://localhost:1880)\n" +
48+
" login (Log user in to the target of the Node-RED admin API)\n" +
49+
" list (List all of the installed nodes)\n" +
50+
" info (Display more information about the module or node)\n" +
51+
" enable (Enable the specified module or node set)\n" +
52+
" disable (Disable the specified module or node set)\n" +
53+
" search (Search NPM for Node-RED modules by matching name, description or keywords with the term)\n" +
54+
" install (Install the module from NPM to Node-RED)\n" +
55+
" remove (Remove the NPM module from Node-RED)\n" +
56+
" hash-pw (creates a hash to use for Node-RED settings like \"adminAuth\")\n"
5757
;
5858
console.log(helpText);
5959
}

package.json

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"name": "node-red-admin",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "The Node-RED admin command line interface",
55
"homepage": "http://nodered.org",
6+
"bugs": {
7+
"url": "https://github.com/node-red/node-red-admin/issues/"
8+
},
69
"license": "Apache-2.0",
710
"repository": {
811
"type": "git",
@@ -20,6 +23,9 @@
2023
}
2124
],
2225
"preferGlobal": "true",
26+
"scripts": {
27+
"test": "./node_modules/.bin/mocha "
28+
},
2329
"dependencies": {
2430
"bcryptjs": "^2.4.3",
2531
"cli-table": "^0.3.1",
@@ -34,7 +40,7 @@
3440
"grunt-cli": "^1.3.2",
3541
"grunt-contrib-jshint": "^2.1.0",
3642
"grunt-simple-mocha": "^0.4.1",
37-
"mocha": "^6.1.4",
43+
"mocha": "^7.1.0",
3844
"should": "^13.2.3",
3945
"sinon": "^1.17.7"
4046
},
@@ -43,5 +49,26 @@
4349
},
4450
"bin": {
4551
"node-red-admin": "node-red-admin.js"
52+
},
53+
"mocha": {
54+
"spec:": "test/**/*.spec.js",
55+
"diff": true,
56+
"extension": [
57+
"js"
58+
],
59+
"opts": false,
60+
"package": "./package.json",
61+
"reporter": "spec",
62+
"slow": 75,
63+
"timeout": 2000,
64+
"ui": "bdd",
65+
"recursive": "true",
66+
"watch-files": [
67+
"lib/**/*.js",
68+
"test/**/*.js"
69+
],
70+
"watch-ignore": [
71+
"lib/vendor"
72+
]
4673
}
4774
}

test/lib/commands/search_spec.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,27 @@ describe("commands/install", function() {
3131
result.reset();
3232
});
3333

34-
3534
it('reports no results when none match',function(done) {
36-
sinon.stub(httpRequest,"get").yields(null,{statusCode:200},JSON.stringify({rows:[]}));
35+
sinon.stub(httpRequest,"get").yields(null,{statusCode:200},JSON.stringify({"objects":[],"total":0,"time":"Thu Feb 27 2020 11:27:22 GMT+0000 (UTC)"}));
3736

3837
command({_:[null,"testnode"]},result).then(function() {
3938
result.log.called.should.be.true;
40-
result.log.args[0][0].should.eql("No results found");
39+
result.log.args[0][0].should.eql("total: 0 objects: 0 found");
40+
result.log.args[1][0].should.eql("No results found");
4141
done();
4242
}).otherwise(done);
4343

4444
});
4545
it('lists matched modules',function(done) {
4646
sinon.stub(httpRequest,"get").yields(null,{statusCode:200},
47-
JSON.stringify({rows:[
48-
{key:["node-red","testnode","a random node"]},
49-
{key:["node-red","another","a testnode match"]},
50-
{key:["node-red","not a match","not a match"]}
51-
]})
47+
JSON.stringify({
48+
"objects":[
49+
{ "package":{"name": "testnode", "description": "a random node", "keywords":["testnode", "node-red", "test"]} },
50+
{ "package":{"name": "testnodes", "description": "a random nodes test", "keywords":["testnodes", "node-red", "tests"]} }
51+
],
52+
"total":2,
53+
"time":"Thu Feb 27 2020 11:27:22 GMT+0000 (UTC)"
54+
})
5255
);
5356

5457
command({_:[null,"testnode"]},result).then(function() {

0 commit comments

Comments
 (0)