Giter Club home page Giter Club logo

pb-to-typescript's Introduction

pb-to-typescript

license

Intro

A converter to transform from Protobuf to Typescript definition files, which is inspired by geotho/protobuf-to-typescript. However, this converter is powered by protobuf.js, which is more tend to regularity and principle.

Protobuf is currently used in micro-service for back end. As a front end web developer, you can generate Typescript defination files based on Protobuf in case to develop your web page easily.

Demo

Live Demo

License

MIT

pb-to-typescript's People

Contributors

brandonxiang avatar wangggym avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pb-to-typescript's Issues

怎么通过命令行的方式使用pbts呢?

我有一个文件Test.proto,想通过命令行转成Test.ts,所以我试着依照https://github.com/brandonxiang/pb-to-typescript/tree/main/packages/cli 的步骤来操作,然后碰到了挺多提示错误的,感觉我的用法好像出现了问题

  1. 一开始我执行了npm i pbts-cli,结果出现了node_modules文件夹,但是我执行pbts会提示找不到命令
  2. 于是我试着执行npm i pbts-cli -g命令,这时,我执行pbts convert -i Test.proto -o Test.ts仍然提示找不到pbts命令
  3. 接着我试着输入pbts-cli -h,屏幕上显示如下提示,这些提示跟里的说明不太一样
Usage: pb-cli [options] [command]

Options:
  -v, --version             output the version number
  -h, --help                output usage information

Commands:
  build [options] <target>  构建proto js/ts文件
  1. 我又试着执行pbts-cli build Test.proto,则出现了一大堆奇怪的报错

我对nodejs并不熟悉,是否是我的操作有误呢,怎么才能直接通过命令行使用pbts呢?

Generation of types.d.ts breaks when the types.js is too big

protobuf.js version: 6.8.6 and latest one (7.2.6).

I have a shell script I use to generate the type definitions from my proto files. It generates properly the types.js, but when it tries to generate the types.d.ts it doesn't generate a new file.

I suspect that probably the script finishes unexpectedly because of the length of the types.js file (almost 1M of lines of code, and continuously growing) and its size (> 59 Mb).

There are no error logs.

My script looks like this.-

#!/usr/bin/env bash

set -e

rm -rf sample_protobuf_build
mkdir sample_protobuf_build
cp -a abc_protobuf sample_protobuf_build/abc_protobuf
cp -a def_protobuf sample_protobuf_build/def_protobuf

cd sample_protobuf_build

if [[ "$OSTYPE" == "darwin"* ]]; then
  LC_ALL=C bash -c "find ./ -type f -print0 | xargs -0 sed -i '' -E 's/( )\\.?(Core)(\\.|\\;)/\\1Proto\\3/g'"
  LC_ALL=C bash -c "find ./ -type f -print0 | xargs -0 sed -i '' -E 's/\\(\\.?(Core)(\\.|\\;)/\\(Proto\\2/g'"
else
  LC_ALL=C bash -c "find ./ -type f -print0 | xargs -0 sed -i -E 's/( )\\.?(Core)(\\.|\\;)/\\1Proto\\3/g'"
  LC_ALL=C bash -c "find ./ -type f -print0 | xargs -0 sed -i -E 's/\\(\\.?(Core)(\\.|\\;)/\\(Proto\\2/g'"
fi


find ./ -name '*.proto' -print0 | LC_ALL=C sort -z | xargs -0 pbjs -t static-module -w commonjs --force-message -o ../dist/types.js
cat ../dist/types.js | pbts -o ../dist/types.d.ts -

Are there any ways to force the command to generate the types.d.ts file disregarding the length and size of the file?

Notes.-

  • I ran my script in a MacOS (M2).
  • I ran the script against zsh and bash.
  • I used the following versions of NodeJS: 18.16.0 and 20.8.1.

TIA!

可以选择安装2.0.2不强制升级吗

可以选择安装2.0.2不强制升级吗

4.0.0安装后报错

pbts -v
node:internal/errors:478
ErrorCaptureStackTrace(err);
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'pkg-updater' imported from /usr/local/lib/node_modules/pbts/bin.js
at new NodeError (node:internal/errors:387:5)
at packageResolve (node:internal/modules/esm/resolve:852:9)
at moduleResolve (node:internal/modules/esm/resolve:901:20)
at defaultResolve (node:internal/modules/esm/resolve:1115:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:837:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_MODULE_NOT_FOUND'
}

现在是npm i [email protected] -g
然后手动修改 /usr/local/lib/node_modules/pbts/package.json 为4.0.0 绕过强制升级才可以正常使用。

Error [ERR_MODULE_NOT_FOUND]: Cannot find module

node:internal/errors:478
ErrorCaptureStackTrace(err);
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/usr/local/lib/node_modules/pbts/node_modules/@pbts/core/src/index.js' imported from /usr/local/lib/node_modules/pbts/src/index.js
at new NodeError (node:internal/errors:387:5)
at finalizeResolution (node:internal/modules/esm/resolve:330:11)
at moduleResolve (node:internal/modules/esm/resolve:907:10)
at defaultResolve (node:internal/modules/esm/resolve:1115:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:837:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_MODULE_NOT_FOUND'
}

node:v16.18.0

[feature request] support transform `optional` and `oneof` keyword?

Is it possible to auto detect optional and oneof keywords and add ? to the export type ?
eg:

message Person {
  string name = 1;
  optional uint32 age = 2;
  oneof test_oneof {
    string test_a = 3;
    string test_b = 4;
  }
}

to:

export interface Person {
  name: string;
  sex?: number;
  testA?: string;
  testB?: string;
}

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.