Giter Club home page Giter Club logo

pb-to-ts's Introduction

自动将pb转换成typescript里面类型文件(可以带着注释一起转换)

1、克隆本项目

2、npm i

3、将需要转换的pb放入到input文件夹下

4、npm run build

5、在output中收货

ps: 支持pb的import,相对引用

ps: 如果不希望转驼峰,在config中可以进行配置

ps: 如果要用proto3,请在pb文件顶部写上"syntax = "proto3";"

ps: pb的三斜杠注释,加上longjs这些,增加了使用成本,基本判定原有的protobufjs不可用了,所以写了这个小工具(我们这边pb都是双斜杠,丢了注释的话,ts类型也就不可维护了)

注释规范

1、块级元素,比如message,enum, 这类的注释必须在mesaage或者enum定义的上一行

2、字段类型的注释,必须跟在后面

/***
    sdfasdf
    我叫MT
*/
message BatchQueryItemsResp {
    // 我就是我,颜色不一样的烟火
  message Item {
      optional string item_id = 1; //商品id
      optional string title = 2; //商品标题
  }
}

❌message上方注释有空行,字段类型的注释写在了其他位置
// 我就是我,颜色不一样的烟火

message Item {
    //商品id
    optional string item_id = 1;
    //商品标题
    optional string title = 2;
}

本工具fork了probufjs的解析器,进行了魔改,然后自己写了一下ast生成ts类型的代码。

目前是通过本地跑命令编译,后续会尽量做的更易用

test

pb-to-ts's People

Contributors

libertyzhao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.