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,258 @@
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/generator.ts
31
+ var generator_exports = {};
32
+ __export(generator_exports, {
33
+ default: () => generator_default,
34
+ generateDTO: () => generateDTO
35
+ });
36
+ module.exports = __toCommonJS(generator_exports);
37
+
38
+ // node_modules/tsup/assets/cjs_shims.js
39
+ 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");
40
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
41
+
42
+ // src/generator.ts
43
+ var import_path2 = __toESM(require("path"), 1);
44
+ var import_typeorm_dto_generator = require("typeorm-dto-generator");
45
+
46
+ // src/lib/model.generator.ts
47
+ var import_fs = require("fs");
48
+ var import_path = __toESM(require("path"), 1);
49
+
50
+ // src/constants.ts
51
+ var import_node_path = require("path");
52
+ var import_node_url = require("url");
53
+ var root = process.cwd();
54
+ var __filename2 = (0, import_node_url.fileURLToPath)(importMetaUrl);
55
+ var __dirname = (0, import_node_path.dirname)(__filename2);
56
+ var isCommonJS = typeof module !== "undefined" && !!module.exports;
57
+ var isESModule = !isCommonJS;
58
+
59
+ // src/lib/model.generator.ts
60
+ var ModelGenerator = class {
61
+ static {
62
+ __name(this, "ModelGenerator");
63
+ }
64
+ options;
65
+ constructor(options) {
66
+ this.options = options;
67
+ if (!(0, import_fs.existsSync)(this.options.entitiesPath)) {
68
+ throw new Error(`Entities folder not found: ${this.options.entitiesPath}`);
69
+ }
70
+ }
71
+ generate() {
72
+ const entityFiles = this.getEntityFiles();
73
+ for (const entityFileName of entityFiles) {
74
+ this.generateEntityModel(entityFileName);
75
+ }
76
+ this.createModelIndexFileTemplate();
77
+ return;
78
+ }
79
+ generateEntityModel(entityFileName) {
80
+ const modelName = entityFileName.replace(/\.entity\.ts$/, "");
81
+ const entityPath = import_path.default.join(this.options.entitiesPath, entityFileName);
82
+ const modelPath = import_path.default.join(this.options.outputPath);
83
+ if (!(0, import_fs.existsSync)(entityPath)) throw new Error(`Entity tidak ditemukan: ${entityPath}`);
84
+ const entityClassName = this.detectClassName(entityPath, modelName);
85
+ this.writeModelFiles(modelPath, [
86
+ {
87
+ name: `${modelName}.model.ts`,
88
+ content: this.createEntityModelTemplate({
89
+ entityPath,
90
+ entityClassName
91
+ })
92
+ }
93
+ ]);
94
+ this.createModelIndexFileTemplate();
95
+ }
96
+ createEntityModelTemplate(options) {
97
+ const entityRelativeFilePath = import_path.default.relative(this.options.outputPath, options.entityPath).replace(/\\/g, "/");
98
+ return `import { BaseModel } from 'mahameru';
99
+ import { ${options.entityClassName} } from '${entityRelativeFilePath.replace(".ts", isESModule ? this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : ".js" : this.options.includeExtensionOnBareModuleImport || "")}';
100
+ import type { DataSource } from 'typeorm';
101
+
102
+ export class ${options.entityClassName}Model extends BaseModel<${options.entityClassName}> {
103
+ constructor(dataSource: DataSource) {
104
+ super(dataSource, ${options.entityClassName})
105
+ }
106
+ }
107
+ `;
108
+ }
109
+ createModelIndexFileTemplate() {
110
+ const modelFiles = this.getModelFiles();
111
+ const dataSourceFilePathRelative = this.resolveImportPath(import_path.default.relative(this.options.outputPath, this.options.dataSourceFilePath).replace(/\\/g, "/"));
112
+ let contents = `import dataSource from '${this.options.includeExtensionOnBareModuleImport ? dataSourceFilePathRelative + "/index." + this.options.includeExtensionOnBareModuleImport : dataSourceFilePathRelative}';
113
+
114
+ `;
115
+ for (const model2 of modelFiles) {
116
+ const modelFilePath = import_path.default.join(this.options.outputPath, model2);
117
+ if (!(0, import_fs.existsSync)(modelFilePath)) continue;
118
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model2));
119
+ contents += `import { ${modelClassName} } from './${this.resolveImportPath(model2)}';
120
+ `;
121
+ }
122
+ contents += `
123
+ `;
124
+ for (const model2 of modelFiles) {
125
+ const modelFilePath = import_path.default.join(this.options.outputPath, model2);
126
+ if (!(0, import_fs.existsSync)(modelFilePath)) continue;
127
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model2));
128
+ const camelName = this.toCamelCase(modelClassName);
129
+ contents += `const ${camelName} = new ${modelClassName}(dataSource)
130
+ `;
131
+ }
132
+ contents += `
133
+ export type {
134
+ `;
135
+ for (const model2 of modelFiles) {
136
+ const modelFilePath = import_path.default.join(this.options.outputPath, model2);
137
+ if (!(0, import_fs.existsSync)(modelFilePath)) continue;
138
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model2));
139
+ contents += ` ${modelClassName},
140
+ `;
141
+ }
142
+ contents += `}
143
+ `;
144
+ contents += `
145
+ const models = {
146
+ `;
147
+ for (const model2 of modelFiles) {
148
+ const modelFilePath = import_path.default.join(this.options.outputPath, model2);
149
+ if (!(0, import_fs.existsSync)(modelFilePath)) continue;
150
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model2));
151
+ const camelName = this.toCamelCase(modelClassName);
152
+ contents += ` ${camelName},
153
+ `;
154
+ }
155
+ contents += `}
156
+
157
+ export type Models = typeof models
158
+ export { models }
159
+ `;
160
+ this.writeFile(import_path.default.join(this.options.outputPath, "index.ts"), contents);
161
+ }
162
+ resolveImportPath(importPath) {
163
+ const extension = this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : "";
164
+ return importPath.replace(".ts", extension);
165
+ }
166
+ writeFile(filePath, content) {
167
+ (0, import_fs.writeFileSync)(filePath, content, "utf8");
168
+ return true;
169
+ }
170
+ getEntityFiles() {
171
+ return (0, import_fs.readdirSync)(this.options.entitiesPath).filter((fileName) => fileName.endsWith(".entity.ts")).sort();
172
+ }
173
+ getModelFiles() {
174
+ return (0, import_fs.readdirSync)(this.options.outputPath).filter((fileName) => fileName.endsWith(".model.ts")).sort();
175
+ }
176
+ writeModelFiles(modelPath, files) {
177
+ (0, import_fs.mkdirSync)(modelPath, {
178
+ recursive: true
179
+ });
180
+ for (const file of files) {
181
+ this.writeFileIfMissing(import_path.default.join(modelPath, file.name), file.content);
182
+ }
183
+ }
184
+ writeFileIfMissing(filePath, content) {
185
+ if ((0, import_fs.existsSync)(filePath)) {
186
+ this.log("warn", `[skip] ${filePath}`);
187
+ return false;
188
+ }
189
+ (0, import_fs.writeFileSync)(filePath, content, "utf8");
190
+ this.log("log", `[create] ${filePath}`);
191
+ return true;
192
+ }
193
+ detectClassName(filePath, fallbackName) {
194
+ const content = (0, import_fs.readFileSync)(filePath, "utf8");
195
+ const match = content.match(/export\s+(?:abstract\s+)?class\s+([A-Za-z_$][A-Za-z0-9_$]*)/);
196
+ return match?.[1] ?? this.toPascalCase(fallbackName);
197
+ }
198
+ toPascalCase(value) {
199
+ return value.split(/[-_\s.]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
200
+ }
201
+ toCamelCase(value) {
202
+ const pascalCase = this.toPascalCase(value);
203
+ return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
204
+ }
205
+ log(type, message) {
206
+ if (!this.options.debug) return;
207
+ if (type === "error") console.error(message);
208
+ else if (type === "warn") console.warn(message);
209
+ else if (type === "log") console.log(message);
210
+ else throw new Error(`Unknown log type: ${type}`);
211
+ }
212
+ };
213
+
214
+ // src/generator.ts
215
+ var root2 = process.cwd();
216
+ var dto = new import_typeorm_dto_generator.TORMDTOGenerator({
217
+ entityPaths: [
218
+ import_path2.default.join(root2, "src", "databases", "db-test", "entities", "*.entity.ts")
219
+ ],
220
+ dtoOutputDir: import_path2.default.join(root2, "src", "types"),
221
+ mapperOutputFile: import_path2.default.join(root2, "src", "common", "dto", "mapper.dto.ts"),
222
+ debug: true
223
+ });
224
+ var srcPath = import_path2.default.join(root2, "src");
225
+ var entitiesPath = import_path2.default.join(srcPath, "databases", "db-test", "entities");
226
+ var outputPath = import_path2.default.join(srcPath, "models");
227
+ var dataSourceFilePath = import_path2.default.join(srcPath, "databases", "db-test");
228
+ var model = new ModelGenerator({
229
+ dbName: "db-test",
230
+ srcPath,
231
+ entitiesPath,
232
+ outputPath,
233
+ dataSourceFilePath,
234
+ debug: true
235
+ });
236
+ var generator = {
237
+ dto,
238
+ model
239
+ };
240
+ async function generateDTO(dir) {
241
+ const newDir = dir.split("/").slice(0, -1).join("/");
242
+ const dto2 = new import_typeorm_dto_generator.TORMDTOGenerator({
243
+ entityPaths: [
244
+ import_path2.default.join(root2, newDir, "*.entity.ts")
245
+ ],
246
+ dtoOutputDir: import_path2.default.join(root2, "src", "types"),
247
+ mapperOutputFile: import_path2.default.join(root2, "src", "common", "dto", "mapper.dto.ts"),
248
+ debug: true
249
+ });
250
+ await dto2.run();
251
+ }
252
+ __name(generateDTO, "generateDTO");
253
+ var generator_default = generator;
254
+ // Annotate the CommonJS export names for ESM import in node:
255
+ 0 && (module.exports = {
256
+ generateDTO
257
+ });
258
+ //# sourceMappingURL=generator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generator.ts","../node_modules/tsup/assets/cjs_shims.js","../src/lib/model.generator.ts","../src/constants.ts"],"sourcesContent":["\r\nimport path from 'path'\r\nimport { TORMDTOGenerator } from 'typeorm-dto-generator'\r\nimport { ModelGenerator } from './lib/model.generator.js'\r\n\r\nconst root = process.cwd()\r\n\r\nconst dto = new TORMDTOGenerator({\r\n entityPaths: [path.join(root, 'src', 'databases', 'db-test', 'entities', '*.entity.ts')],\r\n dtoOutputDir: path.join(root, 'src', 'types'),\r\n mapperOutputFile: path.join(root, 'src', 'common', 'dto', 'mapper.dto.ts'),\r\n debug: true\r\n})\r\n\r\nconst srcPath = path.join(root, 'src')\r\nconst entitiesPath = path.join(srcPath, 'databases', 'db-test', 'entities')\r\nconst outputPath = path.join(srcPath, 'models')\r\nconst dataSourceFilePath = path.join(srcPath, 'databases', 'db-test')\r\n\r\nconst model = new ModelGenerator({\r\n dbName: 'db-test',\r\n srcPath,\r\n entitiesPath,\r\n outputPath,\r\n dataSourceFilePath,\r\n debug: true\r\n})\r\n\r\nconst generator = {\r\n dto,\r\n model\r\n}\r\n\r\nexport async function generateDTO(dir: string) {\r\n const newDir = dir.split('/').slice(0, -1).join('/')\r\n\r\n const dto = new TORMDTOGenerator({\r\n entityPaths: [path.join(root, newDir, '*.entity.ts')],\r\n dtoOutputDir: path.join(root, 'src', 'types'),\r\n mapperOutputFile: path.join(root, 'src', 'common', 'dto', 'mapper.dto.ts'),\r\n debug: true\r\n })\r\n\r\n await dto.run()\r\n}\r\n\r\nexport default generator\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 { 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;;ACIA,IAAMA,mBAAmB,6BACvB,OAAOC,aAAa,cAChB,IAAIC,IAAI,QAAQC,UAAAA,EAAY,EAAEC,OAC7BH,SAASI,iBAAiBJ,SAASI,cAAcC,QAAQC,YAAW,MAAO,WAC1EN,SAASI,cAAcG,MACvB,IAAIN,IAAI,WAAWD,SAASQ,OAAO,EAAEL,MALpB;AAOlB,IAAMM,gBAAgCV,iCAAAA;;;ADX7C,IAAAW,eAAiB;AACjB,mCAAiC;;;AEFjC,gBAAgF;AAChF,kBAAiB;;;ACDjB,uBAAwB;AACxB,sBAA8B;AAEvB,IAAMC,OAAOC,QAAQC,IAAG;AACxB,IAAMC,kBAAaC,+BAAc,aAAe;AAChD,IAAMC,gBAAYC,0BAAQH,WAAAA;AAC1B,IAAMI,aAAa,OAAOC,WAAW,eAAe,CAAC,CAACA,OAAOC;AAC7D,IAAMC,aAAa,CAACH;;;ADOpB,IAAMI,iBAAN,MAAMA;EAdb,OAcaA;;;;EACT,YAAoBC,SAAgC;SAAhCA,UAAAA;AAChB,QAAI,KAACC,sBAAW,KAAKD,QAAQE,YAAY,GAAG;AACxC,YAAM,IAAIC,MAAM,8BAA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KI,SAAS,aAAa,WAAW,UAAA;AAChE,IAAME,aAAaP,aAAAA,QAAKC,KAAKI,SAAS,QAAA;AACtC,IAAMG,qBAAqBR,aAAAA,QAAKC,KAAKI,SAAS,aAAa,SAAA;AAE3D,IAAMI,QAAQ,IAAIC,eAAe;EAC7BC,QAAQ;EACRN;EACAC;EACAC;EACAC;EACAJ,OAAO;AACX,CAAA;AAEA,IAAMQ,YAAY;EACdf;EACAY;AACJ;AAEA,eAAsBI,YAAYC,KAAW;AACzC,QAAMC,SAASD,IAAIE,MAAM,GAAA,EAAKC,MAAM,GAAG,EAAC,EAAGhB,KAAK,GAAA;AAEhD,QAAMJ,OAAM,IAAIC,8CAAiB;IAC7BC,aAAa;MAACC,aAAAA,QAAKC,KAAKP,OAAMqB,QAAQ,aAAA;;IACtCb,cAAcF,aAAAA,QAAKC,KAAKP,OAAM,OAAO,OAAA;IACrCS,kBAAkBH,aAAAA,QAAKC,KAAKP,OAAM,OAAO,UAAU,OAAO,eAAA;IAC1DU,OAAO;EACX,CAAA;AAEA,QAAMP,KAAIqB,IAAG;AACjB;AAXsBL;AAatB,IAAA,oBAAeD;","names":["getImportMetaUrl","document","URL","__filename","href","currentScript","tagName","toUpperCase","src","baseURI","importMetaUrl","import_path","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","root","process","cwd","dto","TORMDTOGenerator","entityPaths","path","join","dtoOutputDir","mapperOutputFile","debug","srcPath","entitiesPath","outputPath","dataSourceFilePath","model","ModelGenerator","dbName","generator","generateDTO","dir","newDir","split","slice","run"]}
@@ -0,0 +1,10 @@
1
+ import { TORMDTOGenerator } from 'typeorm-dto-generator';
2
+ import { ModelGenerator } from './lib/model.generator.cjs';
3
+
4
+ declare const generator: {
5
+ dto: TORMDTOGenerator;
6
+ model: ModelGenerator;
7
+ };
8
+ declare function generateDTO(dir: string): Promise<void>;
9
+
10
+ export { generator as default, generateDTO };
@@ -0,0 +1,10 @@
1
+ import { TORMDTOGenerator } from 'typeorm-dto-generator';
2
+ import { ModelGenerator } from './lib/model.generator.js';
3
+
4
+ declare const generator: {
5
+ dto: TORMDTOGenerator;
6
+ model: ModelGenerator;
7
+ };
8
+ declare function generateDTO(dir: string): Promise<void>;
9
+
10
+ export { generator as default, generateDTO };
@@ -0,0 +1,220 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/generator.ts
5
+ import path2 from "path";
6
+ import { TORMDTOGenerator } from "typeorm-dto-generator";
7
+
8
+ // src/lib/model.generator.ts
9
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "fs";
10
+ import path from "path";
11
+
12
+ // src/constants.ts
13
+ import { dirname } from "path";
14
+ import { fileURLToPath } from "url";
15
+ var root = process.cwd();
16
+ var __filename = fileURLToPath(import.meta.url);
17
+ var __dirname = dirname(__filename);
18
+ var isCommonJS = typeof module !== "undefined" && !!module.exports;
19
+ var isESModule = !isCommonJS;
20
+
21
+ // src/lib/model.generator.ts
22
+ var ModelGenerator = class {
23
+ static {
24
+ __name(this, "ModelGenerator");
25
+ }
26
+ options;
27
+ constructor(options) {
28
+ this.options = options;
29
+ if (!existsSync(this.options.entitiesPath)) {
30
+ throw new Error(`Entities folder not found: ${this.options.entitiesPath}`);
31
+ }
32
+ }
33
+ generate() {
34
+ const entityFiles = this.getEntityFiles();
35
+ for (const entityFileName of entityFiles) {
36
+ this.generateEntityModel(entityFileName);
37
+ }
38
+ this.createModelIndexFileTemplate();
39
+ return;
40
+ }
41
+ generateEntityModel(entityFileName) {
42
+ const modelName = entityFileName.replace(/\.entity\.ts$/, "");
43
+ const entityPath = path.join(this.options.entitiesPath, entityFileName);
44
+ const modelPath = path.join(this.options.outputPath);
45
+ if (!existsSync(entityPath)) throw new Error(`Entity tidak ditemukan: ${entityPath}`);
46
+ const entityClassName = this.detectClassName(entityPath, modelName);
47
+ this.writeModelFiles(modelPath, [
48
+ {
49
+ name: `${modelName}.model.ts`,
50
+ content: this.createEntityModelTemplate({
51
+ entityPath,
52
+ entityClassName
53
+ })
54
+ }
55
+ ]);
56
+ this.createModelIndexFileTemplate();
57
+ }
58
+ createEntityModelTemplate(options) {
59
+ const entityRelativeFilePath = path.relative(this.options.outputPath, options.entityPath).replace(/\\/g, "/");
60
+ return `import { BaseModel } from 'mahameru';
61
+ import { ${options.entityClassName} } from '${entityRelativeFilePath.replace(".ts", isESModule ? this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : ".js" : this.options.includeExtensionOnBareModuleImport || "")}';
62
+ import type { DataSource } from 'typeorm';
63
+
64
+ export class ${options.entityClassName}Model extends BaseModel<${options.entityClassName}> {
65
+ constructor(dataSource: DataSource) {
66
+ super(dataSource, ${options.entityClassName})
67
+ }
68
+ }
69
+ `;
70
+ }
71
+ createModelIndexFileTemplate() {
72
+ const modelFiles = this.getModelFiles();
73
+ const dataSourceFilePathRelative = this.resolveImportPath(path.relative(this.options.outputPath, this.options.dataSourceFilePath).replace(/\\/g, "/"));
74
+ let contents = `import dataSource from '${this.options.includeExtensionOnBareModuleImport ? dataSourceFilePathRelative + "/index." + this.options.includeExtensionOnBareModuleImport : dataSourceFilePathRelative}';
75
+
76
+ `;
77
+ for (const model2 of modelFiles) {
78
+ const modelFilePath = path.join(this.options.outputPath, model2);
79
+ if (!existsSync(modelFilePath)) continue;
80
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model2));
81
+ contents += `import { ${modelClassName} } from './${this.resolveImportPath(model2)}';
82
+ `;
83
+ }
84
+ contents += `
85
+ `;
86
+ for (const model2 of modelFiles) {
87
+ const modelFilePath = path.join(this.options.outputPath, model2);
88
+ if (!existsSync(modelFilePath)) continue;
89
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model2));
90
+ const camelName = this.toCamelCase(modelClassName);
91
+ contents += `const ${camelName} = new ${modelClassName}(dataSource)
92
+ `;
93
+ }
94
+ contents += `
95
+ export type {
96
+ `;
97
+ for (const model2 of modelFiles) {
98
+ const modelFilePath = path.join(this.options.outputPath, model2);
99
+ if (!existsSync(modelFilePath)) continue;
100
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model2));
101
+ contents += ` ${modelClassName},
102
+ `;
103
+ }
104
+ contents += `}
105
+ `;
106
+ contents += `
107
+ const models = {
108
+ `;
109
+ for (const model2 of modelFiles) {
110
+ const modelFilePath = path.join(this.options.outputPath, model2);
111
+ if (!existsSync(modelFilePath)) continue;
112
+ const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model2));
113
+ const camelName = this.toCamelCase(modelClassName);
114
+ contents += ` ${camelName},
115
+ `;
116
+ }
117
+ contents += `}
118
+
119
+ export type Models = typeof models
120
+ export { models }
121
+ `;
122
+ this.writeFile(path.join(this.options.outputPath, "index.ts"), contents);
123
+ }
124
+ resolveImportPath(importPath) {
125
+ const extension = this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : "";
126
+ return importPath.replace(".ts", extension);
127
+ }
128
+ writeFile(filePath, content) {
129
+ writeFileSync(filePath, content, "utf8");
130
+ return true;
131
+ }
132
+ getEntityFiles() {
133
+ return readdirSync(this.options.entitiesPath).filter((fileName) => fileName.endsWith(".entity.ts")).sort();
134
+ }
135
+ getModelFiles() {
136
+ return readdirSync(this.options.outputPath).filter((fileName) => fileName.endsWith(".model.ts")).sort();
137
+ }
138
+ writeModelFiles(modelPath, files) {
139
+ mkdirSync(modelPath, {
140
+ recursive: true
141
+ });
142
+ for (const file of files) {
143
+ this.writeFileIfMissing(path.join(modelPath, file.name), file.content);
144
+ }
145
+ }
146
+ writeFileIfMissing(filePath, content) {
147
+ if (existsSync(filePath)) {
148
+ this.log("warn", `[skip] ${filePath}`);
149
+ return false;
150
+ }
151
+ writeFileSync(filePath, content, "utf8");
152
+ this.log("log", `[create] ${filePath}`);
153
+ return true;
154
+ }
155
+ detectClassName(filePath, fallbackName) {
156
+ const content = readFileSync(filePath, "utf8");
157
+ const match = content.match(/export\s+(?:abstract\s+)?class\s+([A-Za-z_$][A-Za-z0-9_$]*)/);
158
+ return match?.[1] ?? this.toPascalCase(fallbackName);
159
+ }
160
+ toPascalCase(value) {
161
+ return value.split(/[-_\s.]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
162
+ }
163
+ toCamelCase(value) {
164
+ const pascalCase = this.toPascalCase(value);
165
+ return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
166
+ }
167
+ log(type, message) {
168
+ if (!this.options.debug) return;
169
+ if (type === "error") console.error(message);
170
+ else if (type === "warn") console.warn(message);
171
+ else if (type === "log") console.log(message);
172
+ else throw new Error(`Unknown log type: ${type}`);
173
+ }
174
+ };
175
+
176
+ // src/generator.ts
177
+ var root2 = process.cwd();
178
+ var dto = new TORMDTOGenerator({
179
+ entityPaths: [
180
+ path2.join(root2, "src", "databases", "db-test", "entities", "*.entity.ts")
181
+ ],
182
+ dtoOutputDir: path2.join(root2, "src", "types"),
183
+ mapperOutputFile: path2.join(root2, "src", "common", "dto", "mapper.dto.ts"),
184
+ debug: true
185
+ });
186
+ var srcPath = path2.join(root2, "src");
187
+ var entitiesPath = path2.join(srcPath, "databases", "db-test", "entities");
188
+ var outputPath = path2.join(srcPath, "models");
189
+ var dataSourceFilePath = path2.join(srcPath, "databases", "db-test");
190
+ var model = new ModelGenerator({
191
+ dbName: "db-test",
192
+ srcPath,
193
+ entitiesPath,
194
+ outputPath,
195
+ dataSourceFilePath,
196
+ debug: true
197
+ });
198
+ var generator = {
199
+ dto,
200
+ model
201
+ };
202
+ async function generateDTO(dir) {
203
+ const newDir = dir.split("/").slice(0, -1).join("/");
204
+ const dto2 = new TORMDTOGenerator({
205
+ entityPaths: [
206
+ path2.join(root2, newDir, "*.entity.ts")
207
+ ],
208
+ dtoOutputDir: path2.join(root2, "src", "types"),
209
+ mapperOutputFile: path2.join(root2, "src", "common", "dto", "mapper.dto.ts"),
210
+ debug: true
211
+ });
212
+ await dto2.run();
213
+ }
214
+ __name(generateDTO, "generateDTO");
215
+ var generator_default = generator;
216
+ export {
217
+ generator_default as default,
218
+ generateDTO
219
+ };
220
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generator.ts","../src/lib/model.generator.ts","../src/constants.ts"],"sourcesContent":["\r\nimport path from 'path'\r\nimport { TORMDTOGenerator } from 'typeorm-dto-generator'\r\nimport { ModelGenerator } from './lib/model.generator.js'\r\n\r\nconst root = process.cwd()\r\n\r\nconst dto = new TORMDTOGenerator({\r\n entityPaths: [path.join(root, 'src', 'databases', 'db-test', 'entities', '*.entity.ts')],\r\n dtoOutputDir: path.join(root, 'src', 'types'),\r\n mapperOutputFile: path.join(root, 'src', 'common', 'dto', 'mapper.dto.ts'),\r\n debug: true\r\n})\r\n\r\nconst srcPath = path.join(root, 'src')\r\nconst entitiesPath = path.join(srcPath, 'databases', 'db-test', 'entities')\r\nconst outputPath = path.join(srcPath, 'models')\r\nconst dataSourceFilePath = path.join(srcPath, 'databases', 'db-test')\r\n\r\nconst model = new ModelGenerator({\r\n dbName: 'db-test',\r\n srcPath,\r\n entitiesPath,\r\n outputPath,\r\n dataSourceFilePath,\r\n debug: true\r\n})\r\n\r\nconst generator = {\r\n dto,\r\n model\r\n}\r\n\r\nexport async function generateDTO(dir: string) {\r\n const newDir = dir.split('/').slice(0, -1).join('/')\r\n\r\n const dto = new TORMDTOGenerator({\r\n entityPaths: [path.join(root, newDir, '*.entity.ts')],\r\n dtoOutputDir: path.join(root, 'src', 'types'),\r\n mapperOutputFile: path.join(root, 'src', 'common', 'dto', 'mapper.dto.ts'),\r\n debug: true\r\n })\r\n\r\n await dto.run()\r\n}\r\n\r\nexport default generator\r\n","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":";;;;AACA,OAAOA,WAAU;AACjB,SAASC,wBAAwB;;;ACFjC,SAASC,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;EAEAE,WAAW;AACP,UAAMC,cAAc,KAAKC,eAAc;AAEvC,eAAWC,kBAAkBF,aAAa;AACtC,WAAKG,oBAAoBD,cAAAA;IAC7B;AAEA,SAAKE,6BAA4B;AAEjC;EACJ;EAEAD,oBAAoBD,gBAAwB;AACxC,UAAMG,YAAYH,eAAeI,QAAQ,iBAAiB,EAAA;AAC1D,UAAMC,aAAaC,KAAKC,KAAK,KAAKd,QAAQE,cAAcK,cAAAA;AACxD,UAAMQ,YAAYF,KAAKC,KAAK,KAAKd,QAAQgB,UAAU;AAEnD,QAAI,CAACf,WAAWW,UAAAA,EACZ,OAAM,IAAIT,MAAM,2BAA2BS,UAAAA,EAAY;AAE3D,UAAMK,kBAAkB,KAAKC,gBAAgBN,YAAYF,SAAAA;AAEzD,SAAKS,g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AA,oBAAeD;","names":["path","TORMDTOGenerator","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","root","process","cwd","dto","TORMDTOGenerator","entityPaths","path","join","dtoOutputDir","mapperOutputFile","debug","srcPath","entitiesPath","outputPath","dataSourceFilePath","model","ModelGenerator","dbName","generator","generateDTO","dir","newDir","split","slice","run"]}