ng_new
Generate a new Angular workspace using 'ng new' by specifying workspace name, directory, and optional configurations. Simplify Angular project setup with predefined structure and settings.
Instructions
Run 'ng new' to create a new Angular workspace
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appRoot | No | 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'. | |
| directory | No | The directory to create the workspace in | |
| name | Yes | The name of the new workspace | |
| options | No | Additional options for ng new |
Implementation Reference
- src/toolHandler.ts:38-49 (handler)Handler logic for the ng_new tool: sets up the npx ng new command using the provided name, sets cwd to directory if specified, adds options as flags, and delegates to runCommand.case "ng_new": { command = "npx"; commandArgs = ["ng", "new", args.name]; if (args.directory) { cwd = args.directory; } if (args.options) { for (const [key, value] of Object.entries(args.options)) { commandArgs.push(`--${key}`, String(value)); } } break;
- src/tools.ts:94-121 (schema)Tool schema definition: specifies input parameters (name required, directory, appRoot, options) for the ng_new tool.{ name: "ng_new", description: "Run 'ng new' to create a new Angular workspace", inputSchema: { type: "object", properties: { name: { type: "string", description: "The name of the new workspace", }, directory: { type: "string", description: "The directory to create the workspace in", }, 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 new", additionalProperties: { type: "string" }, }, }, required: ["name"], }, },
- src/tools.ts:3-225 (registration)Registration of ng_new tool within the createToolDefinitions function that returns the array of all tool definitions.export function createToolDefinitions() { return [ { name: "ng_generate", description: "Run 'ng generate' to create a new Angular artifact (component, service, etc.)", inputSchema: { type: "object", properties: { schematic: { type: "string", description: "The schematic to generate (e.g., component, service)", }, name: { type: "string", description: "The name of the artifact to generate", }, path: { type: "string", description: "The path where the artifact should be created, relative to the appRoot (do not include the app folder itself). For example, if the full path is 'webui/src/app/modules/alerts' and appRoot is 'webui', then path should be 'src/app/modules/alerts'.", default: "src/app", }, 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 the schematic", properties: { defaults: { type: "boolean", description: "Disable interactive input prompts for options with a default.", default: false, }, dryRun: { type: "boolean", description: "Run through and report activity without writing out results.", default: false, }, force: { type: "boolean", description: "Force overwriting of existing files.", default: false, }, help: { type: "boolean", description: "Shows a help message for this command in the console.", default: false, }, interactive: { type: "boolean", description: "Enable interactive input prompts.", default: true, }, }, additionalProperties: { type: "string" }, }, }, required: ["schematic", "name", "appRoot"], }, }, { name: "ng_add", description: "Run 'ng add' to add a package to the Angular workspace", inputSchema: { type: "object", properties: { package: { type: "string", description: "The npm package to add (e.g., @angular/material)", }, 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 add", additionalProperties: { type: "string" }, }, }, required: ["package", "appRoot"], }, }, { name: "ng_new", description: "Run 'ng new' to create a new Angular workspace", inputSchema: { type: "object", properties: { name: { type: "string", description: "The name of the new workspace", }, directory: { type: "string", description: "The directory to create the workspace in", }, 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 new", additionalProperties: { type: "string" }, }, }, required: ["name"], }, }, { 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"], }, }, { name: "ng_update", description: "Run 'ng update' to update Angular packages and run migrations.", inputSchema: { type: "object", properties: { packages: { oneOf: [ { type: "string", description: "The name of the package to update (e.g., @angular/core)", }, { type: "array", items: { type: "string" }, description: "The names of packages to update.", }, ], }, 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'.", }, next: { type: "boolean", description: "Use the prerelease version, including beta and RCs.", default: false, }, force: { type: "boolean", description: "Ignore peer dependency version mismatches.", default: false, }, allowDirty: { type: "boolean", description: "Allow updating when the repository contains modified or untracked files.", default: false, }, createCommits: { type: "boolean", description: "Create source control commits for updates and migrations.", default: false, }, from: { type: "string", description: "Version from which to migrate from (only with migrate-only and single package).", }, to: { type: "string", description: "Version up to which to apply migrations (only with migrate-only and single package).", }, migrateOnly: { type: "boolean", description: "Only perform a migration, do not update the installed version.", default: false, }, name: { type: "string", description: "The name of the migration to run (only with migrate-only and single package).", }, verbose: { type: "boolean", description: "Display additional details about internal operations during execution.", default: false, }, }, required: ["packages", "appRoot"], }, }, ] as const satisfies Tool[];
- src/toolHandler.ts:86-112 (helper)Helper function to spawn and execute the shell command, capturing stdout/stderr, used by the ng_new handler.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); }); }); }