Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADDED: configuration entry for the regExp #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,29 @@ To install:
3. Click the "Install from URL..." button
4. Paste (or enter) `https://github.com/gruehle/exclude-folders` and click "Install"

By default, this extension excludes all `node_modules` folders. If you want to exclude additional folders, edit the regular expression on line 41 of `main.js`. For example, if you want to exclude all items that contain the words `node_modules`, `bin`, and `componenets`, use:
By default, this extension excludes all `node_modules` folders. If you want to exclude additional folders, open the preferences file (menu `debug -> open preferences file`), locate the entry called "exclude-folders" and enter any valid regExp. For example, if you want to exclude all items that contain the words `node_modules`, `bin`, and `componenets`, use:

```js
return !name.match(/node_modules|bin|components/);
```json
{
"exclude-folders.regExp": "node_modules|bin|components"
}
```

Note that this will match these words *anywhere* in the folder *or* file name. For example, if you have a folder named "my-components", it will also be excluded. You can use the `^` and `$` anchors to ensure that the name must be a complete match:


```js
return !name.match(/^(node_modules|bin|components)$/);
```json
{
"exclude-folders.regExp": "^(node_modules|bin|components)$"
}
```

Matching is case sensitive by default. Add `i` to the end to make it case-insensitive:
Matching is case sensitive by default. Add `i` to the `exclude-folders.flags` node:


```js
return !name.match(/^(node_modules|bin|components)$/i);
```json
"exclude-folders.regExp": "^(node_modules|bin|components)$",
"exclude-folders.flags": "i"
```


Expand Down
66 changes: 50 additions & 16 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,53 @@

define(function (require, exports, module) {
"use strict";

var FileSystem = brackets.getModule("filesystem/FileSystem");

var _oldFilter = FileSystem._FileSystem.prototype._indexFilter;

FileSystem._FileSystem.prototype._indexFilter = function (path, name) {
// Call old filter
var result = _oldFilter.apply(this, arguments);

if (!result) {
return false;
}

return !name.match(/node_modules/);
};
});

var EXTENSION_NAME = "exclude-folders",
AppInit = brackets.getModule('utils/AppInit'),
FileSystem = brackets.getModule("filesystem/FileSystem"),
prefs = brackets.getModule("preferences/PreferencesManager").getExtensionPrefs(EXTENSION_NAME);

var ExcludeFolders = {
init: function() {
if (typeof prefs.get('regExp') === 'undefined') {
this.createPreferences();
}

prefs.on('change', ExcludeFolders.getPreferences);

this.getPreferences();
this.installFilter();
},
createPreferences: function() {
prefs.definePreference('regExp', 'string', 'node_modules');
prefs.definePreference('flags', 'string', '');

prefs.set('regExp', 'node_modules');
prefs.set('flags', '');

prefs.save();
},
getPreferences: function() {
ExcludeFolders.regExp = new RegExp(prefs.get('regExp'), prefs.get('flags'));
},
installFilter: function() {
var _oldFilter = FileSystem._FileSystem.prototype._indexFilter;

FileSystem._FileSystem.prototype._indexFilter = function (path, name) {
// Call old filter
var result = _oldFilter.apply(this, arguments),
fullPath = path + name;

if (!result) {
return false;
}

return !fullPath.match(ExcludeFolders.regExp);
};
}
};

AppInit.appReady(function() {
ExcludeFolders.init();
});
});