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
Feature/ Support regex path names #74
Changes from 2 commits
d7617ac
eb19185
26a74b1
c34baea
21ef2fd
315bbef
cc86eaa
1ab087d
330cfd3
8468c85
baceb55
4db71a7
abaca42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,8 @@ function CleanWebpackPlugin(paths, options) { | |
// determine webpack root | ||
options.root = options.root || path.dirname(module.parent.filename); | ||
|
||
// allows for a single string entry | ||
if (typeof paths == 'string' || paths instanceof String) { | ||
// allows for a single string entry or a regular expression | ||
if (typeof paths == 'string' || paths instanceof String || paths instanceof RegExp) { | ||
paths = [paths]; | ||
} | ||
|
||
|
@@ -52,6 +52,27 @@ function CleanWebpackPlugin(paths, options) { | |
this.options = options; | ||
} | ||
|
||
/** | ||
* Gives back file paths that match the given pattern | ||
* | ||
* @param {string} root | ||
* @param {RegExp} pattern | ||
* @returns [string] | ||
*/ | ||
function resolveRegexPaths(root, pattern) { | ||
const rootChildren = fs.readdir(root); | ||
|
||
const resolvedPaths = []; | ||
|
||
rootChildren.forEach(child => { | ||
if (pattern.test(child) === true) { | ||
resolvedPaths.push(child); | ||
} | ||
}); | ||
|
||
return resolvedPaths; | ||
} | ||
|
||
var clean = function() { | ||
var _this = this; | ||
var results = []; | ||
|
@@ -86,6 +107,16 @@ var clean = function() { | |
webpackDir = upperCaseWindowsRoot(webpackDir); | ||
} | ||
|
||
// Resolve RegExp paths. | ||
_this.paths.reduce((acc, currentPath) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be assigning the result of this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, okay I'll look into it! |
||
if (path instanceof RegExp) { | ||
const resolvedPaths = resolveRegexPaths(_this.options.root, currentPath); | ||
return [...acc, ...resolvedPaths]; | ||
} | ||
return [...acc, currentPath] | ||
}, []); | ||
|
||
|
||
// preform an rm -rf on each path | ||
_this.paths.forEach(function(rimrafPath) { | ||
rimrafPath = path.resolve(_this.options.root, rimrafPath); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codebase is very ES5 right now. I believe we can maintain one style for now. We can later on rewrite the entire plugin in one go with ES6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay :D