-
Notifications
You must be signed in to change notification settings - Fork 2
/
ignoreRules.js
100 lines (86 loc) · 2.51 KB
/
ignoreRules.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const fs = require('fs');
const path = require('path');
const ignore = require('ignore');
const findup = require('findup-sync');
const ignoreList = [
'fields.output.json',
'hubspot.config.yml',
'hubspot.config.yaml',
'node_modules', // dependencies
'.*', // hidden files/folders
'*.log', // Error log for npm
'*.swp', // Swap file for vim state
'.env', // Dotenv file
// # macOS
'Icon\\r', // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop
'__MACOSX', // Resource fork
// # Linux
'~', // Backup file
// # Emacs
'*~', // Backup file
// # Windows
'Thumbs.db', // Image file cache
'ehthumbs.db', // Folder config file
'Desktop.ini', // Stores custom folder attributes
'@eaDir', // Synology Diskstation "hidden" folder where the server stores thumbnails
];
const ignoreRules = ignore().add(ignoreList);
let searchDomain = null;
let loaded = false;
/**
* @deprecated
* Use the corresponding export from @hubspot/local-dev-lib
* https://github.com/HubSpot/hubspot-local-dev-lib
*/
function loadIgnoreConfig(isInProject = false) {
if (loaded) {
return;
}
// Temporary solution to improve serverless beta: https://git.hubteam.com/HubSpot/cms-devex-super-repo/issues/2
// Do not do this when in a developer project b/c we want the package-lock.json file uploaded.
if (!isInProject) {
ignoreRules.add('package-lock.json');
}
const file = findup('.hsignore');
if (file) {
if (fs.existsSync(file)) {
ignoreRules.add(fs.readFileSync(file).toString());
searchDomain = path.dirname(file);
}
}
loaded = true;
}
/**
* @deprecated
* Use the corresponding export from @hubspot/local-dev-lib
* https://github.com/HubSpot/hubspot-local-dev-lib
*/
function shouldIgnoreFile(file, isInProject) {
loadIgnoreConfig(isInProject);
const relativeTo = searchDomain || '/';
const relativePath = path.relative(relativeTo, file);
return !!relativePath && ignoreRules.ignores(relativePath);
}
/**
* @deprecated
* Use the corresponding export from @hubspot/local-dev-lib
* https://github.com/HubSpot/hubspot-local-dev-lib
*/
function createIgnoreFilter(isInProject) {
loadIgnoreConfig(isInProject);
return file => !shouldIgnoreFile(file);
}
/**
* @deprecated
* Use the corresponding export from @hubspot/local-dev-lib
* https://github.com/HubSpot/hubspot-local-dev-lib
*/
function ignoreFile(filePath) {
ignoreRules.add(filePath);
}
module.exports = {
loadIgnoreConfig,
shouldIgnoreFile,
createIgnoreFilter,
ignoreFile,
};