@common-grants/cli

中文文档
0.5.0发布于 2026/10/28CC0-1.0CommonJS构建来源已验证近 30 天下载 2773

The CommonGrants protocol CLI tool

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. Initialize a Project
  4. Compile TypeSpec to OpenAPI
  5. Preview OpenAPI Specification
  6. Validate an API Specification
  7. Development status
  8. Anticipated features
  9. Validate API Implementation

CommonGrants CLI

The CommonGrants CLI (cg) is a tool for working with the CommonGrants protocol. It simplifies the process of defining, implementing, and validating CommonGrants APIs.

Note: This package is currently in alpha. The commands described below are mocked implementations that will be replaced with full functionality in future releases.

Installation

# Install globally
npm install -g @common-grants/cli

# Or use with npx
npx @common-grants/cli <command>

Usage

View available commands and options:

cg --help

Output:

CommonGrants CLI tools

Options:
  -V, --version           output the version number
  -h, --help              display help for command

Commands:
  init [options]          Initialize a new CommonGrants project
  preview <specPath>      Preview an OpenAPI specification
  check                   Validate APIs and specifications
  compile <typespecPath>  Compile a TypeSpec file to OpenAPI
  help [command]          display help for command

Initialize a Project

Create a new CommonGrants project from a template:

# Initialize interactively
cg init

# List available templates
cg init --list

# Use a specific template
cg init --template custom-api

Compile TypeSpec to OpenAPI

Compile a TypeSpec file to an OpenAPI specification:

cg compile spec.tsp

This is a thin wrapper around the tsp compile command and uses your project's tspconfig.yaml file to determine the output format.

Preview OpenAPI Specification

Preview an API specification using Swagger UI:

# Preview a YAML file
cg preview openapi.yaml

# Preview a JSON file
cg preview openapi.json

Validate an API Specification

Validate an API specification against the CommonGrants base protocol. You can optionally specify a specific protocol version to check against, or provide a path to your own base spec. By default, check spec uses the latest version of the base protocol bundled with the CLI.

# Using the base protocol spec bundled with @common-grants/cli, uses the latest version by default
cg check spec openapi.yaml

# Using a specific protocol version
cg check spec openapi.yaml --protocol-version 0.4.0

# Using the path to a locally compiled base spec
cg check spec openapi.yaml --base <path-to-base-spec>

Findings are reported as either errors or warnings. Errors fail the command with exit code 1. Warnings are printed, marked (warning), and the command still succeeds with exit code 0, because a route the base spec tags optional MAY be omitted by a compliant implementation.

Development status

This CLI is under active development and only supports the following commands:

  • cg init with a limited set of templates
  • cg compile
  • cg preview
  • cg check spec

Anticipated features

The following examples describe the anticipated features of the CLI, but these are not yet implemented and are subject to change.

Validate API Implementation

Check if an API implementation matches its specification:

# Basic validation
cg check api https://api.example.com spec.yaml

# Generate validation report
cg check api https://api.example.com spec.yaml --report json

# Validate with authentication
cg check api https://api.example.com spec.yaml --auth bearer:token

版本与发布记录

@common-grants/cli 共发布 36 个版本,首次发布于 2025/02/06;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.0latest2026/10/2813 天前
0.4.12026/10/1427 天前
0.4.02026/08/152 个月前
0.3.92026/08/103 个月前
0.3.82026/08/063 个月前
0.3.72026/08/063 个月前

关于 @common-grants/cli 的常见问题

@common-grants/cli 是什么?

The CommonGrants protocol CLI tool

如何安装 @common-grants/cli?

在项目目录运行 npm install @common-grants/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 cg,可以用 npx cg 直接运行。

@common-grants/cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/common-grants__cli 是否存在。

@common-grants/cli 支持 ESM 还是 CommonJS?

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

@common-grants/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@common-grants/cli 可以商用吗?

@common-grants/cli 使用 CC0-1.0 许可。作者放弃著作权,可不受限制地使用。以上为概括,不构成法律意见,请以许可原文为准。

@common-grants/cli 的下载量有多少?

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

@common-grants/cli 还在维护吗?

最新版本 0.5.0 发布于 2026/10/28(13 天前);至今共发布 36 个版本,其中过去 12 个月发布了 15 个;首次发布于 2025/02/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。