UNPKG

949 BMarkdownView Raw
1Returns a list of candidate root files for CommonJS or AMD JavaScript applications within a directory.
2
3A root/entry-point file is one that has dependencies but is not depended on (i.e., no other file requires it).
4
5`npm install app-root`
6
7*This is useful for automatically deducing the entry point for r.js or browserify configurations.*
8
9```javascript
10var getAppRoot = require('app-root');
11
12// Find the application roots within the js folder
13getAppRoot('./js', function (roots) {
14 ...
15})
16```
17
18### Ignoring particular subdirectories
19
20Supply an options object as the second parameter with a field `ignore`
21that contains a list of the directories that you want to ignore
22when looking for candidate app roots.
23
24*Otherwise, you'd end up with junk roots for 3rd party libraries/dependencies.*
25
26```javascript
27var options = {
28 ignore: ['bower_components', 'vendor', 'node_modules', '.git']
29};
30
31getAppRoot('./js', options, function (roots) {
32 ...
33})
34```
\No newline at end of file