tasks/changelog.js
function writeChangelog(changelog) {
      var fileContents = null;
      var firstLineFile = null;
      var firstLineFileHeader = null;
      var regex = null;

      if (options.insertType && grunt.file.exists(options.dest)) {
        fileContents = grunt.file.read(options.dest);
        firstLineFile = fileContents.split('\n')[0];
        grunt.log.debug('firstLineFile = ' + firstLineFile);

        switch (options.insertType) {
          case 'prepend':
            changelog = changelog + '\n' + fileContents;
            break;
          case 'append':
            changelog = fileContents + '\n' + changelog;
            break;
          default:
            grunt.fatal('"' + options.insertType + '" is not a valid insertType. Please use "append" or "prepend".');
            return false;
        }
      }

      if (options.fileHeader) {
        firstLineFileHeader = options.fileHeader.split('\n')[0];
        grunt.log.debug('firstLineFileHeader = ' + firstLineFileHeader);

        if (options.insertType === 'prepend') {
          if (firstLineFile !== firstLineFileHeader) {
            changelog = options.fileHeader + '\n\n' + changelog;
          } else {
            regex = new RegExp(options.fileHeader+'\n\n','m');
            changelog = options.fileHeader + '\n\n' + changelog.replace(regex, '');
          }

        // insertType === 'append' || undefined
        } else {
          if (firstLineFile !== firstLineFileHeader) {
            changelog = options.fileHeader + '\n\n' + changelog;
          }
        }

      }


      grunt.file.write(options.dest, changelog);

      // Log the results.
      grunt.log.ok(changelog);
      grunt.log.writeln();
      grunt.log.writeln('Changelog created at '+ options.dest.toString().cyan + '.');
    }
function writeChangelog(changelog) {
      var fileContents = null;
      var firstLineFile = null;
      var firstLineFileHeader = null;
      var regex = null;

      if (options.insertType && grunt.file.exists(options.dest)) {
        fileContents = grunt.file.read(options.dest);
        firstLineFile = fileContents.split('\n')[0];
        grunt.log.debug('firstLineFile = ' + firstLineFile);

        switch (options.insertType) {
          case 'prepend':
            changelog = changelog + '\n' + fileContents;
            break;
          case 'append':
            changelog = fileContents + '\n' + changelog;
            break;
          default:
            grunt.fatal('"' + options.insertType + '" is not a valid insertType. Please use "append" or "prepend".');
            return false;
        }
      }

      if (options.fileHeader) {
        firstLineFileHeader = options.fileHeader.split('\n')[0];
        grunt.log.debug('firstLineFileHeader = ' + firstLineFileHeader);

        if (options.insertType === 'prepend') {
          if (firstLineFile !== firstLineFileHeader) {
            changelog = options.fileHeader + '\n\n' + changelog;
          } else {
            regex = new RegExp(options.fileHeader+'\n\n','m');
            changelog = options.fileHeader + '\n\n' + changelog.replace(regex, '');
          }

        // insertType === 'append' || undefined
        } else {
          if (firstLineFile !== firstLineFileHeader) {
            changelog = options.fileHeader + '\n\n' + changelog;
          }
        }

      }


      grunt.file.write(options.dest, changelog);

      // Log the results.
      grunt.log.ok(changelog);
      grunt.log.writeln();
      grunt.log.writeln('Changelog created at '+ options.dest.toString().cyan + '.');
    }
function writeChangelog ( changelog ) { var fileContents = null ; var firstLineFile = null ; var firstLineFileHeader = null ; var regex = null ; if ( options . insertType && grunt . file . exists ( options . dest ) ) { fileContents = grunt . file . read ( options . dest ) ; firstLineFile = fileContents . split ( '\n' ) [ 0 ] ; grunt . log . debug ( 'firstLineFile = ' + firstLineFile ) ; switch ( options . insertType ) { case 'prepend' : changelog = changelog + '\n' + fileContents ; break ; case 'append' : changelog = fileContents + '\n' + changelog ; break ; default : grunt . fatal ( '"' + options . insertType + '" is not a valid insertType. Please use "append" or "prepend".' ) ; return false ; } } if ( options . fileHeader ) { firstLineFileHeader = options . fileHeader . split ( '\n' ) [ 0 ] ; grunt . log . debug ( 'firstLineFileHeader = ' + firstLineFileHeader ) ; if ( options . insertType === 'prepend' ) { if ( firstLineFile !== firstLineFileHeader ) { changelog = options . fileHeader + '\n\n' + changelog ; } else { regex = new RegExp ( options . fileHeader + '\n\n' , 'm' ) ; changelog = options . fileHeader + '\n\n' + changelog . replace ( regex , '' ) ; } // insertType === 'append' || undefined } else { if ( firstLineFile !== firstLineFileHeader ) { changelog = options . fileHeader + '\n\n' + changelog ; } } } grunt . file . write ( options . dest , changelog ) ; // Log the results. grunt . log . ok ( changelog ) ; grunt . log . writeln ( ) ; grunt . log . writeln ( 'Changelog created at ' + options . dest . toString ( ) . cyan + '.' ) ; }
Write the changelog to the destination file.
Write the changelog to the destination file .