A Visual Studio Code extension that automatically generates code snippets for Angular components based on their TypeScript definitions.
- Parses Angular component TypeScript files
- Extracts @Input and @Output properties
- Generates VS Code snippets for HTML usage
- Supports type-aware snippet placeholders
- Handles optional properties and EventEmitters
- Clone this repository
- Run
npm installto install dependencies - Run
npm run compileto build the TypeScript code - Run
npm testto execute the test suite
The extension provides utilities to parse Angular components and generate snippets:
import { parseComponent } from './src/parser';
import { createSnippet } from './src/snippet';
const componentCode = `
@Component({
selector: 'my-component',
template: '<div></div>'
})
export class MyComponent {
@Input() title: string;
@Output() onClick = new EventEmitter<void>();
}
`;
const components = parseComponent(componentCode);
const snippet = createSnippet(components[0]);This repository includes a small CLI to generate snippets from a folder.
Generate snippets from a folder:
# generate snippets from ./src/components and write to snippets.generated.code-snippets
npx ts-node src/cli.ts generate:folder ./src/components --out snippets.generated.code-snippets
## API
### parseComponent(fileData: string)
Parses a TypeScript file containing Angular components and returns an array of component information.
**Parameters:**
- `fileData` (string): The content of the TypeScript file
**Returns:** `ComponentInfo[] | undefined`
### createSnippet(component: ComponentInfo)
Creates a VS Code snippet definition for an Angular component.
**Parameters:**
- `component` (ComponentInfo): The component information
**Returns:** `Record<string, any>` - The snippet definition
## Development
### Running Tests
```bash
npm test
npm run compilenpm run lint- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details