1- import { Project , SyntaxKind } from "ts-morph" ;
1+ import { Project , SyntaxKind } from "ts-morph"
22
33/**
44 * Deduplicates enum definitions in a TypeScript file.
@@ -7,58 +7,58 @@ import { Project, SyntaxKind } from "ts-morph";
77 * This script consolidates them into a single canonical definition.
88 */
99async function deduplicateEnums ( filePath : string ) : Promise < void > {
10- console . log ( `Cleaning up duplicate enums in ${ filePath } ...` ) ;
10+ console . log ( `Cleaning up duplicate enums in ${ filePath } ...` )
1111
12- const project = new Project ( ) ;
13- const sourceFile = project . addSourceFileAtPath ( filePath ) ;
12+ const project = new Project ( )
13+ const sourceFile = project . addSourceFileAtPath ( filePath )
1414
1515 const enumsToClean = [
1616 "NodeType" ,
1717 "PortType" ,
1818 "OperatorEventType" ,
1919 "DeploymentEventType" ,
2020 "ParameterSpecType" ,
21- ] ;
21+ ]
2222
2323 for ( const baseName of enumsToClean ) {
2424 const enumDeclarations = sourceFile
2525 . getEnums ( )
26- . filter ( ( e ) => e . getName ( ) . match ( new RegExp ( `^${ baseName } \\d*$` ) ) ) ;
26+ . filter ( ( e ) => e . getName ( ) . match ( new RegExp ( `^${ baseName } \\d*$` ) ) )
2727
2828 if ( enumDeclarations . length === 0 ) {
29- continue ;
29+ continue
3030 }
3131
3232 // Find the canonical enum (without numbers), or use the first one
3333 const canonicalEnum =
3434 enumDeclarations . find ( ( e ) => e . getName ( ) === baseName ) ||
35- enumDeclarations [ 0 ] ;
36- const enumsToRemove = enumDeclarations . filter ( ( e ) => e !== canonicalEnum ) ;
35+ enumDeclarations [ 0 ]
36+ const enumsToRemove = enumDeclarations . filter ( ( e ) => e !== canonicalEnum )
3737
3838 // Update all numbered enum references to point to the base name
3939 sourceFile . getDescendantsOfKind ( SyntaxKind . Identifier ) . forEach ( ( node ) => {
40- const text = node . getText ( ) ;
41- const match = text . match ( new RegExp ( `^${ baseName } \\d+$` ) ) ;
40+ const text = node . getText ( )
41+ const match = text . match ( new RegExp ( `^${ baseName } \\d+$` ) )
4242 if ( match ) {
43- node . replaceWithText ( baseName ) ;
43+ node . replaceWithText ( baseName )
4444 }
45- } ) ;
45+ } )
4646
4747 // Remove duplicate enum declarations
4848 enumsToRemove . forEach ( ( enumDecl ) => {
49- enumDecl . remove ( ) ;
50- } ) ;
49+ enumDecl . remove ( )
50+ } )
5151
5252 console . log (
53- ` ✓ Consolidated ${ enumDeclarations . length } definition(s) for ${ baseName } `
54- ) ;
53+ ` ✓ Consolidated ${ enumDeclarations . length } definition(s) for ${ baseName } ` ,
54+ )
5555 }
5656
5757 // Save the cleaned file
58- await sourceFile . save ( ) ;
59- console . log ( "Cleanup complete." ) ;
58+ await sourceFile . save ( )
59+ console . log ( "Cleanup complete." )
6060}
6161
6262// Execute
63- const filePath = "src/types/gen.ts" ;
64- await deduplicateEnums ( filePath ) ;
63+ const filePath = "src/types/gen.ts"
64+ await deduplicateEnums ( filePath )
0 commit comments