auto-builder

1.1.36 • Public • Published

Auto Builder

Auto Builder is an implementation of GNU make. Instead of the configuration being found inside a makefile, it uses a javascript object which describes the dependency graph. This makes it easy to dynamically generate the configuration in your build script.

Installation

npm install auto-builder

Usage

The library itself exports a single factory function. This factory is used to create a runner which can then be used to generate a series of targets:

    const autoBuilder = require( "auto-builder" );
 
    const buildCfg = { ... }; 
    var runner = autoBuilder( buildCfg );
 
    Promise.resolve()
        // generate target x
        .then( () => runner( [ "target_x" ] ) )
        // generate targets z and y
        .then( () => runner( [ "target_z", "target_y" ] ) );

The runner will only re-generate targets with dependencies that have modified dates later than that of the target. This prevents redundant regeneration.

Targets will be built with maximum parallelism - using the dependency graph specified by the configuration. The meat of this work is offloaded to the orchestrator library.

Configuration

The Auto Builder configuration is an object mapping target to: recipe and dependencies.

The target is the name of some file that needs to be generated. The dependencies are the names of the files required for the generation and the recipe is a function that performs the actual regeneration.

The recipe function should be a nullary function that returns a promise which resolves upon completion. If the recipe doesn't create the target file, an empty file will be created by the library.

Heres a toy example:

{
    // no actual *work* is done here - just collect all dependencies 
    "dist/build" : {
        dependencies : [ "dist/index.js" ],
    },
 
    // compile the javascript into es7
    "dist/index.js.es7" : {
        dependencies : [ "index.js" ],
        recipe : () => compileToES7( "index.js", "dist/index.js.es7" )
    },
 
    // minify the compiled javascript and save it at the target location
    "dist/index.js" : {
        dependencies : [ "dist/index.js.es7" ],
        recipe : () => minify( "dist/index.js.es7", "dist/index.js" )
    },
    
    // clear the directory. Need to add a dummy dependency as otherwise will only clean once..
    "dist/clean" : {
        dependencies : [ "dist/.clean" ],
        recipe : () => fsPromise.clearDir( "dist" )
    },
 
    // dummy clean dependency - ensures clean can be run multiple times
    "dist/.clean" : {
    },
 
}

To perform a clean and then a build, you would do:

    Promise.resolve()
        .then( () => runner( [ "dist/clean" ] ) )
        .then( () => runner( [ "dist/build" ] ) );

Package Sidebar

Install

npm i auto-builder

Weekly Downloads

3

Version

1.1.36

License

MIT

Last publish

Collaborators

  • maambmb