Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Jan 16, 2022
1 parent 11d6bf4 commit 9af4e08
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 431 deletions.
31 changes: 1 addition & 30 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ rules_proto_dependencies()
rules_proto_toolchains()

# Setup cypress

load("@build_bazel_rules_nodejs//toolchains/cypress:cypress_repositories.bzl", "cypress_repositories")

cypress_repositories(
Expand Down Expand Up @@ -94,32 +93,4 @@ crate_universe(

load("@crates//:defs.bzl", "pinned_rust_install")

pinned_rust_install()


# Set up swc
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "aspect_rules_swc",
sha256 = "b58c8f3681215af30842bc3eeec30c9d2047cdf63302bba7d2e86c55a5c77edf",
strip_prefix = "rules_swc-0.3.1",
url = "https://github.com/aspect-build/rules_swc/archive/v0.3.1.tar.gz",
)

# Fetches the rules_swc dependencies.
# If you want to have a different version of some dependency,
# you should fetch it *before* calling this.
# Alternatively, you can skip calling this function, so long as you've
# already fetched all the dependencies.
load("@aspect_rules_swc//swc:dependencies.bzl", "rules_swc_dependencies")
rules_swc_dependencies()

# Fetches a pre-built Rust-node binding from
# https://github.com/swc-project/swc/releases.
# If you'd rather compile it from source, you can use rules_rust, fetch the project,
# then register the toolchain yourself. (Note, this is not yet documented)
load("@aspect_rules_swc//swc:repositories.bzl", "swc_register_toolchains")
swc_register_toolchains(
name = "swc",
swc_version = "v1.2.118",
)
pinned_rust_install()
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"@types/google-protobuf": "^3.15.5",
"@types/jasmine": "^3.7.7",
"@types/node": "^15.12.5",
"express": "^4.17.1"
"@swc/cli": "^0.1.55",
"@swc/core": "^1.2.124",
"http-server": "^14.0.0"
}
}
69 changes: 0 additions & 69 deletions test/web/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("@npm//@bazel/typescript:index.bzl", "ts_project")
load("@npm//@bazel/cypress:index.bzl", "cypress_web_test")
Expand All @@ -9,74 +8,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("//:index.bzl", "ts_proto_library")

proto_library(
name = "protos",
srcs = glob(["**/*.proto"])
)

ts_proto_library(
name = "codegen",
deps = [
":protos",
],
target = "web"
)


# Server

ts_project(
name = "server",
srcs = [
"weather.ts",
"server.ts"
],
tsconfig = {
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS"
},
},
deps = [
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//google-protobuf",
"@npm//@grpc/grpc-js",
"@npm//grpc-web",
],
)

nodejs_binary(
name = "bin",
entry_point = ":server.js",
data = [
":server",
]
)

expand_runfiles(
name = "runfiles",
binary = ":bin"
)

pkg_tar(
name = "entrypoint",
strip_prefix = ".",
srcs = [
":runfiles",
],
)

container(
name = "server",
base = "envoyproxy/envoy:latest",
cmd = ["/test/web/bin.sh"],
layers = [
":entrypoint"
]
)


cypress_web_test(
name = "test",
srcs = [
Expand Down
53 changes: 53 additions & 0 deletions test/web/client/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:index.bzl", "ts_proto_library")
load("@npm//@swc/cli:index.bzl", "spack")
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
load("@npm//http-server:index.bzl", "http_server")

proto_library(
name = "protos",
srcs = glob(["**/*.proto"])
)

ts_proto_library(
name = "codegen",
deps = [
":protos",
],
target = "web"
)

generated_file_test(
name = "weather_checked_in",
generated = "src/weather.ts",
src = ":codegen",
)

spack(
name = "bundle",
outs = ["index.js"],
args = [
"--entry", "$(execpath src/index.ts)",
"--target", "browser",
"--config", "../../../$(rootpath spack.config.js)",
"-o", "$(RULEDIR)",
],
data = [
"src/index.ts",
"src/weather.ts",
"spack.config.js",
"@npm//google-protobuf",
"@npm//grpc-web"
],
)


http_server(
name = "server",
data = [
"index.js",
"index.html",
],
templated_args = ["test/web/client/"],
)
51 changes: 51 additions & 0 deletions test/web/client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather</title>
<script>
function __swcpack_require__(mod) {
function interop(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {
};
if (obj != null) {
for(var key in obj){
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {
};
if (desc.get || desc.set) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
}
newObj.default = obj;
return newObj;
}
}
var cache;
if (cache) {
return cache;
}
var module = {
exports: {
}
};
mod(module, module.exports);
cache = interop(module.exports);
return cache;
}
</script>
<script type="module" src="/index.js"></script>
</head>
<body>
It is kinda working!
</body>
</html>
8 changes: 8 additions & 0 deletions test/web/client/spack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { config } = require('@swc/core/spack')

module.exports = config({
output: {
path: process.argv[process.argv.length - 1],
name: "app",
},
});
41 changes: 41 additions & 0 deletions test/web/client/src/weather.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
syntax = "proto3";

package weather;

message City {
// See: https://en.wikipedia.org/wiki/ISO_3166-2
string code = 1;
string name = 2;
}

message Temperature {
// See: https://en.wikipedia.org/wiki/ISO_3166-2
string code = 1;
int32 current = 2;
}

message CityQuery {
message Result { repeated City cities = 2; }
}

message GetTemperature { string code = 1; }

message Ping {
message Ack {}
}

message Forecast {
string code = 1;
string date = 2;
message Result {
Temperature temperature = 1;
}
}

service Weather {
rpc cities(CityQuery) returns (CityQuery.Result);
rpc get(GetTemperature) returns (stream Temperature);
// Unsupported at the moment
// rpc ping(stream Ping) returns (Ping.Ack);
// rpc forecast(stream Forecast) returns (stream Forecast.Result);
}
Loading

0 comments on commit 9af4e08

Please sign in to comment.