@bb-cli/base

中文文档
2.7.0发布于 2020/01/03SEE LICENSE IN LICENSETypeScriptCommonJS近 30 天下载 2939

Common utilities and interface parser for the pluggable CLIs

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

原始使用文档
文档目录13 节
  1. Modules
  2. Functions
  3. cli : object
  4. error : object
  5. log : object
  6. sh : object
  7. ui : object
  8. ui.prompt ⇒ Promise
  9. ui.colors : object
  10. utils : object
  11. utils.md2html(mdStr) ⇒ string
  12. utils.md2term(mdStr) ⇒ string
  13. fileExists(file) ⇒ boolean

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

cli : object

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

error : object

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(),
  });
}

log : object

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

sh : object

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);
});

ui : object

User Interface for the terminal (Prompting / Styles / Spinners / Progress)

ui.prompt ⇒ Promise

Create a self contained inquirer module via inquirer.createPromptModule method.

Kind: static constant of ui
Access: public
Link: https://github.com/sboudrias/Inquirer.js

ParamTypeDescription
questionsarray | objectA 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.
})

ui.colors : object

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);

colors.defaultTheme : enum

Colors default styles

Kind: static enum of colors
Properties

NameTypeDefault
sillyobjectrainbow
inputobjectgrey
verboseobjectcyan
promptobjectgrey
infoobject["green","underline"]
dataobjectgrey
helpobjectcyan
warnobjectyellow
debugobjectblue
errorobjectred
headingobject["white","bold"]

utils : object

Set of utilities.

utils.md2html(mdStr) ⇒ string

Converts markdown to html output

Kind: static method of utils
Returns: string - html string

ParamTypeDescription
mdStrstringMarkdown content string

Example
Basic Example

const htmlStr = utils.md2html(fs.readFileSync('some-markdown-file.md', 'utf8').toString());

utils.md2term(mdStr) ⇒ string

Kind: static method of utils
Todo

  • Make it work with colors instead of ansi-styles
ParamTypeDescription
mdStrstringmarkdown content string

Example
Basic Example

const termMdOut = utils.md2term(fs.readFileSync('some-markdown-file.md', 'utf8').toString());

fileExists(file) ⇒ boolean

Kind: global function

ParamType
filestring

版本与发布记录

@bb-cli/base 共发布 27 个版本,首次发布于 2016/09/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.7.0latest2020/01/036 年前
2.6.12019/06/067 年前
2.6.02019/03/067 年前
2.6.0-pr.1pr2019/02/287 年前
2.6.0-pr.02019/02/287 年前
2.5.12019/01/317 年前

关于 @bb-cli/base 的常见问题

@bb-cli/base 是什么?

Common utilities and interface parser for the pluggable CLIs注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @bb-cli/base?

在项目目录运行 npm install @bb-cli/base,或使用 pnpm add / yarn add / bun add。

@bb-cli/base 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bb-cli/base 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bb-cli/base 可以商用吗?

@bb-cli/base 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@bb-cli/base 的下载量有多少?

根据 npm 官方下载统计,@bb-cli/base 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,939 次,日均约 98 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bb-cli/base 还在维护吗?

最新版本 2.7.0 发布于 2020/01/03(6 年前);至今共发布 27 个版本,其中过去 12 个月发布了 0 个;首次发布于 2016/09/13。作者已将其标记为弃用,新项目建议寻找替代方案。