forked from cvat-ai/cvat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint-staged.config.js
39 lines (31 loc) · 1.34 KB
/
lint-staged.config.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
// lint-staged.config.js
const micromatch = require('micromatch');
function containsInPath(pattern, list) {
return list.filter((item) => micromatch.contains(item, pattern));
}
function makePattern(extension) {
return `**/*.${extension}`;
}
module.exports = (stagedFiles) => {
const eslintExtensions = ['ts', 'tsx', 'js'].map(makePattern);
const eslintFiles = micromatch(stagedFiles, eslintExtensions);
const cvatData = containsInPath('/cvat-data/', eslintFiles);
const cvatCore = containsInPath('/cvat-core/', eslintFiles);
const cvatCanvas = containsInPath('/cvat-canvas/', eslintFiles);
const cvatCanvas3d = containsInPath('/cvat-canvas3d/', eslintFiles);
const cvatUI = containsInPath('/cvat-ui/', eslintFiles);
const mapping = {};
const commands = [];
mapping['npm run precommit:cvat-ui -- '] = cvatUI.join(' ');
mapping['npm run precommit:cvat-data -- '] = cvatData.join(' ');
mapping['npm run precommit:cvat-core -- '] = cvatCore.join(' ');
mapping['npm run precommit:cvat-canvas -- '] = cvatCanvas.join(' ');
mapping['npm run precommit:cvat-canvas3d -- '] = cvatCanvas3d.join(' ');
for (const command of Object.keys(mapping)) {
const files = mapping[command];
if (files.length) {
commands.push(`${command} ${files}`);
}
}
return commands;
};