1
0
mirror of https://github.com/angular/angular-cli.git synced 2025-05-20 05:24:57 +08:00
angular-cli/tools/ts_json_schema.bzl
Keen Yee Liau a3b05a0283 build: Use fine-grained node_module deps
This commit updates the BUILD files to specify fine-grained node_module deps
by replacing "@typings" comments with actual @npm node module.

Moved tools/bazel.rc -> .bazelrc

Removed "jasmine" typings from base tsconfig.json

Added @bazel/karma to devDependencies, needed for `ts_web_test`
2018-10-31 20:56:27 -07:00

84 lines
2.1 KiB
Python

# Copyright Google Inc. All Rights Reserved.
#
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE file at https://angular.io/license
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
# @external_begin
def _ts_json_schema_interface_impl(ctx):
args = [
ctx.files.src[0].path,
ctx.outputs.ts.path,
]
ctx.actions.run(
inputs = ctx.files.src + ctx.files.data,
executable = ctx.executable._binary,
outputs = [ctx.outputs.ts],
arguments = args,
)
return [DefaultInfo()]
_ts_json_schema_interface = rule(
_ts_json_schema_interface_impl,
attrs = {
"src": attr.label(
allow_files = FileType([
".json",
]),
mandatory = True,
),
"out": attr.string(
mandatory = True,
),
"data": attr.label_list(
allow_files = FileType([
".json",
]),
),
"_binary": attr.label(
default = Label("//tools:quicktype_runner"),
executable = True,
cfg = "host",
),
},
outputs = {
"ts": "%{out}"
},
)
# @external_end
# Generates a library that contains the interface for a JSON Schema file. Takes a single `src`
# argument as input, an optional data field for reference files, and produces a ts_library()
# rule containing the typescript interface.
# The file produced will have the same name, with the extension replaced from `.json` to `.ts`.
# Any filename collision will be an error thrown by Bazel.
def ts_json_schema(name, src, data = []):
out = src.replace(".json", ".ts")
# @external_begin
_ts_json_schema_interface(
name = name + ".interface",
src = src,
out = out,
data = data,
)
# @external_end
ts_library(
name = name,
deps = [
"@npm//@types/node",
],
# Remove these to empty the rule, since those files are also compiled elsewhere.
# @external_begin
srcs = [
out,
]
# @external_end
)