Giter Club home page Giter Club logo

nodejs-eol-converter-cli's Introduction

Newlines (EOL) converter CLI

Having troubles with different line endings? ๐Ÿ˜ณ

This library will simply convert files of your choice to Windows (CRLF), or popular LF line ends used on Linux and Mac.

Installation:

npm i -g eol-converter-cli

API: eolConverter OptionalModifier "glob_files_regex"

  • OptionalModifier can be empty, warmup, or crlf - see examples.
  • For files paths resolution is used GLOB regex

Examples

Run just warmup - to see which files will be affected:

eolConverter warmup "**/*.js"

Run conversions (cannot be undone):

To LF (Unix & Mac default)

eolConverter "**/*.js"
eolConverter "**/*.{js,jsx,ts,tsx}"
eolConverter "src/**/*.js"
eolConverter "{src,tests}/**/*.js"

To CRLF (Windows default)

eolConverter crlf "**/*.js"

Tips

PS: Don't forget to configure you favourite IDE to work with desired line endings, so that you won't need this tool again! ๐Ÿ˜

Please give project โญ if you like it!

License

Apache 2.0 ยฉ Juraj Husรกr

nodejs-eol-converter-cli's People

Contributors

jurosh avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

nodejs-eol-converter-cli's Issues

Does not work for absolute path

Hi @jurosh ๐Ÿ‘‹

I tried using eolConverter in lint-staged, but it did not work for me. Here's what my config looked like in package.json:

  "lint-staged": {
    "{**/*.md,{*,src/**/*}.{json,js,jsx,ts,tsx,css}}": [
      "prettier --write",
      "eolConverter",
      "git add"
    ]

Context: prettier/prettier#5320

The above config resulted the following commands to run before committing:

prettier --write /path/to/repo/path/to/file1.js
prettier --write /path/to/repo/path/to/file2.js
eolConverter /path/to/repo/path/to/file1.js
eolConverter /path/to/repo/path/to/file2.js

eolConverter was treating /path/to/repo/path/to/file1.js as glob and converted it to /path/to/repo/path/to/repo/path/to/file1.js, which resulted into Error: ENOENT: no such file or directory.

It'd be great if your tool could deal with absolute paths too!

Warmup might display which files will be directly affected by conversion

Now warmup only list all files which will be processed - they might be changed or not, depends on execution.

Would be nice to see which files will be really updated and which does not need modification because have correct line ending.

Also would be nice to add percentage of all files which needs to be modified.

Eg.

Files will not be touched (have proper EOL):
{LIST1}

Files will be updates (needs EOL conversion):
{LIST2}

XY% files needs to be updated.

Pattern "**/*" Raises Folders Error

First of all, thanks for this really great tool โ€” immensely useful!

I'm facing a problem (using Win 10 x64, Node v9.5.0).

When I want to fix EOLs in all files, including subfolders I use:

eolConverter crlf "**/*"

because if I use the "**/*.*" pattern, it will miss extensionless files (eg: LICENCE). But the problem with the "**/*" pattern is that eolConverter will also try to fix EOLs in folders, and for each folder raises errors like the following:

{ Error: EISDIR: illegal operation on a directory, read
    at Object.fs.readSync (fs.js:693:18)
    at tryReadSync (fs.js:557:20)
    at Object.fs.readFileSync (fs.js:600:19)
[..etc..]

This error doesn't alt the execution, so at the end all files get processed; but I think that eolConverter should check if the file being processed is actually a folder, and skip it.

This fix would allow working with "**/*" catch-all patterns without these undue errors.

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.