Find package command-line interface (CLI) commands.
var findCommands = require( '@stdlib/_tools/pkgs/cmds' );Asynchronously searches for package command-line interface commands.
findCommands( done );
function done( error, cmds ) {
if ( error ) {
throw error;
}
console.log( cmds.join( '\n' ) );
}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 current working directory. Default: current working directory.
- pattern: glob pattern used to find packages. Default:
'**/package.json'(note: pattern must end withpackage.json). - ignore: list of glob patterns used to exclude matches.
To search from an alternative directory, set the dir option.
var opts = {
'dir': '/foo/bar/baz'
};
findCommands( opts, done );
function done( error, cmds ) {
if ( error ) {
throw error;
}
console.log( cmds.join( '\n' ) );
}To provide an alternative include filter, set the pattern option.
var opts = {
'pattern': '**/foo/**/package.json'
};
findCommands( opts, done );
function done( error, cmds ) {
if ( error ) {
throw error;
}
console.log( cmds.join( '\n' ) );
}To exclude matches, set the ignore option.
var opts = {
'ignore': [
'node_modules/**',
'build/**',
'reports/**'
]
};
findCommands( opts, done );
function done( error, cmds ) {
if ( error ) {
throw error;
}
console.log( cmds.join( '\n' ) );
}Synchronously searches for package command-line interface commands.
var files = findCommands.sync();
// returns [...]The function accepts the same options as findCommands() above.
- The implementation resolves command-line interfaces by reading
package.jsonfiles and extracting command names found in thebinfield. - No attempt is made to ensure that a command-line interface implementation exists.
- The implementation assumes that a
binfield is valid; i.e., either astringor anobject.
var resolve = require( 'path' ).resolve;
var findCommands = require( '@stdlib/_tools/pkgs/cmds' );
var opts = {
'dir': resolve( __dirname, '..', '..' )
};
findCommands( opts, done );
function done( error, cmds ) {
if ( error ) {
throw error;
}
console.log( cmds.join( '\n' ) );
}Usage: find-pkg-cmds [options] [<dir>]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--pattern pattern Inclusion glob pattern.
--ignore pattern Exclusion glob pattern.
-
If not provided a
dirargument, the current working directory is the search directory. -
To provide multiple exclusion glob patterns, set multiple
--ignoreoption arguments.$ find-pkg-cmds --ignore=node_modules/** --ignore=build/** --ignore=reports/**
$ find-pkg-cmds
<cmd>
<cmd>
...