Created
August 18, 2014 06:58
-
-
Save hail2u/35332245d3f47100d04e to your computer and use it in GitHub Desktop.
David DMのページをなんとなく開いてくれるNode.jsスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// $ david-dm | |
// $ david-dm [<path>] | |
'use strict'; | |
var exec = require('child_process').exec; | |
var fs = require('fs'); | |
var path = require('path'); | |
if (process.argv.length > 2) { | |
process.chdir(process.argv[2]); | |
} | |
exec('git rev-parse --show-toplevel', function (err, stdout, stderr) { | |
if (err) { | |
throw err; | |
} | |
var gitroot = path.normalize(stdout.replace(/[\r\n]*$/, '')); | |
var p = JSON.parse(fs.readFileSync(path.join(gitroot, 'package.json'), 'utf-8')); | |
if (!p.repository || p.repository.type !== 'git' || !/\bgithub\.com\//.test(p.repository.url)) { | |
throw new Error('Cannot find GitHub repository URL'); | |
} | |
var giturl = p.repository.url; | |
var davidurl = 'https://david-dm.org/' + giturl.replace(/^.*?github\.com\/(.*?)\.git$/, '$1'); | |
exec('open ' + davidurl); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment