Skip to content

Commit 4b0223b

Browse files
committed
build: automate @angular/cli schema.json generation
With this change we automate the generation of `@angular/cli/lib/config/schema.json`. While on paper we could use quicktype for this. Quicktype doesn't handle `patternProperties` and `oneOf` that well. How does this works? Relative `$ref` will be resolved and inlined as part of the root schema definitions. Example ```json "@schematics/angular:enum": { "$ref": "../../../../schematics/angular/enum/schema.json" }, ``` Will be parsed and transformed to ```json "@schematics/angular:enum": { "$ref": "#/definitions/SchematicsAngularEnumSchema" }, "definitions: { "SchematicsAngularEnumSchema": { "title": "Angular Enum Options Schema", "type": "object", "description": "Generates a new, generic enum definition for the given or default project.", "properties": {...} } } ```
1 parent d254d05 commit 4b0223b

12 files changed

Lines changed: 782 additions & 2189 deletions

File tree

packages/angular/cli/BUILD.bazel

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
77
load("//tools:ts_json_schema.bzl", "ts_json_schema")
8+
load("//tools:ng_cli_schema_generator.bzl", "cli_json_schema")
89
load("//tools:defaults.bzl", "ts_library")
910

1011
# @external_begin
@@ -28,7 +29,7 @@ ts_library(
2829
) + [
2930
# @external_begin
3031
# These files are generated from the JSON schema
31-
"//packages/angular/cli:lib/config/schema.ts",
32+
"//packages/angular/cli:lib/config/workspace-schema.ts",
3233
"//packages/angular/cli:commands/analytics.ts",
3334
"//packages/angular/cli:commands/add.ts",
3435
"//packages/angular/cli:commands/build.ts",
@@ -58,8 +59,11 @@ ts_library(
5859
exclude = [
5960
# NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
6061
"node_modules/**",
62+
"cli/lib/config/workspace-schema.json",
6163
],
62-
),
64+
) + [
65+
"//packages/angular/cli:lib/config/schema.json",
66+
],
6367
module_name = "@angular/cli",
6468
# strict_checks = False,
6569
deps = [
@@ -84,9 +88,46 @@ ts_library(
8488
],
8589
)
8690

91+
CLI_SCHEMA_DATA = [
92+
"//packages/angular_devkit/build_angular:src/app-shell/schema.json",
93+
"//packages/angular_devkit/build_angular:src/browser/schema.json",
94+
"//packages/angular_devkit/build_angular:src/dev-server/schema.json",
95+
"//packages/angular_devkit/build_angular:src/extract-i18n/schema.json",
96+
"//packages/angular_devkit/build_angular:src/karma/schema.json",
97+
"//packages/angular_devkit/build_angular:src/ng-packagr/schema.json",
98+
"//packages/angular_devkit/build_angular:src/protractor/schema.json",
99+
"//packages/angular_devkit/build_angular:src/server/schema.json",
100+
"//packages/angular_devkit/build_angular:src/tslint/schema.json",
101+
"//packages/schematics/angular:app-shell/schema.json",
102+
"//packages/schematics/angular:application/schema.json",
103+
"//packages/schematics/angular:class/schema.json",
104+
"//packages/schematics/angular:component/schema.json",
105+
"//packages/schematics/angular:directive/schema.json",
106+
"//packages/schematics/angular:enum/schema.json",
107+
"//packages/schematics/angular:guard/schema.json",
108+
"//packages/schematics/angular:interceptor/schema.json",
109+
"//packages/schematics/angular:interface/schema.json",
110+
"//packages/schematics/angular:library/schema.json",
111+
"//packages/schematics/angular:module/schema.json",
112+
"//packages/schematics/angular:ng-new/schema.json",
113+
"//packages/schematics/angular:pipe/schema.json",
114+
"//packages/schematics/angular:resolver/schema.json",
115+
"//packages/schematics/angular:service/schema.json",
116+
"//packages/schematics/angular:service-worker/schema.json",
117+
"//packages/schematics/angular:web-worker/schema.json",
118+
]
119+
120+
cli_json_schema(
121+
name = "cli_config_schema",
122+
src = "lib/config/workspace-schema.json",
123+
out = "lib/config/schema.json",
124+
data = CLI_SCHEMA_DATA,
125+
)
126+
87127
ts_json_schema(
88128
name = "cli_schema",
89-
src = "lib/config/schema.json",
129+
src = "lib/config/workspace-schema.json",
130+
data = CLI_SCHEMA_DATA,
90131
)
91132

92133
ts_json_schema(

packages/angular/cli/commands/add-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { analytics, tags } from '@angular-devkit/core';
99
import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools';
1010
import { dirname, join } from 'path';
1111
import { intersects, prerelease, rcompare, satisfies, valid, validRange } from 'semver';
12-
import { PackageManager } from '../lib/config/schema';
12+
import { PackageManager } from '../lib/config/workspace-schema';
1313
import { isPackageNameSafeForAnalytics } from '../models/analytics';
1414
import { Arguments } from '../models/interface';
1515
import { RunSchematicOptions, SchematicCommand } from '../models/schematic-command';

packages/angular/cli/commands/update-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { execSync } from 'child_process';
1111
import * as fs from 'fs';
1212
import * as path from 'path';
1313
import * as semver from 'semver';
14-
import { PackageManager } from '../lib/config/schema';
14+
import { PackageManager } from '../lib/config/workspace-schema';
1515
import { Command } from '../models/command';
1616
import { Arguments } from '../models/interface';
1717
import { SchematicEngineHost } from '../models/schematic-engine-host';

0 commit comments

Comments
 (0)