ng_run
Execute custom architect targets in Angular projects using the 'ng run' command. Specify the target, app root path, and additional options to streamline development workflows.
Instructions
Run 'ng run' to execute a custom architect target
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appRoot | Yes | The absolute path to the first folder in the 'path' property. For example, if 'path' is 'webui/src/app/modules/alerts', then 'appRoot' should be the absolute path to 'webui'. | |
| options | No | Additional options for ng run | |
| target | Yes | The target to run (e.g., app:build:production) |
Implementation Reference
- src/toolHandler.ts:51-59 (handler)The switch case in handleToolCall that implements the 'ng_run' tool by constructing the command 'npx ng run <target>' with any provided options and passing it to the shared runCommand helper.case "ng_run": { command = "npx"; commandArgs = ["ng", "run", args.target]; if (args.options) { for (const [key, value] of Object.entries(args.options)) { commandArgs.push(`--${key}`, String(value)); } } break;
- src/tools.ts:122-145 (schema)The tool definition including name, description, and input schema for 'ng_run', which requires 'target' and 'appRoot', and accepts 'options'.{ name: "ng_run", description: "Run 'ng run' to execute a custom architect target", inputSchema: { type: "object", properties: { target: { type: "string", description: "The target to run (e.g., app:build:production)", }, appRoot: { type: "string", description: "The absolute path to the first folder in the 'path' property. For example, if 'path' is 'webui/src/app/modules/alerts', then 'appRoot' should be the absolute path to 'webui'.", }, options: { type: "object", description: "Additional options for ng run", additionalProperties: { type: "string" }, }, }, required: ["target", "appRoot"], }, },
- src/requestHandler.ts:11-13 (registration)Registers the list tools request handler that returns the array of tool definitions, including 'ng_run'.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools, }));
- src/requestHandler.ts:16-18 (registration)Registers the call tool request handler that dispatches to handleToolCall based on the tool name, which handles 'ng_run'.server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}, server) );
- src/toolHandler.ts:86-112 (helper)Shared helper function that spawns and executes the shell command, capturing output, used by the 'ng_run' handler and other ng tools.function runCommand( command: string, args: string[], cwd: string ): Promise<string> { return new Promise((resolve, reject) => { const proc = spawn(command, args, { cwd, shell: true }); let stdout = ""; let stderr = ""; proc.stdout.on("data", (data) => { stdout += data.toString(); }); proc.stderr.on("data", (data) => { stderr += data.toString(); }); proc.on("close", (code) => { if (code === 0) { resolve(stdout); } else { reject(stderr || `Process exited with code ${code}`); } }); proc.on("error", (err) => { reject(err); }); }); }