-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
executable file
·90 lines (73 loc) · 2.12 KB
/
index.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
#!/usr/bin/env node
// Packages
const SaveLocal = require('save-local')
const gitLabels = require('git-labels')
const meow = require('meow')
const shoutSuccess = require('shout-success')
const shoutError = require('shout-error')
const chalk = require('chalk')
const inquirer = require('inquirer')
const updateNotifier = require('update-notifier')
const loadJsonFile = require('load-json-file')
const saveLocal = new SaveLocal('git-labels-store')
const cli = meow(
`
Usage:
$ git-labels <project-name> create new labels to github project
$ git-labels --auth github authentication
$ git-labels --file labels.json import custom labels
Example:
$ git-labels bukinoshita/git-labels
$ git-labels --auth
$ git-labels --file labels.json
Options:
-a, --auth github authentication to be able to create labels
-f, --file import custom labels
-h, --help show help options
-v, --version show version
`,
{
alias: {
a: 'auth',
f: 'file',
h: 'help',
v: 'version'
}
}
)
updateNotifier({ pkg: cli.pkg }).notify()
async function run() {
await saveLocal.init()
const { flags, input } = cli
if (flags.auth) {
const { token } = await inquirer.prompt([
{
message: 'Your access token',
name: 'token'
}
])
return saveLocal.set({ name: 'token', value: token })
}
const project = input[0]
if (project) {
const token = await saveLocal.get('token')
if (!token) {
return shoutError(
`You don't have an access token. Please, create at https://github.com/settings/tokens/new and run ${chalk.bold(
'$ git-labels --auth'
)}.`
)
}
const labels = flags.file ? loadJsonFile.sync(flags.file) : undefined
try {
await gitLabels({ project, labels, token })
return shoutSuccess(
`Labels created. Check on https://github.com/${project}/labels`
)
} catch (error) {
return shoutError(error)
}
}
cli.showHelp()
}
run()