Code Monkey home page Code Monkey logo

grunt-lineending's Introduction

grunt-lineending Build Status

Convert line ending like dos2unix ( or unix2dos) command on Grunt.

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-lineending --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-lineending');

This plugin was designed to work with Grunt 0.4.x.

Lineending task

Run this task with the grunt lineending command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Overview

In your project's Gruntfile, add a section named lineending to the data object passed into grunt.initConfig().

Options

eol

Type: String
Choices: 'lf', 'cr', 'crlf'
Default: grunt.util.linefeed value

Usage Examples

Example Config

grunt.initConfig({
  lineending: {               // Task
    dist: {                   // Target
      options: {              // Target options
        eol: 'crlf'
      },
      files: {                // Files to process
        '/path/to/target': ['test/fixtures/file']
      }
    }
  }
});

grunt.loadNpmTasks('grunt-lineending');

grunt.registerTask('default', ['lineending']);

Default Options

By default convert line ending to lf(\n).

grunt.initConfig({
  lineending: {
    your_target: {
      '/path/to/output': ['/path/to/target']
    },
  }
});

Convert files manually

grunt.initConfig({
  lineending: {
    dist: {
      options: {
        eol: 'crlf'
      },
      files: {
        "./tmp/to_crlf/cr": ["./test/fixtures/cr"],
        "./tmp/to_crlf/crlf": ["./test/fixtures/crlf"],
        "./tmp/to_crlf/lf": ["./test/fixtures/lf"]
      }
    }
  }
});

Convert all files

grunt.initConfig({
  lineending: {
    dist: {
      options: {
        eol: 'crlf'
      },
      files: [{
        expand: true,
        cwd: './',
        src: ['test/fixtures/*'],
        dest: 'tmp/to_crlf/'
      }]
    }
  }
});

Convert files in-place (overwrite)

(This is experimental option)

Set overwrite option to true (default is false). The destination is ignored and can be set to ''.

This option only overwrites a source file if the line endings need to be updated otherwise it leaves the file untouched.

grunt.initConfig({
  lineending: {
    dist: {
      options: {
        overwrite: true
      },
      files: {
        '': ['test/fixtures/*']
      }
    }
  }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 2013-05-26 v0.1.1 Remove console.log
  • 2013-03-16 v0.1.0 Initial release.

grunt-lineending's People

Contributors

aleemb avatar maks3w avatar piuccio avatar psyrendust avatar suisho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gruntjs-updater

grunt-lineending's Issues

Issues with "expand: true"

On mutiple change of files needs expand: true on each setup, why that? Without that option it creates a "undefined" file...

It would be nice to have expand: true inside the "global" option...

Multiple files or directories not working

Not working for me, tested under Win8 with Grunt 0.4.1...

It seems that reading files used to fail, after try {} right into the catch ()...
Single files used to work but not multiple files or directories... sad

Setup:

files:
{
'includes/.php': ['includes/.php']
}

Screenshot:

eol

Best regards
Henry

Only write new files if needed

Hello,

what about writting files ONLY if there were changes?
Finally this would return a more accurate output to the user what files changed.

Regards
Henry

Nested folders

grunt.initConfig({
  lineending: {
    dist: {
      options: {
        overwrite: true
      },
      files: {
        '': ['test/fixtures/*']
      }
    }
  }
});

If test/fixtures/ contains nested folders you'll get the exception

Error: Unable to read "test/fixtures/nested" file (Error code: EISDIR).
    at Object.util.error (c:\repo\node_modules\grunt\node_modules\grunt-legacy-util\index.js:54:39)
    at Object.file.read (c:\repo\node_modules\grunt\lib\grunt\file.js:247:22)
    at lineEnding (c:\repo\node_modules\grunt-lineending\tasks\lineending.js:21:27)
    at c:\repo\node_modules\grunt-lineending\tasks\lineending.js:55:28

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.