-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.js
93 lines (85 loc) · 2.04 KB
/
cli.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env node
const meow = require('meow')
const fs = require('mz/fs')
const path = require('path')
const fn = require('./src/index')
const gitRemoteOriginUrl = require('git-remote-origin-url')
const gitRemoteUpstreamUrl = require('git-remote-upstream-url')
const cli = meow({
'help': `
Usage
$ build-a-space <input> [opts]
Options
-f, --fork Create and use a fork instead of pushing to a branch
-t, --test Don't open issues or create pull requests
-c, --config The path to a configuration file
-b, --branch The default branch to use instead of 'master'
--email The email for the Code of Conduct
--licensee The person to license the repository to
--travis Edit the travis file
--open Open the PR url afterwards
Examples
$ build-a-space mntnr/build-a-space
`,
'flags': {
'help': {
type: 'boolean',
alias: 'h'
},
'fork': {
type: 'boolean',
alias: 'f'
},
'test': {
type: 'boolean',
alias: 't'
},
'config': {
type: 'string',
alias: 'c'
},
'branch': {
type: 'string',
alias: 'b'
},
'email': {
type: 'string'
},
'licensee': {
type: 'string'
},
'travis': {
type: 'boolean',
default: false
},
'open': {
type: 'boolean',
defaul: false
},
'version': {
type: 'boolean',
alias: 'v'
}
}
})
// TODO Make this into it's own module, gh-get-shortname
function getRepoFromConfig () {
return gitRemoteUpstreamUrl()
.catch(() => gitRemoteOriginUrl())
.then(res => res.match(/([^/:]+\/[^/.]+)(\.git)?$/)[1])
}
async function getConfig (configPath) {
if (configPath) {
let config = await fs.readFileSync(path.join(__dirname, configPath))
.toString('utf8')
return JSON.parse(config)
}
}
async function letsGo () {
console.log('')
const repoName = cli.input[0] || await getRepoFromConfig()
Object.assign(cli.flags, await getConfig(cli.flags.config))
await fn(repoName, cli.flags)
console.log('')
}
letsGo()