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/api/v4/'
|
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 | flags: {
|
40 | url: {
|
41 | alias: 'u',
|
42 | default: process.env.CONVENTIONAL_GITLAB_URL || 'https://gitlab.com/api/v4/',
|
43 | type: 'string'
|
44 | },
|
45 | token: {
|
46 | alias: 't',
|
47 | default: process.env.CONVENTIONAL_GITLAB_RELEASER_TOKEN,
|
48 | type: 'string'
|
49 | },
|
50 | preset: {
|
51 | alias: 'p',
|
52 | type: 'string'
|
53 | },
|
54 | pkg: {
|
55 | alias: 'k',
|
56 | type: 'string'
|
57 | },
|
58 | releaseCount: {
|
59 | alias: 'r',
|
60 | default: 1,
|
61 | type: 'number'
|
62 | },
|
63 | verbose: {
|
64 | alias: 'v',
|
65 | default: 'false',
|
66 | type: 'boolean'
|
67 | },
|
68 | config: {
|
69 | alias: 'n',
|
70 | type: 'string'
|
71 | },
|
72 | context: {
|
73 | alias: 'c',
|
74 | type: 'string'
|
75 | }
|
76 | }
|
77 | })
|
78 |
|
79 | const flags = cli.flags
|
80 |
|
81 | let templateContext
|
82 |
|
83 | try {
|
84 | if (flags.context) {
|
85 | templateContext = require(flags.context)
|
86 | }
|
87 | } catch (err) {
|
88 | console.error('Failed to get file. ' + err)
|
89 | process.exit(1)
|
90 | }
|
91 |
|
92 | const changelogOpts = {
|
93 | preset: flags.preset,
|
94 | pkg: {
|
95 | path: flags.pkg
|
96 | },
|
97 | releaseCount: flags.releaseCount,
|
98 | config: flags.config
|
99 | }
|
100 |
|
101 | if (flags.verbose) {
|
102 | changelogOpts.debug = console.info.bind(console)
|
103 | changelogOpts.warn = console.warn.bind(console)
|
104 | }
|
105 |
|
106 | conventionalGitlabReleaser({
|
107 | url: flags.url,
|
108 | token: flags.token
|
109 | }, changelogOpts, templateContext, function (err, data) {
|
110 | if (err) {
|
111 | console.error(err.toString())
|
112 | process.exit(1)
|
113 | }
|
114 |
|
115 | if (flags.verbose) {
|
116 | console.log(data)
|
117 | }
|
118 | })
|