Skip to content

Commit 7d38341

Browse files
authored
Merge pull request #913 from IntersectMBO/add-all-proto-files-to-nix-output
Modify `proto-to-js.nix` to bundle all proto files
2 parents 6a1001a + 6c6217f commit 7d38341

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

nix/proto-to-js.nix

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,46 +40,49 @@ in pkgs.stdenv.mkDerivation {
4040
GEN_JS_PATH=./generated-js
4141
BUNDLE_PATH=./bundled-js
4242
43-
mkdir -p $GEN_JS_PATH
44-
mkdir -p $BUNDLE_PATH
45-
46-
PROTO_FILE=$PROTO_INCLUDE_PATH/cardano/rpc/node.proto
43+
mkdir -p "$GEN_JS_PATH"
44+
mkdir -p "$BUNDLE_PATH"
4745
4846
echo "--- Compiling .proto file: $PROTO_FILE ---"
4947
50-
protoc \
51-
-I=$PROTO_INCLUDE_PATH \
52-
--js_out=import_style=commonjs,binary:$GEN_JS_PATH \
53-
--grpc-web_out=import_style=commonjs,mode=grpcwebtext:$GEN_JS_PATH \
54-
$PROTO_FILE
48+
for PROTO_FILE in `find "$PROTO_INCLUDE_PATH" -type f -name "*.proto"`
49+
do
50+
protoc \
51+
-I="$PROTO_INCLUDE_PATH" \
52+
--js_out=import_style=commonjs,binary:"$GEN_JS_PATH" \
53+
--grpc-web_out=import_style=commonjs,mode=grpcwebtext:"$GEN_JS_PATH" \
54+
"$PROTO_FILE"
55+
done
5556
5657
echo "--- Compilation finished. Generated files are in $GEN_JS_PATH ---"
57-
ls -R $GEN_JS_PATH
58-
59-
GENERATED_GRPC_FILE=$GEN_JS_PATH/cardano/rpc/node_grpc_web_pb.js
58+
ls -R "$GEN_JS_PATH"
6059
61-
if [ ! -f "$GENERATED_GRPC_FILE" ]; then
62-
echo "Error: Protoc did not generate the expected gRPC-Web file!"
63-
exit 1
60+
# Check if there are any files in the top-level generated directory
61+
if [ ! "$(ls -1 "$GEN_JS_PATH" | head -n 1)" ]; then
62+
echo "Error: protoc did not generate any gRPC-Web files!"
63+
exit 1
6464
fi
6565
6666
echo "--- Setting up node_modules for browserify ---"
6767
ln -s ${node-deps}/node_modules ./node_modules
6868
6969
echo "--- Bundling generated JS with browserify ---"
7070
71-
browserify --standalone grpc $GENERATED_GRPC_FILE > $BUNDLE_PATH/node_grpc_web_pb.js
71+
for GENERATED_GRPC_FILE in `find "$GEN_JS_PATH" -type f -name "*.js"`
72+
do
73+
browserify --standalone grpc "$GENERATED_GRPC_FILE" > "$BUNDLE_PATH/$(basename $GENERATED_GRPC_FILE)"
74+
done
7275
73-
echo "--- Bundling complete. Final file is in $BUNDLE_PATH ---"
74-
ls $BUNDLE_PATH
76+
echo "--- Bundling complete. Final files are in $BUNDLE_PATH ---"
77+
ls "$BUNDLE_PATH"
7578
7679
runHook postBuild
7780
'';
7881

7982
installPhase = ''
8083
runHook preInstall
81-
mkdir -p $out
82-
cp ./bundled-js/node_grpc_web_pb.js $out/
84+
mkdir -p "$out"
85+
cp ./bundled-js/*_grpc_web_pb.js "$out/"
8386
runHook postInstall
8487
'';
8588

0 commit comments

Comments
 (0)