Skip to content

Commit

Permalink
✨ Add silentConsole option to silent all console output
Browse files Browse the repository at this point in the history
  • Loading branch information
kghugo committed Aug 4, 2020
1 parent bc5ab2a commit 8fd1ce3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = postcss.plugin('postcss-rfs-autopilot', ({
includedSelectors,
excludedSelectors,
includedUnits,
excludedUnits
excludedUnits,
silentConsole
}) => {
const options = {
includedRules: includedRules || [
Expand All @@ -22,7 +23,8 @@ module.exports = postcss.plugin('postcss-rfs-autopilot', ({
],
excludedSelectors: excludedSelectors || [],
includedUnits: includedUnits || ['px', 'rem'],
excludedUnits: excludedUnits || []
excludedUnits: excludedUnits || [],
silentConsole: silentConsole || false
}
// Filter includedRules here with excludedRules
// options.includedRules = filterIdenticalValues(options.includedRules, options.excludedRules)
Expand Down
5 changes: 4 additions & 1 deletion test/inclusionLogic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ describe('Test shouldBeTransformed()', function () {

const result = await postcss([
postcssRfsAutopilot(options)
]).process(css, { from: undefined }).then(result => result.css)
]).process(css, { from: undefined }).then(result => {
console.log(result)
return result.css
})

console.log(result)
done()
Expand Down
12 changes: 8 additions & 4 deletions utilities/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const isIncluded = (decl, inclusionRules) => {
return inclusionRules.some(unit => RegExp(unit).test(decl))
}

const log = (msg, msgType) => {
const log = (msg, msgType, silentConsole) => {
if (silentConsole === true) {
return
}

switch (msgType) {
case 'success':
console.log(chalk.green(msg))
Expand All @@ -29,7 +33,7 @@ const log = (msg, msgType) => {

const shouldBeTransformed = (decl, options) => {
if (hasWrappedInRFS(decl)) {
log(`${decl.parent.selector}{ ${decl.prop}: ${decl.value} } has already been wrapped in rfs()`, 'notice')
log(`${decl.parent.selector}{ ${decl.prop}: ${decl.value} } has already been wrapped in rfs()`, 'notice', options.silentConsole)
return false
}

Expand All @@ -39,12 +43,12 @@ const shouldBeTransformed = (decl, options) => {

for (const [index, value] of validationValues.entries()) {
if (!isIncluded(value, inclusionRules[index]) || isIncluded(value, exclusionRules[index])) {
log(`${decl.parent.selector}{ ${decl.prop}: ${decl.value} } has been excluded`, 'error')
log(`${decl.parent.selector}{ ${decl.prop}: ${decl.value} } has been excluded`, 'error', options.silentConsole)
return false
}
}

log(`${decl.parent.selector}{ ${decl.prop}: ${decl.value} } has been wrapped with rfs()`, 'success')
log(`${decl.parent.selector}{ ${decl.prop}: ${decl.value} } has been wrapped with rfs()`, 'success', options.silentConsole)

return true
}
Expand Down

0 comments on commit 8fd1ce3

Please sign in to comment.