1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict'
|
4 |
|
5 | const meow = require('meow')
|
6 | const conventionalGitlabReleaser = require('./')
|
7 |
|
8 | const cli = meow({
|
9 | help: `
|
10 | Usage
|
11 | conventional-gitlab-releaser
|
12 |
|
13 | Example
|
14 | conventional-gitlab-releaser -p angular
|
15 |
|
16 | Options
|
17 | -u, --url URL of your GitLab provider. Defaults to 'https://gitlab.com'
|
18 | -t, --token Your GitLab auth token
|
19 |
|
20 | -p, --preset Name of the preset you want to use. Must be one of the following:
|
21 | angular, atom, codemirror, ember, eslint, express, jquery, jscs or jshint
|
22 |
|
23 | -k, --pkg A filepath of where your package.json is located
|
24 | Default is the closest package.json from cwd
|
25 |
|
26 | -r, --release-count How many releases to be generated from the latest
|
27 | If 0, the whole changelog will be regenerated and the outfile will be overwritten
|
28 | Default: 1
|
29 |
|
30 | -v, --verbose Verbose output. Use this for debugging
|
31 | Default: false
|
32 |
|
33 | -n, --config A filepath of your config script
|
34 | Example of a config script: https://github.com/conventional-changelog/conventional-changelog-angular/blob/master/index.js
|
35 | This value is ignored if preset is specified
|
36 |
|
37 | -c, --context A filepath of a javascript that is used to define template constntiables
|
38 | `
|
39 | }, {
|
40 | alias: {
|
41 | u: 'url',
|
42 | t: 'token',
|
43 | p: 'preset',
|
44 | k: 'pkg',
|
45 | r: 'releaseCount',
|
46 | v: 'verbose',
|
47 | n: 'config',
|
48 | c: 'context'
|
49 | }
|
50 | })
|
51 |
|
52 | const flags = cli.flags
|
53 |
|
54 | let templateContext
|
55 |
|
56 | try {
|
57 | if (flags.context) {
|
58 | templateContext = require(flags.context)
|
59 | }
|
60 | } catch (err) {
|
61 | console.error('Failed to get file. ' + err)
|
62 | process.exit(1)
|
63 | }
|
64 |
|
65 | const changelogOpts = {
|
66 | preset: flags.preset,
|
67 | pkg: {
|
68 | path: flags.pkg
|
69 | },
|
70 | releaseCount: flags.releaseCount,
|
71 | config: flags.config
|
72 | }
|
73 |
|
74 | if (flags.verbose) {
|
75 | changelogOpts.debug = console.info.bind(console)
|
76 | changelogOpts.warn = console.warn.bind(console)
|
77 | }
|
78 |
|
79 | conventionalGitlabReleaser({
|
80 | url: flags.url || process.env.CONVENTIONAL_GITLAB_URL || 'https://gitlab.com',
|
81 | token: flags.token || process.env.CONVENTIONAL_GITLAB_RELEASER_TOKEN
|
82 | }, changelogOpts, templateContext, function (err, data) {
|
83 | if (err) {
|
84 | console.error(err.toString())
|
85 | process.exit(1)
|
86 | }
|
87 |
|
88 | if (flags.verbose) {
|
89 | console.log(data)
|
90 | }
|
91 | })
|