So its kind like recursive command line diff, but in JavaScript

Introduction

Ye ol Unix diff application provides the means to compare changes of all files in a directory tree. diff is awesome at its job, but it certainly isn't Pretty Diff.

When used with Node.js Pretty Diff can now output diffs to the command line in color for entire directory trees just like git diff. If you needed to compare an NPM package and all of its dependencies, for example, to a prior version of that package now you can. Changes in each modified file will be listed to the command line as well as files removed and added.

A brief example

If I wanted to execute Pretty Diff from the command line with minimal effort I could do the following:

> cd prettydiff > node api/node-local.js source:"../gulp" diff:"../gulpa"

The above command tells Node to execute the file api/node-local.js file relatively from the Pretty Diff application. I am going to pass in two arguments which are the source and something to compare it to. In the following example there will be a change to a single line in one file, which could look like the following:

lib/somefile.js Line 34 } else if (x[cc] === "[") { block = "]"; ee += 1; ef += 3; dd += 1; }

A line of code with two changes.

How this executes

The default presentation is to wrap each modification with two lines of unchanged code to provide some context. This can be changed by passing in the context option. If the context option is provided a non-negative integer you get that many lines of context, and if you provide any other value to this option you get the entire file contents.

The output is written with just console.log by Node. The entire process is asynchronous, except one point between the moment of reading files and performing the code comparison. The application must sort and compare relative paths to determine if a file is modified and thus needs a formal comparison or is either deleted or inserted.

The node file supplied with Pretty Diff can auto-detect file types. This is helpful if Pretty Diff is told to compare two resources but not told what those resources are. If Pretty Diff is provided directories to compare and not told how to read these resources with the readmethod option it will make the assumption that all files in all subdirectories should be analyzed.

The command line output is the default behavior if the output option is omitted, which tells Pretty Diff where to save files of the diff results. The command line output can also be forced if the diffcli option is provided with a value of "true".

The original intention of Pretty Diff is to be a language aware code analysis tool, but this can be overridden as well. To perform traditional literal text comparisons just pass in the option lang with a value of "text".

When I tested the application on a mutilated gulp module I was able to perform several dozen comparisons from over a 1000 evaluated files around 1 second in time.

Using all these options on the command line may look something like:

> node api/node-local.js source:"../gulp" diff:"../gulpa" diffcli:"true" context:5 lang:"text" readmethod:"subdirectory"

For additional options check out the documentation. I take bug and suggestions for enhancements via email and at Github.