neat

1.2.2

Compilation and Packaging

Neat is clearly opiniated and favor CoffeeScript over pure JavaScript. As result, Neat provides tools to deal with compilation and packaging of coffee files for both node and browsers.

These tools will allow you to perform operation on files at any point of the process. And you can even easily build your own operators.

Most of the hard work is handled by the cake build task, also aliased as cake compile. Builds are defined in the project Neatfile.

Table Of Content

Neatfile

Every Neat project have a Neatfile at its root. The Neatfile describes the build process to operate for a project.

The default Neatfile look like this:

build 'lib', (build) ->
  # Use glob like expression to source the build
  build.source 'src/**/*.coffee'

  # Invoke the processors you need
  build
  .do(compile bare: false)      # compile all the files
  .then(remove 'lib')           # removes the lib directory
  .then(relocate 'src', 'lib')  # relocate the compiled file to lib
  .then(writeFiles)             # write files to their path

The build call initiate a new build with the name lib. The build is then passed as argument to the block.

The build.source method allow to defines the patterns for files to process in this build. As for the example, all the files with a coffee extension will be processed by the build.

The build.do and build.then add operations in the build stack. Each of these operation will be executed sequentially, passing from one to another their results.

Build Operators

Operators are promise that operates on a file buffer. A file buffer is a simple object where keys contains the file's path and values are the content of these files. Such as

buffer = {
  '/path/to/file_1': 'Content file 1'
  '/path/to/file_2': 'Content file 2'
}

The following operators are currently available:

Note: Some processors requires a configuration, they'll be listed with their arguments in the list below such as compile(options). Processors that don't needs arguments must be passed direcly without calling them.

Common

CoffeeSCript

JavaScript

Build Utilities

Custom Build Operators

Custom build operators should be placed in the lib/processing directory.

Without Configuration

myCustomOperator = (buffer) ->
  # Either return a new buffer synchronously
  # or a promise whose value is a buffer

With Configuration

myCustomOperator = (args...) ->
  # The operator function returns a promise returning function
  # taking the buffer as argument.

  return (buffer) ->
    # Either return a new buffer synchronously
    # or a promise whose value is a buffer