Skip to content

Commit

Permalink
The ability to specify the source map destination in the plugin. grun…
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidmetal committed Sep 24, 2015
1 parent 73546de commit 6ab379d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tasks/sass.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var path = require('path');
var os = require('os');
var fs = require('fs');
var dargs = require('dargs');
var async = require('async');
var chalk = require('chalk');
Expand Down Expand Up @@ -58,6 +59,13 @@ module.exports = function (grunt) {
file.dest
].concat(passedArgs);

var sourcemapDest = '';
if (options.sourcemapDest) {
grunt.verbose.writeln('Source map destination was passed');
sourcemapDest = options.sourcemapDest;
args.splice(args.indexOf('--sourcemap-dest'), 2);
}

if (options.update) {
// When the source file hasn't yet been compiled SASS will write an empty file.
// If this is the first time the file has been written we treat it as if `update` was not passed
Expand Down Expand Up @@ -101,6 +109,25 @@ module.exports = function (grunt) {
return;
}

if(options.sourcemap && options.sourcemap!='none' && options.sourcemapDest) {
var mapPath = file.dest + '.map';
var newPath = path.join(sourcemapDest, path.basename(file.dest) + '.map');
var stats = fs.lstatSync(mapPath);
if(!stats.isFile()) {
grunt.verbose.writeln('The map file does not exist: ' + mapPath);
grunt.verbose.writeln('Skipping moving the file to source map destination' + sourcemapDest);
} else {
grunt.verbose.writeln('Moving "'+ mapPath + '" to "' + newPath);

// Make sure grunt creates the destination folders if they don't exist
if (!grunt.file.exists(newPath)) {
grunt.file.write(newPath, '');
}

fs.rename(mapPath, newPath);
}
}

grunt.verbose.writeln('File ' + chalk.cyan(file.dest) + ' created');
next();
});
Expand Down

0 comments on commit 6ab379d

Please sign in to comment.