Skip to content

Commit

Permalink
fix bug in guessing line ending
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory PELLETEY committed Oct 10, 2016
1 parent 845d8fc commit 0b299e0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tasks/injector.js
Expand Up @@ -59,6 +59,7 @@ module.exports = function(grunt) {
var that = this;
options.lineEnding = getDefaultLineEnding(options, that, grunt);
}


// Iterate over all specified file groups and gather files to inject:

Expand Down Expand Up @@ -296,16 +297,18 @@ function getDefaultLineEnding(options, that, grunt) {
// when destination file is a template
var destination = options.template || options.templateString;

// when destination file is destFile
if (options.destFile) {
destination = options.destFile;
} else {
//if the destination file does not exist yet
// try to figure out lineEnding through src files
if (!grunt.file.exists(that.files[0].dest)) {
destination = that.filesSrc[0];
// if destination file not found, try to guess from destFile
if (typeof destination === 'undefined') {
if (options.destFile && grunt.file.exists(that.files[0].dest)) {
destination = options.destFile;
} else {
destination = that.files[0].dest;
//if the destination file does not exist yet
// try to figure out lineEnding through src files
if (!grunt.file.exists(that.files[0].dest)) {
destination = that.filesSrc[0];
} else {
destination = that.files[0].dest;
}
}
}

Expand All @@ -318,6 +321,6 @@ function getDefaultLineEnding(options, that, grunt) {
contents = String(grunt.file.read(destination));
}
}

return /\r\n/.test(contents) ? '\r\n' : '\n';
}

0 comments on commit 0b299e0

Please sign in to comment.