Skip to content

Commit

Permalink
Add Node.js SDK, example and docs - closes #538
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-supersolid authored and markmandel committed Mar 6, 2019
1 parent 0b9af68 commit 2344edb
Show file tree
Hide file tree
Showing 22 changed files with 6,345 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
!.dockerignore
!.golangci.yml
!.gcloudignore
!.eslintrc.*
!.nycrc
*.iml
bin
*.o
Expand Down
7 changes: 6 additions & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,17 @@ push-release-chart: $(ensure-build-image)
build-sdks: build-sdk-cpp

# Run all tests
test: $(ensure-build-image) test-go test-install-yaml site-test
test: $(ensure-build-image) test-go test-nodejs test-install-yaml site-test

# Run go tests
test-go:
$(GO_TEST) $(agones_package)/pkg/... \
$(agones_package)/sdks/... $(agones_package)/cmd/...

# Run Node.js SDK tests
test-nodejs:
docker run --rm $(common_mounts) -w $(mount_path)/sdks/nodejs $(build_tag) npm install-test

# Runs end-to-end tests on the current configured cluster
# For minikube user the minikube-test-e2e targets
test-e2e: $(ensure-build-image)
Expand Down Expand Up @@ -356,6 +360,7 @@ gen-gameservers-sdk-grpc: $(ensure-build-image)
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-go.sh
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-cpp.sh
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-rust.sh
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-nodejs.sh

# Generate the client for our CustomResourceDefinition
gen-crd-client: $(ensure-build-image)
Expand Down
32 changes: 32 additions & 0 deletions build/build-image/gen-grpc-nodejs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -x

header() {
cat ./build/boilerplate.go.txt $1 >> ./tmp.js && mv ./tmp.js $1
}

googleapis=/go/src/agones.dev/agones/vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis

cd /go/src/agones.dev/agones

protoc -I ${googleapis} -I . --grpc_out=./sdks/nodejs/lib --plugin=protoc-gen-grpc=`which grpc_node_plugin` sdk.proto
protoc -I ${googleapis} -I . --js_out=import_style=commonjs,binary:./sdks/nodejs/lib sdk.proto ${googleapis}/google/api/annotations.proto ${googleapis}/google/api/http.proto

header ./sdks/nodejs/lib/sdk_pb.js
header ./sdks/nodejs/lib/google/api/annotations_pb.js
header ./sdks/nodejs/lib/google/api/http_pb.js
1 change: 1 addition & 0 deletions examples/nodejs-simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
4 changes: 4 additions & 0 deletions examples/nodejs-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Instructions
`npm install` - install dependencies

`npm start` - start the self-running example
8 changes: 8 additions & 0 deletions examples/nodejs-simple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"agones": "../../sdks/nodejs"
},
"scripts": {
"start": "node src/index.js"
}
}
32 changes: 32 additions & 0 deletions examples/nodejs-simple/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const AgonesSDK = require('agones');

let agonesSDK = new AgonesSDK();

let connect = async function() {
agonesSDK.watchGameServer((result) => {
console.log('watch', result);
});

try {
await agonesSDK.ready();
await agonesSDK.setLabel("label", "labelValue");
await agonesSDK.setAnnotation("annotation", "annotationValue");
let result = await agonesSDK.getGameServer();
console.log('gameServer', result);
setTimeout(() => {
console.log('send health ping');
agonesSDK.health();
}, 2000);
setTimeout(() => {
console.log('send shutdown request');
agonesSDK.shutdown();
}, 4000);
setTimeout(() => {
process.exit();
}, 6000);
} catch (error) {
console.error(error);
}
};

connect();
10 changes: 10 additions & 0 deletions sdks/nodejs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2017
}
}
2 changes: 2 additions & 0 deletions sdks/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/
/coverage/
9 changes: 9 additions & 0 deletions sdks/nodejs/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"include": [
"src/**/*.js"
],
"reporter": [
"lcov",
"text"
]
}
8 changes: 8 additions & 0 deletions sdks/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Instructions
`npm install` - install dependencies

`npm run cover` - run tests and report code coverage

`npm run lint` - lint the code

`npm test` - run the tests
55 changes: 55 additions & 0 deletions sdks/nodejs/lib/google/api/annotations_pb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2018 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This code was autogenerated. Do not edit directly.
/**
* @fileoverview
* @enhanceable
* @public
*/
// GENERATED CODE -- DO NOT EDIT!

var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();

var google_api_http_pb = require('../../google/api/http_pb.js');
var google_protobuf_descriptor_pb = require('google-protobuf/google/protobuf/descriptor_pb.js');
goog.exportSymbol('google.api.http', null, global);

/**
* A tuple of {field number, class constructor} for the extension
* field named `http`.
* @type {!jspb.ExtensionFieldInfo.<!proto.google.api.HttpRule>}
*/
proto.google.api.http = new jspb.ExtensionFieldInfo(
72295728,
{http: 0},
google_api_http_pb.HttpRule,
/** @type {?function((boolean|undefined),!jspb.Message=): !Object} */ (
google_api_http_pb.HttpRule.toObject),
0);

google_protobuf_descriptor_pb.MethodOptions.extensionsBinary[72295728] = new jspb.ExtensionFieldBinaryInfo(
proto.google.api.http,
jspb.BinaryReader.prototype.readMessage,
jspb.BinaryWriter.prototype.writeMessage,
google_api_http_pb.HttpRule.serializeBinaryToWriter,
google_api_http_pb.HttpRule.deserializeBinaryFromReader,
false);
// This registers the extension field with the extended class, so that
// toObject() will function correctly.
google_protobuf_descriptor_pb.MethodOptions.extensions[72295728] = proto.google.api.http;

goog.object.extend(exports, proto.google.api);
Loading

0 comments on commit 2344edb

Please sign in to comment.