-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to postcss 7, refactored code to current plugin boilerplate
closes #15
- Loading branch information
Showing
9 changed files
with
3,786 additions
and
1,049 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
language: node_js | ||
cache: yarn | ||
node_js: | ||
- node | ||
- "8" | ||
- "6" | ||
- "4" | ||
install: | ||
- YARN_IGNORE_ENGINES=true yarn |
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 |
---|---|---|
@@ -1,33 +1,36 @@ | ||
'use strict'; | ||
var eslint = require('gulp-eslint') | ||
var gulp = require('gulp') | ||
var jest = require('gulp-jest').default | ||
|
||
const eslint = require('gulp-eslint'); | ||
const mocha = require('gulp-mocha'); | ||
const gulp = require('gulp'); | ||
var files = ['index.js', 'test/*.js', 'gulpfile.js'] | ||
|
||
let files = ['index.js', 'test/*.js', 'gulpfile.js']; | ||
function lintTask (cb) { | ||
gulp.src(files) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()) | ||
cb() | ||
} | ||
|
||
function lintTask(cb) { | ||
function lintWatchTask (cb) { | ||
gulp.src(files) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()); | ||
cb(); | ||
cb() | ||
} | ||
|
||
function testTask(cb) { | ||
function testTask (cb) { | ||
gulp.src('test/*.js', { read: false }) | ||
.pipe(mocha()); | ||
cb(); | ||
.pipe(jest()) | ||
cb() | ||
} | ||
|
||
const defaultTask = gulp.series(lintTask, testTask); | ||
var defaultTask = gulp.series(lintTask, testTask) | ||
|
||
function watchTask(cb) { | ||
gulp.watch(files, defaultTask); | ||
cb(); | ||
function watchTask (cb) { | ||
gulp.watch(files, gulp.series(lintWatchTask, testTask)) | ||
cb() | ||
} | ||
|
||
const devTask = gulp.series(defaultTask, watchTask); | ||
|
||
exports.default = defaultTask; | ||
exports.dev = devTask; | ||
exports.default = defaultTask | ||
exports.watch = gulp.series(lintWatchTask, testTask, watchTask) |
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 |
---|---|---|
@@ -1,36 +1,35 @@ | ||
'use strict'; | ||
const postcss = require('postcss'); | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
var postcss = require('postcss') | ||
var escapeStringRegexp = require('escape-string-regexp') | ||
|
||
let plugin = postcss.plugin('postcss-selector-prefix', (prefix) => { | ||
return (root) => { | ||
root.walkRules((rule) => { | ||
var plugin = postcss.plugin('postcss-selector-prefix', function (prefix) { | ||
return function (root) { | ||
root.walkRules(function (rule) { | ||
// don't touch @keyframes children | ||
if (rule.parent && rule.parent.name === 'keyframes') { | ||
return; | ||
return | ||
} | ||
rule.selectors = rule.selectors.map((selector) => { | ||
rule.selectors = rule.selectors.map(function (selector) { | ||
// replace combinator selectors that can't be prefixed. | ||
selector = selector.replace( | ||
/^html\.body\.|^html\.|^body\./, prefix + '.' | ||
); | ||
) | ||
|
||
// replace descendant combinators that can't be prefixed. | ||
selector = selector.replace(/^body$|^html$/, prefix); | ||
selector = selector.replace(/^body$|^html$/, prefix) | ||
|
||
// create prefix regex. | ||
let escapedPrefix = escapeStringRegexp(prefix); | ||
let re = new RegExp('^' + escapedPrefix); | ||
var escapedPrefix = escapeStringRegexp(prefix) | ||
var re = new RegExp('^' + escapedPrefix) // eslint-disable-line security/detect-non-literal-regexp | ||
|
||
// don't prefix the already prefixed. | ||
if (selector.match(re)) { | ||
return selector; | ||
return selector | ||
} else { | ||
return prefix + ' ' + selector; | ||
return prefix + ' ' + selector | ||
} | ||
}); | ||
}); | ||
}; | ||
}); | ||
}) | ||
}) | ||
} | ||
}) | ||
|
||
module.exports = plugin; | ||
module.exports = plugin |
Oops, something went wrong.