Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nDmitry committed Dec 27, 2013
1 parent 3c2d71b commit 8a5deac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"curly": true,
"eqeqeq": true,
"expr": true,
"immed": true,
"latedef": true,
"newcap": true,
Expand Down
45 changes: 18 additions & 27 deletions tasks/autoprefixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,13 @@ 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);

return JSON.stringify(map);
}

/**
* @param {array} sources
* @param {string} to
* @returns {array}
*/
function fixSources(sources, to) {
sources.forEach(function(source, index) {

Expand All @@ -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)) {
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8a5deac

Please sign in to comment.