UNPKG

1.54 kBJavaScriptView Raw
1const fs = require('fs');
2const path = require('path');
3const ignore = require('ignore');
4const findup = require('findup-sync');
5
6const ignoreList = [
7 'hubspot.config.yml',
8 'hubspot.config.yaml',
9 'node_modules', // dependencies
10 '.*', // hidden files/folders
11 '*.log', // Error log for npm
12 '*.swp', // Swap file for vim state
13
14 // # macOS
15 'Icon\\r', // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop
16 '__MACOSX', // Resource fork
17
18 // # Linux
19 '~', // Backup file
20
21 // # Windows
22 'Thumbs.db', // Image file cache
23 'ehthumbs.db', // Folder config file
24 'Desktop.ini', // Stores custom folder attributes
25 '@eaDir', // Synology Diskstation "hidden" folder where the server stores thumbnails
26];
27
28const ignoreRules = ignore().add(ignoreList);
29
30let configPath = null;
31let loaded = false;
32function loadIgnoreConfig() {
33 if (loaded) {
34 return;
35 }
36 const file = findup('.hsignore');
37 if (file) {
38 if (fs.existsSync(file)) {
39 ignoreRules.add(fs.readFileSync(file).toString());
40 configPath = path.dirname(file);
41 }
42 }
43 loaded = true;
44}
45
46function shouldIgnoreFile(file, cwd) {
47 loadIgnoreConfig();
48 const relativeTo = configPath || cwd;
49 return ignoreRules.ignores(path.relative(relativeTo, file));
50}
51
52function createIgnoreFilter(cwd) {
53 loadIgnoreConfig();
54 return file => !shouldIgnoreFile(file, cwd);
55}
56
57function ignoreFile(filePath) {
58 ignoreRules.add(filePath);
59}
60
61module.exports = {
62 loadIgnoreConfig,
63 shouldIgnoreFile,
64 createIgnoreFilter,
65 ignoreFile,
66};