Skip to content

Commit 1d82deb

Browse files
authored
Merge pull request #11 from SamuAlfageme/node_cs3apis_gen
Add support to build Node.js CS3API bindings and push them to GitHub
2 parents 65e9c24 + 7deb31f commit 1d82deb

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ RUN sudo python -m pip install grpcio grpcio-tools --ignore-installed
2222
RUN curl -sSL https://github.com/grpc/grpc-web/releases/download/1.0.6/protoc-gen-grpc-web-1.0.6-linux-x86_64 -o /tmp/protoc-gen-grpc-web
2323
RUN sudo mv /tmp/protoc-gen-grpc-web /usr/local/bin/ && sudo chmod u+x /usr/local/bin/protoc-gen-grpc-web
2424

25+
# deps for node.js
26+
RUN curl -fsSL https://deb.nodesource.com/setup_15.x | bash -
27+
RUN apt-get install -y nodejs
28+
RUN npm install -g grpc-tools
29+
2530
# compile build tool and put it into path
2631
ADD . /root/cs3apis-build
2732
RUN cd /root/cs3apis-build/ && go build . && sudo cp cs3apis-build /usr/local/bin && sudo chmod u+x cs3apis-build

build.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ var (
3232

3333
_buildJs = flag.Bool("build-js", false, "Build Js library")
3434
_pushJs = flag.Bool("push-js", false, "Push Js library to github.com/cs3org/js-cs3apis")
35+
36+
_buildNode = flag.Bool("build-node", false, "Build Node.js library")
37+
_pushNode = flag.Bool("push-node", false, "Push Node.js library to github.com/cs3org/node-cs3apis")
3538
)
3639

3740
func init() {
@@ -42,17 +45,20 @@ func init() {
4245
*_buildGo = true
4346
*_buildPython = true
4447
*_buildJs = true
48+
*_buildNode = true
4549

4650
*_pushGo = true
4751
*_pushPython = true
4852
*_pushJs = true
53+
*_pushNode = true
4954
}
5055

5156
if *_only_build {
5257
*_buildProto = true
5358
*_buildGo = true
5459
*_buildPython = true
5560
*_buildJs = true
61+
*_buildNode = true
5662
}
5763
}
5864

@@ -418,6 +424,44 @@ func buildJS() {
418424
commit(repo, msg)
419425
}
420426

427+
func buildNode() {
428+
// Remove build dir
429+
os.RemoveAll("build/node-cs3apis")
430+
os.MkdirAll("build", 0755)
431+
432+
// Clone repo and set branch to current branch
433+
clone("cs3org/node-cs3apis", "build")
434+
protoBranch := getGitBranch(".")
435+
buildBranch := getGitBranch("build/node-cs3apis")
436+
fmt.Printf("Proto branch: %s\nBuild branch: %s\n", protoBranch, buildBranch)
437+
438+
if buildBranch != protoBranch {
439+
checkout(protoBranch, "build/node-cs3apis")
440+
}
441+
442+
nodeProtocPlugin, err := exec.LookPath("grpc_tools_node_protoc_plugin")
443+
444+
if err != nil {
445+
panic(fmt.Sprintf("grpc_tools_node_protoc_plugin binary not found in PATH: %v\n", err))
446+
}
447+
448+
// remove leftovers (existing defs)
449+
os.RemoveAll("build/node-cs3apis/cs3")
450+
451+
files := findProtos()
452+
453+
args := []string{"--js_out=import_style=commonjs,binary:./build/node-cs3apis", "--grpc_out=./build/node-cs3apis/", "--plugin=protoc-gen-grpc=" + nodeProtocPlugin}
454+
args = append(args, files...)
455+
cmd := exec.Command("grpc_tools_node_protoc", args...)
456+
run(cmd)
457+
458+
// get proto repo commit id
459+
hash := getCommitID(".")
460+
repo := "build/node-cs3apis"
461+
msg := "Synced to https://github.com/cs3org/cs3apis/tree/" + hash
462+
commit(repo, msg)
463+
}
464+
421465
func pushPython() {
422466
push("build/python-cs3apis")
423467
}
@@ -430,9 +474,13 @@ func pushJS() {
430474
push("build/js-cs3apis")
431475
}
432476

477+
func pushNode() {
478+
push("build/node-cs3apis")
479+
}
480+
433481
func main() {
434482
if *_buildProto {
435-
fmt.Println("Compiling and liniting protobufs ...")
483+
fmt.Println("Compiling and linting protobufs ...")
436484
buildProto()
437485
}
438486

@@ -465,4 +513,14 @@ func main() {
465513
fmt.Println("Pushing Js ...")
466514
pushJS()
467515
}
516+
517+
if *_buildNode {
518+
fmt.Println("Building Node.js ...")
519+
buildNode()
520+
}
521+
522+
if *_pushNode {
523+
fmt.Println("Pushing Node.js ...")
524+
pushNode()
525+
}
468526
}

0 commit comments

Comments
 (0)