@skalfa/skalfa-api-core 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/.github/workflows/publish.yml +40 -0
  2. package/dist/auth/auth.d.ts +19 -0
  3. package/dist/auth/auth.js +227 -0
  4. package/dist/auth/auth.js.map +1 -0
  5. package/dist/auth/index.d.ts +1 -0
  6. package/dist/auth/index.js +2 -0
  7. package/dist/auth/index.js.map +1 -0
  8. package/dist/auth.util.d.ts +19 -0
  9. package/dist/auth.util.js +183 -0
  10. package/dist/auth.util.js.map +1 -0
  11. package/dist/commands/cli.d.ts +1 -0
  12. package/dist/commands/cli.js +78 -0
  13. package/dist/commands/cli.js.map +1 -0
  14. package/dist/commands/make/basic-controller.d.ts +2 -0
  15. package/dist/commands/make/basic-controller.js +40 -0
  16. package/dist/commands/make/basic-controller.js.map +1 -0
  17. package/dist/commands/make/basic-migration.d.ts +5 -0
  18. package/dist/commands/make/basic-migration.js +60 -0
  19. package/dist/commands/make/basic-migration.js.map +1 -0
  20. package/dist/commands/make/basic-model.d.ts +2 -0
  21. package/dist/commands/make/basic-model.js +25 -0
  22. package/dist/commands/make/basic-model.js.map +1 -0
  23. package/dist/commands/make/basic-seeder.d.ts +3 -0
  24. package/dist/commands/make/basic-seeder.js +32 -0
  25. package/dist/commands/make/basic-seeder.js.map +1 -0
  26. package/dist/commands/make/blueprint.d.ts +2 -0
  27. package/dist/commands/make/blueprint.js +29 -0
  28. package/dist/commands/make/blueprint.js.map +1 -0
  29. package/dist/commands/make/da-migration.d.ts +5 -0
  30. package/dist/commands/make/da-migration.js +60 -0
  31. package/dist/commands/make/da-migration.js.map +1 -0
  32. package/dist/commands/make/light-controller.d.ts +3 -0
  33. package/dist/commands/make/light-controller.js +54 -0
  34. package/dist/commands/make/light-controller.js.map +1 -0
  35. package/dist/commands/make/light-model.d.ts +3 -0
  36. package/dist/commands/make/light-model.js +50 -0
  37. package/dist/commands/make/light-model.js.map +1 -0
  38. package/dist/commands/make/mail.d.ts +2 -0
  39. package/dist/commands/make/mail.js +41 -0
  40. package/dist/commands/make/mail.js.map +1 -0
  41. package/dist/commands/make/notification.d.ts +2 -0
  42. package/dist/commands/make/notification.js +33 -0
  43. package/dist/commands/make/notification.js.map +1 -0
  44. package/dist/commands/make/queue.d.ts +2 -0
  45. package/dist/commands/make/queue.js +35 -0
  46. package/dist/commands/make/queue.js.map +1 -0
  47. package/dist/commands/runner/barrels.d.ts +3 -0
  48. package/dist/commands/runner/barrels.js +78 -0
  49. package/dist/commands/runner/barrels.js.map +1 -0
  50. package/dist/commands/runner/blueprint/controller-generation.d.ts +1 -0
  51. package/dist/commands/runner/blueprint/controller-generation.js +147 -0
  52. package/dist/commands/runner/blueprint/controller-generation.js.map +1 -0
  53. package/dist/commands/runner/blueprint/documentation-generation.d.ts +6 -0
  54. package/dist/commands/runner/blueprint/documentation-generation.js +337 -0
  55. package/dist/commands/runner/blueprint/documentation-generation.js.map +1 -0
  56. package/dist/commands/runner/blueprint/migration-generation.d.ts +1 -0
  57. package/dist/commands/runner/blueprint/migration-generation.js +120 -0
  58. package/dist/commands/runner/blueprint/migration-generation.js.map +1 -0
  59. package/dist/commands/runner/blueprint/model-generation.d.ts +1 -0
  60. package/dist/commands/runner/blueprint/model-generation.js +122 -0
  61. package/dist/commands/runner/blueprint/model-generation.js.map +1 -0
  62. package/dist/commands/runner/blueprint/runner.d.ts +23 -0
  63. package/dist/commands/runner/blueprint/runner.js +139 -0
  64. package/dist/commands/runner/blueprint/runner.js.map +1 -0
  65. package/dist/commands/runner/blueprint/seeder-generation.d.ts +1 -0
  66. package/dist/commands/runner/blueprint/seeder-generation.js +40 -0
  67. package/dist/commands/runner/blueprint/seeder-generation.js.map +1 -0
  68. package/dist/commands/runner/da-migration.d.ts +39 -0
  69. package/dist/commands/runner/da-migration.js +262 -0
  70. package/dist/commands/runner/da-migration.js.map +1 -0
  71. package/dist/commands/runner/migration.d.ts +11 -0
  72. package/dist/commands/runner/migration.js +188 -0
  73. package/dist/commands/runner/migration.js.map +1 -0
  74. package/dist/commands/runner/seeder.d.ts +3 -0
  75. package/dist/commands/runner/seeder.js +40 -0
  76. package/dist/commands/runner/seeder.js.map +1 -0
  77. package/dist/commands/stubs/index.d.ts +14 -0
  78. package/dist/commands/stubs/index.js +277 -0
  79. package/dist/commands/stubs/index.js.map +1 -0
  80. package/dist/context/context.d.ts +7 -0
  81. package/dist/context/context.js +11 -0
  82. package/dist/context/context.js.map +1 -0
  83. package/dist/context/index.d.ts +1 -0
  84. package/dist/context/index.js +2 -0
  85. package/dist/context/index.js.map +1 -0
  86. package/dist/context.util.d.ts +7 -0
  87. package/dist/context.util.js +11 -0
  88. package/dist/context.util.js.map +1 -0
  89. package/dist/controller/controller.d.ts +118 -0
  90. package/dist/controller/controller.js +147 -0
  91. package/dist/controller/controller.js.map +1 -0
  92. package/dist/controller/index.d.ts +1 -0
  93. package/dist/controller/index.js +2 -0
  94. package/dist/controller/index.js.map +1 -0
  95. package/dist/controller.util.d.ts +118 -0
  96. package/dist/controller.util.js +144 -0
  97. package/dist/controller.util.js.map +1 -0
  98. package/dist/conversion/conversion.d.ts +8 -0
  99. package/dist/conversion/conversion.js +52 -0
  100. package/dist/conversion/conversion.js.map +1 -0
  101. package/dist/conversion/index.d.ts +1 -0
  102. package/dist/conversion/index.js +2 -0
  103. package/dist/conversion/index.js.map +1 -0
  104. package/dist/conversion.util.d.ts +8 -0
  105. package/dist/conversion.util.js +52 -0
  106. package/dist/conversion.util.js.map +1 -0
  107. package/dist/db/db.d.ts +84 -0
  108. package/dist/db/db.js +177 -0
  109. package/dist/db/db.js.map +1 -0
  110. package/dist/db/index.d.ts +1 -0
  111. package/dist/db/index.js +2 -0
  112. package/dist/db/index.js.map +1 -0
  113. package/dist/db.util.d.ts +84 -0
  114. package/dist/db.util.js +177 -0
  115. package/dist/db.util.js.map +1 -0
  116. package/dist/index.d.ts +21 -0
  117. package/dist/index.js +14 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/logger/index.d.ts +1 -0
  120. package/dist/logger/index.js +2 -0
  121. package/dist/logger/index.js.map +1 -0
  122. package/dist/logger/logger.d.ts +30 -0
  123. package/dist/logger/logger.js +126 -0
  124. package/dist/logger/logger.js.map +1 -0
  125. package/dist/logger.util.d.ts +30 -0
  126. package/dist/logger.util.js +126 -0
  127. package/dist/logger.util.js.map +1 -0
  128. package/dist/mail/index.d.ts +1 -0
  129. package/dist/mail/index.js +2 -0
  130. package/dist/mail/index.js.map +1 -0
  131. package/dist/mail/mail.d.ts +21 -0
  132. package/dist/mail/mail.js +53 -0
  133. package/dist/mail/mail.js.map +1 -0
  134. package/dist/mail.util.d.ts +21 -0
  135. package/dist/mail.util.js +53 -0
  136. package/dist/mail.util.js.map +1 -0
  137. package/dist/middleware/index.d.ts +1 -0
  138. package/dist/middleware/index.js +2 -0
  139. package/dist/middleware/index.js.map +1 -0
  140. package/dist/middleware/middleware.d.ts +263 -0
  141. package/dist/middleware/middleware.js +233 -0
  142. package/dist/middleware/middleware.js.map +1 -0
  143. package/dist/middleware.util.d.ts +263 -0
  144. package/dist/middleware.util.js +233 -0
  145. package/dist/middleware.util.js.map +1 -0
  146. package/dist/model/index.d.ts +3 -0
  147. package/dist/model/index.js +4 -0
  148. package/dist/model/index.js.map +1 -0
  149. package/dist/model/model.d.ts +204 -0
  150. package/dist/model/model.js +1495 -0
  151. package/dist/model/model.js.map +1 -0
  152. package/dist/model.util.d.ts +204 -0
  153. package/dist/model.util.js +1495 -0
  154. package/dist/model.util.js.map +1 -0
  155. package/dist/permission/index.d.ts +1 -0
  156. package/dist/permission/index.js +2 -0
  157. package/dist/permission/index.js.map +1 -0
  158. package/dist/permission/permission.d.ts +38 -0
  159. package/dist/permission/permission.js +91 -0
  160. package/dist/permission/permission.js.map +1 -0
  161. package/dist/permission.util.d.ts +38 -0
  162. package/dist/permission.util.js +91 -0
  163. package/dist/permission.util.js.map +1 -0
  164. package/dist/registry/index.d.ts +1 -0
  165. package/dist/registry/index.js +2 -0
  166. package/dist/registry/index.js.map +1 -0
  167. package/dist/registry/registry.d.ts +28 -0
  168. package/dist/registry/registry.js +19 -0
  169. package/dist/registry/registry.js.map +1 -0
  170. package/dist/registry.util.d.ts +28 -0
  171. package/dist/registry.util.js +19 -0
  172. package/dist/registry.util.js.map +1 -0
  173. package/dist/route/index.d.ts +1 -0
  174. package/dist/route/index.js +2 -0
  175. package/dist/route/index.js.map +1 -0
  176. package/dist/route/route.d.ts +1 -0
  177. package/dist/route/route.js +12 -0
  178. package/dist/route/route.js.map +1 -0
  179. package/dist/route.util.d.ts +1 -0
  180. package/dist/route.util.js +12 -0
  181. package/dist/route.util.js.map +1 -0
  182. package/dist/storage/index.d.ts +1 -0
  183. package/dist/storage/index.js +2 -0
  184. package/dist/storage/index.js.map +1 -0
  185. package/dist/storage/storage.d.ts +56 -0
  186. package/dist/storage/storage.js +86 -0
  187. package/dist/storage/storage.js.map +1 -0
  188. package/dist/storage.util.d.ts +56 -0
  189. package/dist/storage.util.js +82 -0
  190. package/dist/storage.util.js.map +1 -0
  191. package/dist/validation/index.d.ts +1 -0
  192. package/dist/validation/index.js +2 -0
  193. package/dist/validation/index.js.map +1 -0
  194. package/dist/validation/validation.d.ts +7 -0
  195. package/dist/validation/validation.js +245 -0
  196. package/dist/validation/validation.js.map +1 -0
  197. package/dist/validation.util.d.ts +7 -0
  198. package/dist/validation.util.js +237 -0
  199. package/dist/validation.util.js.map +1 -0
  200. package/package.json +34 -0
  201. package/src/auth/auth.ts +282 -0
  202. package/src/auth/index.ts +1 -0
  203. package/src/commands/cli.ts +89 -0
  204. package/src/commands/make/basic-controller.ts +49 -0
  205. package/src/commands/make/basic-migration.ts +89 -0
  206. package/src/commands/make/basic-model.ts +32 -0
  207. package/src/commands/make/basic-seeder.ts +38 -0
  208. package/src/commands/make/blueprint.ts +36 -0
  209. package/src/commands/make/da-migration.ts +90 -0
  210. package/src/commands/make/light-controller.ts +67 -0
  211. package/src/commands/make/light-model.ts +61 -0
  212. package/src/commands/make/mail.ts +51 -0
  213. package/src/commands/make/notification.ts +43 -0
  214. package/src/commands/make/queue.ts +45 -0
  215. package/src/commands/runner/barrels.ts +85 -0
  216. package/src/commands/runner/blueprint/controller-generation.ts +194 -0
  217. package/src/commands/runner/blueprint/documentation-generation.ts +463 -0
  218. package/src/commands/runner/blueprint/migration-generation.ts +153 -0
  219. package/src/commands/runner/blueprint/model-generation.ts +149 -0
  220. package/src/commands/runner/blueprint/runner.ts +181 -0
  221. package/src/commands/runner/blueprint/seeder-generation.ts +55 -0
  222. package/src/commands/runner/da-migration.ts +333 -0
  223. package/src/commands/runner/migration.ts +245 -0
  224. package/src/commands/runner/seeder.ts +44 -0
  225. package/src/commands/stubs/index.ts +289 -0
  226. package/src/context/context.ts +17 -0
  227. package/src/context/index.ts +1 -0
  228. package/src/controller/controller.ts +240 -0
  229. package/src/controller/index.ts +1 -0
  230. package/src/conversion/conversion.ts +65 -0
  231. package/src/conversion/index.ts +1 -0
  232. package/src/index.ts +22 -0
  233. package/src/logger/index.ts +1 -0
  234. package/src/logger/logger.ts +177 -0
  235. package/src/mail/index.ts +1 -0
  236. package/src/mail/mail.ts +86 -0
  237. package/src/middleware/index.ts +1 -0
  238. package/src/middleware/middleware.ts +289 -0
  239. package/src/permission/index.ts +1 -0
  240. package/src/permission/permission.ts +136 -0
  241. package/src/registry/index.ts +1 -0
  242. package/src/registry/registry.ts +37 -0
  243. package/src/route/index.ts +1 -0
  244. package/src/route/route.ts +12 -0
  245. package/src/storage/index.ts +1 -0
  246. package/src/storage/storage.ts +107 -0
  247. package/src/validation/index.ts +1 -0
  248. package/src/validation/validation.ts +346 -0
  249. package/tsconfig.json +23 -0
@@ -0,0 +1,49 @@
1
+ import path from "path";
2
+ import { writeFileSync, mkdirSync, existsSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { basicControllerStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:controller
9
+ // =====================================>
10
+ export const makeControllerCommand = new Command("make:controller")
11
+ .argument("<name>", "Name of controller")
12
+ .description("Create new controller")
13
+ .action((controllerName) => {
14
+ const basePath = path.join(process.cwd(), "src", "controllers");
15
+
16
+ if (!controllerName || controllerName.trim() === "") {
17
+ logger.error("Controller name invalid!");
18
+ process.exit(1);
19
+ }
20
+
21
+ const names = controllerName.split("/");
22
+ const realName = names[names.length - 1];
23
+ const name = conversion.strPascal(realName) + "Controller";
24
+ const filename = conversion.strSlug(realName) + ".controller.ts";
25
+
26
+ names.pop();
27
+ const folder = names.join("/");
28
+
29
+ const filePath = folder ? path.join(basePath, folder, filename) : path.join(basePath, filename);
30
+
31
+ if (existsSync(filePath)) {
32
+ logger.error("Controller already exists!");
33
+ process.exit(1);
34
+ }
35
+
36
+ const targetDir = folder ? path.join(basePath, folder) : basePath;
37
+ if (!existsSync(targetDir)) {
38
+ mkdirSync(targetDir, { recursive: true });
39
+ logger.info(`Create folder ${targetDir}...`);
40
+ }
41
+
42
+ let content = basicControllerStub;
43
+ content = content.replace(/{{\s*name\s*}}/g, name || "");
44
+
45
+ writeFileSync(filePath, content);
46
+
47
+ logger.info(`Controller ${controllerName} created!`);
48
+ process.exit(0);
49
+ });
@@ -0,0 +1,89 @@
1
+ import path from "path";
2
+ import { writeFileSync, mkdirSync, existsSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { basicMigrationStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:migration
9
+ // =====================================>
10
+ export const makeMigrationCommand = new Command("make:migration")
11
+ .argument("<name>", "Nama migration")
12
+ .option("--init", "Buat migration init (0000_00)")
13
+ .description("Membuat file migration baru")
14
+ .action((name, options) => {
15
+ makeMigration(name, options);
16
+ });
17
+
18
+ // =====================================>
19
+ // ## Command: migration helpers
20
+ // =====================================>
21
+ export const makeMigration = (
22
+ migrationName: string,
23
+ options: { init?: boolean }
24
+ ) => {
25
+ const name = conversion.strSnake(conversion.strPlural(migrationName));
26
+
27
+ const now = new Date();
28
+
29
+ const baseDir = path.join(
30
+ process.cwd(),
31
+ "src",
32
+ "database",
33
+ "migrations"
34
+ );
35
+
36
+ let targetDir: string;
37
+ let fileName: string;
38
+
39
+ if (options.init) {
40
+ targetDir = path.join(baseDir, "0000_00");
41
+ fileName = `${name}.ts`;
42
+ } else {
43
+ const yearMonth = `${now.getFullYear()}_${String(
44
+ now.getMonth() + 1
45
+ ).padStart(2, "0")}`;
46
+
47
+ targetDir = path.join(baseDir, yearMonth);
48
+
49
+ const time = migrationPrefixFile(now);
50
+ fileName = `${time}_${name}_table.ts`;
51
+ }
52
+
53
+ if (!existsSync(targetDir)) {
54
+ mkdirSync(targetDir, { recursive: true });
55
+ }
56
+
57
+ const { className, tableName } = parseName(name);
58
+
59
+ let content = basicMigrationStub;
60
+
61
+ content = content.replace(/{{\s*className\s*}}/g, className);
62
+ content = content.replace(/{{\s*tableName\s*}}/g, tableName);
63
+
64
+ const filePath = path.join(targetDir, fileName);
65
+
66
+ writeFileSync(filePath, content);
67
+
68
+ logger.info(`Migration created: ${path.relative(baseDir, filePath)}`);
69
+
70
+ process.exit(0);
71
+ };
72
+
73
+ const migrationPrefixFile = (date: Date) => {
74
+ const d = String(date.getDate()).padStart(2, '0');
75
+ const h = String(date.getHours()).padStart(2, "0");
76
+ const m = String(date.getMinutes()).padStart(2, "0");
77
+ const s = String(date.getSeconds()).padStart(2, "0");
78
+
79
+ return `${d}_${h}${m}${s}`;
80
+ };
81
+
82
+ const parseName = (str: string) => {
83
+ const parts = str.split('_');
84
+
85
+ const className = parts.map(p => p.charAt(0).toUpperCase() + p.slice(1)).join('');
86
+ const tableName = parts.slice(1).join('_');
87
+
88
+ return { className, tableName };
89
+ };
@@ -0,0 +1,32 @@
1
+ import path from "path";
2
+ import { writeFileSync, mkdirSync, existsSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { basicModelStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:model
9
+ // =====================================>
10
+ export const makeModelCommand = new Command("make:model")
11
+ .argument("<name>", "Name of model")
12
+ .description("Membuat file model baru")
13
+ .action((modelName) => {
14
+ const name = conversion.strPascal(modelName);
15
+ const filename = conversion.strSlug(modelName) + ".model.ts";
16
+
17
+ const filePath = path.join(process.cwd(), "src", "models", filename);
18
+
19
+ if (!existsSync(path.dirname(filePath))) {
20
+ mkdirSync(path.dirname(filePath), { recursive: true });
21
+ }
22
+
23
+ let content = basicModelStub;
24
+
25
+ content = content.replace(/{{\s*name\s*}}/g, name || "");
26
+
27
+ writeFileSync(filePath, content);
28
+
29
+ logger.info(`Model ${modelName} created!`);
30
+
31
+ process.exit(0);
32
+ });
@@ -0,0 +1,38 @@
1
+ import path from "path";
2
+ import { writeFileSync, mkdirSync, existsSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { basicSeederStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:seeder
9
+ // =====================================>
10
+ export const makeSeederCommand = new Command("make:seeder")
11
+ .argument("<name>", "Name of seeder")
12
+ .option("-m, --model <model>", "Attach model to controller")
13
+ .description("Buat seeder baru")
14
+ .action((name, options) => {
15
+ makeSeeder(name, options.model);
16
+ process.exit(0);
17
+ });
18
+
19
+ export const makeSeeder = (seederName: string, model?: string) => {
20
+ const name = conversion.strPascal(seederName) + "Seeder";
21
+ const filename = conversion.strSlug(seederName) + ".seeder.ts";
22
+ const modelName = model || conversion.strPascal(seederName);
23
+
24
+ const dir = path.join(process.cwd(), "src", "database", "seeders");
25
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
26
+
27
+ const filePath = path.join(dir, filename);
28
+
29
+ let content = basicSeederStub;
30
+
31
+ content = content
32
+ .replace(/{{\s*name\s*}}/g, name || "")
33
+ .replace(/{{\s*model\s*}}/g, modelName || "");
34
+
35
+ writeFileSync(filePath, content, { flag: "w" });
36
+
37
+ logger.info(`Seeder ${name} created`);
38
+ };
@@ -0,0 +1,36 @@
1
+ import path from "path";
2
+ import { writeFileSync, existsSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { blueprintStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:blueprint
9
+ // =====================================>
10
+ export const makeBlueprintCommand = new Command("make:blueprint")
11
+ .argument("<name>", "Name of blueprint")
12
+ .description("Create new blueprint")
13
+ .action((name) => {
14
+ const basePath = path.join(process.cwd(), "src", "blueprints");
15
+
16
+ if (!name || name.trim() === "") {
17
+ logger.error("Blueprint name invalid!");
18
+ process.exit(1);
19
+ }
20
+
21
+ const filename = conversion.strSlug(name) + ".blueprint.json";
22
+
23
+ const filePath = path.join(basePath, filename);
24
+
25
+ if (existsSync(filePath)) {
26
+ logger.error("Blueprint already exists!");
27
+ process.exit(1);
28
+ }
29
+
30
+ const content = blueprintStub;
31
+
32
+ writeFileSync(filePath, content);
33
+
34
+ logger.info(`Blueprint ${filename} created!`);
35
+ process.exit(0);
36
+ });
@@ -0,0 +1,90 @@
1
+ import path from "path";
2
+ import { writeFileSync, mkdirSync, existsSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { logger } from "@utils";
5
+ import { daMigrationStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:da:migration
9
+ // =====================================>
10
+ export const makeDaMigrationCommand = new Command("make:da:migration")
11
+ .argument("<name>", "Nama migration")
12
+ .option("--init", "Buat migration init (0000_00)")
13
+ .description("Membuat file migration baru")
14
+ .action((name, options) => {
15
+ makeDaMigration(name, options);
16
+ });
17
+
18
+ export const makeDaMigration = (
19
+ migrationName: string,
20
+ options: { init?: boolean }
21
+ ) => {
22
+ const name = migrationName.toLowerCase();
23
+ const now = new Date();
24
+
25
+ const baseDir = path.join(
26
+ process.cwd(),
27
+ "src",
28
+ "database",
29
+ "da.migrations"
30
+ );
31
+
32
+ let targetDir: string;
33
+ let fileName: string;
34
+
35
+ if (options.init) {
36
+ targetDir = path.join(baseDir, "0000_00");
37
+ fileName = `${name}.ts`;
38
+ } else {
39
+ const yearMonth = `${now.getFullYear()}_${String(
40
+ now.getMonth() + 1
41
+ ).padStart(2, "0")}`;
42
+
43
+ targetDir = path.join(baseDir, yearMonth);
44
+
45
+ const time = migrationPrefixFile(now);
46
+ fileName = `${time}_${name}_table.ts`;
47
+ }
48
+
49
+ if (!existsSync(targetDir)) {
50
+ mkdirSync(targetDir, { recursive: true });
51
+ }
52
+
53
+ const { className, tableName } = parseName(name);
54
+
55
+ let content = daMigrationStub;
56
+
57
+ content = content.replace(/{{\s*className\s*}}/g, className);
58
+ content = content.replace(/{{\s*tableName\s*}}/g, tableName);
59
+
60
+ const filePath = path.join(targetDir, fileName);
61
+
62
+ writeFileSync(filePath, content);
63
+
64
+ logger.info(
65
+ `DA Migration created: ${path.relative(baseDir, filePath)}`
66
+ );
67
+
68
+ process.exit(0);
69
+ };
70
+
71
+ // =====================================>
72
+ // ## Command: migration helpers
73
+ // =====================================>
74
+ const migrationPrefixFile = (date: Date) => {
75
+ const d = String(date.getDate()).padStart(2, '0');
76
+ const h = String(date.getHours()).padStart(2, "0");
77
+ const m = String(date.getMinutes()).padStart(2, "0");
78
+ const s = String(date.getSeconds()).padStart(2, "0");
79
+
80
+ return `${d}_${h}${m}${s}`;
81
+ };
82
+
83
+ const parseName = (str: string) => {
84
+ const parts = str.split('_');
85
+
86
+ const className = parts.map(p => p.charAt(0).toUpperCase() + p.slice(1)).join('');
87
+ const tableName = parts.slice(1).join('_');
88
+
89
+ return { className, tableName };
90
+ };
@@ -0,0 +1,67 @@
1
+ import path from "path";
2
+ import { writeFileSync, mkdirSync, existsSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { lightControllerStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:light-controller
9
+ // =====================================>
10
+ export const makeLightControllerCommand = new Command("make:light-controller")
11
+ .argument("<name>", "Name of controller")
12
+ .option("-m, --model <model>", "Attach model to controller")
13
+ .description("Make the Light Controller")
14
+ .action((name, options) => {
15
+ makeLightController(name, options.model);
16
+ process.exit(0);
17
+ });
18
+
19
+ export const makeLightController = (controllerName: string, modelName?: string) => {
20
+ const basePath = path.join(process.cwd(), "src", "controllers");
21
+
22
+ if (!controllerName || controllerName.trim() === "") {
23
+ logger.error("Controller name invalid!");
24
+ process.exit(1);
25
+ }
26
+
27
+ const names = controllerName.split("/");
28
+ const realName = names[names.length - 1];
29
+ const name = conversion.strPascal(realName) + "Controller";
30
+ const filename = conversion.strSlug(realName) + ".controller.ts";
31
+ const model = modelName || conversion.strPascal(realName);
32
+
33
+ names.pop();
34
+ const folder = names.join("/");
35
+
36
+ const filePath = path.join(basePath, filename);
37
+
38
+ if (existsSync(filePath)) {
39
+ logger.error("Controller already exists!");
40
+ process.exit(1);
41
+ }
42
+
43
+ const targetDir = folder ? path.join(basePath, folder) : basePath;
44
+ if (!existsSync(targetDir)) {
45
+ mkdirSync(targetDir, { recursive: true });
46
+ logger.info(`Create folder ${targetDir}...`);
47
+ }
48
+
49
+ let stub = lightControllerStub;
50
+
51
+ stub = stub.replace(
52
+ /{{\s*name\s*}}|{{\s*model\s*}}|{{\s*validations\s*}}|{{\s*marker\s*}}/g,
53
+ (match) => {
54
+ switch (match) {
55
+ case "{{ name }}":
56
+ return name;
57
+ case "{{ model }}":
58
+ return model;
59
+ default:
60
+ return "";
61
+ }
62
+ }
63
+ );
64
+
65
+ writeFileSync(filePath, stub);
66
+ logger.info(`Successfully create light controller: ${filePath}!`);
67
+ };
@@ -0,0 +1,61 @@
1
+ import path from "path";
2
+ import { writeFileSync, mkdirSync, existsSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { makeLightController } from "./light-controller";
6
+ import { makeMigration } from "./basic-migration";
7
+ import { makeSeeder } from "./basic-seeder";
8
+ import { lightModelStub } from "../stubs";
9
+
10
+ // =====================================>
11
+ // ## Command: make:light-model
12
+ // =====================================>
13
+ export const makeLightModelCommand = new Command("make:light-model")
14
+ .argument("<name>", "Name of model")
15
+ .option("-r", "Generate all resource (controller, migration, seeder)")
16
+ .description("Make the Light Model")
17
+ .action((name, options) => {
18
+ makeLightModel(name);
19
+
20
+ if (options.r) {
21
+ makeLightController(name);
22
+ makeMigration("create_" + name, { init: true });
23
+ makeSeeder(name);
24
+ }
25
+
26
+ process.exit(0);
27
+ });
28
+
29
+ export const makeLightModel = (modelName: string) => {
30
+ const name = conversion.strPascal(modelName);
31
+ const filename = conversion.strSlug(modelName) + ".model.ts";
32
+
33
+ const basePath = path.join(process.cwd(), "src", "models");
34
+
35
+ if (!existsSync(basePath)) {
36
+ mkdirSync(basePath, { recursive: true });
37
+ }
38
+
39
+ const filePath = path.join(basePath, filename);
40
+
41
+ if (existsSync(filePath)) {
42
+ logger.error(`Model ${name} already exists!`);
43
+ return;
44
+ }
45
+
46
+ let stub = lightModelStub;
47
+
48
+ stub = stub
49
+ .replace(/{{\s*name\s*}}/g, name)
50
+ .replace(/{{\s*fields\s*}}/g, "")
51
+ .replace(/{{\s*attributes\s*}}/g, "")
52
+ .replace(/{{\s*relations\s*}}/g, "")
53
+ .replace(/{{\s*hooks\s*}}/g, "")
54
+ .replace(/{{\s*import\s*}}/g, "")
55
+ .replace(/{{\s*import_utils\s*}}/g, "")
56
+ .replace(/{{\s*marker\s*}}/g, "");
57
+
58
+ writeFileSync(filePath, stub);
59
+
60
+ logger.info(`Successfully create light model ${name}!`);
61
+ };
@@ -0,0 +1,51 @@
1
+ import path from "path";
2
+ import { writeFileSync, existsSync, mkdirSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { mailStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:mail
9
+ // =====================================>
10
+ export const makeMailCommand = new Command("make:mail")
11
+ .argument("<name>", "Name of mail")
12
+ .description("Create new mail")
13
+ .action((name) => {
14
+ const basePath = path.join(process.cwd(), "src", "outputs", "mails");
15
+ const templatePath = path.join(process.cwd(), "src", "outputs", "mails", "templates");
16
+
17
+ if (!name || name.trim() === "") {
18
+ logger.error("Mail name invalid!");
19
+ process.exit(1);
20
+ }
21
+
22
+ const filename = conversion.strSlug(name) + ".mail.ts";
23
+ const templateName = conversion.strSlug(name) + ".mail.stub";
24
+
25
+ const filePath = path.join(basePath, filename);
26
+
27
+ if (existsSync(filePath)) {
28
+ logger.error("Mail already exists!");
29
+ process.exit(1);
30
+ }
31
+
32
+ if (!existsSync(basePath)) {
33
+ mkdirSync(basePath, { recursive: true });
34
+ }
35
+ if (!existsSync(templatePath)) {
36
+ mkdirSync(templatePath, { recursive: true });
37
+ }
38
+
39
+ let content = mailStub;
40
+
41
+ content = content
42
+ .replace(/{{\s*name\s*}}/g, conversion.strCamel(name) || "")
43
+ .replace(/{{\s*title\s*}}/g, conversion.strPascal(name, " ") || "");
44
+
45
+ writeFileSync(filePath, content);
46
+ writeFileSync(path.join(templatePath, templateName), "");
47
+
48
+ logger.info(`Mail ${filename} created!`);
49
+
50
+ process.exit(0);
51
+ });
@@ -0,0 +1,43 @@
1
+ import path from "path";
2
+ import { writeFileSync, existsSync, mkdirSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { notificationStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:notification
9
+ // =====================================>
10
+ export const makeNotificationCommand = new Command("make:notification")
11
+ .argument("<name>", "Name of notification")
12
+ .description("Create new notification")
13
+ .action((name) => {
14
+ const basePath = path.join(process.cwd(), "src", "outputs", "notifications");
15
+
16
+ if (!name || name.trim() === "") {
17
+ logger.error("Notification name invalid!");
18
+ process.exit(1);
19
+ }
20
+
21
+ const filename = conversion.strSlug(name) + ".notification.ts";
22
+
23
+ const filePath = path.join(basePath, filename);
24
+
25
+ if (existsSync(filePath)) {
26
+ logger.error("Notification already exists!");
27
+ process.exit(1);
28
+ }
29
+
30
+ if (!existsSync(basePath)) {
31
+ mkdirSync(basePath, { recursive: true });
32
+ }
33
+
34
+ let content = notificationStub;
35
+
36
+ content = content.replace(/{{\s*name\s*}}/g, conversion.strCamel(name) || "");
37
+
38
+ writeFileSync(filePath, content);
39
+
40
+ logger.info(`Notification ${filename} created!`);
41
+
42
+ process.exit(0);
43
+ });
@@ -0,0 +1,45 @@
1
+ import path from "path";
2
+ import { writeFileSync, existsSync, mkdirSync } from "fs";
3
+ import { Command } from "commander";
4
+ import { conversion, logger } from "@utils";
5
+ import { queueStub } from "../stubs";
6
+
7
+ // =====================================>
8
+ // ## Command: make:queue
9
+ // =====================================>
10
+ export const makeQueueCommand = new Command("make:queue")
11
+ .argument("<name>", "Name of queue")
12
+ .description("Create new queue")
13
+ .action((name) => {
14
+ const basePath = path.join(process.cwd(), "src", "jobs", "queues");
15
+
16
+ if (!name || name.trim() === "") {
17
+ logger.error("Queue name invalid!");
18
+ process.exit(1);
19
+ }
20
+
21
+ const filename = conversion.strSlug(name) + ".queue.worker.ts";
22
+
23
+ const filePath = path.join(basePath, filename);
24
+
25
+ if (existsSync(filePath)) {
26
+ logger.error("Queue already exists!");
27
+ process.exit(1);
28
+ }
29
+
30
+ if (!existsSync(basePath)) {
31
+ mkdirSync(basePath, { recursive: true });
32
+ }
33
+
34
+ let content = queueStub;
35
+
36
+ content = content
37
+ .replace(/{{\s*name\s*}}/g, conversion.strCamel(name) || "")
38
+ .replace(/{{\s*worker_name\s*}}/g, conversion.strSlug(name, " ") || "");
39
+
40
+ writeFileSync(filePath, content);
41
+
42
+ logger.info(`Queue ${filename} created!`);
43
+
44
+ process.exit(0);
45
+ });