mirror of
https://github.com/stakwork/sphinx-relay.git
synced 2026-08-13 12:33:24 +02:00
move cln proto files to a subdirectory
This commit is contained in:
parent
8062f55b7f
commit
0d6dabacaa
4 changed files with 29 additions and 19 deletions
|
|
@ -15,16 +15,23 @@ rm -rf src/grpc/types
|
|||
# https://github.com/protobufjs/protobuf.js/issues/1799
|
||||
sed -Ei '/^ +\/\/.*/d' proto/*.proto
|
||||
|
||||
cd proto
|
||||
dirs=$(find -type d)
|
||||
cd ..
|
||||
|
||||
# generate types to tmp dir
|
||||
npx proto-loader-gen-types \
|
||||
--keepCase \
|
||||
--longs=String \
|
||||
--enums=String \
|
||||
--defaults \
|
||||
--oneofs \
|
||||
--grpcLib=@grpc/grpc-js \
|
||||
--outDir=src/grpc/types \
|
||||
proto/*.proto || exit 1
|
||||
for d in $dirs
|
||||
do
|
||||
npx proto-loader-gen-types \
|
||||
--keepCase \
|
||||
--longs=String \
|
||||
--enums=String \
|
||||
--defaults \
|
||||
--oneofs \
|
||||
--grpcLib=@grpc/grpc-js \
|
||||
--outDir=src/grpc/types/"$d" \
|
||||
proto/"$d"/*.proto || exit 1
|
||||
done
|
||||
|
||||
# undo `sed` on the proto dir
|
||||
git restore proto
|
||||
|
|
@ -46,10 +53,12 @@ done
|
|||
# replace any with unknown in some generated type
|
||||
sed -zi 's/{\n}/{ [k: string]: never }/g;s/Constructor extends new (...args: any) => any/Constructor extends new (...args: unknown[]) => unknown/g' **/*.ts
|
||||
|
||||
# array of names of the .ts files without their extension
|
||||
protos=$(ls *.ts | sed 's/\..*$//')
|
||||
cd ../../../proto
|
||||
|
||||
cd .. # src/grpc
|
||||
# array of names of the .proto files without their extension
|
||||
protos=$(ls **/*.proto | sed 's/\..*$//')
|
||||
|
||||
cd ../src/grpc
|
||||
|
||||
# header of generated file, notice one redirect symbol (>), this creates a fresh file with this content
|
||||
echo -e "// Generated file. Do not edit. Edit the template proto.ts.template instead.\n" > proto.ts
|
||||
|
|
@ -57,11 +66,12 @@ echo -e "// Generated file. Do not edit. Edit the template proto.ts.template ins
|
|||
# loop through lines of the template file and echo lines to the generated file. >> is used here to append it
|
||||
cat proto.ts.template | while read line
|
||||
do
|
||||
if echo "$line" | grep -i '{{name}}' > /dev/null 2>&1; then
|
||||
# this line contains {{Name}} or {{name}}
|
||||
if echo "$line" | grep -E '{{name}}|{{path}}' > /dev/null 2>&1; then
|
||||
# this line contains {{name}} or {{path}}
|
||||
for p in $protos
|
||||
do
|
||||
echo "$line" | sed "s/{{name}}/$p/g;s/{{Name}}/${p^}/g"
|
||||
n=$(basename "$p")
|
||||
echo "$line" | sed "s|{{name}}|${n^}|g;s|{{path}}|$p|g"
|
||||
done
|
||||
else
|
||||
# just write, nothing special
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
import * as grpc from '@grpc/grpc-js'
|
||||
import { loadSync, Options } from '@grpc/proto-loader'
|
||||
|
||||
import type { ProtoGrpcType as {{Name}}ProtoGrpcType } from './types/{{name}}'
|
||||
import type { ProtoGrpcType as {{name}}ProtoGrpcType } from './types/{{path}}'
|
||||
|
||||
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'
|
||||
|
||||
type ProtoName =
|
||||
| '{{name}}'
|
||||
| '{{path}}'
|
||||
|
||||
type ProtoGrpcType =
|
||||
| {{Name}}ProtoGrpcType
|
||||
| {{name}}ProtoGrpcType
|
||||
|
||||
const opts: Options = {
|
||||
keepCase: true,
|
||||
|
|
@ -19,7 +19,7 @@ const opts: Options = {
|
|||
oneofs: true,
|
||||
}
|
||||
|
||||
export function loadProto(name: '{{name}}'): {{Name}}ProtoGrpcType
|
||||
export function loadProto(name: '{{path}}'): {{name}}ProtoGrpcType
|
||||
export function loadProto(name: ProtoName): ProtoGrpcType
|
||||
export function loadProto(name: ProtoName): ProtoGrpcType {
|
||||
return grpc.loadPackageDefinition(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue