6.1.22 • Published 3 years ago

grpc-code-gen v6.1.22

Weekly downloads
48
License
MIT
Repository
github
Last release
3 years ago

grpc-code-gen

Code generator for grpc, for typescript and javascript.

CLI usage

grpc-code-gen gen -u git@git.myscrm.cn:2c/panther-statistics-proto.git,git@git.myscrm.cn: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: 'git@git.myscrm.cn:ykcommon/ykproto.git',
      branch: 'master',
    },
    // 服务依赖proto
    {
      url: 'git@git.myscrm.cn:ykcommon/common-proto.git',
      branch: 'master',
      type:'lib'
    },
    { 
      url: 'git@git.myscrm.cn:2c/panther-statistics-proto.git',
      // panther-statistics 服务proto依赖于 common-proto
      deps:['git@git.myscrm.cn:ykcommon/common.git']
    },
    {
      url: 'git@git.myscrm.cn: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

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

callOptions

参数类型说明默认值
timeout?number超时时间,单位:msundefined

logOptions

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

Program usage

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

base.gen({
  gitUrls: [
    {
      url: 'git@git.myscrm.cn:ykcommon/ykproto.git',
      branch: 'master',
    },
    'git@git.myscrm.cn:2c/panther-statistics-proto.git',
    'git@git.myscrm.cn: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 新增热重启功能

6.1.22

3 years ago

6.1.21

3 years ago

6.1.16

3 years ago

6.1.19

3 years ago

6.1.18

3 years ago

6.1.20

3 years ago

6.1.15-rc.1

3 years ago

6.1.14

4 years ago

6.1.13

4 years ago

6.1.12

4 years ago

6.1.11

4 years ago

6.0.11

4 years ago

6.1.10

4 years ago

6.1.9

4 years ago

6.1.8

4 years ago

6.1.7

4 years ago

6.1.6

4 years ago

6.1.5

4 years ago

6.1.4

4 years ago

4.1.4

4 years ago

6.1.3

4 years ago

6.1.2

4 years ago

6.1.1

4 years ago

6.1.0

4 years ago

6.0.10

4 years ago

6.0.9

4 years ago

6.0.8

4 years ago

6.0.7

4 years ago

6.0.6

4 years ago

6.0.5

4 years ago

6.0.4

4 years ago

6.0.3

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.4.4

5 years ago

5.4.3

5 years ago

5.4.2

5 years ago

5.4.1

5 years ago

5.4.0

5 years ago

5.3.2

5 years ago

5.3.1

5 years ago

5.3.0

5 years ago

5.2.7

5 years ago

5.2.6

5 years ago

5.2.5

5 years ago

5.2.4

5 years ago

5.2.3

5 years ago

5.2.2

5 years ago

5.2.1

5 years ago

5.2.0

5 years ago

5.1.0

5 years ago

5.0.8

5 years ago

5.0.7

5 years ago

5.0.6

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.6.1

5 years ago

4.6.0

5 years ago

4.5.6

5 years ago

4.5.5

5 years ago

4.5.4

5 years ago

4.5.3

5 years ago

4.5.2

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.0

5 years ago

4.3.11

5 years ago

4.3.10

5 years ago

4.3.9

5 years ago

4.3.8

5 years ago

4.3.7

5 years ago

4.3.6

5 years ago

4.3.5

5 years ago

4.3.4

5 years ago

4.3.3

5 years ago

4.3.2

5 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.3

5 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.6.3

5 years ago

3.6.2

5 years ago

3.6.1

5 years ago

3.6.0

5 years ago

3.5.0

5 years ago

3.4.16

5 years ago

3.4.15

5 years ago

3.4.14

5 years ago

3.4.13

5 years ago

3.4.12

5 years ago

3.4.11

5 years ago

3.4.10

5 years ago

3.4.9

5 years ago

3.4.8

5 years ago

3.4.7

5 years ago

3.4.6

5 years ago

3.4.5

5 years ago

3.4.4

5 years ago

3.4.3

5 years ago

3.4.2

5 years ago

3.4.1

5 years ago

3.4.0

5 years ago

3.3.3

5 years ago

3.3.2

5 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.1

5 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago