create-craftjs 1.0.14 → 1.0.16

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 (38) hide show
  1. package/bin/index.js +9 -2
  2. package/package.json +1 -1
  3. package/template/craft/commands/db-seed.js +22 -0
  4. package/template/craft/commands/key-generate.js +12 -1
  5. package/template/craft.js +10 -1
  6. package/template/package-lock.json +935 -59
  7. package/template/package.json +4 -6
  8. package/template/prisma/migrations/20250518142257_create_table_users/migration.sql +1 -1
  9. package/template/prisma/migrations/20260118135332_create_table_auth_refresh_tokens/migration.sql +16 -0
  10. package/template/prisma/schema.prisma +20 -5
  11. package/template/prisma/seed.ts +4 -5
  12. package/template/prisma.config.ts +12 -0
  13. package/template/src/apidocs/auth-docs.ts +8 -28
  14. package/template/src/apidocs/users-docs.ts +87 -57
  15. package/template/src/config/database.ts +13 -3
  16. package/template/src/config/env.ts +7 -1
  17. package/template/src/config/logger.ts +2 -2
  18. package/template/src/controllers/auth-controller.ts +10 -4
  19. package/template/src/controllers/user-controller.ts +21 -17
  20. package/template/src/dtos/pagination-dto.ts +21 -0
  21. package/template/src/dtos/user-dto.ts +37 -16
  22. package/template/src/main.ts +2 -7
  23. package/template/src/middleware/auth-middleware.ts +41 -34
  24. package/template/src/repositories/auth-token-repository.ts +25 -0
  25. package/template/src/repositories/user-repository.ts +20 -9
  26. package/template/src/routes/auth-route.ts +3 -12
  27. package/template/src/routes/user-route.ts +5 -29
  28. package/template/src/services/auth-service.ts +56 -41
  29. package/template/src/services/user-service.ts +60 -30
  30. package/template/src/utils/cookieEncrypt.ts +39 -0
  31. package/template/src/utils/pagination.ts +32 -0
  32. package/template/src/utils/response.ts +9 -31
  33. package/template/src/utils/swagger.ts +10 -9
  34. package/template/src/utils/validation.ts +8 -1
  35. package/template/src/validations/user-validation.ts +25 -27
  36. package/template/test/user.test.ts +2 -2
  37. package/template/tsconfig.json +3 -2
  38. package/template/src/dtos/list-dto.ts +0 -12
package/bin/index.js CHANGED
@@ -82,14 +82,21 @@ const ask = (question) => {
82
82
 
83
83
  const envContent = `APP_NAME="${projectName}"
84
84
  APP_SECRET=
85
+ BASE_URL="http://localhost:4444"
86
+ BASE_API_URL="http://localhost:4444/api"
85
87
  NODE_ENV="development"
86
88
  TZ="Asia/Jakarta"
87
89
  DATETIME_FORMAT="dd-MM-yyyy HH:mm:ss"
88
90
  DATABASE_URL="mysql://root:@localhost:3306/${projectName}"
89
- BASE_URL="http://localhost:4444"
90
- BASE_API_URL="http://localhost:4444/api"
91
+ DATABASE_USER="root"
92
+ DATABASE_PASSWORD=""
93
+ DATABASE_NAME="${projectName}"
94
+ DATABASE_HOST="localhost"
95
+ DATABASE_PORT=3306
96
+ DATABASE_CONNECTION_LIMIT=5
91
97
  PORT=4444
92
98
  JWT_SECRET=
99
+ COOKIE_ENCRYPTION_KEY=
93
100
  `;
94
101
 
95
102
  const envExampleContent = envContent.replace(/=.*/g, "=");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-craftjs",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "A starter kit backend framework powered by Express, TypeScript, EJS Engine, and Prisma — designed for rapid development, simplicity, and scalability.",
5
5
  "bin": {
6
6
  "create-craftjs": "bin/index.js"
@@ -0,0 +1,22 @@
1
+ const { spawnSync } = require("child_process");
2
+ const chalk = require("chalk");
3
+
4
+ function DbSeed() {
5
+ console.log(chalk.blue("🚀 Running prisma seeder..."));
6
+
7
+ const result = spawnSync("npx", ["prisma", "db", "seed"], {
8
+ stdio: "inherit",
9
+ shell: true,
10
+ });
11
+
12
+ if (result.status !== 0) {
13
+ console.error(chalk.red("❌ Seeder failed."));
14
+ if (result.error) {
15
+ console.error(chalk.red(`Error: ${result.error.message}`));
16
+ }
17
+ process.exit(result.status ?? 1);
18
+ } else {
19
+ console.log(chalk.green("✅ Seeding completed."));
20
+ }
21
+ }
22
+ module.exports = DbSeed;
@@ -32,10 +32,21 @@ function keyGenerate() {
32
32
  envContent += `\APP_SECRET=${generateKey(32)}`;
33
33
  }
34
34
 
35
+ if (envContent.includes("COOKIE_ENCRYPTION_KEY=")) {
36
+ envContent = envContent.replace(
37
+ /COOKIE_ENCRYPTION_KEY=.*/g,
38
+ `COOKIE_ENCRYPTION_KEY=${generateKey(32)}`
39
+ );
40
+ } else {
41
+ envContent += `\COOKIE_ENCRYPTION_KEY=${generateKey(32)}`;
42
+ }
43
+
35
44
  fs.writeFileSync(envPath, envContent);
36
45
 
37
46
  console.log(
38
- chalk.green("✅ App Secret and JWT Secret generated successfully.")
47
+ chalk.green(
48
+ "✅ App Secret, JWT Secret , and Cookie Encryption Key generated successfully."
49
+ )
39
50
  );
40
51
  }
41
52
  module.exports = keyGenerate;
package/template/craft.js CHANGED
@@ -22,6 +22,15 @@ yargs(hideBin(process.argv))
22
22
  dbgenerate();
23
23
  }
24
24
  )
25
+ .command(
26
+ "db:seed",
27
+ "Running prisma db seed",
28
+ () => {},
29
+ () => {
30
+ const dbgenerate = require("./craft/commands/db-seed.js");
31
+ dbgenerate();
32
+ }
33
+ )
25
34
  .command(
26
35
  "db:migrate",
27
36
  "Running prisma migration",
@@ -241,7 +250,7 @@ yargs(hideBin(process.argv))
241
250
  start();
242
251
  }
243
252
  )
244
- .command(
253
+ .command(
245
254
  "build:docker",
246
255
  "Docker build for production",
247
256
  () => {},