-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
index.js
42 lines (35 loc) · 1008 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { relative } from 'path';
import scms from './scms';
import formatFiles from './formatFiles';
import createIgnorer from './createIgnorer';
import isSupportedExtension from './isSupportedExtension';
export default (
directory,
{
config,
since,
staged,
onFoundSinceRevision,
onFoundChangedFiles,
onWriteFile,
} = {}
) => {
const scm = scms(directory);
if (!scm) {
throw new Error('Unable to detect a source control manager.');
}
const revision = since || scm.getSinceRevision(directory, { staged });
onFoundSinceRevision && onFoundSinceRevision(scm.name, revision);
const changedFiles = scm
.getChangedFiles(directory, revision)
.filter(isSupportedExtension)
.filter(createIgnorer(directory));
onFoundChangedFiles && onFoundChangedFiles(changedFiles);
formatFiles(directory, changedFiles, {
config,
onWriteFile: file => {
onWriteFile && onWriteFile(file);
staged && scm.stageFile(directory, file);
},
});
};