-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathcli.js
146 lines (123 loc) · 3.53 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env node
'use strict'
const meow = require('meow')
const conventionalGithubReleaser = require('./index')
const resolve = require('path').resolve
const cli = meow({
help: `
Usage
conventional-github-releaser
Example
conventional-github-releaser -p angular
Options
-u, --url URL of your GitHub provider. Defaults to 'https://api.github.com/'
-t, --token Your GitHub 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
-c, --context A filepath of a javascript that is used to define template variables
-d, --draft Publishes a draft instead of a real release
Default: false
`,
flags: {
url: {
alias: 'u',
default: process.env.CONVENTIONAL_GITHUB_URL || 'https://api.github.com/',
type: 'string'
},
token: {
alias: 't',
default: process.env.CONVENTIONAL_GITHUB_RELEASER_TOKEN || process.env.GH_TOKEN || process.env.GITHUB_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'
},
draft: {
alias: 'd',
default: false,
type: 'boolean'
}
}
})
let config = {}
const flags = cli.flags
let templateContext
let gitRawCommitsOpts
let parserOpts
let writerOpts
try {
if (flags.context) {
templateContext = require(resolve(process.cwd(), flags.context))
}
if (flags.config) {
config = require(resolve(process.cwd(), flags.config))
}
if (config.gitRawCommitsOpts) {
gitRawCommitsOpts = config.gitRawCommitsOpts
}
if (config.parserOpts) {
parserOpts = config.parserOpts
}
if (config.writerOpts) {
writerOpts = config.writerOpts
}
} catch (err) {
console.error('Failed to get file. ' + err)
process.exit(1)
}
const changelogOpts = {
preset: flags.preset,
pkg: {
path: flags.pkg
},
releaseCount: flags.releaseCount,
draft: flags.draft
}
if (flags.verbose) {
changelogOpts.debug = console.info.bind(console)
changelogOpts.warn = console.warn.bind(console)
}
conventionalGithubReleaser({
url: flags.url,
token: flags.token
}, changelogOpts, templateContext, gitRawCommitsOpts, parserOpts, writerOpts, function (err, data) {
if (err) {
console.error(err.toString())
process.exit(1)
}
if (flags.verbose) {
console.log(data)
}
})