Skip to content

Commit c2db008

Browse files
committed
fixup! feat(@schematics/angular): update ai-config to include Angular MCP server config
1 parent 4490726 commit c2db008

3 files changed

Lines changed: 15 additions & 42 deletions

File tree

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exports_files([
1515
"tsconfig-build-ng.json",
1616
"tsconfig-build.json",
1717
"package.json",
18+
"node_modules/@angular/core/resources/best-practices.md",
1819
])
1920

2021
npm_link_all_packages()

packages/schematics/angular/BUILD.bazel

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.dev/license
55

6+
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
67
load("@npm//:defs.bzl", "npm_link_all_packages")
78
load("//tools:defaults.bzl", "copy_to_bin", "jasmine_test", "npm_package", "ts_project")
89
load("//tools:ts_json_schema.bzl", "ts_json_schema")
@@ -45,15 +46,10 @@ copy_to_bin(
4546
srcs = glob(["**/schema.json"]),
4647
)
4748

48-
genrule(
49+
copy_file(
4950
name = "angular_best_practices",
50-
srcs = [
51-
"//:node_modules/@angular/core/dir",
52-
],
53-
outs = ["ai-config/files/__bestPracticesName__.template"],
54-
cmd = """
55-
cp "$(location //:node_modules/@angular/core/dir)/resources/best-practices.md" $@
56-
""",
51+
src = "//:node_modules/@angular/core/resources/best-practices.md",
52+
out = "ai-config/files/__bestPracticesName__.template",
5753
)
5854

5955
RUNTIME_ASSETS = [

packages/schematics/angular/ai-config/file_utils.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
strings,
1919
url,
2020
} from '@angular-devkit/schematics';
21+
import { JSONFile } from '../utility/json-file';
2122
import { FileConfigurationHandlerOptions } from './types';
2223

2324
const TOML_MCP_SERVERS_PROP = '[mcp_servers.angular-cli]';
@@ -26,7 +27,7 @@ const TOML_MCP_SERVERS_PROP = '[mcp_servers.angular-cli]';
2627
* Create or update a JSON MCP configuration file to include the Angular MCP server.
2728
*/
2829
export function addJsonMcpConfig(
29-
{ tree, context, fileInfo, tool }: FileConfigurationHandlerOptions,
30+
{ tree, fileInfo }: FileConfigurationHandlerOptions,
3031
mcpServersProperty: string,
3132
): Rule {
3233
const { name, directory } = fileInfo;
@@ -45,43 +46,18 @@ export function addJsonMcpConfig(
4546
return file;
4647
}
4748

48-
const existingFileBuffer = tree.read(file.path);
49-
5049
// If we have an existing file, update the server property with
5150
// Angular MCP server configuration.
52-
if (existingFileBuffer) {
53-
// The JSON config file should be record-like.
54-
let existing: Record<string, unknown>;
55-
try {
56-
existing = JSON.parse(existingFileBuffer.toString());
57-
} catch {
58-
const path = `${directory}/${name}`;
59-
const toolName = strings.classify(tool);
60-
context.logger.warn(
61-
`Skipping Angular MCP server configuration for '${toolName}'.\n` +
62-
`Unable to modify '${path}'. ` +
63-
'Make sure that the file has a valid JSON syntax.\n',
64-
);
51+
const existingConfig = new JSONFile(tree, file.path);
52+
const existingMcpServers = existingConfig.get([mcpServersProperty]) ?? {};
53+
const templateServersProp = JSON.parse(file.content.toString())[mcpServersProperty];
6554

66-
return null;
67-
}
68-
const existingServersProp = existing[mcpServersProperty];
69-
const templateServersProp = JSON.parse(file.content.toString())[mcpServersProperty];
70-
71-
// Note: If the Angular MCP server config already exists, we'll overwrite it.
72-
existing[mcpServersProperty] = existingServersProp
73-
? {
74-
...existingServersProp,
75-
...templateServersProp,
76-
}
77-
: templateServersProp;
78-
79-
tree.overwrite(file.path, JSON.stringify(existing, null, 2));
55+
existingConfig.modify([mcpServersProperty], {
56+
...existingMcpServers,
57+
...templateServersProp,
58+
});
8059

81-
return null;
82-
}
83-
84-
return file;
60+
return null;
8561
}),
8662
]),
8763
);

0 commit comments

Comments
 (0)