When I needed to generate some C# code, for example DTO classes from xsd schema, or an excel table, I've used some roslyn API's.
Is there something simmilar for typescript?
[EDIT]: I've end up using ts-morph
The TypeScript compiler compiles these files and outputs the JavaScript with . js extension by keeping the same file name as the individual input file. The TypeScript compiler also preserves the original file path, hence the . js output file will be generated where the input file was in the directory structure.
TypeScript is a superset of the JavaScript language that has a single open-source compiler and is developed mainly by a single vendor: Microsoft. The goal of TypeScript is to help catch mistakes early through a type system and to make JavaScript development more efficient.
Compiler. The TypeScript compiler, named tsc , is written in TypeScript. As a result, it can be compiled into regular JavaScript and can then be executed in any JavaScript engine (e.g. a browser).
The Typescript client library allows you to integrate FusionAuth with your JavaScript application. Regardless of the fact that this is written in TypeScript, this client supports both NodeJS and Browser environments without requiring that your application is also written in typescript.
Try ts-morph. Only been working with it for about an hour but it seems really capable.
import {Project, Scope, SourceFile} from "ts-morph"; const project = new Project(); const sourceFile = project.createSourceFile(`./target/file.ts`); const classDeclaration = sourceFile.addClass({ name: 'SomeClass' }); const constr = classDeclaration.addConstructor({}); constr.setBodyText('this.myProp = myProp'); classDeclaration.addProperty({ name: 'myProp', type: 'string', initializer: 'hello world!', scope: Scope.Public }); sourceFile.formatText(); console.log(sourceFile.getText());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With