/
pretty-quick.js
executable file
·60 lines (50 loc) · 1.5 KB
/
pretty-quick.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
'use strict';
const chalk = require('chalk');
const mri = require('mri');
const prettyQuick = require('..').default;
const args = mri(process.argv.slice(2));
const prettyQuickResult = prettyQuick(
process.cwd(),
Object.assign({}, args, {
onFoundSinceRevision: (scm, revision) => {
console.log(
`🔍 Finding changed files since ${chalk.bold(
scm
)} revision ${chalk.bold(revision)}.`
);
},
onFoundChangedFiles: changedFiles => {
console.log(
`🎯 Found ${chalk.bold(changedFiles.length)} changed ${
changedFiles.length === 1 ? 'file' : 'files'
}.`
);
},
onPartiallyStagedFile: file => {
console.log(`✗ Found ${chalk.bold('partially')} staged file ${file}.`);
},
onWriteFile: file => {
console.log(`✍️ Fixing up ${chalk.bold(file)}.`);
},
onExamineFile: file => {
console.log(`🔍 Examining ${chalk.bold(file)}.`);
},
})
);
if (prettyQuickResult.success) {
console.log('✅ Everything is awesome!');
} else {
if (prettyQuickResult.errors.indexOf('PARTIALLY_STAGED_FILE') !== -1) {
console.log(
'✗ Partially staged files were fixed up.' +
` ${chalk.bold('Please update stage before committing')}.`
);
}
if (prettyQuickResult.errors.indexOf('BAIL_ON_WRITE') !== -1) {
console.log(
'✗ File had to be prettified and prettyQuick was set to bail mode.'
);
}
process.exit(1); // ensure git hooks abort
}