Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Package Tree

Generate a stdlib package tree.

Usage

var pkgTree = require( '@stdlib/_tools/pkgs/tree' );

pkgTree( [options,] clbk )

Asynchronously generates a package tree.

pkgTree( onTree );

function onTree( error, tree ) {
    if ( error ) {
        throw error;
    }
    console.dir( tree );
}

The function accepts the following options:

  • dir: root directory from which to search for packages. May be either an absolute path or a path relative to the stdlib/lib/node_modules/ directory. Default: /path/to/stdlib/lib/node_modules/.
  • pattern: glob pattern used to find packages. Default: '**/package.json' (note: pattern must end with package.json).
  • ignore: list of glob patterns used to exclude matches.

To search from a descendant directory, set the dir option.

var opts = {
    'dir': './@stdlib/math/base'
};

pkgTree( opts, onTree );

function onTree( error, tree ) {
    if ( error ) {
        throw error;
    }
    console.dir( tree );
}

To provide an alternative include filter, set the pattern option.

var opts = {
    'pattern': '**/foo/**/package.json'
};

pkgTree( opts, onTree );

function onTree( error, tree ) {
    if ( error ) {
        throw error;
    }
    console.dir( tree );
}

To exclude matches, set the ignore option.

var opts = {
    'ignore': [
        'node_modules/**',
        'build/**',
        'reports/**',
        'foo/**'
    ]
};

pkgTree( opts, onTree );

function onTree( error, tree ) {
    if ( error ) {
        throw error;
    }
    console.dir( tree );
}

pkgTree.sync( [options] )

Synchronously generates a package tree.

var tree = pkgTree.sync();
// returns {...}

The function accepts the same options as pkgTree() above.

Notes

  • Both functions only return packages under the @stdlib scope.
  • Both functions always ignore examples/fixtures, test/fixtures, and benchmark/fixtures directories, irrespective of whether an ignore option is provided.

Examples

var pkgTree = require( '@stdlib/_tools/pkgs/tree' );

pkgTree( onTree );

function onTree( error, tree ) {
    if ( error ) {
        throw error;
    }
    console.dir( tree );
}

CLI

Usage

Usage: stdlib-pkg-tree [options] [<dir>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --pattern pattern     Inclusion glob pattern.
         --ignore pattern      Exclusion glob pattern.

Notes

  • If not provided a dir argument, the search directory is the current working directory.

  • To provide multiple exclusion glob patterns, set multiple --ignore option arguments.

    $ stdlib-pkg-tree --ignore=node_modules/** --ignore=build/** --ignore=reports/**

Examples

$ stdlib-pkg-tree