Permalink
Browse files

add support for custom colors, default repo to search

  • Loading branch information...
1 parent 1ba88c5 commit b7ae690902523f66a14e1181ee906466ba15f557 @cdibened committed Feb 1, 2014
Showing with 88 additions and 34 deletions.
  1. +46 −7 README.md
  2. +20 −10 bin/cordova-plugins.js
  3. +2 −2 package.json
  4. +10 −8 scripts/plugreg-com.js
  5. +10 −7 scripts/registry-cordova-io.js
View
53 README.md
@@ -4,12 +4,12 @@ cordova-plugins
NPM package to list/download available Phonegap plugins from [http://plugins.cordova.io/](http://plugins.cordova.io/) and/or
[http://plugreg.com/](http://plugreg.com/)
-Comparison between the two sites:
+Comparison between the two repos:
http://plugreg.com | http://plugins.cordova.io
--- | ---
REST API | REST API
-~270 plugins | ~100 plugins
+~500 plugins | ~100 plugins
Git plugin project URL | .tgz plugin tarball URL
Supports platform filter | No support for platform filter
Supports version number | Supports version number
@@ -29,8 +29,8 @@ Bright Red - activity more than 2 months ago
`sudo npm install -g cordova-plugins`
-###Usage
+###Usage
cordova-plugins [options] command [term]
```
@@ -42,9 +42,9 @@ options:
-p - comma delimited (no spaces) platforms to filter by.
Valid platforms are: ios, android, blackberry10, wp7, wp8, firefoxos.
Default is all.
- -u - the url of the repo to use.
+ -r - the url/name of the repo to use.
Valid urls are: http://plugreg.com (shortform plugreg) and
- http://plugins.cordova.io. Default is http://plugins.cordova.io
+ http://registry.cordova.io (shortform cordova). Default is http://registry.cordova.io
term - term to use when using the `search` command.
Wrap the term in quotes if there are spaces.
@@ -54,16 +54,55 @@ term - term to use when using the `search` command.
###Examples
cordova-plugins -p ios,android list
-- will list all plugins from `http://plugins.cordova.io` (the -p option has no effect)
+- will list all plugins from `http://registry.cordova.io` (the -p option has no effect)
cordova-plugins -p ios,android -u http://plugreg.com (or plugreg) list
- will list all plugins from `http://plugreg.com` that are on the ios and/or android platforms
cordova-plugins search camera
-- will list all plugins from `http://plugins.cordova.io` that have the term `camera` in the name or description. The search term matches will be highlighted and CAPTIALIZED to notice easier.
+- will list all plugins from `http://plugins.cordova.io` that have the term `camera` in the name or description. The search term matches will be highlighted and CAPITALIZED to notice easier.
+
+###Changed
+Commandline argument `-u` has been changed to `-r` to reflect the naming convention of repo instead of url.
+
+###New
+Support for default `repo` url. Valid urls are: `http://plugreg.com` (shortform `plugreg`) and `http://registry.cordova.io` (shortform `cordova`). Default is `http://registry.cordova.io`.
+
+Support to customize output foreground colors. Currently you can change the color of the `url` and `description` output. This is done by creating a `.cordova-plugins` valid JSON file in your HOME directory.
+
+Ex:
+```
+{
+ "repo": "plugreg",
+ "urlColor": "blue",
+ "descriptionColor": "whiteBright"
+}
+```
+Supported colors are (taken from https://github.com/medikoo/cli-color):
+
+<table>
+ <tbody>
+ <tr><td>black</td><td><img src="http://medyk.org/colors/000000.png" width="30" height="30" /></td></tr>
+ <tr><td>red</td><td><img src="http://medyk.org/colors/800000.png" width="30" height="30" /></td></tr>
+ <tr><td>green</td><td><img src="http://medyk.org/colors/008000.png" width="30" height="30" /></td></tr>
+ <tr><td>yellow</td><td><img src="http://medyk.org/colors/808000.png" width="30" height="30" /></td></tr>
+ <tr><td>blue</td><td><img src="http://medyk.org/colors/000080.png" width="30" height="30" /></td></tr>
+ <tr><td>magenta</td><td><img src="http://medyk.org/colors/800080.png" width="30" height="30" /></td></tr>
+ <tr><td>cyan</td><td><img src="http://medyk.org/colors/008080.png" width="30" height="30" /></td></tr>
+ <tr><td>white</td><td><img src="http://medyk.org/colors/c0c0c0.png" width="30" height="30" /></td></tr>
+ <tr><td>blackBright</td><td><img src="http://medyk.org/colors/808080.png" width="30" height="30" /></td></tr>
+ <tr><td>redBright</td><td><img src="http://medyk.org/colors/ff0000.png" width="30" height="30" /></td></tr>
+ <tr><td>greenBright</td><td><img src="http://medyk.org/colors/00ff00.png" width="30" height="30" /></td></tr>
+ <tr><td>yellowBright</td><td><img src="http://medyk.org/colors/ffff00.png" width="30" height="30" /></td></tr>
+ <tr><td>blueBright</td><td><img src="http://medyk.org/colors/0000ff.png" width="30" height="30" /></td></tr>
+ <tr><td>magentaBright</td><td><img src="http://medyk.org/colors/ff00ff.png" width="30" height="30" /></td></tr>
+ <tr><td>cyanBright</td><td><img src="http://medyk.org/colors/00ffff.png" width="30" height="30" /></td></tr>
+ <tr><td>whiteBright</td><td><img src="http://medyk.org/colors/ffffff.png" width="30" height="30" /></td></tr>
+ </tbody>
+</table>
###2-Dew
View
30 bin/cordova-plugins.js
@@ -11,11 +11,11 @@
updateNotifier = require('update-notifier'),
knownOpts = {
'platforms': String,
- 'url': String
+ 'repo': String
},
shortHands = {
'p': ['--platforms'],
- 'u': ['--url']
+ 'r': ['--repo']
},
parsed = nopt(knownOpts, shortHands, process.argv, 2),
plugreg = require('../scripts/plugreg-com'),
@@ -36,16 +36,16 @@
console.log( 'cordova-plugins [options] command [term]');
console.log( '' );
console.log( ' commands:');
- console.log( ' list - display all available plugins. Is the default.');
+ console.log( ' list - display all available plugins');
console.log( ' search - search plugins for a specfic term/phrase ');
console.log( '' );
console.log( ' options:');
console.log( ' -p - comma delimited (no spaces) platforms to filter by.');
console.log(' Valid platforms are: ' + clc.redBright( 'ios android blackberry10 wp7 wp8 firefoxos' ) + '.' );
console.log(' Default is all.');
- console.log( ' -u - the url of the repo to use.');
+ console.log( ' -r - the url/name of the repo to use.');
console.log(' Valid urls are: '+ clc.yellowBright( 'http://plugreg.com') + ' or use shortform ' + clc.yellowBright( 'plugreg' ) );
- console.log(' and ' + clc.yellowBright('http://plugins.cordova.io') + '. Default is http://plugins.cordova.io');
+ console.log(' and ' + clc.yellowBright('http://registry.cordova.io') + ' or use shortform ' + clc.yellowBright( 'cordova' ) + '. Default is http://registry-cordova-io.cordova.io');
console.log( '' );
console.log( ' term - term to use when using the `search` command.');
console.log(' Wrap the term in quotes if there are spaces.');
@@ -54,18 +54,28 @@
}
else {
var platforms = (parsed.platforms ? parsed.platforms.split(',') : []),
- url = parsed.url,
+ repo = parsed.repo,
command = parsed.argv.remain[0] || 'list',
- plugin = parsed.argv.remain[1];
+ plugin = parsed.argv.remain[1],
+ userconfig = null;
+
+ // userconfig = require(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']+'/.cordova-plugins');
+ try {
+ userconfig = JSON.parse(fs.readFileSync(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']+'/.cordova-plugins', 'utf8' ));
+ repo = repo || (userconfig && userconfig.repo);
+ }
+ catch(e) {
+ console.log( 'Cannot find or parse config file. Please make sure it exists and is valid json. Using Defaults.\n');
+ }
switch (command.toLowerCase()) {
case 'list':
case 'search':
- if( url && ( url.toLowerCase().indexOf( 'plugreg' ) !== -1 ) ) {
- plugreg.fetch(plugin,platforms);
+ if( repo && ( repo.toLowerCase().indexOf( 'plugreg' ) !== -1 ) ) {
+ plugreg.fetch(plugin,platforms,userconfig);
}
else {
- registrycordova.fetch(plugin,platforms);
+ registrycordova.fetch(plugin,platforms,userconfig);
}
break;
// case 'get':
View
4 package.json
@@ -1,6 +1,6 @@
{
"name": "cordova-plugins",
- "version": "0.0.8",
+ "version": "0.0.9",
"author": "Cesidio DiBenedetto <sid.dibenedetto@gmail.com>",
"description": "List/download available Phonegap plugins from http://plugins.cordova.io and http://plugreg.com",
"keywords": [
@@ -29,7 +29,7 @@
"prompt": ">=0.2.*",
"request": ">=2.27.0",
"update-notifier": ">=0.1.7",
- "ping": ">=0.1.6"
+ "ping": ">=0.1.7"
},
"engines": {
"node": ">=0.8.0"
View
18 scripts/plugreg-com.js
@@ -26,12 +26,12 @@
ping = require('ping'),
// prompt = require( 'prompt' ),
request = require('request'),
-
tmp = os.tmpdir(),
pluginsfile = tmp + '/pr-plugins.json',
- url = 'http://plugreg.com/api/plugins',
- urlColor = clc.magentaBright,
- descriptionColor = clc.cyanBright,
+ host = 'plugreg.com',
+ url = 'http://'+host+'/api/plugins',
+ urlColor = 'magentaBright',
+ descriptionColor = 'cyanBright',
searchMatchColor = clc.inverse,
dateFromColorNotication = ['greenBright', 'yellowBright', 'redBright'];
@@ -82,13 +82,15 @@
}
}
- function _fetch(search, platforms) {
- ping.sys.probe(url, function(isAlive){
- if( !isAlive ) {
- console.log(url + ": " + clc.redBright(" is not reachable." ) );
+ function _fetch(search, platforms, userconfig) {
+ ping.sys.probe(host, function(isAlive){
+ if(!isAlive) {
+ console.log(clc.whiteBright(url) + clc.redBright(' is not reachable.'));
exit(1);
}
});
+ urlColor = clc[(userconfig && userconfig.urlColor) || urlColor];
+ descriptionColor = clc[(userconfig && userconfig.descriptionColor) || descriptionColor];
var file = fs.createWriteStream(pluginsfile,'w+'),
req = request(url).pipe(file);
req.on( 'finish', function() {
View
17 scripts/registry-cordova-io.js
@@ -35,9 +35,10 @@
request = require('request'),
tmp = os.tmpdir(),
pluginsfile = tmp + '/rc-plugins.json',
- url = 'http://registry.cordova.io/-/all',
- urlColor = clc.magentaBright,
- descriptionColor = clc.cyanBright,
+ host = 'registry.cordova.io',
+ url = 'http://'+host+'/-/all',
+ urlColor = 'magentaBright',
+ descriptionColor = 'cyanBright',
searchMatchColor = clc.inverse,
dateFromColorNotication = ['greenBright', 'yellowBright', 'redBright'];
@@ -88,13 +89,15 @@
}
}
- function _fetch(search, platforms) {
- ping.sys.probe(url, function(isAlive){
- if( !isAlive ) {
- console.log(url + ": " + clc.redBright(" is not reachable." ) );
+ function _fetch(search, platforms, userconfig) {
+ ping.sys.probe(host, function(isAlive){
+ if(!isAlive) {
+ console.log(clc.whiteBright(url) + clc.redBright(' is not reachable.'));
exit(1);
}
});
+ urlColor = clc[(userconfig && userconfig.urlColor) || urlColor];
+ descriptionColor = clc[(userconfig && userconfig.descriptionColor) || descriptionColor];
var file = fs.createWriteStream(pluginsfile,'w+'),
req = request(url).pipe(file);
req.on( 'finish', function() {

0 comments on commit b7ae690

Please sign in to comment.