Skip to content

Commit

Permalink
Merge pull request #11 from SamuAlfageme/node_cs3apis_gen
Browse files Browse the repository at this point in the history
Add support to build Node.js CS3API bindings and push them to GitHub
  • Loading branch information
ishank011 authored Apr 13, 2021
2 parents 65e9c24 + 7deb31f commit 1d82deb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ RUN sudo python -m pip install grpcio grpcio-tools --ignore-installed
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
RUN sudo mv /tmp/protoc-gen-grpc-web /usr/local/bin/ && sudo chmod u+x /usr/local/bin/protoc-gen-grpc-web

# deps for node.js
RUN curl -fsSL https://deb.nodesource.com/setup_15.x | bash -
RUN apt-get install -y nodejs
RUN npm install -g grpc-tools

# compile build tool and put it into path
ADD . /root/cs3apis-build
RUN cd /root/cs3apis-build/ && go build . && sudo cp cs3apis-build /usr/local/bin && sudo chmod u+x cs3apis-build
Expand Down
60 changes: 59 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var (

_buildJs = flag.Bool("build-js", false, "Build Js library")
_pushJs = flag.Bool("push-js", false, "Push Js library to github.com/cs3org/js-cs3apis")

_buildNode = flag.Bool("build-node", false, "Build Node.js library")
_pushNode = flag.Bool("push-node", false, "Push Node.js library to github.com/cs3org/node-cs3apis")
)

func init() {
Expand All @@ -42,17 +45,20 @@ func init() {
*_buildGo = true
*_buildPython = true
*_buildJs = true
*_buildNode = true

*_pushGo = true
*_pushPython = true
*_pushJs = true
*_pushNode = true
}

if *_only_build {
*_buildProto = true
*_buildGo = true
*_buildPython = true
*_buildJs = true
*_buildNode = true
}
}

Expand Down Expand Up @@ -418,6 +424,44 @@ func buildJS() {
commit(repo, msg)
}

func buildNode() {
// Remove build dir
os.RemoveAll("build/node-cs3apis")
os.MkdirAll("build", 0755)

// Clone repo and set branch to current branch
clone("cs3org/node-cs3apis", "build")
protoBranch := getGitBranch(".")
buildBranch := getGitBranch("build/node-cs3apis")
fmt.Printf("Proto branch: %s\nBuild branch: %s\n", protoBranch, buildBranch)

if buildBranch != protoBranch {
checkout(protoBranch, "build/node-cs3apis")
}

nodeProtocPlugin, err := exec.LookPath("grpc_tools_node_protoc_plugin")

if err != nil {
panic(fmt.Sprintf("grpc_tools_node_protoc_plugin binary not found in PATH: %v\n", err))
}

// remove leftovers (existing defs)
os.RemoveAll("build/node-cs3apis/cs3")

files := findProtos()

args := []string{"--js_out=import_style=commonjs,binary:./build/node-cs3apis", "--grpc_out=./build/node-cs3apis/", "--plugin=protoc-gen-grpc=" + nodeProtocPlugin}
args = append(args, files...)
cmd := exec.Command("grpc_tools_node_protoc", args...)
run(cmd)

// get proto repo commit id
hash := getCommitID(".")
repo := "build/node-cs3apis"
msg := "Synced to https://github.com/cs3org/cs3apis/tree/" + hash
commit(repo, msg)
}

func pushPython() {
push("build/python-cs3apis")
}
Expand All @@ -430,9 +474,13 @@ func pushJS() {
push("build/js-cs3apis")
}

func pushNode() {
push("build/node-cs3apis")
}

func main() {
if *_buildProto {
fmt.Println("Compiling and liniting protobufs ...")
fmt.Println("Compiling and linting protobufs ...")
buildProto()
}

Expand Down Expand Up @@ -465,4 +513,14 @@ func main() {
fmt.Println("Pushing Js ...")
pushJS()
}

if *_buildNode {
fmt.Println("Building Node.js ...")
buildNode()
}

if *_pushNode {
fmt.Println("Pushing Node.js ...")
pushNode()
}
}

0 comments on commit 1d82deb

Please sign in to comment.