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.
- package/README.md +28 -0
- package/dist/api.error.cjs +107 -0
- package/dist/api.error.cjs.map +1 -0
- package/dist/api.error.d.cts +65 -0
- package/dist/api.error.d.ts +65 -0
- package/dist/api.error.js +83 -0
- package/dist/api.error.js.map +1 -0
- package/dist/base-class/base.controller.cjs +148 -0
- package/dist/base-class/base.controller.cjs.map +1 -0
- package/dist/base-class/base.controller.d.cts +38 -0
- package/dist/base-class/base.controller.d.ts +38 -0
- package/dist/base-class/base.controller.js +126 -0
- package/dist/base-class/base.controller.js.map +1 -0
- package/dist/base-class/base.entity.cjs +79 -0
- package/dist/base-class/base.entity.cjs.map +1 -0
- package/dist/base-class/base.entity.d.cts +8 -0
- package/dist/base-class/base.entity.d.ts +8 -0
- package/dist/base-class/base.entity.js +57 -0
- package/dist/base-class/base.entity.js.map +1 -0
- package/dist/base-class/base.model.cjs +204 -0
- package/dist/base-class/base.model.cjs.map +1 -0
- package/dist/base-class/base.model.d.cts +68 -0
- package/dist/base-class/base.model.d.ts +68 -0
- package/dist/base-class/base.model.js +182 -0
- package/dist/base-class/base.model.js.map +1 -0
- package/dist/base-class/base.service.cjs +37 -0
- package/dist/base-class/base.service.cjs.map +1 -0
- package/dist/base-class/base.service.d.cts +5 -0
- package/dist/base-class/base.service.d.ts +5 -0
- package/dist/base-class/base.service.js +15 -0
- package/dist/base-class/base.service.js.map +1 -0
- package/dist/base-class/index.cjs +392 -0
- package/dist/base-class/index.cjs.map +1 -0
- package/dist/base-class/index.d.cts +6 -0
- package/dist/base-class/index.d.ts +6 -0
- package/dist/base-class/index.js +365 -0
- package/dist/base-class/index.js.map +1 -0
- package/dist/cli/index.cjs +706 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +3 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +681 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/scripts/on-build.cjs +56 -0
- package/dist/cli/scripts/on-build.cjs.map +1 -0
- package/dist/cli/scripts/on-build.d.cts +3 -0
- package/dist/cli/scripts/on-build.d.ts +3 -0
- package/dist/cli/scripts/on-build.js +28 -0
- package/dist/cli/scripts/on-build.js.map +1 -0
- package/dist/cli/scripts/on-dev.cjs +483 -0
- package/dist/cli/scripts/on-dev.cjs.map +1 -0
- package/dist/cli/scripts/on-dev.d.cts +5 -0
- package/dist/cli/scripts/on-dev.d.ts +5 -0
- package/dist/cli/scripts/on-dev.js +449 -0
- package/dist/cli/scripts/on-dev.js.map +1 -0
- package/dist/cli/scripts/on-init.cjs +96 -0
- package/dist/cli/scripts/on-init.cjs.map +1 -0
- package/dist/cli/scripts/on-init.d.cts +3 -0
- package/dist/cli/scripts/on-init.d.ts +3 -0
- package/dist/cli/scripts/on-init.js +68 -0
- package/dist/cli/scripts/on-init.js.map +1 -0
- package/dist/cli/scripts/on-start.cjs +55 -0
- package/dist/cli/scripts/on-start.cjs.map +1 -0
- package/dist/cli/scripts/on-start.d.cts +3 -0
- package/dist/cli/scripts/on-start.d.ts +3 -0
- package/dist/cli/scripts/on-start.js +27 -0
- package/dist/cli/scripts/on-start.js.map +1 -0
- package/dist/client.cjs +405 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +7 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +371 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.cjs +51 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +7 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +16 -0
- package/dist/constants.js.map +1 -0
- package/dist/database/column/index.cjs +34 -0
- package/dist/database/column/index.cjs.map +1 -0
- package/dist/database/column/index.d.cts +2 -0
- package/dist/database/column/index.d.ts +2 -0
- package/dist/database/column/index.js +8 -0
- package/dist/database/column/index.js.map +1 -0
- package/dist/database/index.cjs +83 -0
- package/dist/database/index.cjs.map +1 -0
- package/dist/database/index.d.cts +2 -0
- package/dist/database/index.d.ts +2 -0
- package/dist/database/index.js +60 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/snake-naming-strategy.class.cjs +78 -0
- package/dist/database/snake-naming-strategy.class.cjs.map +1 -0
- package/dist/database/snake-naming-strategy.class.d.cts +16 -0
- package/dist/database/snake-naming-strategy.class.d.ts +16 -0
- package/dist/database/snake-naming-strategy.class.js +56 -0
- package/dist/database/snake-naming-strategy.class.js.map +1 -0
- package/dist/error.cjs +46 -0
- package/dist/error.cjs.map +1 -0
- package/dist/error.d.cts +10 -0
- package/dist/error.d.ts +10 -0
- package/dist/error.js +28 -0
- package/dist/error.js.map +1 -0
- package/dist/express/app.cjs +233 -0
- package/dist/express/app.cjs.map +1 -0
- package/dist/express/app.d.cts +16 -0
- package/dist/express/app.d.ts +16 -0
- package/dist/express/app.js +205 -0
- package/dist/express/app.js.map +1 -0
- package/dist/express/index.cjs +239 -0
- package/dist/express/index.cjs.map +1 -0
- package/dist/express/index.d.cts +3 -0
- package/dist/express/index.d.ts +3 -0
- package/dist/express/index.js +205 -0
- package/dist/express/index.js.map +1 -0
- package/dist/express/middleware/cors.middleware.cjs +54 -0
- package/dist/express/middleware/cors.middleware.cjs.map +1 -0
- package/dist/express/middleware/cors.middleware.d.cts +9 -0
- package/dist/express/middleware/cors.middleware.d.ts +9 -0
- package/dist/express/middleware/cors.middleware.js +26 -0
- package/dist/express/middleware/cors.middleware.js.map +1 -0
- package/dist/express/middleware/error.middleware.cjs +136 -0
- package/dist/express/middleware/error.middleware.cjs.map +1 -0
- package/dist/express/middleware/error.middleware.d.cts +5 -0
- package/dist/express/middleware/error.middleware.d.ts +5 -0
- package/dist/express/middleware/error.middleware.js +116 -0
- package/dist/express/middleware/error.middleware.js.map +1 -0
- package/dist/express/middleware/filter.middleware.cjs +38 -0
- package/dist/express/middleware/filter.middleware.cjs.map +1 -0
- package/dist/express/middleware/filter.middleware.d.cts +5 -0
- package/dist/express/middleware/filter.middleware.d.ts +5 -0
- package/dist/express/middleware/filter.middleware.js +20 -0
- package/dist/express/middleware/filter.middleware.js.map +1 -0
- package/dist/express/middleware/index.cjs +206 -0
- package/dist/express/middleware/index.cjs.map +1 -0
- package/dist/express/middleware/index.d.cts +19 -0
- package/dist/express/middleware/index.d.ts +19 -0
- package/dist/express/middleware/index.js +169 -0
- package/dist/express/middleware/index.js.map +1 -0
- package/dist/express/middleware/not-found.middleware.cjs +79 -0
- package/dist/express/middleware/not-found.middleware.cjs.map +1 -0
- package/dist/express/middleware/not-found.middleware.d.cts +5 -0
- package/dist/express/middleware/not-found.middleware.d.ts +5 -0
- package/dist/express/middleware/not-found.middleware.js +59 -0
- package/dist/express/middleware/not-found.middleware.js.map +1 -0
- package/dist/generator.cjs +258 -0
- package/dist/generator.cjs.map +1 -0
- package/dist/generator.d.cts +10 -0
- package/dist/generator.d.ts +10 -0
- package/dist/generator.js +220 -0
- package/dist/generator.js.map +1 -0
- package/dist/http.cjs +82 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +11 -0
- package/dist/http.d.ts +11 -0
- package/dist/http.js +64 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +831 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +783 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/create-env-file.cjs +69 -0
- package/dist/lib/create-env-file.cjs.map +1 -0
- package/dist/lib/create-env-file.d.cts +3 -0
- package/dist/lib/create-env-file.d.ts +3 -0
- package/dist/lib/create-env-file.js +31 -0
- package/dist/lib/create-env-file.js.map +1 -0
- package/dist/lib/helper.cjs +94 -0
- package/dist/lib/helper.cjs.map +1 -0
- package/dist/lib/helper.d.cts +13 -0
- package/dist/lib/helper.d.ts +13 -0
- package/dist/lib/helper.js +62 -0
- package/dist/lib/helper.js.map +1 -0
- package/dist/lib/model.generator.cjs +212 -0
- package/dist/lib/model.generator.cjs.map +1 -0
- package/dist/lib/model.generator.d.cts +29 -0
- package/dist/lib/model.generator.d.ts +29 -0
- package/dist/lib/model.generator.js +174 -0
- package/dist/lib/model.generator.js.map +1 -0
- package/dist/lib/pre-init-dev-script.cjs +336 -0
- package/dist/lib/pre-init-dev-script.cjs.map +1 -0
- package/dist/lib/pre-init-dev-script.d.cts +2 -0
- package/dist/lib/pre-init-dev-script.d.ts +2 -0
- package/dist/lib/pre-init-dev-script.js +311 -0
- package/dist/lib/pre-init-dev-script.js.map +1 -0
- package/dist/mahameru.cjs +397 -0
- package/dist/mahameru.cjs.map +1 -0
- package/dist/mahameru.d.cts +78 -0
- package/dist/mahameru.d.ts +78 -0
- package/dist/mahameru.js +359 -0
- package/dist/mahameru.js.map +1 -0
- package/dist/request.cjs +35 -0
- package/dist/request.cjs.map +1 -0
- package/dist/request.d.cts +4 -0
- package/dist/request.d.ts +4 -0
- package/dist/request.js +13 -0
- package/dist/request.js.map +1 -0
- package/dist/response.cjs +35 -0
- package/dist/response.cjs.map +1 -0
- package/dist/response.d.cts +4 -0
- package/dist/response.d.ts +4 -0
- package/dist/response.js +13 -0
- package/dist/response.js.map +1 -0
- package/dist/types.cjs +1 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/import-dynamic-module.cjs +34 -0
- package/dist/utils/import-dynamic-module.cjs.map +1 -0
- package/dist/utils/import-dynamic-module.d.cts +3 -0
- package/dist/utils/import-dynamic-module.d.ts +3 -0
- package/dist/utils/import-dynamic-module.js +12 -0
- package/dist/utils/import-dynamic-module.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,336 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
26
|
+
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");
|
|
27
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
28
|
+
|
|
29
|
+
// src/lib/pre-init-dev-script.ts
|
|
30
|
+
var import_promises = require("fs/promises");
|
|
31
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
32
|
+
var import_node_url2 = require("url");
|
|
33
|
+
|
|
34
|
+
// src/lib/model.generator.ts
|
|
35
|
+
var import_fs = require("fs");
|
|
36
|
+
var import_path = __toESM(require("path"), 1);
|
|
37
|
+
|
|
38
|
+
// src/constants.ts
|
|
39
|
+
var import_node_path = require("path");
|
|
40
|
+
var import_node_url = require("url");
|
|
41
|
+
var root = process.cwd();
|
|
42
|
+
var __filename2 = (0, import_node_url.fileURLToPath)(importMetaUrl);
|
|
43
|
+
var __dirname = (0, import_node_path.dirname)(__filename2);
|
|
44
|
+
var isCommonJS = typeof module !== "undefined" && !!module.exports;
|
|
45
|
+
var isESModule = !isCommonJS;
|
|
46
|
+
|
|
47
|
+
// src/lib/model.generator.ts
|
|
48
|
+
var ModelGenerator = class {
|
|
49
|
+
static {
|
|
50
|
+
__name(this, "ModelGenerator");
|
|
51
|
+
}
|
|
52
|
+
options;
|
|
53
|
+
constructor(options) {
|
|
54
|
+
this.options = options;
|
|
55
|
+
if (!(0, import_fs.existsSync)(this.options.entitiesPath)) {
|
|
56
|
+
throw new Error(`Entities folder not found: ${this.options.entitiesPath}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
generate() {
|
|
60
|
+
const entityFiles = this.getEntityFiles();
|
|
61
|
+
for (const entityFileName of entityFiles) {
|
|
62
|
+
this.generateEntityModel(entityFileName);
|
|
63
|
+
}
|
|
64
|
+
this.createModelIndexFileTemplate();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
generateEntityModel(entityFileName) {
|
|
68
|
+
const modelName = entityFileName.replace(/\.entity\.ts$/, "");
|
|
69
|
+
const entityPath = import_path.default.join(this.options.entitiesPath, entityFileName);
|
|
70
|
+
const modelPath = import_path.default.join(this.options.outputPath);
|
|
71
|
+
if (!(0, import_fs.existsSync)(entityPath)) throw new Error(`Entity tidak ditemukan: ${entityPath}`);
|
|
72
|
+
const entityClassName = this.detectClassName(entityPath, modelName);
|
|
73
|
+
this.writeModelFiles(modelPath, [
|
|
74
|
+
{
|
|
75
|
+
name: `${modelName}.model.ts`,
|
|
76
|
+
content: this.createEntityModelTemplate({
|
|
77
|
+
entityPath,
|
|
78
|
+
entityClassName
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
]);
|
|
82
|
+
this.createModelIndexFileTemplate();
|
|
83
|
+
}
|
|
84
|
+
createEntityModelTemplate(options) {
|
|
85
|
+
const entityRelativeFilePath = import_path.default.relative(this.options.outputPath, options.entityPath).replace(/\\/g, "/");
|
|
86
|
+
return `import { BaseModel } from 'mahameru';
|
|
87
|
+
import { ${options.entityClassName} } from '${entityRelativeFilePath.replace(".ts", isESModule ? this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : ".js" : this.options.includeExtensionOnBareModuleImport || "")}';
|
|
88
|
+
import type { DataSource } from 'typeorm';
|
|
89
|
+
|
|
90
|
+
export class ${options.entityClassName}Model extends BaseModel<${options.entityClassName}> {
|
|
91
|
+
constructor(dataSource: DataSource) {
|
|
92
|
+
super(dataSource, ${options.entityClassName})
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
createModelIndexFileTemplate() {
|
|
98
|
+
const modelFiles = this.getModelFiles();
|
|
99
|
+
const dataSourceFilePathRelative = this.resolveImportPath(import_path.default.relative(this.options.outputPath, this.options.dataSourceFilePath).replace(/\\/g, "/"));
|
|
100
|
+
let contents = `import dataSource from '${this.options.includeExtensionOnBareModuleImport ? dataSourceFilePathRelative + "/index." + this.options.includeExtensionOnBareModuleImport : dataSourceFilePathRelative}';
|
|
101
|
+
|
|
102
|
+
`;
|
|
103
|
+
for (const model of modelFiles) {
|
|
104
|
+
const modelFilePath = import_path.default.join(this.options.outputPath, model);
|
|
105
|
+
if (!(0, import_fs.existsSync)(modelFilePath)) continue;
|
|
106
|
+
const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
|
|
107
|
+
contents += `import { ${modelClassName} } from './${this.resolveImportPath(model)}';
|
|
108
|
+
`;
|
|
109
|
+
}
|
|
110
|
+
contents += `
|
|
111
|
+
`;
|
|
112
|
+
for (const model of modelFiles) {
|
|
113
|
+
const modelFilePath = import_path.default.join(this.options.outputPath, model);
|
|
114
|
+
if (!(0, import_fs.existsSync)(modelFilePath)) continue;
|
|
115
|
+
const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
|
|
116
|
+
const camelName = this.toCamelCase(modelClassName);
|
|
117
|
+
contents += `const ${camelName} = new ${modelClassName}(dataSource)
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
contents += `
|
|
121
|
+
export type {
|
|
122
|
+
`;
|
|
123
|
+
for (const model of modelFiles) {
|
|
124
|
+
const modelFilePath = import_path.default.join(this.options.outputPath, model);
|
|
125
|
+
if (!(0, import_fs.existsSync)(modelFilePath)) continue;
|
|
126
|
+
const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
|
|
127
|
+
contents += ` ${modelClassName},
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
contents += `}
|
|
131
|
+
`;
|
|
132
|
+
contents += `
|
|
133
|
+
const models = {
|
|
134
|
+
`;
|
|
135
|
+
for (const model of modelFiles) {
|
|
136
|
+
const modelFilePath = import_path.default.join(this.options.outputPath, model);
|
|
137
|
+
if (!(0, import_fs.existsSync)(modelFilePath)) continue;
|
|
138
|
+
const modelClassName = this.detectClassName(modelFilePath, this.resolveImportPath(model));
|
|
139
|
+
const camelName = this.toCamelCase(modelClassName);
|
|
140
|
+
contents += ` ${camelName},
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
contents += `}
|
|
144
|
+
|
|
145
|
+
export type Models = typeof models
|
|
146
|
+
export { models }
|
|
147
|
+
`;
|
|
148
|
+
this.writeFile(import_path.default.join(this.options.outputPath, "index.ts"), contents);
|
|
149
|
+
}
|
|
150
|
+
resolveImportPath(importPath) {
|
|
151
|
+
const extension = this.options.includeExtensionOnBareModuleImport ? `.${this.options.includeExtensionOnBareModuleImport}` : "";
|
|
152
|
+
return importPath.replace(".ts", extension);
|
|
153
|
+
}
|
|
154
|
+
writeFile(filePath, content) {
|
|
155
|
+
(0, import_fs.writeFileSync)(filePath, content, "utf8");
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
getEntityFiles() {
|
|
159
|
+
return (0, import_fs.readdirSync)(this.options.entitiesPath).filter((fileName) => fileName.endsWith(".entity.ts")).sort();
|
|
160
|
+
}
|
|
161
|
+
getModelFiles() {
|
|
162
|
+
return (0, import_fs.readdirSync)(this.options.outputPath).filter((fileName) => fileName.endsWith(".model.ts")).sort();
|
|
163
|
+
}
|
|
164
|
+
writeModelFiles(modelPath, files) {
|
|
165
|
+
(0, import_fs.mkdirSync)(modelPath, {
|
|
166
|
+
recursive: true
|
|
167
|
+
});
|
|
168
|
+
for (const file of files) {
|
|
169
|
+
this.writeFileIfMissing(import_path.default.join(modelPath, file.name), file.content);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
writeFileIfMissing(filePath, content) {
|
|
173
|
+
if ((0, import_fs.existsSync)(filePath)) {
|
|
174
|
+
this.log("warn", `[skip] ${filePath}`);
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
(0, import_fs.writeFileSync)(filePath, content, "utf8");
|
|
178
|
+
this.log("log", `[create] ${filePath}`);
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
detectClassName(filePath, fallbackName) {
|
|
182
|
+
const content = (0, import_fs.readFileSync)(filePath, "utf8");
|
|
183
|
+
const match = content.match(/export\s+(?:abstract\s+)?class\s+([A-Za-z_$][A-Za-z0-9_$]*)/);
|
|
184
|
+
return match?.[1] ?? this.toPascalCase(fallbackName);
|
|
185
|
+
}
|
|
186
|
+
toPascalCase(value) {
|
|
187
|
+
return value.split(/[-_\s.]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
188
|
+
}
|
|
189
|
+
toCamelCase(value) {
|
|
190
|
+
const pascalCase = this.toPascalCase(value);
|
|
191
|
+
return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
|
|
192
|
+
}
|
|
193
|
+
log(type, message) {
|
|
194
|
+
if (!this.options.debug) return;
|
|
195
|
+
if (type === "error") console.error(message);
|
|
196
|
+
else if (type === "warn") console.warn(message);
|
|
197
|
+
else if (type === "log") console.log(message);
|
|
198
|
+
else throw new Error(`Unknown log type: ${type}`);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/lib/pre-init-dev-script.ts
|
|
203
|
+
var import_node_fs = require("fs");
|
|
204
|
+
var import_typeorm_dto_generator = require("typeorm-dto-generator");
|
|
205
|
+
|
|
206
|
+
// src/lib/helper.ts
|
|
207
|
+
function toKebabCase(str) {
|
|
208
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
209
|
+
}
|
|
210
|
+
__name(toKebabCase, "toKebabCase");
|
|
211
|
+
|
|
212
|
+
// src/lib/pre-init-dev-script.ts
|
|
213
|
+
var import_node_util = require("util");
|
|
214
|
+
(async () => {
|
|
215
|
+
try {
|
|
216
|
+
const { values } = (0, import_node_util.parseArgs)({
|
|
217
|
+
args: process.argv.slice(2),
|
|
218
|
+
options: {
|
|
219
|
+
"init-db": {
|
|
220
|
+
type: "boolean",
|
|
221
|
+
default: false
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
if (values["init-db"]) {
|
|
226
|
+
const root2 = process.cwd();
|
|
227
|
+
const srcPath = import_node_path2.default.join(root2, "src");
|
|
228
|
+
const databasesDir = import_node_path2.default.join(root2, "src", "databases");
|
|
229
|
+
await generateEntitiesIndexFiles(databasesDir);
|
|
230
|
+
await generateModels({
|
|
231
|
+
srcPath,
|
|
232
|
+
databasesDir
|
|
233
|
+
});
|
|
234
|
+
await generateDTO(srcPath, databasesDir);
|
|
235
|
+
}
|
|
236
|
+
} catch (error) {
|
|
237
|
+
console.error(error);
|
|
238
|
+
process.exit(1);
|
|
239
|
+
}
|
|
240
|
+
})();
|
|
241
|
+
async function generateEntitiesIndexFiles(databasesDir) {
|
|
242
|
+
const resultScanDir = await (0, import_promises.readdir)(databasesDir);
|
|
243
|
+
if (resultScanDir.length === 0) return;
|
|
244
|
+
for (const fileOrDirName of resultScanDir) {
|
|
245
|
+
const fileOrDirPath = import_node_path2.default.join(databasesDir, fileOrDirName);
|
|
246
|
+
const fileStat = await (0, import_promises.stat)(fileOrDirPath).catch(() => null);
|
|
247
|
+
if (fileStat?.isFile()) continue;
|
|
248
|
+
await generateEntitiesIndexFile(fileOrDirPath);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
__name(generateEntitiesIndexFiles, "generateEntitiesIndexFiles");
|
|
252
|
+
async function generateEntitiesIndexFile(databaseDir) {
|
|
253
|
+
const entitiesPath = import_node_path2.default.join(databaseDir, "entities");
|
|
254
|
+
const indexFilePath = import_node_path2.default.join(entitiesPath, "index.ts");
|
|
255
|
+
const resultScanEntities = await (0, import_promises.readdir)(entitiesPath).catch(() => []);
|
|
256
|
+
if (resultScanEntities.length === 0) return;
|
|
257
|
+
const entities = [];
|
|
258
|
+
for (const entityFile of resultScanEntities) {
|
|
259
|
+
if (entityFile === "index.ts" || entityFile === "index.js" || !entityFile.endsWith(".entity.ts")) continue;
|
|
260
|
+
const entityFilePath = import_node_path2.default.join(entitiesPath, entityFile);
|
|
261
|
+
const entityStat = await (0, import_promises.stat)(entityFilePath).catch(() => null);
|
|
262
|
+
if (!entityStat?.isFile()) continue;
|
|
263
|
+
const fileUrl = (0, import_node_url2.pathToFileURL)(entityFilePath).href;
|
|
264
|
+
const module2 = await import(fileUrl);
|
|
265
|
+
const exportNames = Object.keys(module2);
|
|
266
|
+
for (const exportName of exportNames) {
|
|
267
|
+
const exportValue = module2[exportName];
|
|
268
|
+
if (isClass(exportValue)) {
|
|
269
|
+
entities.push({
|
|
270
|
+
className: exportValue.name,
|
|
271
|
+
fileName: entityFile.replace(/\.ts$/, ".js")
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (entities.length === 0) return;
|
|
277
|
+
const importStatements = entities.map((e) => `import { ${e.className} } from './${e.fileName}';`).join("\n");
|
|
278
|
+
const classNamesOnly = entities.map((e) => e.className).join(", ");
|
|
279
|
+
const contents = `${importStatements}
|
|
280
|
+
|
|
281
|
+
export const entities = [${entities.map((e) => e.className).join(", ")}]
|
|
282
|
+
|
|
283
|
+
export { ${classNamesOnly} };
|
|
284
|
+
`;
|
|
285
|
+
await (0, import_promises.writeFile)(indexFilePath, contents, "utf-8");
|
|
286
|
+
}
|
|
287
|
+
__name(generateEntitiesIndexFile, "generateEntitiesIndexFile");
|
|
288
|
+
async function generateModels({ srcPath, databasesDir }) {
|
|
289
|
+
const resultScanDBDir = await (0, import_promises.readdir)(databasesDir);
|
|
290
|
+
if (resultScanDBDir.length === 0) return;
|
|
291
|
+
for (const fileOrDirName of resultScanDBDir) {
|
|
292
|
+
const fileOrDirPath = import_node_path2.default.join(databasesDir, fileOrDirName);
|
|
293
|
+
const fileStat = await (0, import_promises.stat)(fileOrDirPath).catch(() => null);
|
|
294
|
+
if (fileStat?.isFile()) continue;
|
|
295
|
+
const entitiesPath = import_node_path2.default.join(databasesDir, fileOrDirName, "entities");
|
|
296
|
+
if (!(0, import_node_fs.existsSync)(entitiesPath)) continue;
|
|
297
|
+
const outputPath = import_node_path2.default.join(srcPath, "models", fileOrDirName);
|
|
298
|
+
const dataSourceFilePath = import_node_path2.default.join(databasesDir, fileOrDirName);
|
|
299
|
+
const generator = new ModelGenerator({
|
|
300
|
+
dbName: toKebabCase(fileOrDirName),
|
|
301
|
+
srcPath,
|
|
302
|
+
entitiesPath,
|
|
303
|
+
outputPath,
|
|
304
|
+
dataSourceFilePath,
|
|
305
|
+
includeExtensionOnBareModuleImport: "js",
|
|
306
|
+
debug: true
|
|
307
|
+
});
|
|
308
|
+
generator.generate();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
__name(generateModels, "generateModels");
|
|
312
|
+
async function generateDTO(srcPath, databasesDir) {
|
|
313
|
+
const resultScanDir = await (0, import_promises.readdir)(databasesDir);
|
|
314
|
+
if (resultScanDir.length === 0) return;
|
|
315
|
+
for (const fileOrDirName of resultScanDir) {
|
|
316
|
+
const fileOrDirPath = import_node_path2.default.join(databasesDir, fileOrDirName);
|
|
317
|
+
const fileStat = await (0, import_promises.stat)(fileOrDirPath).catch(() => null);
|
|
318
|
+
if (fileStat?.isFile()) continue;
|
|
319
|
+
const dto = new import_typeorm_dto_generator.TORMDTOGenerator({
|
|
320
|
+
entityPaths: [
|
|
321
|
+
import_node_path2.default.join(fileOrDirPath, "entities", "*.entity.ts")
|
|
322
|
+
],
|
|
323
|
+
dtoOutputDir: import_node_path2.default.join(srcPath, "types"),
|
|
324
|
+
mapperOutputFile: import_node_path2.default.join(srcPath, "common", "dto", fileOrDirName + ".dto-mapper.ts"),
|
|
325
|
+
debug: true,
|
|
326
|
+
includeExtensionOnImports: "js"
|
|
327
|
+
});
|
|
328
|
+
await dto.run();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
__name(generateDTO, "generateDTO");
|
|
332
|
+
function isClass(v) {
|
|
333
|
+
return typeof v === "function" && /^\s*class\s+/.test(v.toString());
|
|
334
|
+
}
|
|
335
|
+
__name(isClass, "isClass");
|
|
336
|
+
//# sourceMappingURL=pre-init-dev-script.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../node_modules/tsup/assets/cjs_shims.js","../../src/lib/pre-init-dev-script.ts","../../src/lib/model.generator.ts","../../src/constants.ts","../../src/lib/helper.ts"],"sourcesContent":["// 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 { readdir, stat, writeFile } from \"node:fs/promises\"\r\nimport path from \"node:path\"\r\nimport { pathToFileURL } from \"node:url\"\r\nimport { ModelGenerator } from \"./model.generator.js\"\r\nimport { existsSync } from \"node:fs\"\r\nimport { TORMDTOGenerator } from \"typeorm-dto-generator\"\r\nimport { toKebabCase } from \"./helper.js\"\r\nimport { parseArgs } from \"node:util\"\r\n\r\n(async () => {\r\n try {\r\n const { values } = parseArgs({\r\n args: process.argv.slice(2),\r\n options: {\r\n 'init-db': { type: 'boolean', default: false },\r\n }\r\n })\r\n\r\n if (values['init-db']) {\r\n const root = process.cwd()\r\n const srcPath = path.join(root, 'src')\r\n const databasesDir = path.join(root, 'src', 'databases')\r\n await generateEntitiesIndexFiles(databasesDir)\r\n await generateModels({\r\n srcPath,\r\n databasesDir\r\n })\r\n await generateDTO(srcPath, databasesDir)\r\n }\r\n } catch (error) {\r\n console.error(error)\r\n\r\n process.exit(1)\r\n }\r\n})()\r\n\r\nasync function generateEntitiesIndexFiles(databasesDir: string) {\r\n const resultScanDir = await readdir(databasesDir)\r\n\r\n if (resultScanDir.length === 0)\r\n return\r\n\r\n for (const fileOrDirName of resultScanDir) {\r\n const fileOrDirPath = path.join(databasesDir, fileOrDirName)\r\n const fileStat = await stat(fileOrDirPath).catch(() => null)\r\n\r\n if (fileStat?.isFile())\r\n continue\r\n\r\n await generateEntitiesIndexFile(fileOrDirPath)\r\n }\r\n}\r\n\r\nasync function generateEntitiesIndexFile(databaseDir: string) {\r\n const entitiesPath = path.join(databaseDir, 'entities');\r\n const indexFilePath = path.join(entitiesPath, 'index.ts')\r\n const resultScanEntities = await readdir(entitiesPath).catch(() => []);\r\n\r\n if (resultScanEntities.length === 0) return;\r\n\r\n const entities: { className: string; fileName: string }[] = [];\r\n\r\n for (const entityFile of resultScanEntities) {\r\n if (entityFile === 'index.ts' || entityFile === 'index.js' || !entityFile.endsWith('.entity.ts'))\r\n continue;\r\n\r\n const entityFilePath = path.join(entitiesPath, entityFile);\r\n const entityStat = await stat(entityFilePath).catch(() => null);\r\n\r\n if (!entityStat?.isFile()) continue;\r\n\r\n const fileUrl = pathToFileURL(entityFilePath).href;\r\n const module = await import(fileUrl);\r\n const exportNames = Object.keys(module);\r\n\r\n for (const exportName of exportNames) {\r\n const exportValue = module[exportName];\r\n\r\n if (isClass(exportValue)) {\r\n entities.push({\r\n className: exportValue.name,\r\n fileName: entityFile.replace(/\\.ts$/, '.js')\r\n });\r\n }\r\n }\r\n }\r\n\r\n if (entities.length === 0) return;\r\n\r\n const importStatements = entities\r\n .map(e => `import { ${e.className} } from './${e.fileName}';`)\r\n .join('\\n');\r\n\r\n const classNamesOnly = entities.map(e => e.className).join(', ');\r\n\r\n const contents = `${importStatements}\r\n\r\nexport const entities = [${entities.map(e => e.className).join(', ')}]\r\n\r\nexport { ${classNamesOnly} };\r\n`;\r\n\r\n await writeFile(indexFilePath, contents, 'utf-8');\r\n}\r\n\r\nasync function generateModels({ srcPath, databasesDir }: { srcPath: string; databasesDir: string }) {\r\n const resultScanDBDir = await readdir(databasesDir)\r\n\r\n if (resultScanDBDir.length === 0)\r\n return\r\n\r\n for (const fileOrDirName of resultScanDBDir) {\r\n const fileOrDirPath = path.join(databasesDir, fileOrDirName)\r\n const fileStat = await stat(fileOrDirPath).catch(() => null)\r\n\r\n if (fileStat?.isFile())\r\n continue\r\n\r\n const entitiesPath = path.join(databasesDir, fileOrDirName, 'entities')\r\n\r\n if (!existsSync(entitiesPath))\r\n continue\r\n\r\n const outputPath = path.join(srcPath, 'models', fileOrDirName)\r\n const dataSourceFilePath = path.join(databasesDir, fileOrDirName)\r\n\r\n const generator = new ModelGenerator({\r\n dbName: toKebabCase(fileOrDirName),\r\n srcPath,\r\n entitiesPath,\r\n outputPath,\r\n dataSourceFilePath,\r\n includeExtensionOnBareModuleImport: 'js',\r\n debug: true\r\n })\r\n\r\n generator.generate()\r\n }\r\n}\r\n\r\nasync function generateDTO(srcPath: string, databasesDir: string) {\r\n const resultScanDir = await readdir(databasesDir)\r\n\r\n if (resultScanDir.length === 0)\r\n return\r\n\r\n for (const fileOrDirName of resultScanDir) {\r\n const fileOrDirPath = path.join(databasesDir, fileOrDirName)\r\n const fileStat = await stat(fileOrDirPath).catch(() => null)\r\n\r\n if (fileStat?.isFile())\r\n continue\r\n\r\n const dto = new TORMDTOGenerator({\r\n entityPaths: [path.join(fileOrDirPath, 'entities', '*.entity.ts')],\r\n dtoOutputDir: path.join(srcPath, 'types'),\r\n mapperOutputFile: path.join(srcPath, 'common', 'dto', fileOrDirName + '.dto-mapper.ts'),\r\n debug: true,\r\n includeExtensionOnImports: 'js'\r\n })\r\n\r\n await dto.run()\r\n }\r\n}\r\n\r\nfunction isClass(v: unknown): boolean {\r\n return typeof v === 'function' && /^\\s*class\\s+/.test(v.toString());\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","export function toKebabCase(str: string) {\r\n return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();\r\n}\r\n\r\nexport function toPascalCase(str: string) {\r\n return str.replace(/(?:^|[-_])[a-z]/g, (match) => match.toUpperCase());\r\n}\r\n\r\nexport function toCamelCase(str: string) {\r\n return str.replace(/(?:^|[-_])[a-z]/g, (match) => match.toUpperCase());\r\n}\r\n\r\nexport function toTitleCase(str: string) {\r\n return str.replace(/(?:^|[-_])[a-z]/g, (match) => match.toUpperCase());\r\n}\r\n\r\nexport function toSnakeCase(str: string) {\r\n return str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();\r\n}\r\n\r\nexport function toConstantCase(str: string) {\r\n return str.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase();\r\n}\r\n\r\nexport function toDotCase(str: string) {\r\n return str.replace(/([a-z])([A-Z])/g, '$1.$2').toLowerCase();\r\n}\r\n\r\nexport function toSpaceCase(str: string) {\r\n return str.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase();\r\n}\r\n\r\nexport function toDashCase(str: string) {\r\n return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();\r\n}\r\n\r\nexport function toPathCase(str: string) {\r\n return str.replace(/([a-z])([A-Z])/g, '$1/$2').toLowerCase();\r\n}\r\n\r\nexport function toHeaderCase(str: string) {\r\n return str.replace(/([a-z])([A-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AAiBH,eAAe;AACvC,UAAMI,gBAAgBb,kBAAAA,QAAKC,KAAKC,cAAcU,aAAAA;AAC9C,UAAME,WAAW,UAAMC,sBAAKF,aAAAA,EAAeG,MAAM,MAAM,IAAA;AAEvD,QAAIF,UAAUG,OAAAA,EACV;AAEJ,UAAM2C,MAAM,IAAIC,8CAAiB;MAC7BC,aAAa;QAAC9D,kBAAAA,QAAKC,KAAKY,eAAe,YAAY,aAAA;;MACnDkD,cAAc/D,kBAAAA,QAAKC,KAAKF,SAAS,OAAA;MACjCiE,kBAAkBhE,kBAAAA,QAAKC,KAAKF,SAAS,UAAU,OAAOa,gBAAgB,gBAAA;MACtE8C,OAAO;MACPO,2BAA2B;IAC/B,CAAA;AAEA,UAAML,IAAIM,IAAG;EACjB;AACJ;AAvBe7D;AAyBf,SAASgC,QAAQ8B,GAAU;AACvB,SAAO,OAAOA,MAAM,cAAc,eAAeC,KAAKD,EAAEE,SAAQ,CAAA;AACpE;AAFShC;","names":["getImportMetaUrl","document","URL","__filename","href","currentScript","tagName","toUpperCase","src","baseURI","importMetaUrl","import_node_path","import_node_url","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","toKebabCase","str","replace","toLowerCase","values","parseArgs","args","process","argv","slice","options","type","default","root","cwd","srcPath","path","join","databasesDir","generateEntitiesIndexFiles","generateModels","generateDTO","error","console","exit","resultScanDir","readdir","length","fileOrDirName","fileOrDirPath","fileStat","stat","catch","isFile","generateEntitiesIndexFile","databaseDir","entitiesPath","indexFilePath","resultScanEntities","entities","entityFile","endsWith","entityFilePath","entityStat","fileUrl","pathToFileURL","href","module","exportNames","Object","keys","exportName","exportValue","isClass","push","className","name","fileName","replace","importStatements","map","e","classNamesOnly","contents","writeFile","resultScanDBDir","existsSync","outputPath","dataSourceFilePath","generator","ModelGenerator","dbName","toKebabCase","includeExtensionOnBareModuleImport","debug","generate","dto","TORMDTOGenerator","entityPaths","dtoOutputDir","mapperOutputFile","includeExtensionOnImports","run","v","test","toString"]}
|