nunjucks-graph

    1.0.2 • Public • Published

    nunjucks-graph

    Parse Nunjucks files in a directory and extract a dependency graph. Inspired by sass-graph.

    Install

    Install with npm

    npm install nunjucks-graph
    

    Usage

    Usage as a Node library:

    var nunjucksGraph = require('./nunjucks-graph');

    API

    parseDir

    Parses a directory and builds a dependency grap of all requested file extensions.

    Options

    extensions

    Type: Array
    Default: ['njk', 'html']

    File Types to be parsed.

    Using a graph

    setDir

    Sets the Graph's base directory

    addFile

    Adds a file to the Graph's index

    getIndex

    Get the graph's index

    getSimpleIndex

    Build and get a simplified version of the graph's index where all types of dependencies are merged

    Example

    const nunjucksGraph = require('nunjucks-graph');
    console.log(nunjucksGraph.parseDir('test/fixtures/simple'));
     
    /* OUTPUT
    { index: {
      'path/to/test/fixtures/simple/main.njk': {
        includes: [ 'path/to/test/fixtures/simple/partial.njk' ],
        includedBy: [],
        extend: [],
        extendedBy: [],
        imports: [],
        importedBy: []
      },
      'path/to/test/fixtures/simple/partial.njk': {
        includes: [],
        includedBy: [ 'path/to/test/fixtures/simple/main.njk' ],
        extend: [],
        extendedBy: [],
        imports: [],
        importedBy: []
      },
    }}
    */

    Running Mocha tests

    You can run the tests by executing the following commands:

    npm install
    npm test
    

    Install

    npm i nunjucks-graph

    DownloadsWeekly Downloads

    5

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    53.6 kB

    Total Files

    31

    Last publish

    Collaborators

    • antoine.combes