Skip to content

Commit

Permalink
Merge pull request #35 from bookshiyi/generate-models-file
Browse files Browse the repository at this point in the history
Generate 'models.dart' file in seperated mode
  • Loading branch information
mmvergara authored Jul 29, 2024
2 parents d4c8a77 + 18d6e80 commit ca7dc31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions generators/Models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Definitions } from "./types";

export const generateModels = (definitions: Definitions) => {
let code = `library models;\n`;
for (let tableName in definitions) {
tableName = tableName.toLowerCase();
code += `export '${tableName}.dart';\n`;
}
return code;
};
8 changes: 7 additions & 1 deletion generators/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { generateDartClasses } from "./Class";
import { generateClientExtension } from "./ClientExtension";
import { generateModels } from "./Models";
import { SupadartAbstractClass } from "./SupadartAbstractClass";
import { getImports } from "./imports";
import { ClientExtension, DartClass, Definitions } from "./types";
Expand All @@ -12,12 +13,14 @@ export const generateBluePrint = (
const dartClasses: DartClass[] = generateDartClasses(definitions);
const imports = getImports(dartClasses, isFlutter);
const clientExtension: ClientExtension = generateClientExtension(definitions);
const models = generateModels(definitions);

return {
imports,
dartClasses,
clientExtension,
SupadartAbstractClass,
models,
};
};

Expand All @@ -41,7 +44,7 @@ export const generateDartModelFilesSeperated = (
definitions: Definitions,
isFlutter: boolean
): Record<string, string> => {
const { clientExtension, dartClasses, SupadartAbstractClass } =
const { clientExtension, dartClasses, SupadartAbstractClass, models } =
generateBluePrint(definitions, isFlutter);

// Per key is a class file and the value is the code
Expand Down Expand Up @@ -76,5 +79,8 @@ export const generateDartModelFilesSeperated = (

// Generated abstract class
output["supadart_abstract_class"] = SupadartAbstractClass;

// Generated models file
output["models"] = models;
return output;
};

0 comments on commit ca7dc31

Please sign in to comment.