|
1 | 1 | #!/usr/bin/env node
|
2 | 2 | require('babel-polyfill'); // eslint-disable-line import/no-unassigned-import
|
3 | 3 |
|
4 |
| -const format = require('@commitlint/format'); |
5 | 4 | const load = require('@commitlint/load');
|
6 | 5 | const lint = require('@commitlint/lint');
|
7 | 6 | const read = require('@commitlint/read');
|
@@ -63,6 +62,12 @@ const flags = {
|
63 | 62 | description: 'lower end of the commit range to lint; applies if edit=false',
|
64 | 63 | type: 'string'
|
65 | 64 | },
|
| 65 | + format: { |
| 66 | + alias: 'o', |
| 67 | + default: null, |
| 68 | + description: 'output format of the results', |
| 69 | + type: 'string' |
| 70 | + }, |
66 | 71 | 'parser-preset': {
|
67 | 72 | alias: 'p',
|
68 | 73 | description: 'configuration preset to use for conventional-commits-parser',
|
@@ -135,6 +140,7 @@ async function main(options) {
|
135 | 140 | const loaded = await load(getSeed(flags), loadOpts);
|
136 | 141 | const parserOpts = selectParserOpts(loaded.parserPreset);
|
137 | 142 | const opts = parserOpts ? {parserOpts} : {parserOpts: {}};
|
| 143 | + const format = loadFormatter(loaded, flags); |
138 | 144 |
|
139 | 145 | // Strip comments if reading from `.git/COMMIT_EDIT_MSG`
|
140 | 146 | if (range.edit) {
|
@@ -248,6 +254,19 @@ function selectParserOpts(parserPreset) {
|
248 | 254 | return parserPreset.parserOpts;
|
249 | 255 | }
|
250 | 256 |
|
| 257 | +function loadFormatter(config, flags) { |
| 258 | + const moduleName = flags.format || config.formatter; |
| 259 | + let modulePath; |
| 260 | + |
| 261 | + try { |
| 262 | + modulePath = require.resolve(`${moduleName}`); |
| 263 | + } catch (error) { |
| 264 | + throw new Error(`Using format ${moduleName}, but cannot find the module.`); |
| 265 | + } |
| 266 | + |
| 267 | + return require(modulePath); |
| 268 | +} |
| 269 | + |
251 | 270 | // Catch unhandled rejections globally
|
252 | 271 | process.on('unhandledRejection', (reason, promise) => {
|
253 | 272 | console.log('Unhandled Rejection at: Promise ', promise, ' reason: ', reason);
|
|
0 commit comments