Comparing version 1.2.0 to 1.2.1
@@ -17,6 +17,7 @@ #!/usr/bin/env node | ||
git = require('../lib/git'), | ||
help = require('../lib/cmds/help').Impl.prototype, | ||
logger = require('../lib/logger'), | ||
nopt = require('nopt'), | ||
path = require('path'), | ||
Help = require('../lib/cmds/help').Impl, | ||
User = require('../lib/cmds/user').Impl, | ||
command, | ||
@@ -40,3 +41,3 @@ commandDir, | ||
if (!remain.length) { | ||
help.run(); | ||
new Help().run(); | ||
process.exit(0); | ||
@@ -71,2 +72,4 @@ } | ||
options.user = config.alias[options.user] || options.user; | ||
options.fwd = config.alias[options.fwd] || options.fwd; | ||
options.submit = config.alias[options.submit] || options.submit; | ||
} | ||
@@ -119,4 +122,4 @@ } | ||
operations.push(git.getCurrentBranch); | ||
operations.push(base.login); | ||
operations.push(base.checkVersion); | ||
operations.push(User.login); | ||
@@ -123,0 +126,0 @@ async.series(operations, function(err, results) { |
103
lib/base.js
@@ -15,3 +15,2 @@ /* | ||
path = require('path'), | ||
prompt = require('prompt'), | ||
updateNotifier = require('update-notifier'), | ||
@@ -21,60 +20,6 @@ userhome = require('userhome'); | ||
exports.github = new github({ | ||
version: "3.0.0", | ||
version: '3.0.0', | ||
debug: false | ||
}); | ||
exports.authorize = function(opt_callback) { | ||
var config; | ||
config = exports.getGlobalConfig(); | ||
exports.github.authenticate({ | ||
type: "oauth", | ||
token: config.github_token | ||
}); | ||
opt_callback && opt_callback(); | ||
}; | ||
exports.createAuthorization = function(opt_callback) { | ||
logger.log('First we need authorization to use GitHub\'s API. Login with your GitHub account.'); | ||
prompt.get([{ | ||
name: "username", | ||
message: "Username", | ||
empty: false | ||
}, | ||
{ | ||
name: "password", | ||
message: "Password", | ||
empty: false, | ||
hidden: true | ||
}], | ||
function(err, result) { | ||
exports.github.authenticate({ | ||
type: "basic", | ||
username: result.username, | ||
password: result.password | ||
}); | ||
exports.github.authorization.create({ | ||
note: 'node-gh', | ||
note_url: 'https://github.com/eduardolundgren/node-gh', | ||
scopes: [ 'user', 'public_repo', 'repo', 'repo:status', 'gist' ] | ||
}, | ||
function(err, res) { | ||
if (err) { | ||
logger.error('Could not authenticate :('); | ||
} | ||
if (res.token) { | ||
exports.writeGlobalConfigCredentials(result.username, res.token); | ||
exports.authorize(opt_callback); | ||
logger.success('Authentication completed :)'); | ||
} | ||
} | ||
); | ||
}); | ||
}; | ||
exports.checkVersion = function(opt_callback) { | ||
@@ -142,37 +87,9 @@ var notifier = updateNotifier({ | ||
exports.getUser = function() { | ||
var config; | ||
var config = exports.getGlobalConfig(); | ||
config = exports.getGlobalConfig(); | ||
return config.github_user; | ||
}; | ||
exports.hasCredentials = function() { | ||
var config; | ||
config = exports.getGlobalConfig(); | ||
if (config.github_token && config.github_user) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
exports.login = function(opt_callback) { | ||
if (exports.hasCredentials()) { | ||
exports.authorize(opt_callback); | ||
} | ||
else { | ||
exports.createAuthorization(opt_callback); | ||
} | ||
}; | ||
exports.logout = function() { | ||
var configPath = exports.getGlobalConfigPath(); | ||
fs.unlink(configPath, logger.defaultCallback); | ||
}; | ||
exports.writeGlobalConfig = function(jsonPath, value) { | ||
var config, | ||
var config = exports.getGlobalConfig(), | ||
i, | ||
@@ -184,3 +101,2 @@ output, | ||
path = jsonPath.split('.'); | ||
config = exports.getGlobalConfig(); | ||
output = config; | ||
@@ -202,5 +118,16 @@ | ||
logger.success('Writing GH config data: ' + configPath); | ||
exports.writeGlobalConfig('github_user', user); | ||
exports.writeGlobalConfig('github_token', token); | ||
logger.success('Writing GH config data: ' + configPath); | ||
}; | ||
exports.removeGlobalConfig = function(key) { | ||
var config = exports.getGlobalConfig(); | ||
delete config[key]; | ||
fs.writeFileSync( | ||
exports.getGlobalConfigPath(), | ||
JSON.stringify(config, null, 4) | ||
); | ||
}; |
@@ -21,2 +21,3 @@ /* | ||
Hello.DETAILS = { | ||
alias: 'he', | ||
description: 'Hello world example. Copy to start a new command.', | ||
@@ -28,2 +29,5 @@ options: { | ||
'w': [ '--world' ] | ||
}, | ||
payload: function(payload, options) { | ||
options.world = true; | ||
} | ||
@@ -37,3 +41,5 @@ }; | ||
instance.world(); | ||
if (options.world) { | ||
instance.world(); | ||
} | ||
}; | ||
@@ -40,0 +46,0 @@ |
@@ -17,5 +17,3 @@ /* | ||
// -- Constructor -------------------------------------------------------------- | ||
function Help(options) { | ||
this.options = options; | ||
} | ||
function Help() {} | ||
@@ -31,3 +29,3 @@ // -- Constants ---------------------------------------------------------------- | ||
var cmdDir = instance.getCmdDir_(), | ||
var cmdDir = path.join(__dirname, '../cmds/'), | ||
cmdList = base.find(cmdDir, /\.js$/), | ||
@@ -57,6 +55,9 @@ cmdOutput = []; | ||
var instance = this, | ||
options = Object.keys(details.options), | ||
shorthands = Object.keys(details.shorthands), | ||
options, | ||
shorthands, | ||
grouped = []; | ||
options = Object.keys(details.options); | ||
shorthands = Object.keys(details.shorthands); | ||
options.forEach(function(option) { | ||
@@ -112,6 +113,2 @@ var foundShorthand, | ||
Help.prototype.getCmdDir_ = function() { | ||
return path.join(__dirname, '../cmds/'); | ||
}; | ||
exports.Impl = Help; |
@@ -9,2 +9,3 @@ /* | ||
* @author Zeno Rocha <zno.rocha@gmail.com> | ||
* @author Eduardo Lundgren <eduardo.lundgren@gmail.com> | ||
*/ | ||
@@ -14,3 +15,4 @@ | ||
var base = require('../base'), | ||
logger = require('../logger'); | ||
logger = require('../logger'), | ||
prompt = require('prompt'); | ||
@@ -25,7 +27,7 @@ // -- Constructor -------------------------------------------------------------- | ||
alias: 'us', | ||
description: 'Provides the ability to logout if needed and re-login.', | ||
description: 'Provides the ability to login and logout if needed.', | ||
options: { | ||
'login' : Boolean, | ||
'logout': Boolean, | ||
'remote' : String | ||
'remote': String | ||
}, | ||
@@ -47,5 +49,7 @@ shorthands: { | ||
if (options.login) { | ||
logger.logTemplate('{{prefix}} [info] You\'re already logged in as {{greenBright options.user}}', { | ||
options: options | ||
}); | ||
if (User.hasCredentials()) { | ||
logger.logTemplate('{{prefix}} [info] You\'re logged in as {{greenBright options.user}}', { | ||
options: options | ||
}); | ||
} | ||
} | ||
@@ -58,10 +62,81 @@ | ||
instance.logout(); | ||
User.logout(); | ||
} | ||
}; | ||
User.prototype.logout = function() { | ||
base.logout(); | ||
// -- Static ------------------------------------------------------------------- | ||
User.authorize = function() { | ||
var config = base.getGlobalConfig(); | ||
base.github.authenticate({ | ||
type: 'oauth', | ||
token: config.github_token | ||
}); | ||
}; | ||
User.createAuthorization = function(opt_callback) { | ||
logger.log('First we need authorization to use GitHub\'s API. Login with your GitHub account.'); | ||
prompt.get([{ | ||
name: 'username', | ||
message: 'Username', | ||
empty: false | ||
}, | ||
{ | ||
name: 'password', | ||
message: 'Password', | ||
empty: false, | ||
hidden: true | ||
}], | ||
function(err, result) { | ||
var payload = { | ||
note: 'Node GH', | ||
note_url: 'https://github.com/eduardolundgren/node-gh', | ||
scopes: [ 'user', 'public_repo', 'repo', 'repo:status', 'gist' ] | ||
}; | ||
base.github.authenticate({ | ||
type: 'basic', | ||
username: result.username, | ||
password: result.password | ||
}); | ||
base.github.authorization.create(payload, function(err, res) { | ||
logger.defaultCallback(err, null, 'Authentication completed.'); | ||
if (res.token) { | ||
base.writeGlobalConfigCredentials(result.username, res.token); | ||
User.authorize(); | ||
} | ||
opt_callback && opt_callback(err); | ||
}); | ||
}); | ||
}; | ||
User.hasCredentials = function() { | ||
var config = base.getGlobalConfig(); | ||
if (config.github_token && config.github_user) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
User.login = function(opt_callback) { | ||
if (User.hasCredentials()) { | ||
User.authorize(); | ||
opt_callback && opt_callback(); | ||
} | ||
else { | ||
User.createAuthorization(opt_callback); | ||
} | ||
}; | ||
User.logout = function() { | ||
base.removeGlobalConfig('github_user'); | ||
base.removeGlobalConfig('github_token'); | ||
}; | ||
exports.Impl = User; |
@@ -112,3 +112,3 @@ /* | ||
exports.parseRemoteUrl = function(url) { | ||
var parsed = /[\/:](\w+)\/(.*?)(?:\.git)?$/.exec(url); | ||
var parsed = /[\/:]([\w-]+)\/(.*?)(?:\.git)?$/.exec(url); | ||
@@ -115,0 +115,0 @@ if (parsed) { |
@@ -16,3 +16,4 @@ /* | ||
handlebars = require('handlebars'), | ||
path = require('path'); | ||
path = require('path'), | ||
wrap = require('wordwrap').hard(0, 80); | ||
@@ -114,2 +115,18 @@ var logger = cll.init({ | ||
handlebars.registerHelper('wordwrap', function(text, padding, stripNewLines) { | ||
var gutter = ''; | ||
if (stripNewLines !== false) { | ||
text = text.replace(/[\r\n\s\t]+/g, ' '); | ||
} | ||
text = wrap(text).split('\n'); | ||
if (padding > 0) { | ||
gutter = (new Array(padding)).join(' '); | ||
} | ||
return text.join('\n' + clc.cyan('gh') + gutter); | ||
}); | ||
logger.registerStyles_(); | ||
@@ -116,0 +133,0 @@ }; |
{ | ||
"name": "gh", | ||
"description": "GitHub command line tools.", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"homepage": "http://nodegh.io", | ||
@@ -33,3 +33,4 @@ "author": { | ||
"scripts": { | ||
"test": "jshint lib/ bin/" | ||
"lint": "node_modules/.bin/jshint lib/ bin/", | ||
"test": "node_modules/.bin/mocha --reporter list" | ||
}, | ||
@@ -43,3 +44,4 @@ "dependencies": { | ||
"git-wrapper": "0.1.1", | ||
"github": "https://github.com/zenorocha/node-github/tarball/master", | ||
"github": "0.1.10", | ||
"wordwrap": "0.0.2", | ||
"nopt": "2.1.1", | ||
@@ -52,3 +54,4 @@ "open": "0.0.3", | ||
"devDependencies": { | ||
"jshint": "2.1.2" | ||
"jshint": "2.1.2", | ||
"mocha": "1.12.0" | ||
}, | ||
@@ -55,0 +58,0 @@ "engines": { |
@@ -533,2 +533,5 @@ # Node GH [![Build Status](https://secure.travis-ci.org/eduardolundgren/node-gh.png?branch=master)](https://travis-ci.org/eduardolundgren/node-gh) [![NPM version](https://badge.fury.io/js/gh.png)](http://badge.fury.io/js/gh) | ||
* **v1.2.1** August 12, 2013 | ||
* Parse remote url with score on username | ||
* Add tests using Mocha | ||
* **v1.2.0** June 7, 2013 | ||
@@ -535,0 +538,0 @@ * Add ability to create alias for users |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
77581
27
1743
615
0
13
2
+ Addedwordwrap@0.0.2
+ Addedgithub@0.1.10(transitive)
+ Addedwordwrap@0.0.2(transitive)
Updatedgithub@0.1.10