npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nocoo/cli-base

v0.2.4

Published

Shared CLI infrastructure for hexly.ai projects

Downloads

3,479

Readme


这是什么

cli-base 是一个 CLI 工具的基础设施库,为多个 CLI 项目提供统一的底层能力。避免在 pika、pew、otter 等项目中重复实现配置管理、OAuth 登录、自动更新等通用逻辑。

┌─────────────────────────────────────────────────┐
│                   Your CLI                       │
├─────────────────────────────────────────────────┤
│  cli-base                                        │
│  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌────────┐ │
│  │ Config  │ │  Login  │ │ Update  │ │  Log   │ │
│  └─────────┘ └─────────┘ └─────────┘ └────────┘ │
├─────────────────────────────────────────────────┤
│  citty · consola · picocolors · yocto-spinner   │
└─────────────────────────────────────────────────┘

功能

  • ConfigManager — 泛型配置文件管理,支持 dev/prod 环境分离,sync/async API,0600 权限保护
  • Login Flow — 浏览器 OAuth 登录流程,本地 loopback 回调服务器,XSS 防护
  • Update Helpers — 自动检测 bun/pnpm/yarn/npm,查询 npm registry 最新版本
  • Version Utils — 从 package.json 读取版本,语义化版本比较
  • Browser — 跨平台打开浏览器(macOS/Windows/Linux)
  • Log — consola 封装,formatDuration/formatSize/formatDate 格式化工具

安装

bun add @nocoo/cli-base
# or
npm install @nocoo/cli-base

使用示例

配置管理

import { ConfigManager } from "@nocoo/cli-base";

interface MyConfig {
  token?: string;
  deviceId?: string;
}

const config = new ConfigManager<MyConfig>("~/.config/my-cli", isDev);
config.write({ token: "xxx" });
const token = config.get("token");

登录流程

import { performLogin, openBrowser } from "@nocoo/cli-base";

const result = await performLogin({
  openBrowser,
  onSaveToken: (token) => config.write({ token }),
  apiUrl: "https://my-saas.com",
  timeoutMs: 120_000,
});

更新检测

import { detectPackageManager, getLatestVersion, getUpdateCommand } from "@nocoo/cli-base";

const pm = detectPackageManager("@nocoo/my-cli");
const latest = await getLatestVersion("@nocoo/my-cli");
if (pm && latest) {
  console.log(getUpdateCommand(pm, "@nocoo/my-cli"));
}

项目结构

cli-base/
├── src/
│   ├── index.ts          # 导出所有模块
│   ├── config.ts         # ConfigManager 泛型类
│   ├── login.ts          # OAuth 登录流程
│   ├── update.ts         # 更新检测工具
│   ├── version.ts        # 版本读取与比较
│   ├── browser.ts        # 跨平台浏览器打开
│   └── log.ts            # consola 封装
├── package.json
├── tsconfig.json
└── vitest.config.ts

技术栈

| 层 | 技术 | |---|------| | CLI 框架 | citty | | 日志 | consola | | 颜色 | picocolors | | 进度 | yocto-spinner | | 测试 | Vitest |

开发

环境要求: Bun 1.0+, Node.js 18+

git clone https://github.com/nocoo/cli-base.git
cd cli-base
bun install

| 命令 | 说明 | |------|------| | bun test | 运行测试 | | bun run test:coverage | 运行测试并输出覆盖率 | | bun run lint | 类型检查 + Biome lint | | bun run build | 编译 TypeScript |

测试

| 层 | 内容 | 触发时机 | |---|------|---------| | L1 | 单元测试 (95%+ 覆盖率) | pre-commit | | G1 | tsc + Biome | pre-commit | | G2 | gitleaks 密钥扫描 | pre-push |

bun run test:coverage

License

MIT © 2026