Skip to content

Commit d752b6e

Browse files
committed
build(forms): setup infrastructure for code examples
This commit introduces the infrastructure for embedding code examples within Angular packages, enabling them to be consumed by the Angular CLI's MCP server. The `@angular/forms` package is the first to adopt this new feature. A new `ng_examples_db` Bazel rule is used to build a SQLite database from markdown files containing code examples. This database is then included in the published npm package. The `package.json` for `@angular/forms` has been updated with an `angular.examples` field to allow tooling to discover and use the code examples.
1 parent 9ace7d7 commit d752b6e

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

packages/forms/BUILD.bazel

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools:defaults.bzl", "api_golden_test", "api_golden_test_npm_package", "generate_api_docs", "ng_package", "ng_project")
1+
load("//tools:defaults.bzl", "api_golden_test", "api_golden_test_npm_package", "generate_api_docs", "ng_examples_db", "ng_package", "ng_project")
22

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

@@ -17,8 +17,23 @@ ng_project(
1717
],
1818
)
1919

20+
ng_examples_db(
21+
name = "forms_example_database",
22+
srcs = glob(
23+
include = [
24+
"examples/**/*.md",
25+
],
26+
allow_empty = True,
27+
),
28+
out = "resources/code-examples.db",
29+
path = "packages/forms/examples",
30+
)
31+
2032
ng_package(
21-
srcs = ["package.json"],
33+
srcs = [
34+
"package.json",
35+
"resources/code-examples.db",
36+
],
2237
package = "@angular/forms",
2338
tags = [
2439
"release-with-framework",

packages/forms/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"url": "https://github.com/angular/angular.git",
2323
"directory": "packages/forms"
2424
},
25+
"angular": {
26+
"examples": {
27+
"format": "sqlite",
28+
"path": "./resources/code-examples.db"
29+
}
30+
},
2531
"ng-update": {
2632
"packageGroup": "NG_UPDATE_PACKAGE_GROUP"
2733
},

tools/defaults.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ load("@devinfra//bazel:extract_types.bzl", _extract_types = "extract_types")
55
load("@devinfra//bazel/api-golden:index.bzl", _api_golden_test = "api_golden_test", _api_golden_test_npm_package = "api_golden_test_npm_package")
66
load("@devinfra//bazel/http-server:index.bzl", _http_server = "http_server")
77
load("@devinfra//bazel/ts_project:index.bzl", "strict_deps_test")
8+
load("@rules_angular//src/ng_examples_db:index.bzl", _ng_examples_db = "ng_examples_db")
89
load("@rules_angular//src/ng_project:index.bzl", _ng_project = "ng_project")
910
load("@rules_angular//src/ts_project:index.bzl", _ts_project = "ts_project")
1011
load("@rules_sass//src:index.bzl", _npm_sass_library = "npm_sass_library", _sass_binary = "sass_binary", _sass_library = "sass_library")
@@ -43,6 +44,7 @@ api_golden_test_npm_package = _api_golden_test_npm_package
4344
copy_to_bin = _copy_to_bin
4445
tsec_test = _tsec_test
4546
js_library = _js_library
47+
ng_examples_db = _ng_examples_db
4648

4749
def _determine_tsconfig(testonly):
4850
if native.package_name().startswith("packages/compiler-cli"):

0 commit comments

Comments
 (0)