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 🙏

© 2024 – Pkg Stats / Ryan Hefner

grpc-code-gen

v6.1.22

Published

Code generator for grpc, for typescript and javascript.

Downloads

38

Readme

grpc-code-gen

Code generator for grpc, for typescript and javascript.

CLI usage

grpc-code-gen gen -u [email protected]:2c/panther-statistics-proto.git,[email protected]:2c/panther-third-proto.git -b test -t ${token} -d test/code-gen-cli

Set params by config file

//grpc-code-gen.config.js
module.exports = {
  gitUrls: [
    {
      url: '[email protected]:ykcommon/ykproto.git',
      branch: 'master',
    },
    // 服务依赖proto
    {
      url: '[email protected]:ykcommon/common-proto.git',
      branch: 'master',
      type:'lib'
    },
    { 
      url: '[email protected]:2c/panther-statistics-proto.git',
      // panther-statistics 服务proto依赖于 common-proto
      deps:['[email protected]:ykcommon/common.git']
    },
    {
      url: '[email protected]:2c/panther-third-proto.git',
      host: 'panther-third', // go 服务别名
    }
  ],
  branch: 'test',
  accessToken: '${token}',
  baseDir: `${__dirname}/code-gen`,
  resolvePath: (origin, target, rootDir) => {
    if (/^git\.myscrm\.cn\/golang\/common\/proto\/(google|common)\//.test(target)) {
      return `${rootDir}/git.myscrm.cn/ykcommon/ykproto/${target.replace(/^git\.myscrm\.cn\/golang\/common\/proto\//, '')}`;
    } else if (/^proto\/(common|google)\//.test(target)) {
      return `${rootDir}/git.myscrm.cn/ykcommon/ykproto/${target.replace(/^proto\//, '')}`;
    } else if (/^proto\//.test(target)) {
      return target.replace(/^proto\/([^\/]+)(.+)/, (_target, $1, $2) => {
        return `${rootDir}/git.myscrm.cn/2c/${$1.replace(/_/g, '-')}${$2}`;
      });
    } else if (/^(common|google\/api)\//.test(target)) {
      return `${rootDir}/git.myscrm.cn/ykcommon/ykproto/${target}`;
    }
    return null;
  },
};

then

grpc-code-gen gen

Params

参数 | 类型 | 说明 | 默认值 ---|---|---|--- gitUrls | Array<string | {url: string, branch?: string, accessToken?: host?: string }> | 仓库地址数组 | null branch | string | 分支,如参数没有,会去读取环境变量参数branch | null accessToken | string | git access token | null baseDir? | string | 生成目录 | null target? | javascript typescript | 目标语言 | null grpcNpmName? | string | grpc npm name, 可取值:grpc, @grpc/grpc-js | grpc jsonSemanticTypes? | boolean | 生成json semantic types | false
loaderOptions? | LoaderOptions | loader生成配置 | { defaults: true } callOptions? | callOptions | 方法调用配置 | null logOptions? | logOptions | 日志配置 | null filterError? | (err: Error) => Error | 错误过滤 | (err) => err loadProtoPlugin? | (option: IGitConfigWithUrl) => Promise | proto加载插件 | unll

callOptions

参数 | 类型 | 说明 | 默认值 ---|---|---|--- timeout? | number | 超时时间,单位:ms | undefined

logOptions

参数 | 类型 | 说明 | 默认值 ---|---|---|--- disable? | boolean | 是否启用 | false attributes? | string[] | 记录字段,request, response | ['request']

Program usage

const base = require('grpc-code-gen/build/base');

base.gen({
  gitUrls: [
    {
      url: '[email protected]:ykcommon/ykproto.git',
      branch: 'master',
    },
    '[email protected]:2c/panther-statistics-proto.git',
    '[email protected]:2c/panther-third-proto.git',
  ],
  branch: 'test',
  accessToken: process.env.token,
  baseDir: `${__dirname}/code-gen`,
  resolvePath: (origin, target, rootDir) => {
    if (/^git\.myscrm\.cn\/golang\/common\/proto\/(google|common)\//.test(target)) {
      return `${rootDir}/git.myscrm.cn/ykcommon/ykproto/${target.replace(/^git\.myscrm\.cn\/golang\/common\/proto\//, '')}`;
    } else if (/^proto\/(common|google)\//.test(target)) {
      return `${rootDir}/git.myscrm.cn/ykcommon/ykproto/${target.replace(/^proto\//, '')}`;
    } else if (/^proto\//.test(target)) {
      return target.replace(/^proto\/([^\/]+)(.+)/, (_target, $1, $2) => {
        return `${rootDir}/git.myscrm.cn/2c/${$1.replace(/_/g, '-')}${$2}`;
      });
    } else if (/^(common|google\/api)\//.test(target)) {
      return `${rootDir}/git.myscrm.cn/ykcommon/ykproto/${target}`;
    }
    return null;
  },
})
  .catch((err)=>{
    console.error(err.stack)
  });

版本说明

  • v6.1.13 版本 gitUrls配置新增服务别名配置项

  • v6.1.0 版本 gitUrls配置新增依赖项

  • v6.0.6 版本 新增 access 日志链路

  • v6.0.4 版本 新增 grpc-service.dev.config.js 本地配置,去掉繁琐的本地host配置

  • v6.0.3 版本 解决编译go proto枚举报错问题

  • v6.0.0 版本 解决grpc-code-gen编译时,后端相同package下有相同service的冲突问题

  • v5.4.4 版本 解决javascript精度文档,js在超过16位的number数字会有精度丢失问题,因此统一把('double', 'float', 'int64', 'uint64', 'sint64', 'fixed64', 'sfixed64')类型转换为string类型

  • v5.3.0 版本 bff grpc 新增热重启功能