-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from postcss/seamusleahy-implicit-components
Add implicitComponents and implicitUtilities option
- Loading branch information
Showing
7 changed files
with
185 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var path = require('path'); | ||
var minimatch = require('minimatch'); | ||
|
||
function minimatchList(path, patternList, options) { | ||
return patternList.some(function(pattern) { | ||
return minimatch(path, pattern, options) | ||
}); | ||
} | ||
|
||
/** | ||
* Check the file matches on of the globs. | ||
* | ||
* @param {string} filename - The filename to test | ||
* @param {string[]} globs - An array of glob strings to test the filename against | ||
* @return {boolean} | ||
*/ | ||
function checkGlob(filename, globs) { | ||
// PostCSS turns relative paths into absolute paths | ||
filename = path.relative(process.cwd(), filename); | ||
return minimatchList(filename, globs); | ||
} | ||
|
||
/** | ||
* @param {string[]|boolean} implicitComponentsConfig - The configuration value implicitComponents | ||
* @param {string} filename - The filename of the CSS file being checked | ||
* @returns {boolean} | ||
*/ | ||
function isImplicitComponent(implicitComponentsConfig, filename) { | ||
if (Array.isArray(implicitComponentsConfig)) { | ||
return checkGlob(filename, implicitComponentsConfig); | ||
} | ||
|
||
return Boolean(implicitComponentsConfig); | ||
} | ||
|
||
/** | ||
* @param {string[]|boolean} implicitUtilitiesConfig - The configuration value implicitUtilities | ||
* @param {string} filename - The filename of the CSS file being checked | ||
* @return {boolean} | ||
*/ | ||
function isImplicitUtilities(implicitUtilitiesConfig, filename) { | ||
if (Array.isArray(implicitUtilitiesConfig)) { | ||
return checkGlob(filename, implicitUtilitiesConfig); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
module.exports = { | ||
isImplicitComponent: isImplicitComponent, | ||
isImplicitUtilities: isImplicitUtilities, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters