Adding C# Support. Badly tested currently, but kindof working
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user