diff options
author | TJ Holowaychuk <tj@vision-media.ca> | 2013-07-05 03:34:45 +0400 |
---|---|---|
committer | Domenic Denicola <domenic@domenicdenicola.com> | 2013-08-16 03:47:43 +0400 |
commit | 0223389130dfd220d2a18dfe7058c4f7f0b14808 (patch) | |
tree | d79c91c25999595d36be78c45d121c37f761763f | |
parent | b17e07c4cc95bf99b6586ab3a3fd3aca3d8a8d39 (diff) |
add "repo" command
-rw-r--r-- | doc/api/repo.md | 19 | ||||
-rw-r--r-- | doc/cli/repo.md | 26 | ||||
-rw-r--r-- | lib/npm.js | 1 | ||||
-rw-r--r-- | lib/repo.js | 29 | ||||
-rw-r--r-- | node_modules/github-url-from-git/.npmignore | 1 | ||||
-rw-r--r-- | node_modules/github-url-from-git/History.md | 10 | ||||
-rw-r--r-- | node_modules/github-url-from-git/Makefile | 5 | ||||
-rw-r--r-- | node_modules/github-url-from-git/Readme.md | 41 | ||||
-rw-r--r-- | node_modules/github-url-from-git/index.js | 12 | ||||
-rw-r--r-- | node_modules/github-url-from-git/package.json | 31 | ||||
-rw-r--r-- | node_modules/github-url-from-git/test.js | 40 | ||||
-rw-r--r-- | package.json | 6 |
12 files changed, 219 insertions, 2 deletions
diff --git a/doc/api/repo.md b/doc/api/repo.md new file mode 100644 index 000000000..af3c52fab --- /dev/null +++ b/doc/api/repo.md @@ -0,0 +1,19 @@ +npm-repo(3) -- Open package repository page in the browser +======================================================== + +## SYNOPSIS + + npm.commands.repo(package, callback) + +## DESCRIPTION + +This command tries to guess at the likely location of a package's +repository URL, and then tries to open it using the `--browser` +config param. + +Like other commands, the first parameter is an array. This command only +uses the first element, which is expected to be a package name with an +optional version number. + +This command will launch a browser, so this command may not be the most +friendly for programmatic use. diff --git a/doc/cli/repo.md b/doc/cli/repo.md new file mode 100644 index 000000000..5c281c28e --- /dev/null +++ b/doc/cli/repo.md @@ -0,0 +1,26 @@ +npm-repo(1) -- Open package repository page in the browser +======================================================== + +## SYNOPSIS + + npm repo <pkgname> + +## DESCRIPTION + +This command tries to guess at the likely location of a package's +repository URL, and then tries to open it using the `--browser` +config param. + +## CONFIGURATION + +### browser + +* Default: OS X: `"open"`, Windows: `"start"`, Others: `"xdg-open"` +* Type: String + +The browser that is called by the `npm repo` command to open websites. + +## SEE ALSO + +* npm-docs(1) +* npm-config(1) diff --git a/lib/npm.js b/lib/npm.js index ea9759265..8b8ee95b0 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -146,6 +146,7 @@ var commandCache = {} , "edit" , "explore" , "docs" + , "repo" , "bugs" , "faq" , "root" diff --git a/lib/repo.js b/lib/repo.js new file mode 100644 index 000000000..19066c822 --- /dev/null +++ b/lib/repo.js @@ -0,0 +1,29 @@ + +module.exports = repo + +repo.usage = "npm repo <pkgname>" + +repo.completion = function (opts, cb) { + if (opts.conf.argv.remain.length > 2) return cb() + registry.get("/-/short", 60000, function (er, list) { + return cb(null, list || []) + }) +} + +var npm = require("./npm.js") + , registry = npm.registry + , log = require("npmlog") + , opener = require("opener") + , github = require('github-url-from-git') + +function repo (args, cb) { + if (!args.length) return cb(repo.usage) + var n = args[0].split("@").shift() + registry.get(n + "/latest", 3600, function (er, d) { + if (er) return cb(er) + var r = d.repository; + if (!r) return cb(new Error('no repository')); + var url = github(r.url); + opener(url, { command: npm.config.get("browser") }, cb) + }) +} diff --git a/node_modules/github-url-from-git/.npmignore b/node_modules/github-url-from-git/.npmignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/node_modules/github-url-from-git/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/github-url-from-git/History.md b/node_modules/github-url-from-git/History.md new file mode 100644 index 000000000..fcb296bc6 --- /dev/null +++ b/node_modules/github-url-from-git/History.md @@ -0,0 +1,10 @@ + +1.1.1 / 2013-04-23 +================== + + * package.json: Move test stuff to devDeps + +1.1.0 / 2013-04-19 +================== + + * Add support for gist urls diff --git a/node_modules/github-url-from-git/Makefile b/node_modules/github-url-from-git/Makefile new file mode 100644 index 000000000..37f330e81 --- /dev/null +++ b/node_modules/github-url-from-git/Makefile @@ -0,0 +1,5 @@ + +test: + @./node_modules/.bin/mocha test.js --reporter spec --require should + +.PHONY: test diff --git a/node_modules/github-url-from-git/Readme.md b/node_modules/github-url-from-git/Readme.md new file mode 100644 index 000000000..d027e8ec6 --- /dev/null +++ b/node_modules/github-url-from-git/Readme.md @@ -0,0 +1,41 @@ + +# github-url-from-git + +```js +describe('parse(url)', function(){ + it('should support git://*', function(){ + var url = 'git://github.com/jamesor/mongoose-versioner'; + parse(url).should.equal('https://github.com/jamesor/mongoose-versioner'); + }) + + it('should support git://*.git', function(){ + var url = 'git://github.com/treygriffith/cellar.git'; + parse(url).should.equal('https://github.com/treygriffith/cellar'); + }) + + it('should support https://*', function(){ + var url = 'https://github.com/Empeeric/i18n-node'; + parse(url).should.equal('https://github.com/Empeeric/i18n-node'); + }) + + it('should support https://*.git', function(){ + var url = 'https://jpillora@github.com/banchee/tranquil.git'; + parse(url).should.equal('https://github.com/banchee/tranquil'); + }) + + it('should return undefined on failure', function(){ + var url = 'git://github.com/justgord/.git'; + assert(null == parse(url)); + }) + + it('should parse git@gist urls', function() { + var url = 'git@gist.github.com:3135914.git'; + parse(url).should.equal('https://gist.github.com/3135914') + }) + + it('should parse https://gist urls', function() { + var url = 'https://gist.github.com/3135914.git'; + parse(url).should.equal('https://gist.github.com/3135914') + }) +}) +``` diff --git a/node_modules/github-url-from-git/index.js b/node_modules/github-url-from-git/index.js new file mode 100644 index 000000000..9ccc215f0 --- /dev/null +++ b/node_modules/github-url-from-git/index.js @@ -0,0 +1,12 @@ +var re = /^(?:https?:\/\/|git:\/\/)?(?:[^@]+@)?(gist.github.com|github.com)[:\/]([^\/]+\/[^\/]+?|[0-9]+)$/ + +module.exports = function(url){ + try { + var m = re.exec(url.replace(/\.git$/, '')); + var host = m[1]; + var path = m[2]; + return 'https://' + host + '/' + path; + } catch (err) { + // ignore + } +}; diff --git a/node_modules/github-url-from-git/package.json b/node_modules/github-url-from-git/package.json new file mode 100644 index 000000000..5673fb989 --- /dev/null +++ b/node_modules/github-url-from-git/package.json @@ -0,0 +1,31 @@ +{ + "name": "github-url-from-git", + "version": "1.1.1", + "description": "Parse a github git url and return the github repo url", + "main": "index.js", + "scripts": { + "test": "mocha test.js --reporter spec --require should" + }, + "repository": "", + "keywords": [ + "github", + "git", + "url", + "parser" + ], + "author": "", + "license": "MIT", + "devDependencies": { + "better-assert": "~1.0.0", + "mocha": "~1.9.0", + "should": "~1.2.2" + }, + "readme": "\n# github-url-from-git\n\n```js\ndescribe('parse(url)', function(){\n it('should support git://*', function(){\n var url = 'git://github.com/jamesor/mongoose-versioner';\n parse(url).should.equal('https://github.com/jamesor/mongoose-versioner');\n })\n\n it('should support git://*.git', function(){\n var url = 'git://github.com/treygriffith/cellar.git';\n parse(url).should.equal('https://github.com/treygriffith/cellar');\n })\n\n it('should support https://*', function(){\n var url = 'https://github.com/Empeeric/i18n-node';\n parse(url).should.equal('https://github.com/Empeeric/i18n-node');\n })\n\n it('should support https://*.git', function(){\n var url = 'https://jpillora@github.com/banchee/tranquil.git';\n parse(url).should.equal('https://github.com/banchee/tranquil');\n })\n\n it('should return undefined on failure', function(){\n var url = 'git://github.com/justgord/.git';\n assert(null == parse(url));\n })\n\n it('should parse git@gist urls', function() {\n var url = 'git@gist.github.com:3135914.git';\n parse(url).should.equal('https://gist.github.com/3135914')\n })\n\n it('should parse https://gist urls', function() {\n var url = 'https://gist.github.com/3135914.git';\n parse(url).should.equal('https://gist.github.com/3135914')\n })\n})\n```\n", + "readmeFilename": "Readme.md", + "_id": "github-url-from-git@1.1.1", + "dist": { + "shasum": "a14903bccbd30c91ea41765ae68ba1b27a53c4d1" + }, + "_from": "github-url-from-git@1.1.1", + "_resolved": "https://registry.npmjs.org/github-url-from-git/-/github-url-from-git-1.1.1.tgz" +} diff --git a/node_modules/github-url-from-git/test.js b/node_modules/github-url-from-git/test.js new file mode 100644 index 000000000..e472302a0 --- /dev/null +++ b/node_modules/github-url-from-git/test.js @@ -0,0 +1,40 @@ + +var parse = require('./'); +var assert = require('better-assert'); + +describe('parse(url)', function(){ + it('should support git://*', function(){ + var url = 'git://github.com/jamesor/mongoose-versioner'; + parse(url).should.equal('https://github.com/jamesor/mongoose-versioner'); + }) + + it('should support git://*.git', function(){ + var url = 'git://github.com/treygriffith/cellar.git'; + parse(url).should.equal('https://github.com/treygriffith/cellar'); + }) + + it('should support https://*', function(){ + var url = 'https://github.com/Empeeric/i18n-node'; + parse(url).should.equal('https://github.com/Empeeric/i18n-node'); + }) + + it('should support https://*.git', function(){ + var url = 'https://jpillora@github.com/banchee/tranquil.git'; + parse(url).should.equal('https://github.com/banchee/tranquil'); + }) + + it('should return undefined on failure', function(){ + var url = 'git://github.com/justgord/.git'; + assert(null == parse(url)); + }) + + it('should parse git@gist urls', function() { + var url = 'git@gist.github.com:3135914.git'; + parse(url).should.equal('https://gist.github.com/3135914') + }) + + it('should parse https://gist urls', function() { + var url = 'https://gist.github.com/3135914.git'; + parse(url).should.equal('https://gist.github.com/3135914') + }) +}) diff --git a/package.json b/package.json index d092c7bdf..2a51766da 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,8 @@ "sha": "~1.2.1", "editor": "0.0.4", "child-process-close": "~0.1.1", - "npm-user-validate": "0.0.3" + "npm-user-validate": "0.0.3", + "github-url-from-git": "1.1.1" }, "bundleDependencies": [ "semver", @@ -116,7 +117,8 @@ "sha", "child-process-close", "editor", - "npm-user-validate" + "npm-user-validate", + "github-url-from-git" ], "devDependencies": { "ronn": "~0.3.6", |