Skip to content

Commit

Permalink
use rules_js instead of rules_nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukedirtwalker committed Oct 31, 2023
1 parent 09f6a05 commit cbd2426
Show file tree
Hide file tree
Showing 32 changed files with 3,507 additions and 3,120 deletions.
2 changes: 1 addition & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin
doc/_build
docker/_build
rules_openapi/tools/node_modules
private/mgmtapi/tools/node_modules
tools/lint/logctxcheck/testdata/src
50 changes: 40 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ lint_setup({

http_archive(
name = "aspect_bazel_lib",
sha256 = "e3151d87910f69cf1fc88755392d7c878034a69d6499b287bcfc00b1cf9bb415",
strip_prefix = "bazel-lib-1.32.1",
url = "https://github.com/aspect-build/bazel-lib/archive/refs/tags/v1.32.1.tar.gz",
sha256 = "a185ccff9c1b8589c63f66d7eb908de15c5d6bb05562be5f46336c53e7a7326a",
strip_prefix = "bazel-lib-2.0.0-rc1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.0.0-rc1/bazel-lib-v2.0.0-rc1.tar.gz",
)

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains")

# Required bazel-lib dependencies

aspect_bazel_lib_dependencies()

# Register bazel-lib toolchains

aspect_bazel_lib_register_toolchains()

# Bazel rules for Golang
http_archive(
name = "io_bazel_rules_go",
Expand Down Expand Up @@ -240,8 +246,10 @@ rules_proto_grpc_buf_repos()

http_archive(
name = "com_github_bazelbuild_buildtools",
strip_prefix = "buildtools-master",
url = "https://github.com/bazelbuild/buildtools/archive/2.2.1.zip",
strip_prefix = "buildtools-6.3.3",
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/6.3.3.tar.gz",
],
)

http_file(
Expand All @@ -262,10 +270,32 @@ load("@com_github_scionproto_scion_python_lint_deps//:requirements.bzl", install

install_python_lint_deps()

load("//rules_openapi:dependencies.bzl", "rules_openapi_dependencies")
http_archive(
name = "aspect_rules_js",
sha256 = "a949d56fed8fa0a8dd82a0a660acc949253a05b2b0c52a07e4034e27f11218f6",
strip_prefix = "rules_js-1.33.1",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.33.1/rules_js-v1.33.1.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

rules_openapi_dependencies()
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "nodejs",
node_version = DEFAULT_NODE_VERSION,
)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
pnpm_lock = "@com_github_scionproto_scion//private/mgmtapi/tools:pnpm-lock.yaml",
verify_node_modules_ignored = "@com_github_scionproto_scion//:.bazelignore",
)

load("//rules_openapi:install.bzl", "rules_openapi_install_yarn_dependencies")
load("@npm//:repositories.bzl", "npm_repositories")

rules_openapi_install_yarn_dependencies()
npm_repositories()
5 changes: 2 additions & 3 deletions control/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
load("//tools/lint:go.bzl", "go_library", "go_test")
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs")
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
load("//private/mgmtapi:api.bzl", "openapi_docs", "openapi_generate_go")

openapi_build_docs(
openapi_docs(
name = "doc",
src = "//spec:control",
out = "index.html",
Expand Down
5 changes: 2 additions & 3 deletions daemon/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
load("//tools/lint:go.bzl", "go_library")
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs")
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
load("//private/mgmtapi:api.bzl", "openapi_docs", "openapi_generate_go")

openapi_build_docs(
openapi_docs(
name = "doc",
src = "//spec:daemon",
out = "index.html",
Expand Down
5 changes: 2 additions & 3 deletions dispatcher/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
load("//tools/lint:go.bzl", "go_library")
load("//rules_openapi:defs.bzl", "openapi_build_docs")
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
load("//private/mgmtapi:api.bzl", "openapi_docs", "openapi_generate_go")

openapi_build_docs(
openapi_docs(
name = "doc",
src = "//spec:dispatcher",
out = "index.html",
Expand Down
5 changes: 2 additions & 3 deletions gateway/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
load("//tools/lint:go.bzl", "go_library")
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs")
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
load("//private/mgmtapi:api.bzl", "openapi_docs", "openapi_generate_go")

openapi_build_docs(
openapi_docs(
name = "doc",
src = "//spec:gateway",
out = "index.html",
Expand Down
62 changes: 62 additions & 0 deletions private/mgmtapi/api.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,68 @@ Macros for generating Go code from OpenAPI specs.

load("//tools/lint:write_source_files.bzl", "write_source_files")
load("//rules_openapi:defs.bzl", _openapi_generate_go = "openapi_generate_go")
load("@npm//private/mgmtapi/tools:@redocly/cli/package_json.bzl", redocly_bin = "bin")

def openapi_docs(
name,
src,
out,
**kwargs):
"""
Generates HTML documentation from an OpenAPI spec.
Args:
name: The name of the rule.
src: The source spec file (yml).
out: The output HTML file.
**kwargs: Additional arguments to pass to openapi binary.
"""

redocly_bin.openapi(
name = name,
srcs = [src],
outs = [out],
args = ["build-docs", "--output", "../../../$@", "../../../$(location {})".format(src)],
**kwargs
)

def openapi_bundle(
name,
entrypoint,
visibility = None,
srcs = [],
**kwargs):
"""
Generates a resolved spec file from a set of OpenAPI spec files.
The file output will be under {{name}}.bzl.gen.yml.
Args:
name: The name of the rules.
entrypoint: The entrypoint spec file.
visibility: The visibility of the target.
srcs: The list of spec files to bundle.
**kwargs: Additional arguments to pass to openapi binary. (should be srcs)
"""
redocly_bin.openapi(
name = name + "-no-header",
outs = [name + "-no-header.bzl.gen.yml"],
srcs = srcs + [entrypoint],
args = [
"bundle",
"--output",
"../../../$@",
"../../../$(location {})".format(entrypoint),
],
**kwargs
)
native.genrule(
name = name,
srcs = [name + "-no-header"],
outs = [name + ".bzl.gen.yml"],
cmd = "(echo '# GENERATED FILE DO NOT EDIT'; cat $<) > $@",
visibility = visibility,
)

def openapi_generate_go(
name,
Expand Down
10 changes: 10 additions & 0 deletions private/mgmtapi/tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@npm//:defs.bzl", "npm_link_all_packages")

exports_files(
[
"package.json",
"pnpm-lock.yml",
],
)

npm_link_all_packages(name = "node_modules")
30 changes: 30 additions & 0 deletions private/mgmtapi/tools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"dependencies": {
"@redocly/cli": "1.0.2",
"@stoplight/spectral-cli": "^6.11.0",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2"
},
"pnpm": {
"packageExtensions": {
"[email protected]": {
"dependencies": {
"react-is": "18.2.0"
}
},
"@redocly/cli": {
"dependencies": {
"lodash.isequal": "4.5.0",
"node-fetch": "2.6.7"
}
},
"redoc@~2.0.0": {
"dependencies": {
"call-me-maybe": "1.0.2",
"yaml": "2.1.3",
"fast-safe-stringify": "2.1.1"
}
}
}
}
}
Loading

0 comments on commit cbd2426

Please sign in to comment.