arkos 1.1.68-test → 1.1.69-test
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/dist/cjs/app.js +1 -1
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/exports/controllers/index.js +5 -3
- package/dist/cjs/exports/controllers/index.js.map +1 -1
- package/dist/cjs/exports/services/index.js +4 -4
- package/dist/cjs/exports/services/index.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/{file-uploader/file-uploader.controller.js → file-upload/file-upload.controller.js} +29 -29
- package/dist/cjs/modules/file-upload/file-upload.controller.js.map +1 -0
- package/dist/cjs/modules/{file-uploader/file-uploader.router.js → file-upload/file-upload.router.js} +7 -7
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -0
- package/dist/cjs/modules/{file-uploader/file-uploader.service.js → file-upload/file-upload.service.js} +38 -38
- package/dist/cjs/modules/file-upload/file-upload.service.js.map +1 -0
- package/dist/cjs/modules/{file-uploader/utils/helpers/file-uploader.helpers.js → file-upload/utils/helpers/file-upload.helpers.js} +1 -1
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -0
- package/dist/cjs/types/arkos-config.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +8 -5
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/generate.js +170 -0
- package/dist/cjs/utils/cli/generate.js.map +1 -0
- package/dist/cjs/utils/cli/index.js +39 -1
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/utils/generators.js +200 -0
- package/dist/cjs/utils/cli/utils/generators.js.map +1 -0
- package/dist/cjs/utils/cli/utils/helpers.js +17 -0
- package/dist/cjs/utils/cli/utils/helpers.js.map +1 -0
- package/dist/cjs/utils/helpers/models.helpers.js +40 -30
- package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
- package/dist/es2020/app.js +1 -1
- package/dist/es2020/app.js.map +1 -1
- package/dist/es2020/exports/controllers/index.js +3 -2
- package/dist/es2020/exports/controllers/index.js.map +1 -1
- package/dist/es2020/exports/services/index.js +2 -2
- package/dist/es2020/exports/services/index.js.map +1 -1
- package/dist/es2020/modules/base/base.service.js.map +1 -1
- package/dist/es2020/modules/{file-uploader/file-uploader.controller.js → file-upload/file-upload.controller.js} +21 -21
- package/dist/es2020/modules/file-upload/file-upload.controller.js.map +1 -0
- package/dist/es2020/modules/{file-uploader/file-uploader.router.js → file-upload/file-upload.router.js} +6 -6
- package/dist/es2020/modules/file-upload/file-upload.router.js.map +1 -0
- package/dist/es2020/modules/{file-uploader/file-uploader.service.js → file-upload/file-upload.service.js} +31 -31
- package/dist/es2020/modules/file-upload/file-upload.service.js.map +1 -0
- package/dist/es2020/modules/{file-uploader/utils/helpers/file-uploader.helpers.js → file-upload/utils/helpers/file-upload.helpers.js} +1 -1
- package/dist/es2020/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -0
- package/dist/es2020/types/arkos-config.js.map +1 -1
- package/dist/es2020/utils/cli/build.js +8 -5
- package/dist/es2020/utils/cli/build.js.map +1 -1
- package/dist/es2020/utils/cli/generate.js +164 -0
- package/dist/es2020/utils/cli/generate.js.map +1 -0
- package/dist/es2020/utils/cli/index.js +38 -1
- package/dist/es2020/utils/cli/index.js.map +1 -1
- package/dist/es2020/utils/cli/utils/generators.js +197 -0
- package/dist/es2020/utils/cli/utils/generators.js.map +1 -0
- package/dist/es2020/utils/cli/utils/helpers.js +10 -0
- package/dist/es2020/utils/cli/utils/helpers.js.map +1 -0
- package/dist/es2020/utils/helpers/models.helpers.js +38 -30
- package/dist/es2020/utils/helpers/models.helpers.js.map +1 -1
- package/dist/types/exports/controllers/index.d.ts +3 -2
- package/dist/types/exports/services/index.d.ts +2 -2
- package/dist/types/modules/{file-uploader/file-uploader.controller.d.ts → file-upload/file-upload.controller.d.ts} +3 -3
- package/dist/types/modules/file-upload/file-upload.router.d.ts +3 -0
- package/dist/types/modules/{file-uploader/file-uploader.service.d.ts → file-upload/file-upload.service.d.ts} +7 -7
- package/dist/types/types/arkos-config.d.ts +2 -2
- package/dist/types/utils/cli/generate.d.ts +12 -0
- package/dist/types/utils/cli/index.d.ts +2 -1
- package/dist/types/utils/cli/utils/generators.d.ts +17 -0
- package/dist/types/utils/cli/utils/helpers.d.ts +2 -0
- package/dist/types/utils/helpers/models.helpers.d.ts +2 -0
- package/package.json +2 -2
- package/dist/cjs/modules/file-uploader/file-uploader.controller.js.map +0 -1
- package/dist/cjs/modules/file-uploader/file-uploader.router.js.map +0 -1
- package/dist/cjs/modules/file-uploader/file-uploader.service.js.map +0 -1
- package/dist/cjs/modules/file-uploader/utils/helpers/file-uploader.helpers.js.map +0 -1
- package/dist/es2020/modules/file-uploader/file-uploader.controller.js.map +0 -1
- package/dist/es2020/modules/file-uploader/file-uploader.router.js.map +0 -1
- package/dist/es2020/modules/file-uploader/file-uploader.service.js.map +0 -1
- package/dist/es2020/modules/file-uploader/utils/helpers/file-uploader.helpers.js.map +0 -1
- package/dist/types/modules/file-uploader/file-uploader.router.d.ts +0 -3
- /package/dist/types/modules/{file-uploader/utils/helpers/file-uploader.helpers.d.ts → file-upload/utils/helpers/file-upload.helpers.d.ts} +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { generateTemplate } from "./utils/generators";
|
|
4
|
+
import { ensureDirectoryExists } from "./utils/helpers";
|
|
5
|
+
import { camelCase, kebabCase, pascalCase, } from "../helpers/change-case.helpers";
|
|
6
|
+
export const generateCommand = {
|
|
7
|
+
controller: async (modelName, options) => {
|
|
8
|
+
if (!modelName) {
|
|
9
|
+
console.error("❌ Model name is required");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
const { path: customPath = "src/modules" } = options;
|
|
13
|
+
const names = {
|
|
14
|
+
pascal: pascalCase(modelName),
|
|
15
|
+
camel: camelCase(modelName),
|
|
16
|
+
kebab: kebabCase(modelName),
|
|
17
|
+
};
|
|
18
|
+
const modulePath = path.join(process.cwd(), customPath, names.kebab);
|
|
19
|
+
const filePath = path.join(modulePath, `${names.kebab}.controller.ts`);
|
|
20
|
+
try {
|
|
21
|
+
ensureDirectoryExists(modulePath);
|
|
22
|
+
const content = generateTemplate("controller", {
|
|
23
|
+
modelName: names,
|
|
24
|
+
imports: {
|
|
25
|
+
baseController: "arkos/controllers",
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
fs.writeFileSync(filePath, content);
|
|
29
|
+
console.log(`✅ Controller generated: ${filePath}`);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error(`❌ Failed to generate controller:`, error);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
service: async (modelName, options) => {
|
|
37
|
+
if (!modelName) {
|
|
38
|
+
console.error("❌ Model name is required");
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
const { path: customPath = "src/modules" } = options;
|
|
42
|
+
const names = {
|
|
43
|
+
pascal: pascalCase(modelName),
|
|
44
|
+
camel: camelCase(modelName),
|
|
45
|
+
kebab: kebabCase(modelName),
|
|
46
|
+
};
|
|
47
|
+
const modulePath = path.join(process.cwd(), customPath, names.kebab);
|
|
48
|
+
const filePath = path.join(modulePath, `${names.kebab}.service.ts`);
|
|
49
|
+
try {
|
|
50
|
+
ensureDirectoryExists(modulePath);
|
|
51
|
+
const content = generateTemplate("service", {
|
|
52
|
+
modelName: names,
|
|
53
|
+
imports: {
|
|
54
|
+
baseService: "arkos/services",
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
fs.writeFileSync(filePath, content);
|
|
58
|
+
console.log(`✅ Service generated: ${filePath}`);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error(`❌ Failed to generate service:`, error);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
router: async (modelName, options) => {
|
|
66
|
+
if (!modelName) {
|
|
67
|
+
console.error("❌ Model name is required");
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
const { path: customPath = "src/modules" } = options;
|
|
71
|
+
const names = {
|
|
72
|
+
pascal: pascalCase(modelName),
|
|
73
|
+
camel: camelCase(modelName),
|
|
74
|
+
kebab: kebabCase(modelName),
|
|
75
|
+
};
|
|
76
|
+
const modulePath = path.join(process.cwd(), customPath, names.kebab);
|
|
77
|
+
const filePath = path.join(modulePath, `${names.kebab}.router.ts`);
|
|
78
|
+
try {
|
|
79
|
+
ensureDirectoryExists(modulePath);
|
|
80
|
+
const content = generateTemplate("router", {
|
|
81
|
+
modelName: names,
|
|
82
|
+
imports: {
|
|
83
|
+
baseRouter: "arkos",
|
|
84
|
+
controller: `./${names.kebab}.controller`,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
fs.writeFileSync(filePath, content);
|
|
88
|
+
console.log(`✅ Router generated: ${filePath}`);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error(`❌ Failed to generate router:`, error);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
middleware: async (middlewareName, options) => {
|
|
96
|
+
if (!middlewareName) {
|
|
97
|
+
console.error("❌ Middleware name is required");
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
const { path: customPath = "src/modules" } = options;
|
|
101
|
+
const names = {
|
|
102
|
+
pascal: pascalCase(middlewareName),
|
|
103
|
+
camel: camelCase(middlewareName),
|
|
104
|
+
kebab: kebabCase(middlewareName),
|
|
105
|
+
};
|
|
106
|
+
const middlewarePath = path.join(process.cwd(), customPath);
|
|
107
|
+
const filePath = path.join(middlewarePath, `${names.kebab}.middlewares.ts`);
|
|
108
|
+
try {
|
|
109
|
+
ensureDirectoryExists(middlewarePath);
|
|
110
|
+
const content = generateTemplate("middleware", { middlewareName: names });
|
|
111
|
+
fs.writeFileSync(filePath, content);
|
|
112
|
+
console.log(`✅ Middleware generated: ${filePath}`);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error(`❌ Failed to generate middleware:`, error);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
authConfig: async (modelName, options) => {
|
|
120
|
+
const { path: customPath = "src/modules" } = options;
|
|
121
|
+
const names = {
|
|
122
|
+
pascal: pascalCase(modelName),
|
|
123
|
+
camel: camelCase(modelName),
|
|
124
|
+
kebab: kebabCase(modelName),
|
|
125
|
+
};
|
|
126
|
+
const configPath = path.join(process.cwd(), customPath);
|
|
127
|
+
const filePath = path.join(configPath, `${names.kebab}.auth.ts`);
|
|
128
|
+
try {
|
|
129
|
+
ensureDirectoryExists(configPath);
|
|
130
|
+
const content = generateTemplate("auth-config");
|
|
131
|
+
fs.writeFileSync(filePath, content);
|
|
132
|
+
console.log(`✅ Auth config generated: ${filePath}`);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
console.error(`❌ Failed to generate auth config:`, error);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
queryOptions: async (modelName, options) => {
|
|
140
|
+
if (!modelName) {
|
|
141
|
+
console.error("❌ Model name is required");
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
const { path: customPath = "src/modules" } = options;
|
|
145
|
+
const names = {
|
|
146
|
+
pascal: pascalCase(modelName),
|
|
147
|
+
camel: camelCase(modelName),
|
|
148
|
+
kebab: kebabCase(modelName),
|
|
149
|
+
};
|
|
150
|
+
const configPath = path.join(process.cwd(), customPath);
|
|
151
|
+
const filePath = path.join(configPath, `${names.kebab}.query.ts`);
|
|
152
|
+
try {
|
|
153
|
+
ensureDirectoryExists(configPath);
|
|
154
|
+
const content = generateTemplate("query-options", { modelName: names });
|
|
155
|
+
fs.writeFileSync(filePath, content);
|
|
156
|
+
console.log(`✅ Query config generated: ${filePath}`);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error(`❌ Failed to generate query config:`, error);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../src/utils/cli/generate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,SAAS,EACT,SAAS,EACT,UAAU,GACX,MAAM,gCAAgC,CAAC;AAMxC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,KAAK,EAAE,SAAiB,EAAE,OAAwB,EAAE,EAAE;QAChE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;QAErD,MAAM,KAAK,GAAG;YACZ,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC;YAC7B,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC;YAC3B,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC;SAC5B,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EA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,CAAC;QAClB,CAAC;IACH,CAAC;IAED,YAAY,EAAE,KAAK,EAAE,SAAiB,EAAE,OAAwB,EAAE,EAAE;QAClE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;QAErD,MAAM,KAAK,GAAG;YACZ,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC;YAC7B,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC;YAC3B,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC;SAC5B,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC,KAAK,WAAW,CAAC,CAAC;QAElE,IAAI,CAAC;YACH,qBAAqB,CAAC,UAAU,CAAC,CAAC;YAElC,MAAM,OAAO,GAAG,gBAAgB,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;YAExE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACpC,OAAO,CAAC,GAAG,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;YAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["// src/utils/cli/generate.ts\nimport fs from \"fs\";\nimport path from \"path\";\nimport { generateTemplate } from \"./utils/generators\";\nimport { ensureDirectoryExists } from \"./utils/helpers\";\nimport {\n camelCase,\n kebabCase,\n pascalCase,\n} from \"../helpers/change-case.helpers\";\n\ninterface GenerateOptions {\n path?: string;\n}\n\nexport const generateCommand = {\n controller: async (modelName: string, options: GenerateOptions) => {\n if (!modelName) {\n console.error(\"❌ Model name is required\");\n process.exit(1);\n }\n\n const { path: customPath = \"src/modules\" } = options;\n\n const names = {\n pascal: pascalCase(modelName),\n camel: camelCase(modelName),\n kebab: kebabCase(modelName),\n };\n\n const modulePath = path.join(process.cwd(), customPath, names.kebab);\n const filePath = path.join(modulePath, `${names.kebab}.controller.ts`);\n\n try {\n ensureDirectoryExists(modulePath);\n\n const content = generateTemplate(\"controller\", {\n modelName: names,\n imports: {\n baseController: \"arkos/controllers\",\n },\n });\n\n fs.writeFileSync(filePath, content);\n console.log(`✅ Controller generated: ${filePath}`);\n } catch (error) {\n console.error(`❌ Failed to generate controller:`, error);\n process.exit(1);\n }\n },\n\n service: async (modelName: string, options: GenerateOptions) => {\n if (!modelName) {\n console.error(\"❌ Model name is required\");\n process.exit(1);\n }\n\n const { path: customPath = \"src/modules\" } = options;\n\n const names = {\n pascal: pascalCase(modelName),\n camel: camelCase(modelName),\n kebab: kebabCase(modelName),\n };\n\n const modulePath = path.join(process.cwd(), customPath, names.kebab);\n const filePath = path.join(modulePath, `${names.kebab}.service.ts`);\n\n try {\n ensureDirectoryExists(modulePath);\n\n const content = generateTemplate(\"service\", {\n modelName: names,\n imports: {\n baseService: \"arkos/services\",\n },\n });\n\n fs.writeFileSync(filePath, content);\n console.log(`✅ Service generated: ${filePath}`);\n } catch (error) {\n console.error(`❌ Failed to generate service:`, error);\n process.exit(1);\n }\n },\n\n router: async (modelName: string, options: GenerateOptions) => {\n if (!modelName) {\n console.error(\"❌ Model name is required\");\n process.exit(1);\n }\n\n const { path: customPath = \"src/modules\" } = options;\n\n const names = {\n pascal: pascalCase(modelName),\n camel: camelCase(modelName),\n kebab: kebabCase(modelName),\n };\n\n const modulePath = path.join(process.cwd(), customPath, names.kebab);\n const filePath = path.join(modulePath, `${names.kebab}.router.ts`);\n\n try {\n ensureDirectoryExists(modulePath);\n\n const content = generateTemplate(\"router\", {\n modelName: names,\n imports: {\n baseRouter: \"arkos\",\n controller: `./${names.kebab}.controller`,\n },\n });\n\n fs.writeFileSync(filePath, content);\n console.log(`✅ Router generated: ${filePath}`);\n } catch (error) {\n console.error(`❌ Failed to generate router:`, error);\n process.exit(1);\n }\n },\n\n middleware: async (middlewareName: string, options: GenerateOptions) => {\n if (!middlewareName) {\n console.error(\"❌ Middleware name is required\");\n process.exit(1);\n }\n\n const { path: customPath = \"src/modules\" } = options;\n\n const names = {\n pascal: pascalCase(middlewareName),\n camel: camelCase(middlewareName),\n kebab: kebabCase(middlewareName),\n };\n\n const middlewarePath = path.join(process.cwd(), customPath);\n const filePath = path.join(middlewarePath, `${names.kebab}.middlewares.ts`);\n\n try {\n ensureDirectoryExists(middlewarePath);\n\n const content = generateTemplate(\"middleware\", { middlewareName: names });\n\n fs.writeFileSync(filePath, content);\n console.log(`✅ Middleware generated: ${filePath}`);\n } catch (error) {\n console.error(`❌ Failed to generate middleware:`, error);\n process.exit(1);\n }\n },\n\n authConfig: async (modelName: string, options: GenerateOptions) => {\n const { path: customPath = \"src/modules\" } = options;\n\n const names = {\n pascal: pascalCase(modelName),\n camel: camelCase(modelName),\n kebab: kebabCase(modelName),\n };\n\n const configPath = path.join(process.cwd(), customPath);\n const filePath = path.join(configPath, `${names.kebab}.auth.ts`);\n\n try {\n ensureDirectoryExists(configPath);\n\n const content = generateTemplate(\"auth-config\");\n\n fs.writeFileSync(filePath, content);\n console.log(`✅ Auth config generated: ${filePath}`);\n } catch (error) {\n console.error(`❌ Failed to generate auth config:`, error);\n process.exit(1);\n }\n },\n\n queryOptions: async (modelName: string, options: GenerateOptions) => {\n if (!modelName) {\n console.error(\"❌ Model name is required\");\n process.exit(1);\n }\n\n const { path: customPath = \"src/modules\" } = options;\n\n const names = {\n pascal: pascalCase(modelName),\n camel: camelCase(modelName),\n kebab: kebabCase(modelName),\n };\n\n const configPath = path.join(process.cwd(), customPath);\n const filePath = path.join(configPath, `${names.kebab}.query.ts`);\n\n try {\n ensureDirectoryExists(configPath);\n\n const content = generateTemplate(\"query-options\", { modelName: names });\n\n fs.writeFileSync(filePath, content);\n console.log(`✅ Query config generated: ${filePath}`);\n } catch (error) {\n console.error(`❌ Failed to generate query config:`, error);\n process.exit(1);\n }\n },\n};\n"]}
|
|
@@ -4,6 +4,7 @@ import path from "path";
|
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import { devCommand } from "./dev";
|
|
6
6
|
import { startCommand } from "./start";
|
|
7
|
+
import { generateCommand } from "./generate";
|
|
7
8
|
export function getVersion() {
|
|
8
9
|
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../../../../package.json"), "utf8"));
|
|
9
10
|
return packageJson.version || "1.0.0";
|
|
@@ -27,6 +28,42 @@ program
|
|
|
27
28
|
.option("-p, --port <number>", "Port number")
|
|
28
29
|
.option("-h, --host <host>", "Host to bind to")
|
|
29
30
|
.action(startCommand);
|
|
31
|
+
const add = program.command("add").description("Generate arkos components");
|
|
32
|
+
add
|
|
33
|
+
.command("controller")
|
|
34
|
+
.description("Generate a new controller")
|
|
35
|
+
.requiredOption("--model <name>", "Model name")
|
|
36
|
+
.option("--path <path>", "Custom path for the controller", "src/modules")
|
|
37
|
+
.action(generateCommand.controller);
|
|
38
|
+
add
|
|
39
|
+
.command("service")
|
|
40
|
+
.description("Generate a new service")
|
|
41
|
+
.requiredOption("--model <name>", "Model name")
|
|
42
|
+
.option("--path <path>", "Custom path for the service", "src/modules")
|
|
43
|
+
.action(generateCommand.service);
|
|
44
|
+
add
|
|
45
|
+
.command("router")
|
|
46
|
+
.description("Generate a new router")
|
|
47
|
+
.requiredOption("--model <name>", "Model name")
|
|
48
|
+
.option("--path <path>", "Custom path for the router", "src/modules")
|
|
49
|
+
.action(generateCommand.router);
|
|
50
|
+
add
|
|
51
|
+
.command("auth-configs")
|
|
52
|
+
.description("Generate auth configuration")
|
|
53
|
+
.option("--path <path>", "Custom path for auth config", "src/modules")
|
|
54
|
+
.action(generateCommand.authConfig);
|
|
55
|
+
add
|
|
56
|
+
.command("query-options")
|
|
57
|
+
.description("Generate prisma query options")
|
|
58
|
+
.requiredOption("--model <name>", "Model name")
|
|
59
|
+
.option("--path <path>", "Custom path for query options", "src/modules")
|
|
60
|
+
.action(generateCommand.queryOptions);
|
|
61
|
+
add
|
|
62
|
+
.command("middlewares")
|
|
63
|
+
.description("Generate a new middleware file")
|
|
64
|
+
.requiredOption("--name <name>", "Middleware name")
|
|
65
|
+
.option("--path <path>", "Custom path for middleware", "src/modules")
|
|
66
|
+
.action(generateCommand.middleware);
|
|
30
67
|
program.parse(process.argv);
|
|
31
|
-
export { program, buildCommand, devCommand, startCommand };
|
|
68
|
+
export { program, buildCommand, devCommand, startCommand, generateCommand };
|
|
32
69
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":"AA6CA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,UAAU,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAC5B,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE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\";\n// import path from \"path\";\n// import fs from \"fs\";\n// import { devCommand } from \"./dev\";\n// import { startCommand } from \"./start\";\n\n// export function getVersion() {\n// const packageJson = JSON.parse(\n// fs.readFileSync(path.join(__dirname, \"../../../../package.json\"), \"utf8\")\n// );\n\n// return packageJson.version || \"1.0.0\";\n// }\n\n// const program = new Command();\n\n// program.name(\"arkos\").description(\"Arkos.js CLI\").version(getVersion());\n\n// program\n// .command(\"build\")\n// .description(\"Build your Arkos project\")\n// .option(\"-m, --module <type>\", \"Module type (cjs or esm)\", \"cjs\")\n// .action(buildCommand);\n\n// program\n// .command(\"dev\")\n// .description(\"Run development server\")\n// .option(\"-p, --port <number>\", \"Port number\")\n// .option(\"-h, --host <host>\", \"Host to bind to\")\n// .action(devCommand);\n\n// program\n// .command(\"start\")\n// .description(\"Run production server\")\n// .option(\"-p, --port <number>\", \"Port number\")\n// .option(\"-h, --host <host>\", \"Host to bind to\")\n// .action(startCommand);\n\n// program.parse(process.argv);\n\n// export { program, buildCommand, devCommand, startCommand };\n\n// src/utils/cli/index.ts\nimport { Command } from \"commander\";\nimport { buildCommand } from \"./build\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { devCommand } from \"./dev\";\nimport { startCommand } from \"./start\";\nimport { generateCommand } from \"./generate\";\n\nexport function getVersion() {\n const packageJson = JSON.parse(\n fs.readFileSync(path.join(__dirname, \"../../../../package.json\"), \"utf8\")\n );\n\n return packageJson.version || \"1.0.0\";\n}\n\nconst program = new Command();\n\nprogram.name(\"arkos\").description(\"Arkos.js CLI\").version(getVersion());\n\nprogram\n .command(\"build\")\n .description(\"Build your Arkos project\")\n .option(\"-m, --module <type>\", \"Module type (cjs or esm)\", \"cjs\")\n .action(buildCommand);\n\nprogram\n .command(\"dev\")\n .description(\"Run development server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(devCommand);\n\nprogram\n .command(\"start\")\n .description(\"Run production server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(startCommand);\n\n// New add command with subcommands\nconst add = program.command(\"add\").description(\"Generate arkos components\");\n\nadd\n .command(\"controller\")\n .description(\"Generate a new controller\")\n .requiredOption(\"--model <name>\", \"Model name\")\n .option(\"--path <path>\", \"Custom path for the controller\", \"src/modules\")\n .action(generateCommand.controller);\n\nadd\n .command(\"service\")\n .description(\"Generate a new service\")\n .requiredOption(\"--model <name>\", \"Model name\")\n .option(\"--path <path>\", \"Custom path for the service\", \"src/modules\")\n .action(generateCommand.service);\n\nadd\n .command(\"router\")\n .description(\"Generate a new router\")\n .requiredOption(\"--model <name>\", \"Model name\")\n .option(\"--path <path>\", \"Custom path for the router\", \"src/modules\")\n .action(generateCommand.router);\n\nadd\n .command(\"auth-configs\")\n .description(\"Generate auth configuration\")\n .option(\"--path <path>\", \"Custom path for auth config\", \"src/modules\")\n .action(generateCommand.authConfig);\n\nadd\n .command(\"query-options\")\n .description(\"Generate prisma query options\")\n .requiredOption(\"--model <name>\", \"Model name\")\n .option(\"--path <path>\", \"Custom path for query options\", \"src/modules\")\n .action(generateCommand.queryOptions);\n\nadd\n .command(\"middlewares\")\n .description(\"Generate a new middleware file\")\n .requiredOption(\"--name <name>\", \"Middleware name\")\n .option(\"--path <path>\", \"Custom path for middleware\", \"src/modules\")\n .action(generateCommand.middleware);\n\nprogram.parse(process.argv);\n\nexport { program, buildCommand, devCommand, startCommand, generateCommand };\n"]}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
export function generateTemplate(type, options = {}) {
|
|
2
|
+
switch (type) {
|
|
3
|
+
case "controller":
|
|
4
|
+
return generateControllerTemplate(options);
|
|
5
|
+
case "service":
|
|
6
|
+
return generateServiceTemplate(options);
|
|
7
|
+
case "router":
|
|
8
|
+
return generateRouterTemplate(options);
|
|
9
|
+
case "auth":
|
|
10
|
+
return generateAuthConfigTemplate();
|
|
11
|
+
case "query":
|
|
12
|
+
return generateQueryConfigTemplate(options);
|
|
13
|
+
case "middleware":
|
|
14
|
+
return generateMiddlewareTemplate(options);
|
|
15
|
+
default:
|
|
16
|
+
throw new Error(`Unknown template type: ${type}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function generateControllerTemplate(options) {
|
|
20
|
+
const { modelName, imports } = options;
|
|
21
|
+
if (!modelName)
|
|
22
|
+
throw new Error("Model name is required for controller template");
|
|
23
|
+
return `import { BaseController } from "${imports?.baseController || "arkos/controllers"}";
|
|
24
|
+
|
|
25
|
+
class ${modelName.pascal}Controller extends BaseController {
|
|
26
|
+
constructor() {
|
|
27
|
+
super("${modelName.kebab}");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const ${modelName.camel}Controller = new ${modelName.pascal}Controller();
|
|
32
|
+
|
|
33
|
+
export default ${modelName.camel}Controller;
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
function generateServiceTemplate(options) {
|
|
37
|
+
const { modelName, imports } = options;
|
|
38
|
+
if (!modelName)
|
|
39
|
+
throw new Error("Model name is required for service template");
|
|
40
|
+
return `import { BaseService } from "${imports?.baseService || "arkos/services"}";
|
|
41
|
+
|
|
42
|
+
class ${modelName.pascal}Service extends BaseService {
|
|
43
|
+
constructor() {
|
|
44
|
+
super("${modelName.kebab}");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Add your custom service methods here
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ${modelName.camel}Service = new ${modelName.pascal}Service();
|
|
51
|
+
|
|
52
|
+
export default ${modelName.camel}Service;
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
function generateRouterTemplate(options) {
|
|
56
|
+
const { modelName, imports } = options;
|
|
57
|
+
if (!modelName)
|
|
58
|
+
throw new Error("Model name is required for router template");
|
|
59
|
+
return `import { Router } from "express";
|
|
60
|
+
import { createRoutes } from "${imports?.baseRouter || "arkos"}";
|
|
61
|
+
import ${modelName.camel}Controller from "${imports?.controller || `./${modelName.kebab}.controller`}";
|
|
62
|
+
|
|
63
|
+
const ${modelName.camel}Router = Router();
|
|
64
|
+
|
|
65
|
+
// Generate CRUD routes automatically
|
|
66
|
+
createRoutes(${modelName.camel}Router, ${modelName.camel}Controller);
|
|
67
|
+
|
|
68
|
+
// Add custom routes here
|
|
69
|
+
// ${modelName.camel}Router.get('/custom', ${modelName.camel}Controller.customMethod);
|
|
70
|
+
|
|
71
|
+
export default ${modelName.camel}Router;
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
function generateAuthConfigTemplate() {
|
|
75
|
+
return `export const authConfig = {
|
|
76
|
+
jwt: {
|
|
77
|
+
secret: process.env.JWT_SECRET || 'your-secret-key',
|
|
78
|
+
expiresIn: process.env.JWT_EXPIRES_IN || '7d',
|
|
79
|
+
refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES_IN || '30d',
|
|
80
|
+
},
|
|
81
|
+
bcrypt: {
|
|
82
|
+
saltRounds: parseInt(process.env.BCRYPT_SALT_ROUNDS || '12'),
|
|
83
|
+
},
|
|
84
|
+
cookie: {
|
|
85
|
+
name: process.env.COOKIE_NAME || 'arkos-token',
|
|
86
|
+
maxAge: parseInt(process.env.COOKIE_MAX_AGE || '604800000'), // 7 days
|
|
87
|
+
httpOnly: true,
|
|
88
|
+
secure: process.env.NODE_ENV === 'production',
|
|
89
|
+
sameSite: 'strict' as const,
|
|
90
|
+
},
|
|
91
|
+
rateLimit: {
|
|
92
|
+
windowMs: parseInt(process.env.RATE_LIMIT_WINDOW || '900000'), // 15 minutes
|
|
93
|
+
max: parseInt(process.env.RATE_LIMIT_MAX || '5'), // 5 attempts
|
|
94
|
+
},
|
|
95
|
+
email: {
|
|
96
|
+
verification: {
|
|
97
|
+
required: process.env.EMAIL_VERIFICATION_REQUIRED === 'true',
|
|
98
|
+
expiresIn: process.env.EMAIL_VERIFICATION_EXPIRES_IN || '24h',
|
|
99
|
+
},
|
|
100
|
+
passwordReset: {
|
|
101
|
+
expiresIn: process.env.PASSWORD_RESET_EXPIRES_IN || '1h',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default authConfig;
|
|
107
|
+
`;
|
|
108
|
+
}
|
|
109
|
+
function generateQueryConfigTemplate(options) {
|
|
110
|
+
const { modelName } = options;
|
|
111
|
+
if (!modelName)
|
|
112
|
+
throw new Error("Model name is required for query config template");
|
|
113
|
+
return `export const ${modelName.camel}QueryOptions = {
|
|
114
|
+
// Define searchable fields
|
|
115
|
+
searchFields: [
|
|
116
|
+
// 'name',
|
|
117
|
+
// 'email',
|
|
118
|
+
// 'description',
|
|
119
|
+
],
|
|
120
|
+
|
|
121
|
+
// Define filterable fields
|
|
122
|
+
filterFields: [
|
|
123
|
+
// 'status',
|
|
124
|
+
// 'type',
|
|
125
|
+
// 'createdAt',
|
|
126
|
+
],
|
|
127
|
+
|
|
128
|
+
// Define sortable fields
|
|
129
|
+
sortFields: [
|
|
130
|
+
'id',
|
|
131
|
+
'createdAt',
|
|
132
|
+
'updatedAt',
|
|
133
|
+
// Add other sortable fields
|
|
134
|
+
],
|
|
135
|
+
|
|
136
|
+
// Define relations to include
|
|
137
|
+
include: {
|
|
138
|
+
// relationName: true,
|
|
139
|
+
// relationName: {
|
|
140
|
+
// select: {
|
|
141
|
+
// id: true,
|
|
142
|
+
// name: true,
|
|
143
|
+
// }
|
|
144
|
+
// }
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
// Define fields to select (if not all)
|
|
148
|
+
select: {
|
|
149
|
+
// id: true,
|
|
150
|
+
// name: true,
|
|
151
|
+
// email: true,
|
|
152
|
+
// createdAt: true,
|
|
153
|
+
// updatedAt: true,
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
// Default pagination
|
|
157
|
+
pagination: {
|
|
158
|
+
defaultLimit: 10,
|
|
159
|
+
maxLimit: 100,
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
// Default sorting
|
|
163
|
+
defaultSort: {
|
|
164
|
+
field: 'createdAt',
|
|
165
|
+
order: 'desc' as const,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export default ${modelName.camel}QueryOptions;
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
function generateMiddlewareTemplate(options) {
|
|
173
|
+
const { middlewareName } = options;
|
|
174
|
+
if (!middlewareName)
|
|
175
|
+
throw new Error("Middleware name is required for middleware template");
|
|
176
|
+
return `import { Request, Response, NextFunction } from 'express';
|
|
177
|
+
|
|
178
|
+
export const ${middlewareName.camel}Middleware = (
|
|
179
|
+
req: Request,
|
|
180
|
+
res: Response,
|
|
181
|
+
next: NextFunction
|
|
182
|
+
): void => {
|
|
183
|
+
try {
|
|
184
|
+
// Add your middleware logic here
|
|
185
|
+
console.log(\`${middlewareName.pascal} middleware executed for \${req.method} \${req.path}\`);
|
|
186
|
+
|
|
187
|
+
// Continue to next middleware
|
|
188
|
+
next();
|
|
189
|
+
} catch (error) {
|
|
190
|
+
next(error);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export default ${middlewareName.camel}Middleware;
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=generators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/generators.ts"],"names":[],"mappings":"AAkBA,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,UAA2B,EAAE;IAE7B,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,YAAY;YACf,OAAO,0BAA0B,CAAC,OAAO,CAAC,CAAC;QAC7C,KAAK,SAAS;YACZ,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAC1C,KAAK,QAAQ;YACX,OAAO,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACzC,KAAK,MAAM;YACT,OAAO,0BAA0B,EAAE,CAAC;QACtC,KAAK,OA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,IAAI,KAAK,SAAS,CAAC,KAAK,aAC7C;;UAEQ,SAAS,CAAC,KAAK;;;iBAGR,SAAS,CAAC,KAAK,WAAW,SAAS,CAAC,KAAK;;;OAGnD,SAAS,CAAC,KAAK,yBAClB,SAAS,CAAC,KACZ;;mBAEiB,SAAS,CAAC,KAAK;GAC/B,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B;IACjC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCN,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,OAAwB;IAC3D,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IAEtE,OAAO,gBAAgB,SAAS,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAwDrB,SAAS,CAAC,KAAK;GAC/B,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B,CAAC,OAAwB;IAC1D,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAEnC,IAAI,CAAC,cAAc;QACjB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAEzE,OAAO;;iBAEQ,cAAc,CAAC,KAAK;;;;;;;sBAOf,cAAc,CAAC,MAAM;;;;;;;;;mBASxB,cAAc,CAAC,KAAK;GACpC,CAAC;AACJ,CAAC","sourcesContent":["interface ModelName {\n pascal: string;\n camel: string;\n kebab: string;\n}\n\ninterface MiddlewareName {\n pascal: string;\n camel: string;\n kebab: string;\n}\n\ninterface TemplateOptions {\n modelName?: ModelName;\n middlewareName?: MiddlewareName;\n imports?: Record<string, string>;\n}\n\nexport function generateTemplate(\n type: string,\n options: TemplateOptions = {}\n): string {\n switch (type) {\n case \"controller\":\n return generateControllerTemplate(options);\n case \"service\":\n return generateServiceTemplate(options);\n case \"router\":\n return generateRouterTemplate(options);\n case \"auth\":\n return generateAuthConfigTemplate();\n case \"query\":\n return generateQueryConfigTemplate(options);\n case \"middleware\":\n return generateMiddlewareTemplate(options);\n default:\n throw new Error(`Unknown template type: ${type}`);\n }\n}\n\nfunction generateControllerTemplate(options: TemplateOptions): string {\n const { modelName, imports } = options;\n\n if (!modelName)\n throw new Error(\"Model name is required for controller template\");\n\n return `import { BaseController } from \"${\n imports?.baseController || \"arkos/controllers\"\n }\";\n \n class ${modelName.pascal}Controller extends BaseController {\n constructor() {\n super(\"${modelName.kebab}\");\n }\n }\n \n const ${modelName.camel}Controller = new ${modelName.pascal}Controller();\n \n export default ${modelName.camel}Controller;\n `;\n}\n\nfunction generateServiceTemplate(options: TemplateOptions): string {\n const { modelName, imports } = options;\n\n if (!modelName)\n throw new Error(\"Model name is required for service template\");\n\n return `import { BaseService } from \"${\n imports?.baseService || \"arkos/services\"\n }\";\n \n class ${modelName.pascal}Service extends BaseService {\n constructor() {\n super(\"${modelName.kebab}\");\n }\n \n // Add your custom service methods here\n }\n \n const ${modelName.camel}Service = new ${modelName.pascal}Service();\n \n export default ${modelName.camel}Service;\n `;\n}\n\nfunction generateRouterTemplate(options: TemplateOptions): string {\n const { modelName, imports } = options;\n\n if (!modelName) throw new Error(\"Model name is required for router template\");\n\n return `import { Router } from \"express\";\n import { createRoutes } from \"${imports?.baseRouter || \"arkos\"}\";\n import ${modelName.camel}Controller from \"${\n imports?.controller || `./${modelName.kebab}.controller`\n }\";\n \n const ${modelName.camel}Router = Router();\n \n // Generate CRUD routes automatically\n createRoutes(${modelName.camel}Router, ${modelName.camel}Controller);\n \n // Add custom routes here\n // ${modelName.camel}Router.get('/custom', ${\n modelName.camel\n }Controller.customMethod);\n \n export default ${modelName.camel}Router;\n `;\n}\n\nfunction generateAuthConfigTemplate(): string {\n return `export const authConfig = {\n jwt: {\n secret: process.env.JWT_SECRET || 'your-secret-key',\n expiresIn: process.env.JWT_EXPIRES_IN || '7d',\n refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES_IN || '30d',\n },\n bcrypt: {\n saltRounds: parseInt(process.env.BCRYPT_SALT_ROUNDS || '12'),\n },\n cookie: {\n name: process.env.COOKIE_NAME || 'arkos-token',\n maxAge: parseInt(process.env.COOKIE_MAX_AGE || '604800000'), // 7 days\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'strict' as const,\n },\n rateLimit: {\n windowMs: parseInt(process.env.RATE_LIMIT_WINDOW || '900000'), // 15 minutes\n max: parseInt(process.env.RATE_LIMIT_MAX || '5'), // 5 attempts\n },\n email: {\n verification: {\n required: process.env.EMAIL_VERIFICATION_REQUIRED === 'true',\n expiresIn: process.env.EMAIL_VERIFICATION_EXPIRES_IN || '24h',\n },\n passwordReset: {\n expiresIn: process.env.PASSWORD_RESET_EXPIRES_IN || '1h',\n },\n },\n };\n \n export default authConfig;\n `;\n}\n\nfunction generateQueryConfigTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n\n if (!modelName)\n throw new Error(\"Model name is required for query config template\");\n\n return `export const ${modelName.camel}QueryOptions = {\n // Define searchable fields\n searchFields: [\n // 'name',\n // 'email',\n // 'description',\n ],\n \n // Define filterable fields\n filterFields: [\n // 'status',\n // 'type',\n // 'createdAt',\n ],\n \n // Define sortable fields\n sortFields: [\n 'id',\n 'createdAt',\n 'updatedAt',\n // Add other sortable fields\n ],\n \n // Define relations to include\n include: {\n // relationName: true,\n // relationName: {\n // select: {\n // id: true,\n // name: true,\n // }\n // }\n },\n \n // Define fields to select (if not all)\n select: {\n // id: true,\n // name: true,\n // email: true,\n // createdAt: true,\n // updatedAt: true,\n },\n \n // Default pagination\n pagination: {\n defaultLimit: 10,\n maxLimit: 100,\n },\n \n // Default sorting\n defaultSort: {\n field: 'createdAt',\n order: 'desc' as const,\n },\n };\n \n export default ${modelName.camel}QueryOptions;\n `;\n}\n\nfunction generateMiddlewareTemplate(options: TemplateOptions): string {\n const { middlewareName } = options;\n\n if (!middlewareName)\n throw new Error(\"Middleware name is required for middleware template\");\n\n return `import { Request, Response, NextFunction } from 'express';\n \n export const ${middlewareName.camel}Middleware = (\n req: Request,\n res: Response,\n next: NextFunction\n ): void => {\n try {\n // Add your middleware logic here\n console.log(\\`${middlewareName.pascal} middleware executed for \\${req.method} \\${req.path}\\`);\n \n // Continue to next middleware\n next();\n } catch (error) {\n next(error);\n }\n };\n \n export default ${middlewareName.camel}Middleware;\n `;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
export function ensureDirectoryExists(dirPath) {
|
|
3
|
+
if (!fs.existsSync(dirPath)) {
|
|
4
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function fileExists(filePath) {
|
|
8
|
+
return fs.existsSync(filePath);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AA2BpB,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// src/utils/cli/utils.ts\nimport fs from \"fs\";\nimport path from \"path\";\n\n// export function toPascalCase(str: string): string {\n// return str\n// .replace(/[\\W_]/g, \" \")\n// .replace(/\\s+/g, \" \")\n// .trim()\n// .split(\" \")\n// .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n// .join(\"\");\n// }\n\n// export function toCamelCase(str: string): string {\n// const pascal = toPascalCase(str);\n// return pascal.charAt(0).toLowerCase() + pascal.slice(1);\n// }\n\n// export function toKebabCase(str: string): string {\n// return str\n// .replace(/([a-z])([A-Z])/g, \"$1-$2\")\n// .replace(/[\\W_]/g, \"-\")\n// .replace(/-+/g, \"-\")\n// .replace(/^-|-$/g, \"\")\n// .toLowerCase();\n// }\n\nexport function ensureDirectoryExists(dirPath: string): void {\n if (!fs.existsSync(dirPath)) {\n fs.mkdirSync(dirPath, { recursive: true });\n }\n}\n\nexport function fileExists(filePath: string): boolean {\n return fs.existsSync(filePath);\n}\n\n// export function getProjectType(): \"typescript\" | \"javascript\" {\n// const tsConfigExists = fileExists(path.join(process.cwd(), \"tsconfig.json\"));\n// const packageJson = path.join(process.cwd(), \"package.json\");\n\n// if (tsConfigExists) return \"typescript\";\n\n// if (fileExists(packageJson)) {\n// try {\n// const pkg = JSON.parse(fs.readFileSync(packageJson, \"utf8\"));\n// if (pkg.devDependencies?.typescript || pkg.dependencies?.typescript) {\n// return \"typescript\";\n// }\n// } catch {\n// // ignore\n// }\n// }\n\n// return \"javascript\";\n// }\n"]}
|
|
@@ -91,6 +91,42 @@ export async function processSubdir(modelName, type, result) {
|
|
|
91
91
|
console.error(error);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
+
export function validateNamingConventions(key, fileName, result) {
|
|
95
|
+
if (key === "prismaQueryOptions") {
|
|
96
|
+
if (result.prismaQueryOptions) {
|
|
97
|
+
throw new Error(`\n Cannot use both ${fileName} and ${fileName.replace("prisma-query-options", "query")} at once, please choose only one name convention. \n`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (key === "prismaQueryOptionsNew") {
|
|
101
|
+
if (result.prismaQueryOptions) {
|
|
102
|
+
throw new Error(`\n Cannot use both ${fileName} and ${fileName.replace("query", "prisma-query-options")} at once, please choose only one name convention. \n`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (key === "authConfigs") {
|
|
106
|
+
if (result.authConfigs) {
|
|
107
|
+
throw new Error(`\n Cannot use both ${fileName} and ${fileName.replace("auth-configs", "auth")} at once, please choose only one name convention. \n`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (key === "authConfigsNew") {
|
|
111
|
+
if (result.authConfigs) {
|
|
112
|
+
throw new Error(`\n Cannot use both ${fileName} and ${fileName.replace("auth", "auth-configs")} at once, please choose only one name convention. \n`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function assignModuleToResult(key, module, result) {
|
|
117
|
+
if (key === "prismaQueryOptions" || key === "prismaQueryOptionsNew") {
|
|
118
|
+
result.prismaQueryOptions = module.default || module;
|
|
119
|
+
}
|
|
120
|
+
else if (key === "authConfigs" || key === "authConfigsNew") {
|
|
121
|
+
result.authConfigs = module.default || module;
|
|
122
|
+
}
|
|
123
|
+
else if (key === "middlewares" || key === "router") {
|
|
124
|
+
result[key] = module;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
result[key] = module.default || module;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
94
130
|
export async function importPrismaModelModules(modelName) {
|
|
95
131
|
const moduleDir = path.resolve(crd(), "src", "modules", kebabCase(modelName));
|
|
96
132
|
const result = {
|
|
@@ -103,36 +139,8 @@ export async function importPrismaModelModules(modelName) {
|
|
|
103
139
|
try {
|
|
104
140
|
const module = await importModule(filePath).catch(() => null);
|
|
105
141
|
if (module) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
throw Error(`\n Cannot use both ${fileName} and ${fileName.replace("prisma-query-options", "query")} at once, please choose only one name convention. \n`);
|
|
109
|
-
}
|
|
110
|
-
result.prismaQueryOptions = module.default || module;
|
|
111
|
-
}
|
|
112
|
-
else if (key === "prismaQueryOptionsNew") {
|
|
113
|
-
if (result.prismaQueryOptions) {
|
|
114
|
-
throw Error(`\n Cannot use both ${fileName} and ${fileName.replace("query", "prisma-query-options")} at once, please choose only one name convention. \n`);
|
|
115
|
-
}
|
|
116
|
-
result.prismaQueryOptions = module.default || module;
|
|
117
|
-
}
|
|
118
|
-
else if (key === "authConfigs") {
|
|
119
|
-
if (result.authConfigs) {
|
|
120
|
-
throw Error(`\n Cannot use both ${fileName} and ${fileName.replace("auth-configs", "auth")} at once, please choose only one name convention. \n`);
|
|
121
|
-
}
|
|
122
|
-
result.authConfigs = module.default || module;
|
|
123
|
-
}
|
|
124
|
-
else if (key === "authConfigsNew") {
|
|
125
|
-
if (result.authConfigs) {
|
|
126
|
-
throw Error(`\n Cannot use both ${fileName} and ${fileName.replace("auth", "auth-configs")} at once, please choose only one name convention. \n`);
|
|
127
|
-
}
|
|
128
|
-
result.authConfigs = module.default || module;
|
|
129
|
-
}
|
|
130
|
-
else if (key === "middlewares" || key === "router") {
|
|
131
|
-
result[key] = module;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
result[key] = module.default || module;
|
|
135
|
-
}
|
|
142
|
+
validateNamingConventions(key, fileName, result);
|
|
143
|
+
assignModuleToResult(key, module, result);
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
catch (err) {
|