Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/acombes/nunjucks-graph
Parse Nunjucks files and extract a dependency graph
https://github.com/acombes/nunjucks-graph
graph includes node npm nunjucks
Last synced: 25 days ago
JSON representation
Parse Nunjucks files and extract a dependency graph
- Host: GitHub
- URL: https://github.com/acombes/nunjucks-graph
- Owner: Acombes
- License: mit
- Created: 2019-04-03T10:53:47.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-26T14:14:57.000Z (over 5 years ago)
- Last Synced: 2024-12-14T20:20:15.821Z (27 days ago)
- Topics: graph, includes, node, npm, nunjucks
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nunjucks-graph
Parse Nunjucks files in a directory and extract a dependency graph. Inspired by [sass-graph](https://github.com/xzyfer/sass-graph).## Install
Install with [npm](https://npmjs.org/package/sass-graph)
```
npm install nunjucks-graph
```## Usage
Usage as a Node library:
```js
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
```js
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
```