Adding C# Support. Badly tested currently, but kindof working

This commit is contained in:
K35
2022-01-05 21:16:17 +00:00
parent 94832ef682
commit 49425cab39
20 changed files with 3825 additions and 71 deletions

View File

@ -1,4 +1,5 @@
import * as FS from "fs";
import * as FSE from "fs-extra"
import * as Path from "path";
import {
EnumDefinition,
@ -8,9 +9,9 @@ import {
TypeDefinition,
} from "./ir";
export abstract class CompileTarget {
export abstract class CompileTarget<T = any> {
abstract name: string;
constructor(private outputFolder: string) {
constructor(private outputFolder: string, protected options: T) {
if (!FS.existsSync(outputFolder)) {
FS.mkdirSync(outputFolder, {
recursive: true,
@ -57,6 +58,14 @@ export abstract class CompileTarget {
return res.join("\n");
}
protected loadTemplateFolder(name:string) {
let root = Path.join(__dirname, "../templates/", name);
FSE.copySync(root, this.outputFolder, {
});
}
}
export default function compile(ir: IR, target: CompileTarget) {
@ -64,12 +73,12 @@ export default function compile(ir: IR, target: CompileTarget) {
// setState("Building for target: " + target.name);
target.start();
ir.forEach((step) => {
ir.steps.forEach((step) => {
const [type, def] = step;
if (type == "type") target.generateType(def as TypeDefinition);
else if (type == "enum") target.generateEnum(def as EnumDefinition);
else if (type == "service")
target.generateService(def as ServiceDefinition);
});
if (target.finalize) target.finalize(ir);
if (target.finalize) target.finalize(ir.steps);
}