* Extracts @Input() property names from a component .ts file using regex. * * Handles patterns: * - @Input() propName = value; * - @Input() propName?: Type; * - @Input() propName!: Type; * - @Input() propName: Type = value; * - @Input({ transform: booleanAttribute }) propName = false; * - @I
(componentFilePath: string)
| 164 | * - @Input({ required: true }) propName!: Type; |
| 165 | */ |
| 166 | function extractInputs(componentFilePath: string): string[] { |
| 167 | const content = fs.readFileSync(componentFilePath, 'utf-8'); |
| 168 | const inputs: string[] = []; |
| 169 | |
| 170 | // Pattern 1: @Input() or @Input({...}) followed by property name (field or setter) |
| 171 | // Handles both single-line and multi-line (decorator on one line, property on next) |
| 172 | const inputRegex = /@Input\s*\([^)]*\)\s*(?:\n\s*)?(?:set\s+)?(\w+)\s*[?!]?\s*[=:(]/g; |
| 173 | let match: RegExpExecArray | null; |
| 174 | |
| 175 | while ((match = inputRegex.exec(content)) !== null) { |
| 176 | const propName = match[1]; |
| 177 | if (propName && !inputs.includes(propName)) { |
| 178 | inputs.push(propName); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | return inputs.sort(); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Extracts @Output() property names from a component .ts file using regex. |