Skip to content

Commit 0a11c72

Browse files
committed
feat: support multiple inputs
1 parent b9351a0 commit 0a11c72

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

.conventional-changelog-lintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"always",
3737
"lowerCase"
3838
],
39-
"scope-empty": [2,
39+
"scope-empty": [0,
4040
"never"
4141
],
4242
"scope-max-length": [0,
@@ -69,7 +69,7 @@
6969
"always",
7070
"lowerCase"
7171
],
72-
"body-empty": [1,
72+
"body-empty": [0,
7373
"never"
7474
],
7575
"body-leading-blank": [1,

source/cli.js

+46-26
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
// polyfills
22
import 'babel-polyfill';
33

4+
// core modules
5+
import {
6+
readFile as readFileNodeback
7+
} from 'fs';
8+
49
// npm modules
510
import chalk from 'chalk';
11+
import denodeify from 'denodeify';
612
import meow from 'meow';
713
import merge from 'lodash.merge';
814
import pick from 'lodash.pick';
915
import stdin from 'get-stdin';
1016
import rc from 'rc';
1117

18+
// local modules
1219
import lint from './';
13-
14-
// Import package for meta data
1520
import pkg from '../package';
1621

22+
// denodeifications
23+
const readFile = denodeify(readFileNodeback);
24+
1725
/**
1826
* Behavioural rules
1927
*/
2028
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
2233
};
2334

2435
// Init meow 😸cli
@@ -57,6 +68,12 @@ const cli = meow({
5768
// TODO: move this to an own module
5869
async function getMessages(settings) {
5970
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+
6077
throw new Error(`Reading from git history not supported yet.`);
6178
}
6279

@@ -121,34 +138,37 @@ async function main(options) {
121138
const fromStdin = rules.fromStdin(raw, flags);
122139

123140
const input = fromStdin ?
124-
await stdin() :
141+
[await stdin()] :
125142
await getMessages(
126143
pick(flags, ['edit', 'from', 'to'])
127144
);
128145

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+
}
148167

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+
}));
152172
}
153173

154174
// Start the engine

0 commit comments

Comments
 (0)