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

cloud-function-cli

v1.0.1

Published

CLI for Cloud Function System - Create, deploy, and manage serverless functions

Readme

Cloud Function CLI

一个强大的命令行工具,用于管理云函数系统 API 的创建、部署和版本控制。

npm version License

✨ 特性

  • 🚀 快速创建 API 接口模板
  • 📤 一键部署到服务器
  • 📥 从服务器拉取 API 代码
  • 📜 版本历史查看
  • 🔄 版本回滚
  • 🔐 安全的 JWT 认证
  • 🎯 支持多环境(dev/prod)

📦 安装

# 全局安装
npm install -g cloud-function-cli

# 或使用 yarn
yarn global add cloud-function-cli

# 或使用 pnpm
pnpm add -g cloud-function-cli

🚀 快速开始

1. 登录

cf login

输入你的用户名和密码。

2. 创建 API

# 创建单个 API
cf create user/hello

# 创建 group 目录下的 API
cf create user/profile

这将在当前目录生成 api/group/name.js 文件,包含完整的 API 模板。

3. 编辑 API

# 编辑生成的文件
nano api/user/hello.js
# 或使用你喜欢的编辑器
code api/user/hello.js

4. 保存到服务器

# 保存单个 API 到开发环境
cf save user/hello --env dev

# 保存整个 group 的所有 API
cf save user --env dev

# 保存到生产环境
cf save user/hello --env prod

5. 调用 API

# 假设后端运行在 localhost:3000
curl http://localhost:3000/api/user/hello

📚 命令详解

cf login

登录系统,保存认证信息到本地配置文件。

cf login

登录成功后,配置文件保存在:

  • Windows: C:\Users\<你>\.cloud-function\config.json
  • macOS/Linux: ~/.cloud-function/config.json

cf create <name>

创建新的 API 接口文件。

# 语法
cf create <group>/<name>

# 示例
cf create user/login
cf create product/list
cf create order/create

生成的文件位于 api/<group>/<name>.js

cf save <name>

保存 API 到服务器。

# 保存单个 API
cf save <group>/<name> --env <env>

# 保存整个 group
cf save <group> --env <env>

# 示例
cf save user/login --env dev
cf save user --env prod

参数:

  • -e, --env <env>: 环境选择(dev/prod,默认 dev)

cf get <name>

从服务器拉取 API 代码。

# 拉取单个 API
cf get <group>/<name> --env <env>

# 拉取整个 group
cf get <group> --env <env>

# 示例
cf get user/login --env dev

参数:

  • -e, --env <env>: 环境选择(dev/prod,默认 dev)

cf history <name>

查看 API 的版本历史。

cf history <group>/<name> --env <env>

# 示例
cf history user/login --env dev

参数:

  • -e, --env <env>: 环境选择(dev/prod,默认 dev)

输出示例:

┌──────┬─────────────────────┬────────────────────┬─────────┐
│ 版本 │    创建时间         │      作者          │  备注   │
├──────┼─────────────────────┼────────────────────┼─────────┤
│   1  │ 2025-01-23 14:30:00 │ admin             │ 初始版本 │
│   2  │ 2025-01-23 15:20:00 │ admin             │ 修复bug  │
│   3  │ 2025-01-23 16:10:00 │ admin             │ 新增功能 │
└──────┴─────────────────────┴────────────────────┴─────────┘

cf rollback <name> <version>

回滚 API 到指定版本。

cf rollback <group>/<name> <version> --env <env>

# 示例
cf rollback user/login 2 --env dev

参数:

  • <version>: 目标版本号
  • -e, --env <env>: 环境选择(dev/prod,默认 dev)

cf list [group]

列出指定环境下的分组或某个分组下的所有 API。

# 列出所有 group(默认 dev)
cf list

# 列出所有 group(生产环境)
cf list --env prod

# 列出指定 group 下的所有 API(默认 dev)
cf list user

# 列出指定 group 下的所有 API(生产环境)
cf list user --env prod

参数:

  • -e, --env <env>: 环境选择(dev/prod,默认 dev)

⚙️ 配置

登录后,配置文件会自动创建在用户目录下的 .cloud-function/config.json

{
  "apiBaseUrl": "http://localhost:3000",
  "token": "your-jwt-token-here",
  "username": "admin",
  "environment": "dev"
}

自定义后端地址

如果你的后端不在 localhost:3000,可以手动修改配置文件:

{
  "apiBaseUrl": "https://your-server.com"
}

或使用环境变量:

export CLOUD_FUNCTION_API_BASE_URL="https://your-server.com"

🏗️ API 模板结构

生成的 API 文件包含以下结构:

async function handler(context) {
  // context 包含:
  // - request: Express Request 对象
  // - query: 查询参数
  // - body: 请求体
  // - headers: 请求头
  // - params: 路径参数
  // - env: 环境变量

  const { request, query, body } = context;

  // 你的业务逻辑
  const result = {
    success: true,
    message: 'Hello from Cloud Function!',
    data: query
  };

  return result;
}

module.exports = { handler };

🔐 安全性

  • 使用 JWT Token 认证
  • Token 自动附加到请求头
  • Token 过期自动提示重新登录
  • 支持 HTTPS 连接

🐛 故障排查

cf: command not found

如果提示命令找不到,请执行:

# 重新安装
npm uninstall -g cloud-function-cli
npm install -g cloud-function-cli

# 或重新打开终端(刷新环境变量)
hash -r  # Unix/Linux/Mac
refreshenv  # Windows PowerShell

Token 过期

如果提示 Token 过期,重新登录:

cf login

连接超时

如果遇到连接超时,检查配置文件中的 apiBaseUrl 是否正确。

# 查看配置文件路径
# Windows: C:\Users\<你>\.cloud-function\config.json
# Mac/Linux: ~/.cloud-function/config.json

📝 许可证

MIT License

🤝 贡献

欢迎提交 Issue 和 Pull Request!

🔗 相关链接