Skip to content

Commit

Permalink
test: add a nest example
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Jul 16, 2019
1 parent d32d3a8 commit 38c810f
Show file tree
Hide file tree
Showing 12 changed files with 1,094 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/nestjs/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions examples/nestjs/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import %workspace%/../../common.bazelrc
15 changes: 15 additions & 0 deletions examples/nestjs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2019 The Bazel Authors. 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.

exports_files(["tsconfig.json"])
1 change: 1 addition & 0 deletions examples/nestjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Nest Bazel Example
61 changes: 61 additions & 0 deletions examples/nestjs/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2017 The Bazel Authors. 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.

workspace(
name = "examples_nestjs",
managed_directories = {"@npm": ["node_modules"]},
)

# In your code, you'd fetch this repository with an `http_archive` call.
# We do this local repository only because this example lives in the same
# repository with the rules_nodejs code and we want to test them together.
local_repository(
name = "build_bazel_rules_nodejs",
path = "../../dist/build_bazel_rules_nodejs/release",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")

yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)

load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")

install_bazel_dependencies()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_docker",
sha256 = "87fc6a2b128147a0a3039a2fd0b53cc1f2ed5adb8716f50756544a572999ae9a",
strip_prefix = "rules_docker-0.8.1",
urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.8.1.tar.gz"],
)

load(
"@io_bazel_rules_docker//repositories:repositories.bzl",
container_repositories = "repositories",
)

container_repositories()

load(
"@io_bazel_rules_docker//nodejs:image.bzl",
nodejs_image_repositories = "repositories",
)

nodejs_image_repositories()
19 changes: 19 additions & 0 deletions examples/nestjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"dependencies": {
"@nestjs/common": "6.5.2",
"@nestjs/core": "6.5.2",
"@nestjs/platform-express": "6.5.2",
"minimist": "1.2.0",
"reflect-metadata": "0.1.13",
"rxjs": "6.5.2"
},
"devDependencies": {
"@bazel/typescript": "file:../../dist/npm_bazel_typescript",
"@types/node": "12.6.3",
"typescript": "3.5.3"
},
"scripts": {
"test": "bazel build ... && bazel build --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 ..."
}
}
55 changes: 55 additions & 0 deletions examples/nestjs/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2019 The Bazel Authors. 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.

package(default_visibility = ["//visibility:public"])

load("@npm_bazel_typescript//:index.bzl", "ts_library")

ts_library(
name = "app",
srcs = glob(["*.ts"]),
deps = [
"@npm//@nestjs/common",
"@npm//@nestjs/core",
"@npm//@types/node",
"@npm//tslib",
],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")

# bazel run //src:server -- --port=4000
nodejs_binary(
name = "server",
data = [
":app",
"@npm//@nestjs/common",
"@npm//@nestjs/core",
"@npm//@nestjs/platform-express",
"@npm//minimist",
],
entry_point = ":main.ts",
)

load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")

# bazel build --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //src:docker
nodejs_image(
name = "docker",
data = [
":app",
],
entry_point = ":main.ts",
node_modules = "@npm//:node_modules",
)
9 changes: 9 additions & 0 deletions examples/nestjs/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Controller, Get} from '@nestjs/common';

@Controller()
export class AppController {
@Get()
getGreeting(): string {
return 'Hello world!';
}
}
9 changes: 9 additions & 0 deletions examples/nestjs/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Module} from '@nestjs/common';
import {AppController} from './app.controller';

@Module({
imports: [],
controllers: [AppController],
providers: [],
})
export class AppModule {}
15 changes: 15 additions & 0 deletions examples/nestjs/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Logger} from '@nestjs/common';
import {NestFactory} from '@nestjs/core';

import {AppModule} from './app.module';

async function bootstrap(port: number) {
const app = await NestFactory.create(AppModule);
await app.listen(port);
Logger.log(`Application served at http://localhost:${port}`);
}

if (require.main === module) {
const argv = require('minimist')(process.argv.slice(2));
bootstrap(argv.port || 3000);
}
Empty file added examples/nestjs/tsconfig.json
Empty file.
Loading

0 comments on commit 38c810f

Please sign in to comment.