From 8a5deacb531e52bdf623a0f818eab321a35f89b3 Mon Sep 17 00:00:00 2001 From: Dmitry Nikitenko Date: Fri, 27 Dec 2013 17:36:52 +0700 Subject: [PATCH] Refactor --- .jshintrc | 1 + tasks/autoprefixer.js | 45 +++++++++++++++++-------------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/.jshintrc b/.jshintrc index 1e68410..3745abd 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,6 +1,7 @@ { "curly": true, "eqeqeq": true, + "expr": true, "immed": true, "latedef": true, "newcap": true, diff --git a/tasks/autoprefixer.js b/tasks/autoprefixer.js index 5c5332e..b45dee0 100644 --- a/tasks/autoprefixer.js +++ b/tasks/autoprefixer.js @@ -44,11 +44,6 @@ module.exports = function(grunt) { } }); - /** - * @param {string} map - * @param {string} fileValue - * @returns {string} - */ function fixFile(map, filePath) { map = JSON.parse(map); map.file = path.basename(filePath); @@ -56,11 +51,6 @@ module.exports = function(grunt) { return JSON.stringify(map); } - /** - * @param {array} sources - * @param {string} to - * @returns {array} - */ function fixSources(sources, to) { sources.forEach(function(source, index) { @@ -71,10 +61,6 @@ module.exports = function(grunt) { return sources; } - /** - * @param {string} mapPath - * @param {string} from - */ function getMapParam(mapPath, from) { if (grunt.file.exists(mapPath)) { @@ -84,6 +70,21 @@ module.exports = function(grunt) { } } + function writeDiff(to, original, prefixed) { + var diffPath = (typeof options.diff === 'string') ? options.diff : to + '.patch'; + + grunt.file.write(diffPath, diff.createPatch(to, original, prefixed)); + } + + function addAnnotation(result, to) { + + // PostCSS doesn't add the annotation yet + result.css = result.css.concat( + grunt.util.linefeed, + '/*# sourceMappingURL=' + path.basename(to) + '.map */' + ); + } + function compile(original, from, to) { var result; @@ -116,27 +117,17 @@ module.exports = function(grunt) { map.sources = fixSources(JSON.parse(grunt.file.read(mapPath)).sources, to); } else { fixSources(map.sources, to); - - // PostCSS doesn't add the annotation yet - result.css = result.css.concat( - grunt.util.linefeed, - '/*# sourceMappingURL=' + path.basename(to) + '.map */' - ); + addAnnotation(result, to); } - result.map = JSON.stringify(map); - - grunt.file.write(to + '.map', result.map); + grunt.file.write(to + '.map', JSON.stringify(map)); } else { result = processor.process(original); } grunt.file.write(to, result.css); - if (options.diff) { - var diffPath = (typeof options.diff === 'string') ? options.diff : to + '.patch'; - grunt.file.write(diffPath, diff.createPatch(to, original, result.css)); - } + options.diff && writeDiff(to, original, result.css); } sources.forEach(function(filepath) {