FELgt TypeScript Contribution Plan
🎯 Objective​
Add TypeScript code generation support to the FELgt repository, similar to how it currently generates C# classes from XSD files.
💡 Why This is a Great Idea​
Benefits for the Community​
-
âś… Broader Language Support
- FELgt currently only supports C#
- TypeScript/Node.js is very popular for FEL integrations
- Many developers in Guatemala use TypeScript
-
âś… Your Experience
- You already have code generation patterns in your codebase
- You understand FEL requirements deeply
- You're actively working on FEL implementation
-
âś… Open Source Contribution
- Helps the entire FEL developer community
- Establishes you as a contributor
- Builds your reputation
-
âś… Mutual Benefit
- You get a maintained tool
- Community gets TypeScript support
- Everyone wins
🔍 Pre-Contribution Research​
Step 1: Analyze Current Repository​
Check:
- Repository structure
- How C# generation works
- XSD parsing approach
- Code generation patterns
- Maintainer activity/response
Questions to Answer:
- Is the repository actively maintained?
- What's the code generation architecture?
- How does it parse XSD files?
- What's the output format for C#?
- Are there tests?
- What's the contribution process?
Step 2: Understand the Codebase​
Key Files to Review:
- XSD parser implementation
- C# code generator
- Main entry point
- Configuration files
- Tests
Pattern to Understand:
XSD File → Parser → AST/Model → Code Generator → Output Files
🏗️ Implementation Approach​
Option 1: Add TypeScript Generator (Recommended)​
Structure:
FELgt/
├── src/
│ ├── parser/ # XSD parser (shared)
│ ├── generators/
│ │ ├── csharp/ # Existing C# generator
│ │ └── typescript/ # New TypeScript generator
│ └── cli.ts # CLI with --lang flag
└── output/
├── csharp/ # Generated C# files
└── typescript/ # Generated TypeScript files
CLI Usage:
# Generate C# (existing)
felgt --lang csharp --input xsd/ --output output/csharp/
# Generate TypeScript (new)
felgt --lang typescript --input xsd/ --output output/typescript/
Option 2: Separate TypeScript Tool​
If repository is inactive:
- Fork and create your own version
- Add TypeScript support
- Maintain independently
- Link back to original
📋 Implementation Plan​
Phase 1: Research & Preparation​
-
Fork the Repository
git clone https://github.com/krudos/FELgt.git
cd FELgt -
Analyze Structure
- Understand XSD parsing
- Understand C# generation
- Identify shared components
-
Create Feature Branch
git checkout -b feature/typescript-generator
Phase 2: TypeScript Generator Implementation​
Key Components:
-
TypeScript Type Generator
class TypeScriptGenerator {
generateTypes(xsdModel: XSDModel): string {
// Generate TypeScript interfaces
// Handle namespaces
// Handle types (string, number, date, etc.)
// Handle required/optional fields
}
} -
Type Mapping
const typeMapping = {
'xs:string': 'string',
'xs:decimal': 'number',
'xs:date': 'string', // ISO date string
'xs:dateTime': 'string',
'xs:boolean': 'boolean',
'xs:integer': 'number',
// ... more mappings
}; -
Namespace Handling
// Generate namespace imports
// Handle qualified names
// Generate type aliases
Phase 3: Output Format​
Generated TypeScript Structure:
// Generated from XSD
// File: fact.types.ts
export namespace DTE {
export interface GTDocumento {
SAT: SAT;
Signature?: Signature;
}
export interface SAT {
ClaseDocumento: string;
DTE: DTE_Type;
Adenda?: Adenda;
}
export interface DatosGenerales {
Tipo: 'FACT' | 'NCRE' | 'NDEB' | 'ANULACION';
FechaHoraEmision: string; // ISO dateTime
CodigoMoneda: string;
}
// ... more interfaces
}
Features:
- âś… TypeScript interfaces
- âś… Proper typing (unions, enums, etc.)
- âś… JSDoc comments from XSD
- âś… Namespace support
- âś… Optional vs required fields
Phase 4: Integration​
Update CLI:
// cli.ts
import { CSharpGenerator } from './generators/csharp';
import { TypeScriptGenerator } from './generators/typescript';
const generators = {
csharp: new CSharpGenerator(),
typescript: new TypeScriptGenerator(),
};
const generator = generators[language];
const output = generator.generate(xsdModel);
🎨 TypeScript-Specific Considerations​
1. Naming Conventions​
C# vs TypeScript:
- C#:
PascalCaseclasses,camelCaseproperties - TypeScript:
PascalCaseinterfaces,camelCaseproperties
Example:
// C#
public class DatosGenerales {
public string Tipo { get; set; }
}
// TypeScript
export interface DatosGenerales {
Tipo: string;
}
2. Type System​
TypeScript Advantages:
- Union types:
'FACT' | 'NCRE' | 'NDEB' - Optional fields:
field?: string - Readonly:
readonly field: string - Generics:
<T extends BaseType>
3. XML Builder Helpers (Optional)​
Could Generate:
// Helper functions for building XML
export function createFactDocument(data: FactDocument): string {
// XML builder logic
}
📝 Contribution Checklist​
Before PR​
- Fork repository
- Understand existing codebase
- Implement TypeScript generator
- Add tests
- Update README
- Add examples
- Test with real XSD files
- Ensure backward compatibility
PR Contents​
- TypeScript generator implementation
- CLI integration (
--lang typescript) - Tests for TypeScript generation
- Updated documentation
- Example output files
- Migration guide (if needed)
Documentation Updates​
- README.md - Add TypeScript section
- USAGE.md - TypeScript examples
- CONTRIBUTING.md - Update if needed
🚀 Recommended Approach​
Strategy: Start Small, Iterate​
-
Phase 1: Proof of Concept
- Implement basic TypeScript generator
- Generate simple interfaces
- Test with one XSD file
-
Phase 2: Full Feature
- Handle all XSD features
- Namespaces, types, constraints
- Comprehensive testing
-
Phase 3: Polish
- Documentation
- Examples
- Error handling
- CLI integration
Alternative: Standalone Tool First​
If repository is inactive:
-
Create Your Own Tool
fel-typescript-generator- Standalone npm package
- Can be contributed back later
-
Benefits:
- Full control
- Can publish to npm
- Can contribute to FELgt later
-
Structure:
fel-typescript-generator/
├── src/
│ ├── parser/
│ ├── generator/
│ └── cli.ts
├── package.json
└── README.md
💻 Implementation Example​
TypeScript Generator Skeleton​
// generators/typescript/generator.ts
import type { XSDModel, XSDElement } from '../parser/types';
export class TypeScriptGenerator {
generate(model: XSDModel): string {
const interfaces = model.elements.map(el => this.generateInterface(el));
return this.wrapInNamespace(interfaces, model.namespace);
}
private generateInterface(element: XSDElement): string {
const properties = element.attributes.map(attr =>
this.generateProperty(attr)
);
return `
export interface ${element.name} {
${properties.join('\n')}
}
`.trim();
}
private generateProperty(attr: XSDAttribute): string {
const optional = attr.required ? '' : '?';
const type = this.mapXSDTypeToTS(attr.type);
return ` ${attr.name}${optional}: ${type};`;
}
private mapXSDTypeToTS(xsdType: string): string {
const mapping: Record<string, string> = {
'xs:string': 'string',
'xs:decimal': 'number',
'xs:dateTime': 'string',
'xs:boolean': 'boolean',
// ... more
};
return mapping[xsdType] || 'any';
}
}
🎯 My Recommendation​
Option A: Contribute to FELgt (If Active)​
Steps:
- Check repository activity
- Open an issue first: "Feature Request: TypeScript Generator"
- Get maintainer feedback
- Implement if positive response
- Submit PR
Pros:
- âś… Helps entire community
- âś… Maintained in one place
- âś… Open source contribution
Cons:
- ⚠️ Depends on maintainer response
- ⚠️ May be slow if inactive
Option B: Create Standalone Tool (If Inactive)​
Steps:
- Create
fel-typescript-generatorpackage - Implement TypeScript generation
- Publish to npm
- Link back to FELgt in README
- Can contribute later if FELgt becomes active
Pros:
- âś… Full control
- âś… Can publish immediately
- âś… Can use in your project
- âś… Can contribute back later
Cons:
- ⚠️ You maintain it
- ⚠️ Split community
Option C: Hybrid Approach (Recommended)​
Steps:
- Create standalone tool first
- Use it in your project
- Open issue/PR to FELgt
- If accepted → contribute
- If not → maintain standalone, link to FELgt
Best of Both Worlds:
- âś… Immediate use in your project
- âś… Can contribute to community
- âś… Flexible approach
📚 Resources​
🎯 Next Steps​
-
Research FELgt Repository:
- Check activity level
- Understand structure
- Review contribution guidelines
-
Decide on Approach:
- Contribute to FELgt?
- Create standalone tool?
- Hybrid approach?
-
Start Implementation:
- Proof of concept first
- Test with real XSD files
- Iterate based on results
Last Updated: 2025-12-18
Status: Contribution Strategy - Ready for Decision