t2-project
Given a specified entry point file, determine and resolve the dependency graph.
Dependencies
The resulting output is an array of data objects containing the following properties:
Name | Description |
---|---|
id | Unique file identity |
file | Absolute path to file |
source | The contents of the file |
For example, the following program:
var Project = ; var project = entry: 'eg/project-conditional/index.js'; project;project; project;
Where eg/project-conditional/
contains:
.
├── a.js
├── b.js
├── c.js
└── index.js
0 directories, 4 files
Would have the following result (just assume ${ABSOLUTE_PATH}
is the absolute path to project-conditional
):
[{
id: '${ABSOLUTE_PATH}/eg/project-conditional/a.js',
source: 'module.exports = function() {\n return \'a\';\n};\n',
deps: {},
file: '${ABSOLUTE_PATH}/eg/project-conditional/a.js'
}, {
file: '${ABSOLUTE_PATH}/eg/project-conditional/index.js',
entry: true,
id: '${ABSOLUTE_PATH}/eg/project-conditional/index.js',
source: 'var conditional = true ? require(\'./a\') : require(\'./b\');\n\nrequire(\'./c\');\n\n\nconsole.log(conditional());\n',
deps: {
'./b': '${ABSOLUTE_PATH}/eg/project-conditional/b.js',
'./c': '${ABSOLUTE_PATH}/eg/project-conditional/c.js',
'./a': '${ABSOLUTE_PATH}/eg/project-conditional/a.js'
}
}]
Usage
Install via npm:
npm install t2-project
var Project = ; var a = entry: './eg/project-simple/index.js'; a; var b = entry: './eg/project-conditional/index.js'; b; /*Or... b.exclude('b.js');b.exclude('c.*'); Or... b.exclude({ files: ['b.js', 'c.*'], basedir: (optionally specify a basedir)});*/ var p = b; p;
API
exclude(file)
: Call this method with a stringfile
name to exclude a single file.exclude([ ...files])
: Call this method with an array of stringfile
names to exclude many files.exclude({ files: [ ...files], basedir: '...' })
: Call this method with an object containing afiles
property, whose value is an array of stringfile
names to exclude many files; and optionally abasedir
property to specify the base directory to exclude from.filter
: meh, this is unfinished and might not live to see another day.
License
Copyright (c) 2015 Rick Waldron waldron.rick@gmail.com Licensed under the MIT license.