forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathts_json_schema.bzl
More file actions
83 lines (73 loc) · 2.13 KB
/
ts_json_schema.bzl
File metadata and controls
83 lines (73 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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
)