-
Notifications
You must be signed in to change notification settings - Fork 11.9k
feat(@angular-devkit/schematics): add schematics to generate ai context files. #30763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<% if (frontmatter) { %><%= frontmatter %> | ||
|
||
<% } %>You are an expert in TypeScript, Angular, and scalable web application development. You write maintainable, performant, and accessible code following Angular and TypeScript best practices. | ||
|
||
## TypeScript Best Practices | ||
|
||
- Use strict type checking | ||
- Prefer type inference when the type is obvious | ||
- Avoid the `any` type; use `unknown` when type is uncertain | ||
|
||
## Angular Best Practices | ||
|
||
- Always use standalone components over NgModules | ||
- Must NOT set `standalone: true` inside Angular decorators. It's the default. | ||
- Use signals for state management | ||
- Implement lazy loading for feature routes | ||
- Do NOT use the `@HostBinding` and `@HostListener` decorators. Put host bindings inside the `host` object of the `@Component` or `@Directive` decorator instead | ||
- Use `NgOptimizedImage` for all static images. | ||
- `NgOptimizedImage` does not work for inline base64 images. | ||
|
||
## Components | ||
|
||
- Keep components small and focused on a single responsibility | ||
- Use `input()` and `output()` functions instead of decorators | ||
- Use `computed()` for derived state | ||
- Set `changeDetection: ChangeDetectionStrategy.OnPush` in `@Component` decorator | ||
- Prefer inline templates for small components | ||
- Prefer Reactive forms instead of Template-driven ones | ||
- Do NOT use `ngClass`, use `class` bindings instead | ||
- DO NOT use `ngStyle`, use `style` bindings instead | ||
|
||
## State Management | ||
|
||
- Use signals for local component state | ||
- Use `computed()` for derived state | ||
- Keep state transformations pure and predictable | ||
- Do NOT use `mutate` on signals, use `update` or `set` instead | ||
|
||
## Templates | ||
|
||
- Keep templates simple and avoid complex logic | ||
- Use native control flow (`@if`, `@for`, `@switch`) instead of `*ngIf`, `*ngFor`, `*ngSwitch` | ||
- Use the async pipe to handle observables | ||
|
||
## Services | ||
|
||
- Design services around a single responsibility | ||
- Use the `providedIn: 'root'` option for singleton services | ||
- Use the `inject()` function instead of constructor injection | ||
|
||
## Common pitfalls | ||
|
||
- Control flow (`@if`): | ||
- You cannot use `as` expressions in `@else if (...)`. E.g. invalid code: `@else if (bla(); as x)`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,36 @@ | |
"type": { | ||
"type": "string", | ||
"description": "Specifies the type of configuration file to generate.", | ||
"enum": ["karma", "browserslist"], | ||
"enum": ["karma", "browserslist", "ai"], | ||
"x-prompt": "Which type of configuration file would you like to create?", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
} | ||
}, | ||
"tool": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a multi-select prompt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentionned by @alan-agius4 here, the prompt would show for the others options. Or do you have an alternative in mind ? |
||
"type": "string", | ||
"description": "Specifies the AI tool to configure when type is 'ai'.", | ||
"enum": ["gemini", "copilot", "claude", "cursor", "windsurf", "all", "none"] | ||
} | ||
}, | ||
"required": ["project", "type"] | ||
"required": ["project", "type"], | ||
"allOf": [ | ||
{ | ||
"if": { | ||
"properties": { | ||
"type": { | ||
"not": { | ||
"const": "ai" | ||
} | ||
} | ||
} | ||
}, | ||
"then": { | ||
"not": { | ||
"required": ["tool"] | ||
} | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import { | |
RepositoryInitializerTask, | ||
} from '@angular-devkit/schematics/tasks'; | ||
import { Schema as ApplicationOptions } from '../application/schema'; | ||
import { Tool as AiTool, Schema as ConfigOptions, Type as ConfigType } from '../config/schema'; | ||
import { Schema as WorkspaceOptions } from '../workspace/schema'; | ||
import { Schema as NgNewOptions } from './schema'; | ||
|
||
|
@@ -60,11 +61,18 @@ export default function (options: NgNewOptions): Rule { | |
zoneless: options.zoneless, | ||
}; | ||
|
||
const configOptions: ConfigOptions = { | ||
project: options.name, | ||
type: ConfigType.Ai, | ||
tool: options.aiConfig as unknown as AiTool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why I couldn't get the enums to match. It works fine for the packageManager above for example. (Yes I also tried with removing "none" from the enum here in ng-new). |
||
}; | ||
|
||
return chain([ | ||
mergeWith( | ||
apply(empty(), [ | ||
schematic('workspace', workspaceOptions), | ||
options.createApplication ? schematic('application', applicationOptions) : noop, | ||
options.aiConfig !== "none" ? schematic('config', configOptions) : noop, | ||
move(options.directory), | ||
]), | ||
), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,4 +103,13 @@ describe('Ng New Schematic', () => { | |
const { cli } = JSON.parse(tree.readContent('/bar/angular.json')); | ||
expect(cli.packageManager).toBe('npm'); | ||
}); | ||
|
||
it('should add ai config file when aiConfig is set', async () => { | ||
const options = { ...defaultOptions, aiConfig: 'gemini' }; | ||
|
||
const tree = await schematicRunner.runSchematic('ng-new', options); | ||
const files = tree.files; | ||
expect(files).toContain('/bar/.gemini/GEMINI.md'); | ||
expect(tree.readContent('/bar/.gemini/GEMINI.md')).toMatch(/^You are an expert in TypeScript/); | ||
Comment on lines
+112
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dgp1130 Is this the location we would want or the workspace root ? |
||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.