返回 Skill 列表
extension
分类: 开发与工程无需 API Key

libcodegen

libcodegen - Protocol Buffer代码生成。TypeGenerator、ServiceGenerator和DefinitionGenerator将.proto文件转换为JavaScript类型、gRPC服务存根和服务类型定义。用于从protobuf模式生成代码,自动化服务存根创建,并在服务间保持类型一致性。

person作者: jakexiaohubgithub

libcodegen Skill

When to Use

  • Generating JavaScript types from Protocol Buffer schemas
  • Creating gRPC service stubs automatically
  • Updating generated code after .proto changes
  • Maintaining type consistency across microservices

Key Concepts

TypeGenerator: Generates JavaScript classes from protobuf message definitions with proper type annotations.

ServiceGenerator: Creates gRPC service stubs with method signatures matching the proto service definitions.

DefinitionGenerator: Generates type definitions for IDE support and documentation.

Usage Patterns

Pattern 1: Generate types from protos

import { TypeGenerator } from "@copilot-ld/libcodegen";

const generator = new TypeGenerator("./proto");
await generator.generate("./generated/types");

Pattern 2: Generate service stubs

import { ServiceGenerator } from "@copilot-ld/libcodegen";

const generator = new ServiceGenerator("./proto");
await generator.generate("./generated/services");

Integration

Run via make codegen after modifying .proto files. Output used by libtype and librpc.