From 6ab379dc52ea816582ddb23732297049256a04f3 Mon Sep 17 00:00:00 2001 From: Utkarsh Sinha Date: Thu, 24 Sep 2015 00:29:09 -0400 Subject: [PATCH] The ability to specify the source map destination in the plugin. #209 --- tasks/sass.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tasks/sass.js b/tasks/sass.js index facb039..ef2c3fd 100644 --- a/tasks/sass.js +++ b/tasks/sass.js @@ -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'); @@ -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 @@ -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(); });