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