@@ -13,101 +13,80 @@ CLEAN.include('spec/pb-ts/*.ts')
1313CLEAN . include ( 'spec/js-client/main.js' )
1414CLEAN . include ( 'spec/node-client/dist/*' )
1515
16- task :compile_protos_js do
17- defs_dir = File . expand_path ( 'spec' , __dir__ )
18- proto_files = Dir [ File . join ( defs_dir , 'pb-src/**/*.proto' ) ]
19- proto_input_files = proto_files . map { it . gsub ( defs_dir , '/defs' ) }
16+ task :down do
17+ sh 'docker compose down'
18+ end
19+
20+ task :build do
21+ sh 'docker compose build'
22+ end
2023
21- # Build the protoc container first
22- sh 'docker compose down && docker compose build'
24+ def protoc ( output_opts )
25+ proto_files = Dir [ File . join ( File . expand_path ( 'spec' , __dir__ ) , 'pb-src/**/*.proto' ) ]
2326
2427 # Generate grpc-web (binary format) JS files
2528 sh [
26- 'docker compose run --remove-orphans --entrypoint protoc protoc' ,
27- '--plugin=protoc-gen-js=/usr/lib/node_modules/protoc-gen-js/bin/protoc-gen-js' ,
28- '--plugin=protoc-gen-grpc-web=/usr/local/bin/protoc-gen-grpc-web' ,
29- '--js_out=import_style=commonjs:/defs/pb-js-grpc-web' ,
30- '--grpc-web_out=import_style=commonjs,mode=grpcweb:/defs/pb-js-grpc-web' ,
31- '-I /defs/pb-src' ,
32- proto_input_files . join ( ' ' ) ,
33- ] . join ( ' ' )
34-
35- # Generate grpc-web-text (base64 format) JS files
36- sh [
37- 'docker compose run --remove-orphans --entrypoint protoc protoc' ,
38- '--plugin=protoc-gen-js=/usr/lib/node_modules/protoc-gen-js/bin/protoc-gen-js' ,
39- '--plugin=protoc-gen-grpc-web=/usr/local/bin/protoc-gen-grpc-web' ,
40- '--js_out=import_style=commonjs:/defs/pb-js-grpc-web-text' ,
41- '--grpc-web_out=import_style=commonjs,mode=grpcwebtext:/defs/pb-js-grpc-web-text' ,
42- '-I /defs/pb-src' ,
43- proto_input_files . join ( ' ' ) ,
44- ] . join ( ' ' )
29+ 'docker compose run --rm --remove-orphans --entrypoint protoc protoc' ,
30+ '--plugin=protoc-gen-js=/usr/lib/node_modules/protoc-gen-js/bin/protoc-gen-js' ,
31+ '--plugin=protoc-gen-ts=/usr/bin/protoc-gen-ts' ,
32+ '--plugin=protoc-gen-grpc-web=/usr/local/bin/protoc-gen-grpc-web' ,
33+ '--plugin=protoc-gen-grpc-ruby=/usr/local/bin/grpc_tools_ruby_protoc_plugin' ,
34+ output_opts ,
35+ '-I /defs/pb-src' ,
36+ proto_files . map { File . basename ( it ) }
37+ ] . flatten . join ( ' ' )
38+ end
39+
40+ task compile_protos_js : [ :down , :build ] do
41+ protoc %w[
42+ --js_out=import_style=commonjs:/defs/pb-js-grpc-web
43+ --grpc-web_out=import_style=commonjs,mode=grpcweb:/defs/pb-js-grpc-web
44+ ]
45+
46+ protoc %w[
47+ --js_out=import_style=commonjs:/defs/pb-js-grpc-web-text
48+ --grpc-web_out=import_style=commonjs,mode=grpcwebtext:/defs/pb-js-grpc-web-text
49+ ]
4550end
4651
4752task :compile_protos_ruby do
48- defs_dir = File . expand_path ( 'spec' , __dir__ )
49- proto_files = Dir [ File . join ( defs_dir , 'pb-src/**/*.proto' ) ]
50- proto_input_files = proto_files . map { it . gsub ( defs_dir , '/defs' ) }
51- sh [
52- 'docker compose down &&' ,
53- 'docker compose build &&' ,
54- 'docker compose run --remove-orphans --entrypoint grpc_tools_ruby_protoc protoc' ,
55- '--ruby_out=/defs/pb-ruby' ,
56- '--grpc_out=/defs/pb-ruby' ,
57- '-I /defs/pb-src' ,
58- proto_input_files . join ( ' ' ) ,
59- ] . join ( ' ' )
53+ protoc %w[
54+ --ruby_out=/defs/pb-ruby
55+ --grpc-ruby_out=/defs/pb-ruby
56+ ]
6057end
6158
6259task :compile_protos_ts do
63- defs_dir = File . expand_path ( 'spec' , __dir__ )
64- proto_files = Dir [ File . join ( defs_dir , 'pb-src/**/*.proto' ) ]
65- proto_input_files = proto_files . map { it . gsub ( defs_dir , '/defs' ) }
66- sh [
67- 'docker compose down &&' ,
68- 'docker compose build &&' ,
69- 'docker compose run --remove-orphans --entrypoint protoc protoc' ,
70- '--plugin=protoc-gen-js=/usr/lib/node_modules/protoc-gen-js/bin/protoc-gen-js' ,
71- '--plugin=protoc-gen-ts=/usr/bin/protoc-gen-ts' ,
72- '--js_out=import_style=commonjs,binary:/defs/pb-ts' ,
73- '--ts_out=service=grpc-web:/defs/pb-ts' ,
74- '-I /defs/pb-src' ,
75- proto_input_files . join ( ' ' ) ,
76- ] . join ( ' ' )
60+ protoc %w[
61+ --js_out=import_style=commonjs,binary:/defs/pb-ts
62+ --ts_out=service=grpc-web:/defs/pb-ts
63+ ]
7764end
7865
79- task compile_js_client : [ :compile_protos_js ] do
66+ task compile_protos : [ :compile_protos_js , :compile_protos_ts , :compile_protos_ruby ]
67+
68+ task compile_js_client : [ :down , :build , :compile_protos_js ] do
8069 compile_js_cmd = '"cd spec/js-client-src; yarn install; yarn run webpack"'
81- sh [
82- 'docker compose down' ,
83- 'docker compose build' ,
84- "docker compose run --use-aliases --remove-orphans ruby #{ compile_js_cmd } " ,
85- ] . join ( ' && ' )
70+ sh "docker compose run --rm --use-aliases --remove-orphans ruby #{ compile_js_cmd } "
8671end
8772
88- task compile_node_client : [ :compile_protos_ts ] do
73+ task compile_node_client : [ :down , :build , : compile_protos_ts] do
8974 compile_node_cmd = '"cd spec/node-client; yarn install; yarn build"'
90- sh [
91- 'docker compose down' ,
92- 'docker compose build' ,
93- "docker compose run --use-aliases --remove-orphans ruby #{ compile_node_cmd } " ,
94- ] . join ( ' && ' )
75+ sh "docker compose run --use-aliases --remove-orphans ruby #{ compile_node_cmd } "
9576end
9677
78+ task compile_clients : [ :compile_js_client , :compile_node_client ]
79+
80+ task compile : [ :compile_protos , :compile_clients ]
81+
9782task :run_specs_in_docker do
98- sh [
99- 'docker compose down' ,
100- 'docker compose build' ,
101- 'docker compose up -d selenium envoy' ,
102- 'docker compose run --use-aliases --remove-orphans ruby rspec' ,
103- 'docker compose down' ,
104- ] . join ( ' && ' )
83+ sh 'docker compose run --rm --use-aliases --remove-orphans ruby rspec'
10584end
10685
10786task default : %i[
10887 clean
109- compile_protos_ruby
110- compile_js_client
111- compile_node_client
88+ down
89+ build
90+ compile
11291 run_specs_in_docker
11392]
0 commit comments