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

cam-fe-code-generator

v1.9.8

Published

`cam-fe-code-generator` 是 CAM 的 npm CLI。它从 CAM 后端拉取指定 Service 的 API 定义与参数结构,生成 TypeScript 类型、可注入请求实现的 Service Class,以及 axios/fetch 使用示例。

Downloads

321

Readme

cam-fe-code-generator

cam-fe-code-generator 是 CAM 的 npm CLI。它从 CAM 后端拉取指定 Service 的 API 定义与参数结构,生成 TypeScript 类型、可注入请求实现的 Service Class,以及 axios/fetch 使用示例。

该包依赖可访问的 CAM 后端和具有相应 Service 权限的账号;它不是 OpenAPI 文件生成器。

安装

npm install -g cam-fe-code-generator

也可在项目中安装:

npm install -D cam-fe-code-generator
npx cam --help

使用流程

# 1. 登录 CAM;交互式输入用户名和密码
cam login

# 2. 在业务项目根目录初始化配置
cam init

# 3. 添加需要生成的服务
cam add user-service:team/user/service@latest

# 4. 拉取接口定义并生成代码
cam update

# 只拉取当前项目中一个已添加服务的最新代码(名称或 UUID)
cam update user-service
cam update team/user/service

cam add 的格式为 名称:service_uuid@版本:

  • 名称 用作输出子目录名称,必须是合法文件名;
  • service_uuid 是 CAM 中的 Service 唯一标识;
  • 版本 可以是 latest 或 x.y.z。

其他命令:

cam whoami                 # 查看当前本地登录用户
cam logout                 # 清除本地登录态
cam remove user-service    # 从当前项目配置中移除服务并重新生成

配置与产物

cam init 会在当前目录创建 cam.config.json:

{
  "services": {},
  "outDir": "src/cam-auto-generate",
  "generateConfig": {}
}

运行 cam update(以及成功的 cam add / cam remove)会清空并重建 outDir,因此不要在生成目录中手写业务代码。

cam update <服务名称或 UUID> 只请求该服务的 latest 版本并重建该服务子目录,不拉取其他服务,不修改其他服务产物或 request-demo.ts,也不改写 cam.config.json 的版本设置。未添加的服务会报错;无参数的 cam update 仍按配置版本更新全部服务。

每个已配置服务会生成:

src/cam-auto-generate/
  <服务名称>/
    index.ts          # Service Class:每个 API 对应一个方法
    namespaces.ts     # 请求/响应 TypeScript 类型
  request-demo.ts     # axios / fetch 接入示例

生成的 Service Class 不绑定网络库:通过构造函数传入 baseURL 与 request 即可接入现有的 axios 实例、fetch 封装、重试或埋点能力。request-demo.ts 给出了 axios 和 fetch 的最小示例。

登录 token 与用户摘要保存在用户主目录的 ~/.camrc,文件写入权限为 0600。不要共享该文件或将其提交到版本控制。

服务端地址

发布工作流会从 GitHub npm Environment 的 SERVER_BASE_URL 变量注入默认服务端地址,安装 CLI 的用户无需配置该变量。私有部署或本地联调可在项目根目录的 .env 中设置 SERVER_BASE_URL,或直接设置同名环境变量;它会覆盖发布包中的默认地址。

本地开发

前置条件:Node.js(建议 LTS)与 npm。

npm install
npm run build

# 在当前仓库直接验证编译后的 CLI
node dist/cli/index.js --help

# 可选:以全局命令方式联调
npm link
cam --help

npm run build 会先从 package.json 写入版本常量,再将 TypeScript 编译到 dist/。构建产物同时包含 CommonJS 入口、命令行入口和类型声明。

发布 npm

发布由 GitHub Actions 通过 npm Trusted Publishing 执行;本地不需要 npm token。运行以下脚本会校验干净的 main 工作区、递增版本、创建 release/<版本>-<时间戳> 分支、构建并检查 tarball,再提交和推送该分支:

./publish.sh                 # 默认递增 patch,例如 1.9.0 -> 1.9.1
./publish.sh minor           # 递增 minor
./publish.sh major           # 递增 major

脚本仅接受 patch、minor、major,只允许从 main 分支运行,且需要本机已安装 pnpm。推送成功后请在 GitHub Actions 中确认工作流完成;同一版本已存在时工作流会跳过发布。

本地手动发布(通常不需要)可使用:

npm run build
npm pack --dry-run
npm version patch  # 或 minor / major
npm publish

prepublishOnly 会在 npm publish 前再次执行构建,发布包仅包含 dist/ 与 npm 默认包含的元数据文件。发布前请确认:版本号符合语义化版本、BASE_URL 指向正确环境、生成器能处理目标 API 合同,并且 npm 账号拥有包名发布权限。

开发约定

  • CLI 命令注册在 src/cli/,远端调用放在 src/services/apis/,生成逻辑放在 src/services/code-generate/。
  • 类型映射和模板改动必须以 CAM 后端的参数模型为准,特别关注嵌套 object、object 数组、可选字段与历史版本草稿。
  • 不要编辑生成目录作为修复手段;应修改模板或生成器并重新运行 cam update。
  • 运行 npm test 构建并执行更新命令回归测试,覆盖名称/UUID 选择、服务隔离、全量更新兼容性与拉取失败处理。

许可证

当前包元数据标记为 ISC。拆库发布前请在根目录提供对应的 LICENSE 文件并确认与团队政策一致。