├── .gitignore ├── .gitattributes ├── tests ├── fixtures │ ├── error.css │ ├── style.css │ ├── good.css │ └── multiple.css └── test.js ├── .travis.yml ├── .editorconfig ├── .jshintrc ├── package.json ├── LICENSE ├── index.js └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /tests/fixtures/error.css: -------------------------------------------------------------------------------- 1 | body { 2 | 3 | { 4 | 5 | {} 6 | 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /tests/fixtures/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #ffffff; 3 | } 4 | h1 { 5 | color: #fffffa; 6 | } 7 | -------------------------------------------------------------------------------- /tests/fixtures/good.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: blue; 3 | } 4 | 5 | h1 { 6 | color: violet; 7 | } 8 | -------------------------------------------------------------------------------- /tests/fixtures/multiple.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #ffffff; 3 | } 4 | h1 { 5 | color: #fffffa; 6 | } 7 | h2 { 8 | color: #fff; 9 | } 10 | h3 { 11 | color: blue; 12 | } 13 | h4 { 14 | color: white; 15 | } 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '0.10' 5 | - '0.12' 6 | - '0.13' 7 | - 'iojs' 8 | matrix: 9 | fast_finish: true 10 | allow_failures: 11 | - node_js: '0.13' 12 | notifications: 13 | email: 14 | on_success: never 15 | on_failure: always 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | 8 | indent_style = space 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | 14 | [*.{js,json,html,jade,md}] 15 | indent_size = 4 16 | 17 | [*.js] 18 | jslint_happy = true 19 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 4, 10 | "latedef": true, 11 | "newcap": true, 12 | "noarg": true, 13 | "quotmark": "single", 14 | "regexp": true, 15 | "undef": true, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-colorguard", 3 | "version": "1.1.0", 4 | "description": "Keep a watchful eye on your css colors", 5 | "repository": "pgilad/gulp-colorguard", 6 | "license": "MIT", 7 | "author": { 8 | "name": "Gilad Peleg", 9 | "email": "giladp007@gmail.com", 10 | "url": "http://giladpeleg.com" 11 | }, 12 | "main": "index.js", 13 | "files": [ 14 | "index.js" 15 | ], 16 | "engines": { 17 | "node": ">=0.10.0" 18 | }, 19 | "scripts": { 20 | "test": "mocha -R spec ./tests/*.js", 21 | "watch": "mocha -R spec -w ./tests/*.js" 22 | }, 23 | "keywords": [ 24 | "gulpplugin", 25 | "colorguard", 26 | "css", 27 | "code", 28 | "style", 29 | "validate", 30 | "lint", 31 | "check", 32 | "checker" 33 | ], 34 | "dependencies": { 35 | "colorguard": "^0.3.0", 36 | "gulp-util": "^3.0.4", 37 | "through2": "^0.6.5" 38 | }, 39 | "devDependencies": { 40 | "expect.js": "*", 41 | "mocha": "*" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Gilad Peleg (giladpeleg.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var gutil = require('gulp-util'); 3 | var through = require('through2'); 4 | var colorguard = require('colorguard'); 5 | 6 | var pluginName = 'gulp-colorguard'; 7 | var PluginError = gutil.PluginError; 8 | 9 | var logNoCollisions = function (filePath) { 10 | gutil.log(gutil.colors.magenta(filePath), 'has no css color collisions'); 11 | }; 12 | 13 | module.exports = function (options) { 14 | options = options || {}; 15 | var logOk = Boolean(options.logOk); 16 | delete options.logOk; 17 | 18 | return through.obj(function (file, enc, cb) { 19 | if (file.isNull()) { 20 | cb(null, file); 21 | return; 22 | } 23 | if (file.isStream()) { 24 | cb(new PluginError(pluginName, 'Streaming not supported')); 25 | return; 26 | } 27 | var results; 28 | try { 29 | results = colorguard.inspect(file.contents.toString(), options); 30 | } catch (err) { 31 | err.message = pluginName + ': ' + err.message; 32 | cb(new PluginError(pluginName, err)); 33 | return; 34 | } 35 | 36 | if (!results || !results.collisions) { 37 | if (logOk) { 38 | logNoCollisions(file.path); 39 | } 40 | } else { 41 | results.collisions.forEach(function (err) { 42 | this.emit('error', new PluginError(pluginName, gutil.colors.magenta(file.path) + ': ' + err.message, { 43 | showStack: false 44 | })); 45 | }, this); 46 | } 47 | cb(null, file); 48 | }); 49 | }; 50 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # [gulp](https://github.com/wearefractal/gulp)-colorguard 2 | > Keep a watchful eye on your css colors. 3 | 4 | [![NPM Version](http://img.shields.io/npm/v/gulp-colorguard.svg?style=flat)](https://npmjs.org/package/gulp-colorguard) 5 | [![NPM Downloads](http://img.shields.io/npm/dm/gulp-colorguard.svg?style=flat)](https://npmjs.org/package/gulp-colorguard) 6 | [![Build Status](http://img.shields.io/travis/pgilad/gulp-colorguard.svg?style=flat)](https://travis-ci.org/pgilad/gulp-colorguard) 7 | 8 | *Issues with the output should be reported on the css-colorguard [issue tracker](https://github.com/SlexAxton/css-colorguard/issues).* 9 | 10 | ## Install 11 | 12 | Install with [npm](https://npmjs.org/package/gulp-colorguard) 13 | 14 | ```bash 15 | $ npm install --save-dev gulp-colorguard 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```js 21 | var gulp = require('gulp'); 22 | var colorguard = require('gulp-colorguard'); 23 | 24 | //example with basic css copying 25 | gulp.task('css', function() { 26 | gulp.src('./src/css/**/*.css') 27 | .pipe(colorguard()) 28 | .pipe(gulp.dest('./public/css')); 29 | }); 30 | 31 | //example with less-preprocesser 32 | var less = require('gulp-less'); 33 | 34 | gulp.task('css', function() { 35 | gulp.src('./src/less/**/*.less') 36 | .pipe(less()) 37 | .pipe(colorguard()) 38 | .pipe(gulp.dest('./public/css')); 39 | }); 40 | 41 | //example with verbose logging 42 | gulp.task('css', function() { 43 | gulp.src('./src/less/**/*.css') 44 | .pipe(colorguard({ 45 | logOk: true 46 | })) 47 | .pipe(gulp.dest('./public/css')); 48 | 49 | // then if no errors: 50 | // --> main.css has no css color collisions 51 | }); 52 | ``` 53 | 54 | ## API 55 | 56 | [Options](https://github.com/SlexAxton/css-colorguard#programmatic) are passed through to css-colorguard, 57 | except for `options.logOk` which affects this gulp plugin behavior only. 58 | 59 | ### logOk 60 | 61 | Be verbose and log files that have no collisions. Off by default. 62 | 63 | **Type**: `Boolean` 64 | 65 | **Default**: `false` 66 | 67 | ## License 68 | 69 | MIT @[Gilad Peleg](http://giladpeleg.com) 70 | -------------------------------------------------------------------------------- /tests/test.js: -------------------------------------------------------------------------------- 1 | /* global describe, it */ 2 | 'use strict'; 3 | var expect = require('expect.js'); 4 | var path = require('path'); 5 | var fs = require('fs'); 6 | 7 | var gutil = require('gulp-util'); 8 | var colorguard = require('../index'); 9 | 10 | describe('gulp-colorguard', function () { 11 | it('files should pass through', function (cb) { 12 | var stream = colorguard(); 13 | 14 | stream.on('error', function () {}).on('data', function (file) { 15 | expect(file.path).to.be('style.css'); 16 | cb(); 17 | }); 18 | var file = './tests/fixtures/style.css'; 19 | 20 | stream.write(new gutil.File({ 21 | base: path.basename(file), 22 | path: path.basename(file), 23 | contents: new Buffer(fs.readFileSync(file).toString()) 24 | })); 25 | 26 | stream.end(); 27 | }); 28 | 29 | it('should throw error on basic validation', function (cb) { 30 | var stream = colorguard(); 31 | 32 | stream.on('error', function (err) { 33 | expect(err.plugin).to.be('gulp-colorguard'); 34 | expect(err.message).to.contain('#fffffa'); 35 | expect(err.message).to.contain('#ffffff'); 36 | expect(err.message).to.contain('line: 2'); 37 | cb(); 38 | }); 39 | var file = './tests/fixtures/style.css'; 40 | 41 | stream.write(new gutil.File({ 42 | base: path.basename(file), 43 | path: path.basename(file), 44 | contents: new Buffer(fs.readFileSync(file).toString()) 45 | })); 46 | 47 | stream.end(); 48 | }); 49 | 50 | it('should throw on multiple colors collisions', function (cb) { 51 | var stream = colorguard(); 52 | 53 | stream.on('error', function (err) { 54 | expect(err.message).to.contain('#fffffa'); 55 | expect(err.message).to.contain('#ffffff'); 56 | expect(err.message).to.contain('line: 2:11, 8:11, 14:11'); 57 | cb(); 58 | }); 59 | var file = './tests/fixtures/multiple.css'; 60 | 61 | stream.write(new gutil.File({ 62 | base: path.basename(file), 63 | path: path.basename(file), 64 | contents: new Buffer(fs.readFileSync(file).toString()) 65 | })); 66 | 67 | stream.end(); 68 | }); 69 | 70 | it('should handle faulty css', function (cb) { 71 | var stream = colorguard(); 72 | 73 | stream.on('error', function (err) { 74 | expect(err.message).to.contain('gulp-colorguard'); 75 | cb(); 76 | }); 77 | var file = './tests/fixtures/error.css'; 78 | 79 | stream.write(new gutil.File({ 80 | base: path.basename(file), 81 | path: path.basename(file), 82 | contents: new Buffer(fs.readFileSync(file).toString()) 83 | })); 84 | 85 | stream.end(); 86 | }); 87 | 88 | it('should be ok with a good css file', function (cb) { 89 | var stream = colorguard(); 90 | 91 | stream.on('error', function (err) { 92 | expect(err).to.not.be.ok(); 93 | }).on('data', function (data) { 94 | expect(data).to.be.ok(); 95 | expect(data.path).to.be('good.css'); 96 | }).on('end', cb); 97 | var file = './tests/fixtures/good.css'; 98 | 99 | stream.write(new gutil.File({ 100 | base: path.basename(file), 101 | path: path.basename(file), 102 | contents: new Buffer(fs.readFileSync(file).toString()) 103 | })); 104 | 105 | stream.end(); 106 | }); 107 | }); 108 | --------------------------------------------------------------------------------