|
1 | 1 | // polyfills
|
2 | 2 | import 'babel-polyfill';
|
3 | 3 |
|
| 4 | +// core modules |
| 5 | +import { |
| 6 | + readFile as readFileNodeback |
| 7 | +} from 'fs'; |
| 8 | + |
4 | 9 | // npm modules
|
5 | 10 | import chalk from 'chalk';
|
| 11 | +import denodeify from 'denodeify'; |
6 | 12 | import meow from 'meow';
|
7 | 13 | import merge from 'lodash.merge';
|
8 | 14 | import pick from 'lodash.pick';
|
9 | 15 | import stdin from 'get-stdin';
|
10 | 16 | import rc from 'rc';
|
11 | 17 |
|
| 18 | +// local modules |
12 | 19 | import lint from './';
|
13 |
| - |
14 |
| -// Import package for meta data |
15 | 20 | import pkg from '../package';
|
16 | 21 |
|
| 22 | +// denodeifications |
| 23 | +const readFile = denodeify(readFileNodeback); |
| 24 | + |
17 | 25 | /**
|
18 | 26 | * Behavioural rules
|
19 | 27 | */
|
20 | 28 | const rules = {
|
21 |
| - fromStdin: (input, settings) => input.length === 0 && settings.from === null && settings.to === null |
| 29 | + fromStdin: (input, settings) => input.length === 0 && |
| 30 | + settings.from === null && |
| 31 | + settings.to === null && |
| 32 | + settings.edit === null |
22 | 33 | };
|
23 | 34 |
|
24 | 35 | // Init meow 😸cli
|
@@ -57,6 +68,12 @@ const cli = meow({
|
57 | 68 | // TODO: move this to an own module
|
58 | 69 | async function getMessages(settings) {
|
59 | 70 | const {from, to, edit} = settings;
|
| 71 | + |
| 72 | + if (edit) { |
| 73 | + const editFile = await readFile(`.git/COMMIT_EDITMSG`); |
| 74 | + return [editFile.toString('utf-8')]; |
| 75 | + } |
| 76 | + |
60 | 77 | throw new Error(`Reading from git history not supported yet.`);
|
61 | 78 | }
|
62 | 79 |
|
@@ -121,34 +138,37 @@ async function main(options) {
|
121 | 138 | const fromStdin = rules.fromStdin(raw, flags);
|
122 | 139 |
|
123 | 140 | const input = fromStdin ?
|
124 |
| - await stdin() : |
| 141 | + [await stdin()] : |
125 | 142 | await getMessages(
|
126 | 143 | pick(flags, ['edit', 'from', 'to'])
|
127 | 144 | );
|
128 | 145 |
|
129 |
| - const results = lint(input, { |
130 |
| - preset: await require(`conventional-changelog-${flags.preset}`), |
131 |
| - configuration: getConfiguration('conventional-changelog-lint', { |
132 |
| - prefix: `conventional-changelog-lint-config` |
133 |
| - }) |
134 |
| - }); |
135 |
| - |
136 |
| - const formatted = format(results, { |
137 |
| - color: flags.color, |
138 |
| - signs: [' ', '⚠', '✖'], |
139 |
| - colors: ['white', 'yellow', 'red'] |
140 |
| - }); |
141 |
| - |
142 |
| - if (!flags.quiet) { |
143 |
| - console.log( |
144 |
| - formatted |
145 |
| - .join('\n') |
146 |
| - ); |
147 |
| - } |
| 146 | + return Promise.all(input |
| 147 | + .map(async commit => { |
| 148 | + const report = lint(commit, { |
| 149 | + preset: await require(`conventional-changelog-${flags.preset}`), |
| 150 | + configuration: getConfiguration('conventional-changelog-lint', { |
| 151 | + prefix: `conventional-changelog-lint-config` |
| 152 | + }) |
| 153 | + }); |
| 154 | + |
| 155 | + const formatted = format(report, { |
| 156 | + color: flags.color, |
| 157 | + signs: [' ', '⚠', '✖'], |
| 158 | + colors: ['white', 'yellow', 'red'] |
| 159 | + }); |
| 160 | + |
| 161 | + if (!flags.quiet) { |
| 162 | + console.log( |
| 163 | + formatted |
| 164 | + .join('\n') |
| 165 | + ); |
| 166 | + } |
148 | 167 |
|
149 |
| - if (results.errors.length > 0) { |
150 |
| - throw new Error(formatted[formatted.length - 1]); |
151 |
| - } |
| 168 | + if (report.errors.length > 0) { |
| 169 | + throw new Error(formatted[formatted.length - 1]); |
| 170 | + } |
| 171 | + })); |
152 | 172 | }
|
153 | 173 |
|
154 | 174 | // Start the engine
|
|
0 commit comments