-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgad.js
35 lines (30 loc) · 1.33 KB
/
gad.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
const { execSync } = require('child_process');
const { homedir } = require('os');
const minimist = require('minimist');
const GithubAgileDashboard = require('./src/GithubAgileDashboard');
const { red } = require('./src/Util/colors');
function lookup(command) { try { return execSync(command).toString().trim(); } catch (error) { return ''; } }
function remote(url) { return (new RegExp('[email protected]:(.+)\\/(.+)\\.git', 'ig').exec(url) || new Array(3).fill(null)).slice(1); }
process.on('uncaughtException', function onError(error) { console.error(red(error.message)); process.exit(1); });
const [defaultOwner, defaultRepo] = remote(lookup('git -C . config --get remote.origin.url'));
const { owner, repo, user, password, cacheDir, _: command} = minimist(process.argv.slice(2), {
stopEarly: true,
default: {
owner: defaultOwner,
repo: defaultRepo,
user: lookup('git config --global github.user') || process.env.USER,
password: lookup('git config --global github.token'),
cacheDir: `${homedir()}/.gad/cache`
},
alias: {
o: 'owner',
r: 'repo',
u: 'user',
p: 'password',
t: 'password',
token: 'password',
c: 'cacheDir',
}
});
module.exports = new GithubAgileDashboard(owner, repo, user, password, cacheDir, command.join(' '));