Skip to content

brandoncarl/pipemaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pipemaker

Powerful chaining of pre- and post-processors, with dynamic dependency downloading.

Installation

$ npm install pipemaker

Examples

var pipemaker = new Pipemaker();

// Simple pipelines (extension, name)
pipemaker.addPipeline("jade");
pipemaker.addPipeline("coffee");
pipemaker.addPipeline("js", "dust");

// Chained pipelines (extension, chain)
pipemaker.addPipeline("css", "css>clean-css");
pipemaker.addPipeline("js", "javascript>uglify-js");
pipemaker.addPipeline("jbs", "jade>handlebars");

function next(err, compiled) { console.log(compiled); }

// Compile
pipemaker.compile("coffee", "console.log 'Hello'", next);
pipemaker.compile("handlebars", "Hello {{ name }}", { name : "Donald" }, next);
pipemaker.compileFile("./path-to/file.coffee", next);

API

PipemakerPipemaker .addPipeline(ext, [chain])function .compile(ext, str, [options], next) .compileBlock(lines, lineNo, [options], next) .compileFile(filename, [options], next) .compileWildcard(str, [options], next) .createPipeline(chain)function .getPipeline(chain)function .hasPipeline(ext)Boolean .removePipeline(ext)

Pipemaker ⇒ Pipemaker

Constructor for Pipemaker class. Automatically installs packages by default.

Returns: Pipemaker - Instance of class.

Param Type Description
mappings Object Keys correspond to extensions, values to pipeline names.
options Object Install directory dir, and whether to fetch if missing.

Example

var pipemaker = new Pipemaker({ dir : process.cwd() });

pipemaker.compile(ext, str, [options], next)

compiles a string using pipeline associated with ext

Param Type Default Description
ext String The extension associated with string (e.g. "coffee").
str String The string to be compiled.
[options] Object {} Options to be passed to rendering pipeline.
next function Callback of type fn(err, compiled).

Example

pipemaker.compile("coffee", "console.log 'Hello'", function(err, compiled) {
    console.log(compiled);
    // => console.log('Hello');
  });

pipemaker.compileFile(filename, [options], next)

compiles a file using pipeline associated with file's extension

Param Type Default Description
filename String Name of file.
[options] Object {} Options to be passed to rendering pipeline.
next function Callback of type fn(err, compiled).

Example

pipemaker.compileFile("app.coffee", function(err, compiled) {
    // Compiled version of app.coffee
  });

pipemaker.compileWildcard(str, [options], next)

Compiles a wildcard string.

Param Type Default Description
str String The string to be compiled.
[options] Object {} Options to be passed to rendering pipeline.
next function Callback of type fn(err, compiled).

pipemaker.compileBlock(lines, lineNo, [options], next)

Recursively compiles a wildcard block.

Param Type Default Description
lines Array The lines to be compiled
lineNo Number The line number to start with
[options] Object {} Options to be passed to rendering pipeline
next function Callback of type fn(err, compiled, numberOfLinesProcessed)

pipemaker.createPipeline(chain) ⇒ function

Returns a compilation function based on input chain.

Returns: function - Compilation function fn(str, options, next).

Param Type Description
chain String String containing names of pipelines to use.

Example

pipemaker.createPipeline("jade");
  pipemaker.createPipeline("jade>handlebars");
  pipemaker.createPipeline("js>uglify-js");

pipemaker.getPipeline(chain) ⇒ function

Gets an pipeline based on chain, creating pipeline if necessary.

Returns: function - Compilation function fn(str, options, next).

Param Type Description
chain String Chain of pipelines.

Example

pipemaker.getPipeline("jade>handlebars");

pipemaker.addPipeline(ext, [chain]) ⇒ function

Adds an pipeline for an extension, creating pipeline if necessary.

Returns: function - Compilation function fn(str, options, next).

Param Type Description
ext String File extension to be associated with pipeline.
[chain] String Optional chain for creating pipeline.

pipemaker.removePipeline(ext)

Removes an pipeline by extension.

Param Type Description
ext String File extension to for removal.

pipemaker.hasPipeline(ext) ⇒ Boolean

Determines if an pipeline currently exists for an extension.

Returns: Boolean - Whether pipeline exists.

Param Type Description
ext String File extension to check.

License

MIT

About

Manages compilation engines and allows for simple chaining

Resources

Stars

Watchers

Forks

Packages

No packages published