Modules
-
cli :
object
-
CLI parser based on commander with some additions and overrides.
-
error :
object
-
Create the new instance of the CommandError object, ensuring that it properly extends from the Error class.
-
log :
object
-
Shared logging system based on the default npmlog system.
-
sh :
object
-
Portable (Windows/Linux/OS X) implementation of Unix shell commands based on shelljs
-
ui :
object
-
User Interface for the terminal (Prompting / Styles / Spinners / Progress)
-
utils :
object
-
Set of utilities.
Functions
-
fileExists(file) ⇒
boolean
object
cli : CLI parser based on commander with some additions and overrides.
Link: https://github.com/tj/commander.js/
Example
Create a main command with 3 sub-commands:
import { cli } from '@bb-cli/base';
cli.version('0.0.1')
.command('install [...packages]', 'install one or more packages')
.command('search [query]', 'search with optional query')
.command('list', 'list packages installed', {isDefault: true})
.parse(process.argv);
Create the install
sub-command:
import { cli } from '@bb-cli/base';
cli
.description('Install package from registry')
.arguments('[...packages]', 'install one or more packages')
.option('-f, --force [force]', 'force installation ', false)
.option('-r, --registry [registry]', 'registry host ')
.alias('i')
.man( path.resolve(__dirname, '../../man/install.md'))
.parse(process.argv);
let packages = cli.args; // get the packages as variadic arguments
let force = cli.force // get the force option
object
error : Create the new instance of the CommandError object, ensuring that it properly extends from the Error class.
Example
Setting up the log header:
import { error } from '@bb-cli/base';
const out = sh.exec('ls', { silent: true });
if (out.code !== 0) {
throw error({
type: 'Shell.Exec',
code: out.code,
message: out.stderr.trim(),
});
}
object
log : Shared logging system based on the default npmlog system.
Link: https://github.com/npm/npmlog
Example
Setting up the log header:
import { log } from '@bb-cli/base';
import { name as packageName } from './package.json';
log.heading = `[${packageName}]`;
Basic commands:
log.silly(prefix, message, ...)
log.verbose(prefix, message, ...)
log.info(prefix, message, ...)
log.http(prefix, message, ...)
log.warn(prefix, message, ...)
log.error(prefix, message, ...)
Setting up the global env LOG_LEVEL:
LOG_LEVEL=verbose bb-my-command
object
sh : Portable (Windows/Linux/OS X) implementation of Unix shell commands based on shelljs
Link: https://github.com/shelljs/shelljs
Example
Basic Example
import { sh } from '@bb-cli/base';
sh.ls(`./`)
// or
sh.exec(`ls ./`, function(exitCode, stdOut, stdErr) {
log.verbose('cmd exitcode:', exitCode);
log.verbose('cmd output:', stdOut);
log.verbose('cmd stderr:', stdErr);
});
object
ui : User Interface for the terminal (Prompting / Styles / Spinners / Progress)
-
ui :
object
-
.prompt ⇒
Promise
-
.colors :
object
-
.defaultTheme :
enum
-
.defaultTheme :
-
.prompt ⇒
Promise
ui.prompt ⇒ Create a self contained inquirer
module via inquirer.createPromptModule
method.
Kind: static constant of ui
Access: public
Link: https://github.com/sboudrias/Inquirer.js
Param | Type | Description |
---|---|---|
questions |
array | object
|
A collection of inquirer questions |
Example
Basic example:
import { ui } from '@bb-cli/base';
const questions = [{
type: 'input',
name: 'name',
message: 'Who are you?',
default: 'Guest',
validate: value => true,
filter: value => value,
}];
ui.prompt(questions).then( answers => {
// do something with the answers here.
})
object
ui.colors : Colors styles console based on colors
Kind: static constant of ui
Access: public
Link: https://github.com/Marak/colors.js
Example
Basic example:
import { ui } from '@bb-cli/base';
let logInfo = ui.colors.info('Some info style output');
log.verbose(`Show ${logInfo}`);
Custom heading style:
let logHead = ui.colors.heading('Some bold white heading');
log.info(logHead);
enum
colors.defaultTheme : Colors default styles
Kind: static enum of colors
Properties
Name | Type | Default |
---|---|---|
silly | object |
rainbow |
input | object |
grey |
verbose | object |
cyan |
prompt | object |
grey |
info | object |
["green","underline"] |
data | object |
grey |
help | object |
cyan |
warn | object |
yellow |
debug | object |
blue |
error | object |
red |
heading | object |
["white","bold"] |
object
utils : Set of utilities.
-
utils :
object
-
.md2html(mdStr) ⇒
string
-
.md2term(mdStr) ⇒
string
-
.md2html(mdStr) ⇒
string
utils.md2html(mdStr) ⇒ Converts markdown to html output
Kind: static method of utils
Returns: string
- html string
Param | Type | Description |
---|---|---|
mdStr | string |
Markdown content string |
Example
Basic Example
const htmlStr = utils.md2html(fs.readFileSync('some-markdown-file.md', 'utf8').toString());
string
utils.md2term(mdStr) ⇒ Kind: static method of utils
Todo
- [ ] Make it work with colors instead of ansi-styles
Param | Type | Description |
---|---|---|
mdStr | string |
markdown content string |
Example
Basic Example
const termMdOut = utils.md2term(fs.readFileSync('some-markdown-file.md', 'utf8').toString());
boolean
fileExists(file) ⇒ Kind: global function
Param | Type |
---|---|
file | string |