-
Notifications
You must be signed in to change notification settings - Fork 34
/
cli.js
executable file
·118 lines (100 loc) · 2.89 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env node
'use strict'
const meow = require('meow')
const conventionalGitlabReleaser = require('./')
const cli = meow({
help: `
Usage
conventional-gitlab-releaser
Example
conventional-gitlab-releaser -p angular
Options
-u, --url URL of your GitLab provider. Defaults to 'https://gitlab.com/api/v4/'
-t, --token Your GitLab auth token
-p, --preset Name of the preset you want to use. Must be one of the following:
angular, atom, codemirror, ember, eslint, express, jquery, jscs or jshint
-k, --pkg A filepath of where your package.json is located
Default is the closest package.json from cwd
-r, --release-count How many releases to be generated from the latest
If 0, the whole changelog will be regenerated and the outfile will be overwritten
Default: 1
-v, --verbose Verbose output. Use this for debugging
Default: false
-n, --config A filepath of your config script
Example of a config script: https://github.com/conventional-changelog/conventional-changelog-angular/blob/master/index.js
This value is ignored if preset is specified
-c, --context A filepath of a javascript that is used to define template constntiables
`,
flags: {
url: {
alias: 'u',
default: process.env.CONVENTIONAL_GITLAB_URL || 'https://gitlab.com/api/v4/',
type: 'string'
},
token: {
alias: 't',
default: process.env.CONVENTIONAL_GITLAB_RELEASER_TOKEN,
type: 'string'
},
preset: {
alias: 'p',
type: 'string'
},
pkg: {
alias: 'k',
type: 'string'
},
releaseCount: {
alias: 'r',
default: 1,
type: 'number'
},
verbose: {
alias: 'v',
default: false,
type: 'boolean'
},
config: {
alias: 'n',
type: 'string'
},
context: {
alias: 'c',
type: 'string'
}
}
})
const flags = cli.flags
let templateContext
try {
if (flags.context) {
templateContext = require(flags.context)
}
} catch (err) {
console.error('Failed to get file. ' + err)
process.exit(1)
}
const changelogOpts = {
preset: flags.preset,
pkg: {
path: flags.pkg
},
releaseCount: flags.releaseCount,
config: flags.config
}
if (flags.verbose) {
changelogOpts.debug = console.info.bind(console)
changelogOpts.warn = console.warn.bind(console)
}
conventionalGitlabReleaser({
url: flags.url,
token: flags.token
}, changelogOpts, templateContext, function (err, data) {
if (err) {
console.error(err.toString())
process.exit(1)
}
if (flags.verbose) {
console.log(data)
}
})