mahameru 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/README.md +28 -0
  2. package/dist/api.error.cjs +107 -0
  3. package/dist/api.error.cjs.map +1 -0
  4. package/dist/api.error.d.cts +65 -0
  5. package/dist/api.error.d.ts +65 -0
  6. package/dist/api.error.js +83 -0
  7. package/dist/api.error.js.map +1 -0
  8. package/dist/base-class/base.controller.cjs +148 -0
  9. package/dist/base-class/base.controller.cjs.map +1 -0
  10. package/dist/base-class/base.controller.d.cts +38 -0
  11. package/dist/base-class/base.controller.d.ts +38 -0
  12. package/dist/base-class/base.controller.js +126 -0
  13. package/dist/base-class/base.controller.js.map +1 -0
  14. package/dist/base-class/base.entity.cjs +79 -0
  15. package/dist/base-class/base.entity.cjs.map +1 -0
  16. package/dist/base-class/base.entity.d.cts +8 -0
  17. package/dist/base-class/base.entity.d.ts +8 -0
  18. package/dist/base-class/base.entity.js +57 -0
  19. package/dist/base-class/base.entity.js.map +1 -0
  20. package/dist/base-class/base.model.cjs +204 -0
  21. package/dist/base-class/base.model.cjs.map +1 -0
  22. package/dist/base-class/base.model.d.cts +68 -0
  23. package/dist/base-class/base.model.d.ts +68 -0
  24. package/dist/base-class/base.model.js +182 -0
  25. package/dist/base-class/base.model.js.map +1 -0
  26. package/dist/base-class/base.service.cjs +37 -0
  27. package/dist/base-class/base.service.cjs.map +1 -0
  28. package/dist/base-class/base.service.d.cts +5 -0
  29. package/dist/base-class/base.service.d.ts +5 -0
  30. package/dist/base-class/base.service.js +15 -0
  31. package/dist/base-class/base.service.js.map +1 -0
  32. package/dist/base-class/index.cjs +392 -0
  33. package/dist/base-class/index.cjs.map +1 -0
  34. package/dist/base-class/index.d.cts +6 -0
  35. package/dist/base-class/index.d.ts +6 -0
  36. package/dist/base-class/index.js +365 -0
  37. package/dist/base-class/index.js.map +1 -0
  38. package/dist/cli/index.cjs +706 -0
  39. package/dist/cli/index.cjs.map +1 -0
  40. package/dist/cli/index.d.cts +3 -0
  41. package/dist/cli/index.d.ts +3 -0
  42. package/dist/cli/index.js +681 -0
  43. package/dist/cli/index.js.map +1 -0
  44. package/dist/cli/scripts/on-build.cjs +56 -0
  45. package/dist/cli/scripts/on-build.cjs.map +1 -0
  46. package/dist/cli/scripts/on-build.d.cts +3 -0
  47. package/dist/cli/scripts/on-build.d.ts +3 -0
  48. package/dist/cli/scripts/on-build.js +28 -0
  49. package/dist/cli/scripts/on-build.js.map +1 -0
  50. package/dist/cli/scripts/on-dev.cjs +483 -0
  51. package/dist/cli/scripts/on-dev.cjs.map +1 -0
  52. package/dist/cli/scripts/on-dev.d.cts +5 -0
  53. package/dist/cli/scripts/on-dev.d.ts +5 -0
  54. package/dist/cli/scripts/on-dev.js +449 -0
  55. package/dist/cli/scripts/on-dev.js.map +1 -0
  56. package/dist/cli/scripts/on-init.cjs +96 -0
  57. package/dist/cli/scripts/on-init.cjs.map +1 -0
  58. package/dist/cli/scripts/on-init.d.cts +3 -0
  59. package/dist/cli/scripts/on-init.d.ts +3 -0
  60. package/dist/cli/scripts/on-init.js +68 -0
  61. package/dist/cli/scripts/on-init.js.map +1 -0
  62. package/dist/cli/scripts/on-start.cjs +55 -0
  63. package/dist/cli/scripts/on-start.cjs.map +1 -0
  64. package/dist/cli/scripts/on-start.d.cts +3 -0
  65. package/dist/cli/scripts/on-start.d.ts +3 -0
  66. package/dist/cli/scripts/on-start.js +27 -0
  67. package/dist/cli/scripts/on-start.js.map +1 -0
  68. package/dist/client.cjs +405 -0
  69. package/dist/client.cjs.map +1 -0
  70. package/dist/client.d.cts +7 -0
  71. package/dist/client.d.ts +7 -0
  72. package/dist/client.js +371 -0
  73. package/dist/client.js.map +1 -0
  74. package/dist/constants.cjs +51 -0
  75. package/dist/constants.cjs.map +1 -0
  76. package/dist/constants.d.cts +7 -0
  77. package/dist/constants.d.ts +7 -0
  78. package/dist/constants.js +16 -0
  79. package/dist/constants.js.map +1 -0
  80. package/dist/database/column/index.cjs +34 -0
  81. package/dist/database/column/index.cjs.map +1 -0
  82. package/dist/database/column/index.d.cts +2 -0
  83. package/dist/database/column/index.d.ts +2 -0
  84. package/dist/database/column/index.js +8 -0
  85. package/dist/database/column/index.js.map +1 -0
  86. package/dist/database/index.cjs +83 -0
  87. package/dist/database/index.cjs.map +1 -0
  88. package/dist/database/index.d.cts +2 -0
  89. package/dist/database/index.d.ts +2 -0
  90. package/dist/database/index.js +60 -0
  91. package/dist/database/index.js.map +1 -0
  92. package/dist/database/snake-naming-strategy.class.cjs +78 -0
  93. package/dist/database/snake-naming-strategy.class.cjs.map +1 -0
  94. package/dist/database/snake-naming-strategy.class.d.cts +16 -0
  95. package/dist/database/snake-naming-strategy.class.d.ts +16 -0
  96. package/dist/database/snake-naming-strategy.class.js +56 -0
  97. package/dist/database/snake-naming-strategy.class.js.map +1 -0
  98. package/dist/error.cjs +46 -0
  99. package/dist/error.cjs.map +1 -0
  100. package/dist/error.d.cts +10 -0
  101. package/dist/error.d.ts +10 -0
  102. package/dist/error.js +28 -0
  103. package/dist/error.js.map +1 -0
  104. package/dist/express/app.cjs +233 -0
  105. package/dist/express/app.cjs.map +1 -0
  106. package/dist/express/app.d.cts +16 -0
  107. package/dist/express/app.d.ts +16 -0
  108. package/dist/express/app.js +205 -0
  109. package/dist/express/app.js.map +1 -0
  110. package/dist/express/index.cjs +239 -0
  111. package/dist/express/index.cjs.map +1 -0
  112. package/dist/express/index.d.cts +3 -0
  113. package/dist/express/index.d.ts +3 -0
  114. package/dist/express/index.js +205 -0
  115. package/dist/express/index.js.map +1 -0
  116. package/dist/express/middleware/cors.middleware.cjs +54 -0
  117. package/dist/express/middleware/cors.middleware.cjs.map +1 -0
  118. package/dist/express/middleware/cors.middleware.d.cts +9 -0
  119. package/dist/express/middleware/cors.middleware.d.ts +9 -0
  120. package/dist/express/middleware/cors.middleware.js +26 -0
  121. package/dist/express/middleware/cors.middleware.js.map +1 -0
  122. package/dist/express/middleware/error.middleware.cjs +136 -0
  123. package/dist/express/middleware/error.middleware.cjs.map +1 -0
  124. package/dist/express/middleware/error.middleware.d.cts +5 -0
  125. package/dist/express/middleware/error.middleware.d.ts +5 -0
  126. package/dist/express/middleware/error.middleware.js +116 -0
  127. package/dist/express/middleware/error.middleware.js.map +1 -0
  128. package/dist/express/middleware/filter.middleware.cjs +38 -0
  129. package/dist/express/middleware/filter.middleware.cjs.map +1 -0
  130. package/dist/express/middleware/filter.middleware.d.cts +5 -0
  131. package/dist/express/middleware/filter.middleware.d.ts +5 -0
  132. package/dist/express/middleware/filter.middleware.js +20 -0
  133. package/dist/express/middleware/filter.middleware.js.map +1 -0
  134. package/dist/express/middleware/index.cjs +206 -0
  135. package/dist/express/middleware/index.cjs.map +1 -0
  136. package/dist/express/middleware/index.d.cts +19 -0
  137. package/dist/express/middleware/index.d.ts +19 -0
  138. package/dist/express/middleware/index.js +169 -0
  139. package/dist/express/middleware/index.js.map +1 -0
  140. package/dist/express/middleware/not-found.middleware.cjs +79 -0
  141. package/dist/express/middleware/not-found.middleware.cjs.map +1 -0
  142. package/dist/express/middleware/not-found.middleware.d.cts +5 -0
  143. package/dist/express/middleware/not-found.middleware.d.ts +5 -0
  144. package/dist/express/middleware/not-found.middleware.js +59 -0
  145. package/dist/express/middleware/not-found.middleware.js.map +1 -0
  146. package/dist/generator.cjs +258 -0
  147. package/dist/generator.cjs.map +1 -0
  148. package/dist/generator.d.cts +10 -0
  149. package/dist/generator.d.ts +10 -0
  150. package/dist/generator.js +220 -0
  151. package/dist/generator.js.map +1 -0
  152. package/dist/http.cjs +82 -0
  153. package/dist/http.cjs.map +1 -0
  154. package/dist/http.d.cts +11 -0
  155. package/dist/http.d.ts +11 -0
  156. package/dist/http.js +64 -0
  157. package/dist/http.js.map +1 -0
  158. package/dist/index.cjs +831 -0
  159. package/dist/index.cjs.map +1 -0
  160. package/dist/index.d.cts +19 -0
  161. package/dist/index.d.ts +19 -0
  162. package/dist/index.js +783 -0
  163. package/dist/index.js.map +1 -0
  164. package/dist/lib/create-env-file.cjs +69 -0
  165. package/dist/lib/create-env-file.cjs.map +1 -0
  166. package/dist/lib/create-env-file.d.cts +3 -0
  167. package/dist/lib/create-env-file.d.ts +3 -0
  168. package/dist/lib/create-env-file.js +31 -0
  169. package/dist/lib/create-env-file.js.map +1 -0
  170. package/dist/lib/helper.cjs +94 -0
  171. package/dist/lib/helper.cjs.map +1 -0
  172. package/dist/lib/helper.d.cts +13 -0
  173. package/dist/lib/helper.d.ts +13 -0
  174. package/dist/lib/helper.js +62 -0
  175. package/dist/lib/helper.js.map +1 -0
  176. package/dist/lib/model.generator.cjs +212 -0
  177. package/dist/lib/model.generator.cjs.map +1 -0
  178. package/dist/lib/model.generator.d.cts +29 -0
  179. package/dist/lib/model.generator.d.ts +29 -0
  180. package/dist/lib/model.generator.js +174 -0
  181. package/dist/lib/model.generator.js.map +1 -0
  182. package/dist/lib/pre-init-dev-script.cjs +336 -0
  183. package/dist/lib/pre-init-dev-script.cjs.map +1 -0
  184. package/dist/lib/pre-init-dev-script.d.cts +2 -0
  185. package/dist/lib/pre-init-dev-script.d.ts +2 -0
  186. package/dist/lib/pre-init-dev-script.js +311 -0
  187. package/dist/lib/pre-init-dev-script.js.map +1 -0
  188. package/dist/mahameru.cjs +397 -0
  189. package/dist/mahameru.cjs.map +1 -0
  190. package/dist/mahameru.d.cts +78 -0
  191. package/dist/mahameru.d.ts +78 -0
  192. package/dist/mahameru.js +359 -0
  193. package/dist/mahameru.js.map +1 -0
  194. package/dist/request.cjs +35 -0
  195. package/dist/request.cjs.map +1 -0
  196. package/dist/request.d.cts +4 -0
  197. package/dist/request.d.ts +4 -0
  198. package/dist/request.js +13 -0
  199. package/dist/request.js.map +1 -0
  200. package/dist/response.cjs +35 -0
  201. package/dist/response.cjs.map +1 -0
  202. package/dist/response.d.cts +4 -0
  203. package/dist/response.d.ts +4 -0
  204. package/dist/response.js +13 -0
  205. package/dist/response.js.map +1 -0
  206. package/dist/types.cjs +1 -0
  207. package/dist/types.cjs.map +1 -0
  208. package/dist/types.d.cts +2 -0
  209. package/dist/types.d.ts +2 -0
  210. package/dist/types.js +1 -0
  211. package/dist/types.js.map +1 -0
  212. package/dist/utils/import-dynamic-module.cjs +34 -0
  213. package/dist/utils/import-dynamic-module.cjs.map +1 -0
  214. package/dist/utils/import-dynamic-module.d.cts +3 -0
  215. package/dist/utils/import-dynamic-module.d.ts +3 -0
  216. package/dist/utils/import-dynamic-module.js +12 -0
  217. package/dist/utils/import-dynamic-module.js.map +1 -0
  218. package/package.json +70 -0
@@ -0,0 +1,212 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/lib/model.generator.ts
31
+ var model_generator_exports = {};
32
+ __export(model_generator_exports, {
33
+ ModelGenerator: () => ModelGenerator
34
+ });
35
+ module.exports = __toCommonJS(model_generator_exports);
36
+
37
+ // node_modules/tsup/assets/cjs_shims.js
38
+ var getImportMetaUrl = /* @__PURE__ */ __name(() => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href, "getImportMetaUrl");
39
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
+
41
+ // src/lib/model.generator.ts
42
+ var import_fs = require("fs");
43
+ var import_path = __toESM(require("path"), 1);
44
+
45
+ // src/constants.ts
46
+ var import_node_path = require("path");
47
+ var import_node_url = require("url");
48
+ var root = process.cwd();
49
+ var __filename2 = (0, import_node_url.fileURLToPath)(importMetaUrl);
50
+ var __dirname = (0, import_node_path.dirname)(__filename2);
51
+ var isCommonJS = typeof module !== "undefined" && !!module.exports;
52
+ var isESModule = !isCommonJS;
53
+
54
+ // src/lib/model.generator.ts
55
+ var ModelGenerator = class {
56
+ static {
57
+ __name(this, "ModelGenerator");
58
+ }
59
+ options;
60
+ constructor(options) {
61
+ this.options = options;
62
+ if (!(0, import_fs.existsSync)(this.options.entitiesPath)) {
63
+ throw new Error(`Entities folder not found: ${this.options.entitiesPath}`);
64
+ }
65
+ }
66
+ generate() {
67
+ const entityFiles = this.getEntityFiles();
68
+ for (const entityFileName of entityFiles) {
69
+ this.generateEntityModel(entityFileName);
70
+ }
71
+ this.createModelIndexFileTemplate();
72
+ return;
73
+ }
74
+ generateEntityModel(entityFileName) {
75
+ const modelName = entityFileName.replace(/\.entity\.ts$/, "");
76
+ const entityPath = import_path.default.join(this.options.entitiesPath, entityFileName);
77
+ const modelPath = import_path.default.join(this.options.outputPath);
78
+ if (!(0, import_fs.existsSync)(entityPath)) throw new Error(`Entity tidak ditemukan: ${entityPath}`);
79
+ const entityClassName = this.detectClassName(entityPath, modelName);
80
+ this.writeModelFiles(modelPath, [
81
+ {
82
+ name: `${modelName}.model.ts`,
83
+ content: this.createEntityModelTemplate({
84
+ entityPath,
85
+ entityClassName
86
+ })
87
+ }
88
+ ]);
89
+ this.createModelIndexFileTemplate();
90
+ }
91
+ createEntityModelTemplate(options) {
92
+ const entityRelativeFilePath = import_path.default.relative(this.options.outputPath, options.entityPath).replace(/\\/g, "/");
93
+ return `import { BaseModel } from 'mahameru';
94
+ import { ${options.entityClassName} } from '${entityRelativeFilePath.replace(".ts", isESModule ? this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : ".js" : this.options.includeExtensionOnBareModuleImport || "")}';
95
+ import type { DataSource } from 'typeorm';
96
+
97
+ export class ${options.entityClassName}Model extends BaseModel<${options.entityClassName}> {
98
+ constructor(dataSource: DataSource) {
99
+ super(dataSource, ${options.entityClassName})
100
+ }
101
+ }
102
+ `;
103
+ }
104
+ createModelIndexFileTemplate() {
105
+ const modelFiles = this.getModelFiles();
106
+ const dataSourceFilePathRelative = this.resolveImportPath(import_path.default.relative(this.options.outputPath, this.options.dataSourceFilePath).replace(/\\/g, "/"));
107
+ let contents = `import dataSource from '${this.options.includeExtensionOnBareModuleImport ? dataSourceFilePathRelative + "/index." + this.options.includeExtensionOnBareModuleImport : dataSourceFilePathRelative}';
108
+
109
+ `;
110
+ for (const model of modelFiles) {
111
+ const modelFilePath = import_path.default.join(this.options.outputPath, model);
112
+ if (!(0, import_fs.existsSync)(modelFilePath)) continue;
113
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
114
+ contents += `import { ${modelClassName} } from './${this.resolveImportPath(model)}';
115
+ `;
116
+ }
117
+ contents += `
118
+ `;
119
+ for (const model of modelFiles) {
120
+ const modelFilePath = import_path.default.join(this.options.outputPath, model);
121
+ if (!(0, import_fs.existsSync)(modelFilePath)) continue;
122
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
123
+ const camelName = this.toCamelCase(modelClassName);
124
+ contents += `const ${camelName} = new ${modelClassName}(dataSource)
125
+ `;
126
+ }
127
+ contents += `
128
+ export type {
129
+ `;
130
+ for (const model of modelFiles) {
131
+ const modelFilePath = import_path.default.join(this.options.outputPath, model);
132
+ if (!(0, import_fs.existsSync)(modelFilePath)) continue;
133
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
134
+ contents += ` ${modelClassName},
135
+ `;
136
+ }
137
+ contents += `}
138
+ `;
139
+ contents += `
140
+ const models = {
141
+ `;
142
+ for (const model of modelFiles) {
143
+ const modelFilePath = import_path.default.join(this.options.outputPath, model);
144
+ if (!(0, import_fs.existsSync)(modelFilePath)) continue;
145
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
146
+ const camelName = this.toCamelCase(modelClassName);
147
+ contents += ` ${camelName},
148
+ `;
149
+ }
150
+ contents += `}
151
+
152
+ export type Models = typeof models
153
+ export { models }
154
+ `;
155
+ this.writeFile(import_path.default.join(this.options.outputPath, "index.ts"), contents);
156
+ }
157
+ resolveImportPath(importPath) {
158
+ const extension = this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : "";
159
+ return importPath.replace(".ts", extension);
160
+ }
161
+ writeFile(filePath, content) {
162
+ (0, import_fs.writeFileSync)(filePath, content, "utf8");
163
+ return true;
164
+ }
165
+ getEntityFiles() {
166
+ return (0, import_fs.readdirSync)(this.options.entitiesPath).filter((fileName) => fileName.endsWith(".entity.ts")).sort();
167
+ }
168
+ getModelFiles() {
169
+ return (0, import_fs.readdirSync)(this.options.outputPath).filter((fileName) => fileName.endsWith(".model.ts")).sort();
170
+ }
171
+ writeModelFiles(modelPath, files) {
172
+ (0, import_fs.mkdirSync)(modelPath, {
173
+ recursive: true
174
+ });
175
+ for (const file of files) {
176
+ this.writeFileIfMissing(import_path.default.join(modelPath, file.name), file.content);
177
+ }
178
+ }
179
+ writeFileIfMissing(filePath, content) {
180
+ if ((0, import_fs.existsSync)(filePath)) {
181
+ this.log("warn", `[skip] ${filePath}`);
182
+ return false;
183
+ }
184
+ (0, import_fs.writeFileSync)(filePath, content, "utf8");
185
+ this.log("log", `[create] ${filePath}`);
186
+ return true;
187
+ }
188
+ detectClassName(filePath, fallbackName) {
189
+ const content = (0, import_fs.readFileSync)(filePath, "utf8");
190
+ const match = content.match(/export\s+(?:abstract\s+)?class\s+([A-Za-z_$][A-Za-z0-9_$]*)/);
191
+ return match?.[1] ?? this.toPascalCase(fallbackName);
192
+ }
193
+ toPascalCase(value) {
194
+ return value.split(/[-_\s.]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
195
+ }
196
+ toCamelCase(value) {
197
+ const pascalCase = this.toPascalCase(value);
198
+ return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
199
+ }
200
+ log(type, message) {
201
+ if (!this.options.debug) return;
202
+ if (type === "error") console.error(message);
203
+ else if (type === "warn") console.warn(message);
204
+ else if (type === "log") console.log(message);
205
+ else throw new Error(`Unknown log type: ${type}`);
206
+ }
207
+ };
208
+ // Annotate the CommonJS export names for ESM import in node:
209
+ 0 && (module.exports = {
210
+ ModelGenerator
211
+ });
212
+ //# sourceMappingURL=model.generator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/model.generator.ts","../../node_modules/tsup/assets/cjs_shims.js","../../src/constants.ts"],"sourcesContent":["import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs'\r\nimport path from 'path'\r\nimport { isESModule } from '../constants.js'\r\n\r\ntype ModelGeneratorOptions = {\r\n dbName: string\r\n srcPath: string\r\n entitiesPath: string\r\n outputPath: string\r\n dataSourceFilePath: string\r\n includeExtensionOnBareModuleImport?: 'ts' | 'js'\r\n debug?: boolean\r\n}\r\n\r\nexport class ModelGenerator {\r\n constructor(private options: ModelGeneratorOptions) {\r\n if (!existsSync(this.options.entitiesPath)) {\r\n throw new Error(`Entities folder not found: ${this.options.entitiesPath}`)\r\n }\r\n }\r\n\r\n generate() {\r\n const entityFiles = this.getEntityFiles()\r\n\r\n for (const entityFileName of entityFiles) {\r\n this.generateEntityModel(entityFileName)\r\n }\r\n\r\n this.createModelIndexFileTemplate()\r\n\r\n return\r\n }\r\n\r\n generateEntityModel(entityFileName: string) {\r\n const modelName = entityFileName.replace(/\\.entity\\.ts$/, '')\r\n const entityPath = path.join(this.options.entitiesPath, entityFileName)\r\n const modelPath = path.join(this.options.outputPath)\r\n\r\n if (!existsSync(entityPath))\r\n throw new Error(`Entity tidak ditemukan: ${entityPath}`)\r\n\r\n const entityClassName = this.detectClassName(entityPath, modelName)\r\n\r\n this.writeModelFiles(modelPath, [\r\n {\r\n name: `${modelName}.model.ts`,\r\n content: this.createEntityModelTemplate({\r\n entityPath,\r\n entityClassName\r\n })\r\n }\r\n ])\r\n\r\n this.createModelIndexFileTemplate()\r\n }\r\n\r\n private createEntityModelTemplate(options: { entityPath: string; entityClassName: string; }) {\r\n const entityRelativeFilePath = path.relative(this.options.outputPath, options.entityPath).replace(/\\\\/g, '/')\r\n\r\n return `import { BaseModel } from 'mahameru';\r\nimport { ${options.entityClassName} } from '${entityRelativeFilePath.replace('.ts', isESModule ? (this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : '.js') : (this.options.includeExtensionOnBareModuleImport || ''))}';\r\nimport type { DataSource } from 'typeorm';\r\n\r\nexport class ${options.entityClassName}Model extends BaseModel<${options.entityClassName}> {\r\n constructor(dataSource: DataSource) {\r\n super(dataSource, ${options.entityClassName})\r\n }\r\n}\r\n`\r\n }\r\n\r\n private createModelIndexFileTemplate() {\r\n const modelFiles = this.getModelFiles()\r\n const dataSourceFilePathRelative = this.resolveImportPath(path.relative(this.options.outputPath, this.options.dataSourceFilePath).replace(/\\\\/g, '/'))\r\n\r\n let contents = `import dataSource from '${this.options.includeExtensionOnBareModuleImport ? dataSourceFilePathRelative + '/index.' + this.options.includeExtensionOnBareModuleImport : dataSourceFilePathRelative}';\\n\\n`;\r\n\r\n for (const model of modelFiles) {\r\n const modelFilePath = path.join(this.options.outputPath, model)\r\n\r\n if (!existsSync(modelFilePath)) continue\r\n\r\n const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model))\r\n\r\n contents += `import { ${modelClassName} } from './${this.resolveImportPath(model)}';\\n`;\r\n }\r\n\r\n contents += `\\n`;\r\n\r\n for (const model of modelFiles) {\r\n const modelFilePath = path.join(this.options.outputPath, model)\r\n\r\n if (!existsSync(modelFilePath)) continue\r\n\r\n const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model))\r\n const camelName = this.toCamelCase(modelClassName)\r\n contents += `const ${camelName} = new ${modelClassName}(dataSource)\\n`;\r\n }\r\n\r\n contents += `\\nexport type {\\n`;\r\n\r\n for (const model of modelFiles) {\r\n const modelFilePath = path.join(this.options.outputPath, model)\r\n\r\n if (!existsSync(modelFilePath)) continue\r\n\r\n const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model))\r\n contents += `\\t${modelClassName},\\n`;\r\n }\r\n\r\n contents += `}\\n`;\r\n\r\n contents += `\\nconst models = {\\n`;\r\n\r\n for (const model of modelFiles) {\r\n const modelFilePath = path.join(this.options.outputPath, model)\r\n\r\n if (!existsSync(modelFilePath)) continue\r\n\r\n const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model))\r\n const camelName = this.toCamelCase(modelClassName)\r\n contents += `\\t${camelName},\\n`;\r\n }\r\n\r\n contents += `}\\n\\nexport type Models = typeof models\\nexport { models }\\n`;\r\n\r\n this.writeFile(path.join(this.options.outputPath, 'index.ts'), contents)\r\n }\r\n\r\n private resolveImportPath(importPath: string) {\r\n const extension = this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : ''\r\n\r\n return importPath.replace('.ts', extension)\r\n }\r\n\r\n private writeFile(filePath: string, content: string) {\r\n writeFileSync(filePath, content, 'utf8')\r\n // this.log('warn',`[create] ${filePath}`)\r\n\r\n return true\r\n }\r\n\r\n private getEntityFiles() {\r\n return readdirSync(this.options.entitiesPath)\r\n .filter(fileName => fileName.endsWith('.entity.ts'))\r\n .sort()\r\n }\r\n\r\n private getModelFiles() {\r\n return readdirSync(this.options.outputPath)\r\n .filter(fileName => fileName.endsWith('.model.ts'))\r\n .sort()\r\n }\r\n\r\n private writeModelFiles(modelPath: string, files: { name: string; content: string }[]) {\r\n mkdirSync(modelPath, {\r\n recursive: true\r\n })\r\n\r\n for (const file of files) {\r\n this.writeFileIfMissing(path.join(modelPath, file.name), file.content)\r\n }\r\n }\r\n\r\n private writeFileIfMissing(filePath: string, content: string) {\r\n if (existsSync(filePath)) {\r\n this.log('warn', `[skip] ${filePath}`)\r\n\r\n return false\r\n }\r\n\r\n writeFileSync(filePath, content, 'utf8')\r\n this.log('log', `[create] ${filePath}`)\r\n\r\n return true\r\n }\r\n\r\n private detectClassName(filePath: string, fallbackName: string) {\r\n const content = readFileSync(filePath, 'utf8')\r\n const match = content.match(/export\\s+(?:abstract\\s+)?class\\s+([A-Za-z_$][A-Za-z0-9_$]*)/)\r\n\r\n return match?.[1] ?? this.toPascalCase(fallbackName)\r\n }\r\n\r\n private toPascalCase(value: string) {\r\n return value\r\n .split(/[-_\\s.]+/)\r\n .filter(Boolean)\r\n .map(part => part.charAt(0).toUpperCase() + part.slice(1))\r\n .join('')\r\n }\r\n\r\n toCamelCase(value: string) {\r\n const pascalCase = this.toPascalCase(value)\r\n\r\n return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1)\r\n }\r\n\r\n private log(type: 'log' | 'warn' | 'error', message: string) {\r\n if (!this.options.debug) return\r\n\r\n if (type === 'error') console.error(message)\r\n else if (type === 'warn') console.warn(message)\r\n else if (type === 'log') console.log(message)\r\n else throw new Error(`Unknown log type: ${type}`)\r\n }\r\n}\r\n\r\n// const root = process.cwd()\r\n// const srcPath = path.join(root, 'src')\r\n// const entitiesPath = path.join(srcPath, 'databases', 'db-test', 'entities')\r\n// const outputPath = path.join(srcPath, 'models')\r\n// const baseModelFilePath = path.join(srcPath, 'common', 'base', 'base.model.ts')\r\n// const dataSourceFilePath = path.join(srcPath, 'databases', 'db-test')\r\n\r\n// const generator = new ModelGenerator({\r\n// srcPath,\r\n// entitiesPath,\r\n// outputPath,\r\n// baseModelFilePath,\r\n// dataSourceFilePath,\r\n// debug: true\r\n// })\r\n\r\n// const isSingleModule = process.argv[2];\r\n\r\n// if (!isSingleModule) {\r\n// generator.generate()\r\n// } else {\r\n// if (typeof isSingleModule === 'string' && isSingleModule === '--name') {\r\n// const moduleName = process.argv[3]\r\n\r\n// if (!moduleName) {\r\n// console.error('Module name is required')\r\n\r\n// process.exit(1)\r\n// }\r\n\r\n// if (typeof moduleName === 'string') {\r\n// generator.generateEntityModel(moduleName + '.entity.ts')\r\n// }\r\n// }\r\n// }\r\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","import { dirname } from \"node:path\";\r\nimport { fileURLToPath } from \"node:url\";\r\n\r\nexport const root = process.cwd();\r\nexport const __filename = fileURLToPath(import.meta.url);\r\nexport const __dirname = dirname(__filename);\r\nexport const isCommonJS = typeof module !== 'undefined' && !!module.exports;\r\nexport const isESModule = !isCommonJS;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACKA,IAAMA,mBAAmB,6BACvB,OAAOC,aAAa,cAChB,IAAIC,IAAI,QAAQC,UAAAA,EAAY,EAAEC,OAC7BH,SAASI,iBAAiBJ,SAASI,cAAcC,QAAQC,YAAW,MAAO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,OAAQG,SAAQE,KAAKJ,OAAAA;aAC9BD,SAAS,MAAOG,SAAQlB,IAAIgB,OAAAA;QAChC,OAAM,IAAIlE,MAAM,qBAAqBiE,IAAAA,EAAM;EACpD;AACJ;","names":["getImportMetaUrl","document","URL","__filename","href","currentScript","tagName","toUpperCase","src","baseURI","importMetaUrl","root","process","cwd","__filename","fileURLToPath","__dirname","dirname","isCommonJS","module","exports","isESModule","ModelGenerator","options","existsSync","entitiesPath","Error","generate","entityFiles","getEntityFiles","entityFileName","generateEntityModel","createModelIndexFileTemplate","modelName","replace","entityPath","path","join","modelPath","outputPath","entityClassName","detectClassName","writeModelFiles","name","content","createEntityModelTemplate","entityRelativeFilePath","relative","isESModule","includeExtensionOnBareModuleImport","modelFiles","getModelFiles","dataSourceFilePathRelative","resolveImportPath","dataSourceFilePath","contents","model","modelFilePath","modelClassName","camelName","toCamelCase","writeFile","importPath","extension","filePath","writeFileSync","readdirSync","filter","fileName","endsWith","sort","files","mkdirSync","recursive","file","writeFileIfMissing","log","fallbackName","readFileSync","match","toPascalCase","value","split","Boolean","map","part","charAt","toUpperCase","slice","pascalCase","toLowerCase","type","message","debug","console","error","warn"]}
@@ -0,0 +1,29 @@
1
+ type ModelGeneratorOptions = {
2
+ dbName: string;
3
+ srcPath: string;
4
+ entitiesPath: string;
5
+ outputPath: string;
6
+ dataSourceFilePath: string;
7
+ includeExtensionOnBareModuleImport?: 'ts' | 'js';
8
+ debug?: boolean;
9
+ };
10
+ declare class ModelGenerator {
11
+ private options;
12
+ constructor(options: ModelGeneratorOptions);
13
+ generate(): void;
14
+ generateEntityModel(entityFileName: string): void;
15
+ private createEntityModelTemplate;
16
+ private createModelIndexFileTemplate;
17
+ private resolveImportPath;
18
+ private writeFile;
19
+ private getEntityFiles;
20
+ private getModelFiles;
21
+ private writeModelFiles;
22
+ private writeFileIfMissing;
23
+ private detectClassName;
24
+ private toPascalCase;
25
+ toCamelCase(value: string): string;
26
+ private log;
27
+ }
28
+
29
+ export { ModelGenerator };
@@ -0,0 +1,29 @@
1
+ type ModelGeneratorOptions = {
2
+ dbName: string;
3
+ srcPath: string;
4
+ entitiesPath: string;
5
+ outputPath: string;
6
+ dataSourceFilePath: string;
7
+ includeExtensionOnBareModuleImport?: 'ts' | 'js';
8
+ debug?: boolean;
9
+ };
10
+ declare class ModelGenerator {
11
+ private options;
12
+ constructor(options: ModelGeneratorOptions);
13
+ generate(): void;
14
+ generateEntityModel(entityFileName: string): void;
15
+ private createEntityModelTemplate;
16
+ private createModelIndexFileTemplate;
17
+ private resolveImportPath;
18
+ private writeFile;
19
+ private getEntityFiles;
20
+ private getModelFiles;
21
+ private writeModelFiles;
22
+ private writeFileIfMissing;
23
+ private detectClassName;
24
+ private toPascalCase;
25
+ toCamelCase(value: string): string;
26
+ private log;
27
+ }
28
+
29
+ export { ModelGenerator };
@@ -0,0 +1,174 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/lib/model.generator.ts
5
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "fs";
6
+ import path from "path";
7
+
8
+ // src/constants.ts
9
+ import { dirname } from "path";
10
+ import { fileURLToPath } from "url";
11
+ var root = process.cwd();
12
+ var __filename = fileURLToPath(import.meta.url);
13
+ var __dirname = dirname(__filename);
14
+ var isCommonJS = typeof module !== "undefined" && !!module.exports;
15
+ var isESModule = !isCommonJS;
16
+
17
+ // src/lib/model.generator.ts
18
+ var ModelGenerator = class {
19
+ static {
20
+ __name(this, "ModelGenerator");
21
+ }
22
+ options;
23
+ constructor(options) {
24
+ this.options = options;
25
+ if (!existsSync(this.options.entitiesPath)) {
26
+ throw new Error(`Entities folder not found: ${this.options.entitiesPath}`);
27
+ }
28
+ }
29
+ generate() {
30
+ const entityFiles = this.getEntityFiles();
31
+ for (const entityFileName of entityFiles) {
32
+ this.generateEntityModel(entityFileName);
33
+ }
34
+ this.createModelIndexFileTemplate();
35
+ return;
36
+ }
37
+ generateEntityModel(entityFileName) {
38
+ const modelName = entityFileName.replace(/\.entity\.ts$/, "");
39
+ const entityPath = path.join(this.options.entitiesPath, entityFileName);
40
+ const modelPath = path.join(this.options.outputPath);
41
+ if (!existsSync(entityPath)) throw new Error(`Entity tidak ditemukan: ${entityPath}`);
42
+ const entityClassName = this.detectClassName(entityPath, modelName);
43
+ this.writeModelFiles(modelPath, [
44
+ {
45
+ name: `${modelName}.model.ts`,
46
+ content: this.createEntityModelTemplate({
47
+ entityPath,
48
+ entityClassName
49
+ })
50
+ }
51
+ ]);
52
+ this.createModelIndexFileTemplate();
53
+ }
54
+ createEntityModelTemplate(options) {
55
+ const entityRelativeFilePath = path.relative(this.options.outputPath, options.entityPath).replace(/\\/g, "/");
56
+ return `import { BaseModel } from 'mahameru';
57
+ import { ${options.entityClassName} } from '${entityRelativeFilePath.replace(".ts", isESModule ? this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : ".js" : this.options.includeExtensionOnBareModuleImport || "")}';
58
+ import type { DataSource } from 'typeorm';
59
+
60
+ export class ${options.entityClassName}Model extends BaseModel<${options.entityClassName}> {
61
+ constructor(dataSource: DataSource) {
62
+ super(dataSource, ${options.entityClassName})
63
+ }
64
+ }
65
+ `;
66
+ }
67
+ createModelIndexFileTemplate() {
68
+ const modelFiles = this.getModelFiles();
69
+ const dataSourceFilePathRelative = this.resolveImportPath(path.relative(this.options.outputPath, this.options.dataSourceFilePath).replace(/\\/g, "/"));
70
+ let contents = `import dataSource from '${this.options.includeExtensionOnBareModuleImport ? dataSourceFilePathRelative + "/index." + this.options.includeExtensionOnBareModuleImport : dataSourceFilePathRelative}';
71
+
72
+ `;
73
+ for (const model of modelFiles) {
74
+ const modelFilePath = path.join(this.options.outputPath, model);
75
+ if (!existsSync(modelFilePath)) continue;
76
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
77
+ contents += `import { ${modelClassName} } from './${this.resolveImportPath(model)}';
78
+ `;
79
+ }
80
+ contents += `
81
+ `;
82
+ for (const model of modelFiles) {
83
+ const modelFilePath = path.join(this.options.outputPath, model);
84
+ if (!existsSync(modelFilePath)) continue;
85
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
86
+ const camelName = this.toCamelCase(modelClassName);
87
+ contents += `const ${camelName} = new ${modelClassName}(dataSource)
88
+ `;
89
+ }
90
+ contents += `
91
+ export type {
92
+ `;
93
+ for (const model of modelFiles) {
94
+ const modelFilePath = path.join(this.options.outputPath, model);
95
+ if (!existsSync(modelFilePath)) continue;
96
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
97
+ contents += ` ${modelClassName},
98
+ `;
99
+ }
100
+ contents += `}
101
+ `;
102
+ contents += `
103
+ const models = {
104
+ `;
105
+ for (const model of modelFiles) {
106
+ const modelFilePath = path.join(this.options.outputPath, model);
107
+ if (!existsSync(modelFilePath)) continue;
108
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
109
+ const camelName = this.toCamelCase(modelClassName);
110
+ contents += ` ${camelName},
111
+ `;
112
+ }
113
+ contents += `}
114
+
115
+ export type Models = typeof models
116
+ export { models }
117
+ `;
118
+ this.writeFile(path.join(this.options.outputPath, "index.ts"), contents);
119
+ }
120
+ resolveImportPath(importPath) {
121
+ const extension = this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : "";
122
+ return importPath.replace(".ts", extension);
123
+ }
124
+ writeFile(filePath, content) {
125
+ writeFileSync(filePath, content, "utf8");
126
+ return true;
127
+ }
128
+ getEntityFiles() {
129
+ return readdirSync(this.options.entitiesPath).filter((fileName) => fileName.endsWith(".entity.ts")).sort();
130
+ }
131
+ getModelFiles() {
132
+ return readdirSync(this.options.outputPath).filter((fileName) => fileName.endsWith(".model.ts")).sort();
133
+ }
134
+ writeModelFiles(modelPath, files) {
135
+ mkdirSync(modelPath, {
136
+ recursive: true
137
+ });
138
+ for (const file of files) {
139
+ this.writeFileIfMissing(path.join(modelPath, file.name), file.content);
140
+ }
141
+ }
142
+ writeFileIfMissing(filePath, content) {
143
+ if (existsSync(filePath)) {
144
+ this.log("warn", `[skip] ${filePath}`);
145
+ return false;
146
+ }
147
+ writeFileSync(filePath, content, "utf8");
148
+ this.log("log", `[create] ${filePath}`);
149
+ return true;
150
+ }
151
+ detectClassName(filePath, fallbackName) {
152
+ const content = readFileSync(filePath, "utf8");
153
+ const match = content.match(/export\s+(?:abstract\s+)?class\s+([A-Za-z_$][A-Za-z0-9_$]*)/);
154
+ return match?.[1] ?? this.toPascalCase(fallbackName);
155
+ }
156
+ toPascalCase(value) {
157
+ return value.split(/[-_\s.]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
158
+ }
159
+ toCamelCase(value) {
160
+ const pascalCase = this.toPascalCase(value);
161
+ return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
162
+ }
163
+ log(type, message) {
164
+ if (!this.options.debug) return;
165
+ if (type === "error") console.error(message);
166
+ else if (type === "warn") console.warn(message);
167
+ else if (type === "log") console.log(message);
168
+ else throw new Error(`Unknown log type: ${type}`);
169
+ }
170
+ };
171
+ export {
172
+ ModelGenerator
173
+ };
174
+ //# sourceMappingURL=model.generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/model.generator.ts","../../src/constants.ts"],"sourcesContent":["import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs'\r\nimport path from 'path'\r\nimport { isESModule } from '../constants.js'\r\n\r\ntype ModelGeneratorOptions = {\r\n dbName: string\r\n srcPath: string\r\n entitiesPath: string\r\n outputPath: string\r\n dataSourceFilePath: string\r\n includeExtensionOnBareModuleImport?: 'ts' | 'js'\r\n debug?: boolean\r\n}\r\n\r\nexport class ModelGenerator {\r\n constructor(private options: ModelGeneratorOptions) {\r\n if (!existsSync(this.options.entitiesPath)) {\r\n throw new Error(`Entities folder not found: ${this.options.entitiesPath}`)\r\n }\r\n }\r\n\r\n generate() {\r\n const entityFiles = this.getEntityFiles()\r\n\r\n for (const entityFileName of entityFiles) {\r\n this.generateEntityModel(entityFileName)\r\n }\r\n\r\n this.createModelIndexFileTemplate()\r\n\r\n return\r\n }\r\n\r\n generateEntityModel(entityFileName: string) {\r\n const modelName = entityFileName.replace(/\\.entity\\.ts$/, '')\r\n const entityPath = path.join(this.options.entitiesPath, entityFileName)\r\n const modelPath = path.join(this.options.outputPath)\r\n\r\n if (!existsSync(entityPath))\r\n throw new Error(`Entity tidak ditemukan: ${entityPath}`)\r\n\r\n const entityClassName = this.detectClassName(entityPath, modelName)\r\n\r\n this.writeModelFiles(modelPath, [\r\n {\r\n name: `${modelName}.model.ts`,\r\n content: this.createEntityModelTemplate({\r\n entityPath,\r\n entityClassName\r\n })\r\n }\r\n ])\r\n\r\n this.createModelIndexFileTemplate()\r\n }\r\n\r\n private createEntityModelTemplate(options: { entityPath: string; entityClassName: string; }) {\r\n const entityRelativeFilePath = path.relative(this.options.outputPath, options.entityPath).replace(/\\\\/g, '/')\r\n\r\n return `import { BaseModel } from 'mahameru';\r\nimport { ${options.entityClassName} } from '${entityRelativeFilePath.replace('.ts', isESModule ? (this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : '.js') : (this.options.includeExtensionOnBareModuleImport || ''))}';\r\nimport type { DataSource } from 'typeorm';\r\n\r\nexport class ${options.entityClassName}Model extends BaseModel<${options.entityClassName}> {\r\n constructor(dataSource: DataSource) {\r\n super(dataSource, ${options.entityClassName})\r\n }\r\n}\r\n`\r\n }\r\n\r\n private createModelIndexFileTemplate() {\r\n const modelFiles = this.getModelFiles()\r\n const dataSourceFilePathRelative = this.resolveImportPath(path.relative(this.options.outputPath, this.options.dataSourceFilePath).replace(/\\\\/g, '/'))\r\n\r\n let contents = `import dataSource from '${this.options.includeExtensionOnBareModuleImport ? dataSourceFilePathRelative + '/index.' + this.options.includeExtensionOnBareModuleImport : dataSourceFilePathRelative}';\\n\\n`;\r\n\r\n for (const model of modelFiles) {\r\n const modelFilePath = path.join(this.options.outputPath, model)\r\n\r\n if (!existsSync(modelFilePath)) continue\r\n\r\n const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model))\r\n\r\n contents += `import { ${modelClassName} } from './${this.resolveImportPath(model)}';\\n`;\r\n }\r\n\r\n contents += `\\n`;\r\n\r\n for (const model of modelFiles) {\r\n const modelFilePath = path.join(this.options.outputPath, model)\r\n\r\n if (!existsSync(modelFilePath)) continue\r\n\r\n const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model))\r\n const camelName = this.toCamelCase(modelClassName)\r\n contents += `const ${camelName} = new ${modelClassName}(dataSource)\\n`;\r\n }\r\n\r\n contents += `\\nexport type {\\n`;\r\n\r\n for (const model of modelFiles) {\r\n const modelFilePath = path.join(this.options.outputPath, model)\r\n\r\n if (!existsSync(modelFilePath)) continue\r\n\r\n const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model))\r\n contents += `\\t${modelClassName},\\n`;\r\n }\r\n\r\n contents += `}\\n`;\r\n\r\n contents += `\\nconst models = {\\n`;\r\n\r\n for (const model of modelFiles) {\r\n const modelFilePath = path.join(this.options.outputPath, model)\r\n\r\n if (!existsSync(modelFilePath)) continue\r\n\r\n const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model))\r\n const camelName = this.toCamelCase(modelClassName)\r\n contents += `\\t${camelName},\\n`;\r\n }\r\n\r\n contents += `}\\n\\nexport type Models = typeof models\\nexport { models }\\n`;\r\n\r\n this.writeFile(path.join(this.options.outputPath, 'index.ts'), contents)\r\n }\r\n\r\n private resolveImportPath(importPath: string) {\r\n const extension = this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : ''\r\n\r\n return importPath.replace('.ts', extension)\r\n }\r\n\r\n private writeFile(filePath: string, content: string) {\r\n writeFileSync(filePath, content, 'utf8')\r\n // this.log('warn',`[create] ${filePath}`)\r\n\r\n return true\r\n }\r\n\r\n private getEntityFiles() {\r\n return readdirSync(this.options.entitiesPath)\r\n .filter(fileName => fileName.endsWith('.entity.ts'))\r\n .sort()\r\n }\r\n\r\n private getModelFiles() {\r\n return readdirSync(this.options.outputPath)\r\n .filter(fileName => fileName.endsWith('.model.ts'))\r\n .sort()\r\n }\r\n\r\n private writeModelFiles(modelPath: string, files: { name: string; content: string }[]) {\r\n mkdirSync(modelPath, {\r\n recursive: true\r\n })\r\n\r\n for (const file of files) {\r\n this.writeFileIfMissing(path.join(modelPath, file.name), file.content)\r\n }\r\n }\r\n\r\n private writeFileIfMissing(filePath: string, content: string) {\r\n if (existsSync(filePath)) {\r\n this.log('warn', `[skip] ${filePath}`)\r\n\r\n return false\r\n }\r\n\r\n writeFileSync(filePath, content, 'utf8')\r\n this.log('log', `[create] ${filePath}`)\r\n\r\n return true\r\n }\r\n\r\n private detectClassName(filePath: string, fallbackName: string) {\r\n const content = readFileSync(filePath, 'utf8')\r\n const match = content.match(/export\\s+(?:abstract\\s+)?class\\s+([A-Za-z_$][A-Za-z0-9_$]*)/)\r\n\r\n return match?.[1] ?? this.toPascalCase(fallbackName)\r\n }\r\n\r\n private toPascalCase(value: string) {\r\n return value\r\n .split(/[-_\\s.]+/)\r\n .filter(Boolean)\r\n .map(part => part.charAt(0).toUpperCase() + part.slice(1))\r\n .join('')\r\n }\r\n\r\n toCamelCase(value: string) {\r\n const pascalCase = this.toPascalCase(value)\r\n\r\n return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1)\r\n }\r\n\r\n private log(type: 'log' | 'warn' | 'error', message: string) {\r\n if (!this.options.debug) return\r\n\r\n if (type === 'error') console.error(message)\r\n else if (type === 'warn') console.warn(message)\r\n else if (type === 'log') console.log(message)\r\n else throw new Error(`Unknown log type: ${type}`)\r\n }\r\n}\r\n\r\n// const root = process.cwd()\r\n// const srcPath = path.join(root, 'src')\r\n// const entitiesPath = path.join(srcPath, 'databases', 'db-test', 'entities')\r\n// const outputPath = path.join(srcPath, 'models')\r\n// const baseModelFilePath = path.join(srcPath, 'common', 'base', 'base.model.ts')\r\n// const dataSourceFilePath = path.join(srcPath, 'databases', 'db-test')\r\n\r\n// const generator = new ModelGenerator({\r\n// srcPath,\r\n// entitiesPath,\r\n// outputPath,\r\n// baseModelFilePath,\r\n// dataSourceFilePath,\r\n// debug: true\r\n// })\r\n\r\n// const isSingleModule = process.argv[2];\r\n\r\n// if (!isSingleModule) {\r\n// generator.generate()\r\n// } else {\r\n// if (typeof isSingleModule === 'string' && isSingleModule === '--name') {\r\n// const moduleName = process.argv[3]\r\n\r\n// if (!moduleName) {\r\n// console.error('Module name is required')\r\n\r\n// process.exit(1)\r\n// }\r\n\r\n// if (typeof moduleName === 'string') {\r\n// generator.generateEntityModel(moduleName + '.entity.ts')\r\n// }\r\n// }\r\n// }\r\n","import { dirname } from \"node:path\";\r\nimport { fileURLToPath } from \"node:url\";\r\n\r\nexport const root = process.cwd();\r\nexport const __filename = fileURLToPath(import.meta.url);\r\nexport const __dirname = dirname(__filename);\r\nexport const isCommonJS = typeof module !== 'undefined' && !!module.exports;\r\nexport const isESModule = !isCommonJS;\r\n"],"mappings":";;;;AAAA,SAASA,YAAYC,WAAWC,aAAaC,cAAcC,qBAAqB;AAChF,OAAOC,UAAU;;;ACDjB,SAASC,eAAe;AACxB,SAASC,qBAAqB;AAEvB,IAAMC,OAAOC,QAAQC,IAAG;AACxB,IAAMC,aAAaJ,cAAc,YAAYK,GAAG;AAChD,IAAMC,YAAYP,QAAQK,UAAAA;AAC1B,IAAMG,aAAa,OAAOC,WAAW,eAAe,CAAC,CAACA,OAAOC;AAC7D,IAAMC,aAAa,CAACH;;;ADOpB,IAAMI,iBAAN,MAAMA;EAdb,OAcaA;;;;EACT,YAAoBC,SAAgC;SAAhCA,UAAAA;AAChB,QAAI,CAACC,WAAW,KAAKD,QAAQE,YAAY,GAAG;AACxC,YAAM,IAAIC,MAAM,8BAA8B,KAAKH,QAAQE,YAAY,EAAE;IAC7E;EACJ;EAE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AAMe,QAAQnC,QAAQmC,MAAM,6DAAA;AAE5B,WAAOA,QAAQ,CAAA,KAAM,KAAKC,aAAaH,YAAAA;EAC3C;EAEQG,aAAaC,OAAe;AAChC,WAAOA,MACFC,MAAM,UAAA,EACNf,OAAOgB,OAAAA,EACPC,IAAIC,CAAAA,SAAQA,KAAKC,OAAO,CAAA,EAAGC,YAAW,IAAKF,KAAKG,MAAM,CAAA,CAAA,EACtDnD,KAAK,EAAA;EACd;EAEAuB,YAAYqB,OAAe;AACvB,UAAMQ,aAAa,KAAKT,aAAaC,KAAAA;AAErC,WAAOQ,WAAWH,OAAO,CAAA,EAAGI,YAAW,IAAKD,WAAWD,MAAM,CAAA;EACjE;EAEQZ,IAAIe,MAAgCC,SAAiB;AACzD,QAAI,CAAC,KAAKrE,QAAQsE,MAAO;AAEzB,QAAIF,SAAS,QAASG,SAAQC,MAAMH,OAAAA;aAC3BD,SAAS,OAAQG,SAAQE,KAAKJ,OAAAA;aAC9BD,SAAS,MAAOG,SAAQlB,IAAIgB,OAAAA;QAChC,OAAM,IAAIlE,MAAM,qBAAqBiE,IAAAA,EAAM;EACpD;AACJ;","names":["existsSync","mkdirSync","readdirSync","readFileSync","writeFileSync","path","dirname","fileURLToPath","root","process","cwd","__filename","url","__dirname","isCommonJS","module","exports","isESModule","ModelGenerator","options","existsSync","entitiesPath","Error","generate","entityFiles","getEntityFiles","entityFileName","generateEntityModel","createModelIndexFileTemplate","modelName","replace","entityPath","path","join","modelPath","outputPath","entityClassName","detectClassName","writeModelFiles","name","content","createEntityModelTemplate","entityRelativeFilePath","relative","isESModule","includeExtensionOnBareModuleImport","modelFiles","getModelFiles","dataSourceFilePathRelative","resolveImportPath","dataSourceFilePath","contents","model","modelFilePath","modelClassName","camelName","toCamelCase","writeFile","importPath","extension","filePath","writeFileSync","readdirSync","filter","fileName","endsWith","sort","files","mkdirSync","recursive","file","writeFileIfMissing","log","fallbackName","readFileSync","match","toPascalCase","value","split","Boolean","map","part","charAt","toUpperCase","slice","pascalCase","toLowerCase","type","message","debug","console","error","warn"]}