Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to combine nested files #558

Closed
faustbrian opened this issue May 1, 2022 · 1 comment
Closed

Best way to combine nested files #558

faustbrian opened this issue May 1, 2022 · 1 comment

Comments

@faustbrian
Copy link

Hey, was wondering what's the best/recommended way to combine a directory with nested folders and files into a single ts file. Currently I do something like the following with protobufjs for bundling:

pbjs -t static-module -w commonjs -o source/proto/nested.js proto/nested/**/*.proto && pbts -o source/proto/nested.d.ts source/proto/nested.js

Would there be an equivalent command for this with this lib? Something along the lines of protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=esModuleInterop=true,forceLong=string --ts_proto_out=source proto/nested/**/*.proto maybe.


Example

I have a directory structure like the following:

proto/vendor
└── tendermint
    ├── abci
    │   └── types.proto
    ├── blocksync
    │   └── types.proto
    ├── consensus
    │   ├── types.proto
    │   └── wal.proto
    ├── crypto
    │   ├── keys.proto
    │   └── proof.proto
    ├── libs
    │   └── bits
    │       └── types.proto
    ├── mempool
    │   └── types.proto
    ├── p2p
    │   ├── conn.proto
    │   ├── pex.proto
    │   └── types.proto
    ├── privval
    │   ├── service.proto
    │   └── types.proto
    ├── rpc
    │   └── grpc
    │       └── types.proto
    ├── state
    │   └── types.proto
    ├── statesync
    │   └── types.proto
    ├── types
    │   ├── block.proto
    │   ├── canonical.proto
    │   ├── events.proto
    │   ├── evidence.proto
    │   ├── params.proto
    │   ├── types.proto
    │   └── validator.proto
    └── version
        └── types.proto

Running pbjs -t static-module -w commonjs -o source/proto/tendermint.js proto/vendor/**/*.proto && pbts -o source/proto/tendermint.d.ts source/proto/tendermint.js will result in the files source/proto/tendermint.d.ts and source/proto/tendermint.js being created. The source/proto/tendermint.js file contains all of the proto files combined instead of having a separate js file for each proto file and source/proto/tendermint.d.ts contains all of the TypeScript types.

This works fine but means I have 2 different APIs to work with for proto files which introduces some inconsistencies, unnecessary overhead in tooling and the way code is written so I was wondering if there's some way to achieve the same with this package.

@stephenh
Copy link
Owner

Hey @faustbrian , yeah, sorry for the super late follow up. I believe this is a duplicate of #212 and has been a long standing ask. Fwiw I don't think a PR to do this would be that hard, we just haven't had anyone tackle it.

Maybe the one wrinkle is dealing with namespace clashes, i.e. if block.proto and events.proto both have a type Foo, then who wins / how does that get represented in the output file?

This could probably be solved with a pretty simple prefixing convention, but again just haven't had anyone give it a try.

Would be amazing if you wanted to submit a PR for it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants