tasks/grep.js
function grepLines(src, ext, destFile){
      src = grunt.util.normalizelf(src);
      var lines = src.split(grunt.util.linefeed),
          dest = [],
          //pattern for all comments containing denotation
          denotationPattern = updatePattern({
            pattern: options.pattern, 
            ext: ext, 
            isDenotationPattern: true}),
          //pattern for one-line grep usage
          pattern = updatePattern({
            pattern: options.pattern, 
            ext: ext}),
          //patterns for multi-line grep usage
          startPattern = updatePattern({
            pattern:options.pattern, 
            augmentPattern: options.startPattern,
            ext: ext}),
          endPattern = updatePattern({
            pattern: options.pattern, 
            augmentPattern: options.endPattern,
            ext: ext});
        if (pattern !== false){
          var startedRemoving;
          //loop over each line looking for either pattern or denotation comments
          lines.forEach(function(line) {
            if (!startedRemoving){
              //looking for one-line or start of multi-line pattern 
              if (line.search(startPattern) === -1 ){
              //looking for one-line or start of one-line pattern 
                if (line.search(pattern) === -1 ){
                  //looking for denotation comments 
                  if (options.removeDenotationComments && line.search(denotationPattern) !== -1){
                    var lineDenotationLess = line.replace(new RegExp(denotationPattern), '');
                    dest.push(lineDenotationLess);
                  } else {
                    //none of patterns found
                    dest.push(line);
                  }
                }
              } else{
                //multi-line found
                startedRemoving = true;
              }
            } else {
              //looking for end of multi-line pattern 
              if (line.search(endPattern) !== -1 ){
                startedRemoving = false;
              }
            }
          });
          var destText = dest.join(grunt.util.linefeed);
          if (grunt.file.exists(destFile)){
            if (!options.fileOverride){
              grunt.fail.warn('File "' + destFile + '" already exists, though is specified as a dest file. ' +
                'Turn on option "fileOverride" so that old file is removed first.');
            } else {
              grunt.file.delete(destFile);
            }
          }
          grunt.file.write(destFile, destText);

          grunt.log.writeln('File "' + destFile + '" created.');
        } else {
          grunt.log.warn('Pattern for \'' + task.target + '\' should be a string.');
        }
    }
function grepLines(src, ext, destFile){
      src = grunt.util.normalizelf(src);
      var lines = src.split(grunt.util.linefeed),
          dest = [],
          //pattern for all comments containing denotation
          denotationPattern = updatePattern({
            pattern: options.pattern, 
            ext: ext, 
            isDenotationPattern: true}),
          //pattern for one-line grep usage
          pattern = updatePattern({
            pattern: options.pattern, 
            ext: ext}),
          //patterns for multi-line grep usage
          startPattern = updatePattern({
            pattern:options.pattern, 
            augmentPattern: options.startPattern,
            ext: ext}),
          endPattern = updatePattern({
            pattern: options.pattern, 
            augmentPattern: options.endPattern,
            ext: ext});
        if (pattern !== false){
          var startedRemoving;
          //loop over each line looking for either pattern or denotation comments
          lines.forEach(function(line) {
            if (!startedRemoving){
              //looking for one-line or start of multi-line pattern 
              if (line.search(startPattern) === -1 ){
              //looking for one-line or start of one-line pattern 
                if (line.search(pattern) === -1 ){
                  //looking for denotation comments 
                  if (options.removeDenotationComments && line.search(denotationPattern) !== -1){
                    var lineDenotationLess = line.replace(new RegExp(denotationPattern), '');
                    dest.push(lineDenotationLess);
                  } else {
                    //none of patterns found
                    dest.push(line);
                  }
                }
              } else{
                //multi-line found
                startedRemoving = true;
              }
            } else {
              //looking for end of multi-line pattern 
              if (line.search(endPattern) !== -1 ){
                startedRemoving = false;
              }
            }
          });
          var destText = dest.join(grunt.util.linefeed);
          if (grunt.file.exists(destFile)){
            if (!options.fileOverride){
              grunt.fail.warn('File "' + destFile + '" already exists, though is specified as a dest file. ' +
                'Turn on option "fileOverride" so that old file is removed first.');
            } else {
              grunt.file.delete(destFile);
            }
          }
          grunt.file.write(destFile, destText);

          grunt.log.writeln('File "' + destFile + '" created.');
        } else {
          grunt.log.warn('Pattern for \'' + task.target + '\' should be a string.');
        }
    }
function grepLines ( src , ext , destFile ) { src = grunt . util . normalizelf ( src ) ; var lines = src . split ( grunt . util . linefeed ) , dest = [ ] , //pattern for all comments containing denotation denotationPattern = updatePattern ( { pattern : options . pattern , ext : ext , isDenotationPattern : true } ) , //pattern for one-line grep usage pattern = updatePattern ( { pattern : options . pattern , ext : ext } ) , //patterns for multi-line grep usage startPattern = updatePattern ( { pattern : options . pattern , augmentPattern : options . startPattern , ext : ext } ) , endPattern = updatePattern ( { pattern : options . pattern , augmentPattern : options . endPattern , ext : ext } ) ; if ( pattern !== false ) { var startedRemoving ; //loop over each line looking for either pattern or denotation comments lines . forEach ( function ( line ) { if ( ! startedRemoving ) { //looking for one-line or start of multi-line pattern  if ( line . search ( startPattern ) === - 1 ) { //looking for one-line or start of one-line pattern  if ( line . search ( pattern ) === - 1 ) { //looking for denotation comments  if ( options . removeDenotationComments && line . search ( denotationPattern ) !== - 1 ) { var lineDenotationLess = line . replace ( new RegExp ( denotationPattern ) , '' ) ; dest . push ( lineDenotationLess ) ; } else { //none of patterns found dest . push ( line ) ; } } } else { //multi-line found startedRemoving = true ; } } else { //looking for end of multi-line pattern  if ( line . search ( endPattern ) !== - 1 ) { startedRemoving = false ; } } } ) ; var destText = dest . join ( grunt . util . linefeed ) ; if ( grunt . file . exists ( destFile ) ) { if ( ! options . fileOverride ) { grunt . fail . warn ( 'File "' + destFile + '" already exists, though is specified as a dest file. ' + 'Turn on option "fileOverride" so that old file is removed first.' ) ; } else { grunt . file . delete ( destFile ) ; } } grunt . file . write ( destFile , destText ) ; grunt . log . writeln ( 'File "' + destFile + '" created.' ) ; } else { grunt . log . warn ( 'Pattern for \'' + task . target + '\' should be a string.' ) ; } }
go through file and remove lines matching patterns, both single- and multi-line
go through file and remove lines matching patterns both single - and multi - line