create-craftjs 1.0.3 → 1.0.5

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 (68) hide show
  1. package/README.md +137 -137
  2. package/bin/index.js +158 -158
  3. package/package.json +24 -24
  4. package/template/Dockerfile +57 -12
  5. package/template/babel.config.json +3 -3
  6. package/template/craft/commands/build.js +16 -15
  7. package/template/craft/commands/db-fresh.js +22 -22
  8. package/template/craft/commands/db-generate.js +23 -23
  9. package/template/craft/commands/db-migrate.js +22 -22
  10. package/template/craft/commands/dev.js +16 -16
  11. package/template/craft/commands/key-generate.js +41 -41
  12. package/template/craft/commands/make-apidocs.js +121 -121
  13. package/template/craft/commands/make-command.js +38 -38
  14. package/template/craft/commands/make-controller.js +95 -71
  15. package/template/craft/commands/make-dto.js +39 -39
  16. package/template/craft/commands/make-middleware.js +46 -46
  17. package/template/craft/commands/make-repository.js +36 -36
  18. package/template/craft/commands/make-route.js +92 -88
  19. package/template/craft/commands/make-service.js +39 -39
  20. package/template/craft/commands/make-test.js +48 -48
  21. package/template/craft/commands/make-utils.js +30 -30
  22. package/template/craft/commands/make-validation.js +42 -42
  23. package/template/craft/commands/make-view.js +42 -42
  24. package/template/craft/commands/start.js +29 -29
  25. package/template/craft/commands/test.js +20 -20
  26. package/template/craft.js +256 -256
  27. package/template/docker-compose.yml +8 -0
  28. package/template/nodemon.json +6 -6
  29. package/template/package-lock.json +8877 -8877
  30. package/template/package.json +84 -84
  31. package/template/prisma/schema.prisma +22 -22
  32. package/template/prisma/seed.ts +29 -29
  33. package/template/src/apidocs/auth-docs.ts +314 -314
  34. package/template/src/apidocs/users-docs.ts +240 -240
  35. package/template/src/config/cloudinary.ts +21 -21
  36. package/template/src/config/database.ts +90 -90
  37. package/template/src/config/env.ts +67 -67
  38. package/template/src/config/logger.ts +139 -139
  39. package/template/src/config/nodemailer.ts +23 -23
  40. package/template/src/config/web.ts +47 -47
  41. package/template/src/controllers/auth-controller.ts +88 -88
  42. package/template/src/controllers/user-controller.ts +79 -79
  43. package/template/src/dtos/list-dto.ts +12 -12
  44. package/template/src/dtos/user-dto.ts +57 -57
  45. package/template/src/main.ts +28 -28
  46. package/template/src/middleware/auth-middleware.ts +44 -44
  47. package/template/src/middleware/error-middleware.ts +27 -27
  48. package/template/src/middleware/http-logger-middleware.ts +31 -31
  49. package/template/src/repositories/user-repository.ts +75 -75
  50. package/template/src/routes/auth-route.ts +20 -20
  51. package/template/src/routes/main-route.ts +25 -25
  52. package/template/src/routes/user-route.ts +35 -35
  53. package/template/src/services/auth-service.ts +162 -162
  54. package/template/src/services/user-service.ts +102 -102
  55. package/template/src/types/type-request.ts +6 -6
  56. package/template/src/utils/async-handler.ts +9 -9
  57. package/template/src/utils/response-error.ts +10 -10
  58. package/template/src/utils/response.ts +60 -60
  59. package/template/src/utils/swagger.ts +135 -135
  60. package/template/src/utils/validation.ts +7 -7
  61. package/template/src/validations/user-validation.ts +127 -127
  62. package/template/src/views/index.ejs +6 -6
  63. package/template/src/views/layouts/main.ejs +14 -14
  64. package/template/src/views/partials/header.ejs +3 -3
  65. package/template/test/user.test.ts +16 -16
  66. package/template/tsconfig.json +13 -13
  67. package/template/.dockerignore +0 -4
  68. package/template/src/controllers/sass-controller.ts +0 -24
@@ -1,39 +1,39 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const chalk = require("chalk");
4
-
5
- const toPascalCase = (str) =>
6
- str.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase());
7
-
8
- function makeService(name) {
9
- if (!name) {
10
- console.log(chalk.red("❌ Please provide a service name."));
11
- return;
12
- }
13
-
14
- const className = `${toPascalCase(name)}Service`;
15
- const fileName = `${name.toLowerCase()}-service.ts`;
16
- const targetDir = path.resolve("src", "services");
17
-
18
- if (!fs.existsSync(targetDir)) {
19
- fs.mkdirSync(targetDir, { recursive: true });
20
- }
21
-
22
- const filePath = path.join(targetDir, fileName);
23
- if (fs.existsSync(filePath)) {
24
- console.log(chalk.yellow("⚠️ Service already exists."));
25
- return;
26
- }
27
-
28
- const content = `export class ${className} {
29
- async doSomething() {
30
- return "Service ${className} is working";
31
- }
32
- }
33
- `;
34
-
35
- fs.writeFileSync(filePath, content);
36
- console.log(chalk.green(`✅ Service created at ${filePath}`));
37
- }
38
-
39
- module.exports = makeService;
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const chalk = require("chalk");
4
+
5
+ const toPascalCase = (str) =>
6
+ str.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase());
7
+
8
+ function makeService(name) {
9
+ if (!name) {
10
+ console.log(chalk.red("❌ Please provide a service name."));
11
+ return;
12
+ }
13
+
14
+ const className = `${toPascalCase(name)}Service`;
15
+ const fileName = `${name.toLowerCase()}-service.ts`;
16
+ const targetDir = path.resolve("src", "services");
17
+
18
+ if (!fs.existsSync(targetDir)) {
19
+ fs.mkdirSync(targetDir, { recursive: true });
20
+ }
21
+
22
+ const filePath = path.join(targetDir, fileName);
23
+ if (fs.existsSync(filePath)) {
24
+ console.log(chalk.yellow("⚠️ Service already exists."));
25
+ return;
26
+ }
27
+
28
+ const content = `export class ${className} {
29
+ async doSomething() {
30
+ return "Service ${className} is working";
31
+ }
32
+ }
33
+ `;
34
+
35
+ fs.writeFileSync(filePath, content);
36
+ console.log(chalk.green(`✅ Service created at ${filePath}`));
37
+ }
38
+
39
+ module.exports = makeService;
@@ -1,48 +1,48 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const chalk = require("chalk");
4
-
5
- function MakeTest(name) {
6
- if (!name) {
7
- console.log(chalk.red("❌ Please provide a test file name."));
8
- process.exit(1);
9
- }
10
-
11
- const testDir = path.resolve(process.cwd(), "test");
12
- if (!fs.existsSync(testDir)) {
13
- fs.mkdirSync(testDir, { recursive: true });
14
- }
15
-
16
- const fileName = name.endsWith(".test.ts") ? name : `${name}.test.ts`;
17
- const filePath = path.join(testDir, fileName);
18
-
19
- if (fs.existsSync(filePath)) {
20
- console.log(chalk.red(`❌ Test file already exists: ${fileName}`));
21
- process.exit(1);
22
- }
23
-
24
- const template = `import supertest from "supertest";
25
- import { web } from "../src/application/web";
26
- import { logger } from "../src/application/logging";
27
-
28
- // example
29
- describe("POST /api/users", () => {
30
- it("should register new user", async () => {
31
- const response = await supertest(web).post("/api/auth/register").send({
32
- fullName: "test",
33
- email: "testing@gmail.com",
34
- password: "12345678",
35
- });
36
- logger.debug(response.body);
37
- expect(response.status).toBe(201);
38
- expect(response.body.data.fullName).toBe("test");
39
- expect(response.body.data.email).toBe("testing@gmail.com");
40
- });
41
- });
42
- `;
43
-
44
- fs.writeFileSync(filePath, template, "utf-8");
45
- console.log(chalk.green(`✅ Test file created at: ${filePath}`));
46
- }
47
-
48
- module.exports = MakeTest;
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const chalk = require("chalk");
4
+
5
+ function MakeTest(name) {
6
+ if (!name) {
7
+ console.log(chalk.red("❌ Please provide a test file name."));
8
+ process.exit(1);
9
+ }
10
+
11
+ const testDir = path.resolve(process.cwd(), "test");
12
+ if (!fs.existsSync(testDir)) {
13
+ fs.mkdirSync(testDir, { recursive: true });
14
+ }
15
+
16
+ const fileName = name.endsWith(".test.ts") ? name : `${name}.test.ts`;
17
+ const filePath = path.join(testDir, fileName);
18
+
19
+ if (fs.existsSync(filePath)) {
20
+ console.log(chalk.red(`❌ Test file already exists: ${fileName}`));
21
+ process.exit(1);
22
+ }
23
+
24
+ const template = `import supertest from "supertest";
25
+ import { web } from "../src/application/web";
26
+ import { logger } from "../src/application/logging";
27
+
28
+ // example
29
+ describe("POST /api/users", () => {
30
+ it("should register new user", async () => {
31
+ const response = await supertest(web).post("/api/auth/register").send({
32
+ fullName: "test",
33
+ email: "testing@gmail.com",
34
+ password: "12345678",
35
+ });
36
+ logger.debug(response.body);
37
+ expect(response.status).toBe(201);
38
+ expect(response.body.data.fullName).toBe("test");
39
+ expect(response.body.data.email).toBe("testing@gmail.com");
40
+ });
41
+ });
42
+ `;
43
+
44
+ fs.writeFileSync(filePath, template, "utf-8");
45
+ console.log(chalk.green(`✅ Test file created at: ${filePath}`));
46
+ }
47
+
48
+ module.exports = MakeTest;
@@ -1,30 +1,30 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const chalk = require("chalk");
4
-
5
- function makeUtils(name) {
6
- if (!name) {
7
- console.log(chalk.red("❌ Please provide a utils name."));
8
- return;
9
- }
10
-
11
- const fileName = `${name.toLowerCase()}.ts`;
12
- const targetDir = path.resolve("src", "utils");
13
-
14
- if (!fs.existsSync(targetDir)) {
15
- fs.mkdirSync(targetDir, { recursive: true });
16
- }
17
-
18
- const filePath = path.join(targetDir, fileName);
19
- if (fs.existsSync(filePath)) {
20
- console.log(chalk.yellow("⚠️ Utils already exists."));
21
- return;
22
- }
23
-
24
- const content = ``;
25
-
26
- fs.writeFileSync(filePath, content);
27
- console.log(chalk.green(`✅ Utils created at ${filePath}`));
28
- }
29
-
30
- module.exports = makeUtils;
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const chalk = require("chalk");
4
+
5
+ function makeUtils(name) {
6
+ if (!name) {
7
+ console.log(chalk.red("❌ Please provide a utils name."));
8
+ return;
9
+ }
10
+
11
+ const fileName = `${name.toLowerCase()}.ts`;
12
+ const targetDir = path.resolve("src", "utils");
13
+
14
+ if (!fs.existsSync(targetDir)) {
15
+ fs.mkdirSync(targetDir, { recursive: true });
16
+ }
17
+
18
+ const filePath = path.join(targetDir, fileName);
19
+ if (fs.existsSync(filePath)) {
20
+ console.log(chalk.yellow("⚠️ Utils already exists."));
21
+ return;
22
+ }
23
+
24
+ const content = ``;
25
+
26
+ fs.writeFileSync(filePath, content);
27
+ console.log(chalk.green(`✅ Utils created at ${filePath}`));
28
+ }
29
+
30
+ module.exports = makeUtils;
@@ -1,42 +1,42 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const chalk = require("chalk");
4
-
5
- const toPascalCase = (str) =>
6
- str.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase());
7
-
8
- function makeValidation(name) {
9
- if (!name) {
10
- console.log(chalk.red("❌ Please provide a validation name."));
11
- return;
12
- }
13
-
14
- const className = `${toPascalCase(name)}Validation`;
15
- const fileName = `${name.toLowerCase()}-validation.ts`;
16
- const targetDir = path.resolve("src", "validations");
17
-
18
- if (!fs.existsSync(targetDir)) {
19
- fs.mkdirSync(targetDir, { recursive: true });
20
- }
21
-
22
- const filePath = path.join(targetDir, fileName);
23
- if (fs.existsSync(filePath)) {
24
- console.log(chalk.yellow("⚠️ Validation already exists."));
25
- return;
26
- }
27
-
28
- const content = `import { z, ZodType } from "zod";
29
-
30
- export class ${className} {
31
- static readonly CREATE: ZodType = z.object({
32
- field1: z.string().min(1, { message: "Field1 wajib diisi" }),
33
- field2: z.number().optional(),
34
- });
35
-
36
- }
37
- `;
38
-
39
- fs.writeFileSync(filePath, content);
40
- console.log(chalk.green(`✅ Validation created at ${filePath}`));
41
- }
42
- module.exports = makeValidation;
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const chalk = require("chalk");
4
+
5
+ const toPascalCase = (str) =>
6
+ str.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase());
7
+
8
+ function makeValidation(name) {
9
+ if (!name) {
10
+ console.log(chalk.red("❌ Please provide a validation name."));
11
+ return;
12
+ }
13
+
14
+ const className = `${toPascalCase(name)}Validation`;
15
+ const fileName = `${name.toLowerCase()}-validation.ts`;
16
+ const targetDir = path.resolve("src", "validations");
17
+
18
+ if (!fs.existsSync(targetDir)) {
19
+ fs.mkdirSync(targetDir, { recursive: true });
20
+ }
21
+
22
+ const filePath = path.join(targetDir, fileName);
23
+ if (fs.existsSync(filePath)) {
24
+ console.log(chalk.yellow("⚠️ Validation already exists."));
25
+ return;
26
+ }
27
+
28
+ const content = `import { z, ZodType } from "zod";
29
+
30
+ export class ${className} {
31
+ static readonly CREATE: ZodType = z.object({
32
+ field1: z.string().min(1, { message: "Field1 wajib diisi" }),
33
+ field2: z.number().optional(),
34
+ });
35
+
36
+ }
37
+ `;
38
+
39
+ fs.writeFileSync(filePath, content);
40
+ console.log(chalk.green(`✅ Validation created at ${filePath}`));
41
+ }
42
+ module.exports = makeValidation;
@@ -1,42 +1,42 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const chalk = require("chalk");
4
-
5
- function makeView(name) {
6
- if (!name) {
7
- console.log(chalk.red("❌ Please provide a view name."));
8
- return;
9
- }
10
-
11
- const fileName = `${name.toLowerCase()}.ejs`;
12
- const targetDir = path.resolve("src", "views");
13
-
14
- if (!fs.existsSync(targetDir)) {
15
- fs.mkdirSync(targetDir, { recursive: true });
16
- }
17
-
18
- const filePath = path.join(targetDir, fileName);
19
- if (fs.existsSync(filePath)) {
20
- console.log(chalk.yellow("⚠️ View already exists."));
21
- return;
22
- }
23
-
24
- const content = `<!DOCTYPE html>
25
- <html lang="en">
26
- <head>
27
- <meta charset="UTF-8" />
28
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
29
- <title><%= title %></title>
30
- </head>
31
- <body
32
- <p>${name}</p>
33
- </body>
34
- </html>
35
- }
36
- `;
37
-
38
- fs.writeFileSync(filePath, content);
39
- console.log(chalk.green(`✅ View created at ${filePath}`));
40
- }
41
-
42
- module.exports = makeView;
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const chalk = require("chalk");
4
+
5
+ function makeView(name) {
6
+ if (!name) {
7
+ console.log(chalk.red("❌ Please provide a view name."));
8
+ return;
9
+ }
10
+
11
+ const fileName = `${name.toLowerCase()}.ejs`;
12
+ const targetDir = path.resolve("src", "views");
13
+
14
+ if (!fs.existsSync(targetDir)) {
15
+ fs.mkdirSync(targetDir, { recursive: true });
16
+ }
17
+
18
+ const filePath = path.join(targetDir, fileName);
19
+ if (fs.existsSync(filePath)) {
20
+ console.log(chalk.yellow("⚠️ View already exists."));
21
+ return;
22
+ }
23
+
24
+ const content = `<!DOCTYPE html>
25
+ <html lang="en">
26
+ <head>
27
+ <meta charset="UTF-8" />
28
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
29
+ <title><%= title %></title>
30
+ </head>
31
+ <body
32
+ <p>${name}</p>
33
+ </body>
34
+ </html>
35
+ }
36
+ `;
37
+
38
+ fs.writeFileSync(filePath, content);
39
+ console.log(chalk.green(`✅ View created at ${filePath}`));
40
+ }
41
+
42
+ module.exports = makeView;
@@ -1,29 +1,29 @@
1
- const { spawnSync } = require("child_process");
2
- const chalk = require("chalk");
3
- const fs = require("fs");
4
- const path = require("path");
5
-
6
- function Start() {
7
- const entryPoint = path.resolve("dist/main.js");
8
-
9
- if (!fs.existsSync(entryPoint)) {
10
- console.error(
11
- chalk.red(
12
- `❌ Build file not found: ${entryPoint}\nPlease run 'node craft build' before starting the production server.`
13
- )
14
- );
15
- process.exit(1);
16
- }
17
-
18
- console.log(chalk.blue("🚀 Starting production server...."));
19
- const result = spawnSync("node", [entryPoint], {
20
- stdio: "inherit",
21
- shell: true,
22
- });
23
-
24
- if (result.status !== 0) {
25
- console.error(chalk.red("❌ Failed to start production server."));
26
- process.exit(result.status ?? 1);
27
- }
28
- }
29
- module.exports = Start;
1
+ const { spawnSync } = require("child_process");
2
+ const chalk = require("chalk");
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ function Start() {
7
+ const entryPoint = path.resolve("dist/main.js");
8
+
9
+ if (!fs.existsSync(entryPoint)) {
10
+ console.error(
11
+ chalk.red(
12
+ `❌ Build file not found: ${entryPoint}\nPlease run 'node craft build' before starting the production server.`
13
+ )
14
+ );
15
+ process.exit(1);
16
+ }
17
+
18
+ console.log(chalk.blue("🚀 Starting production server...."));
19
+ const result = spawnSync("node", [entryPoint], {
20
+ stdio: "inherit",
21
+ shell: true,
22
+ });
23
+
24
+ if (result.status !== 0) {
25
+ console.error(chalk.red("❌ Failed to start production server."));
26
+ process.exit(result.status ?? 1);
27
+ }
28
+ }
29
+ module.exports = Start;
@@ -1,20 +1,20 @@
1
- const { spawnSync } = require("child_process");
2
- const chalk = require("chalk");
3
-
4
- function RunTest() {
5
- console.log(chalk.blue("🧪 Running tests..."));
6
-
7
- const result = spawnSync("npx", ["jest", "-i"], {
8
- stdio: "inherit",
9
- shell: true,
10
- });
11
-
12
- if (result.status !== 0) {
13
- console.error(chalk.red("❌ Tests failed."));
14
- process.exit(result.status ?? 1);
15
- } else {
16
- console.log(chalk.green("✅ Tests passed."));
17
- }
18
- }
19
-
20
- module.exports = RunTest;
1
+ const { spawnSync } = require("child_process");
2
+ const chalk = require("chalk");
3
+
4
+ function RunTest() {
5
+ console.log(chalk.blue("🧪 Running tests..."));
6
+
7
+ const result = spawnSync("npx", ["jest", "-i"], {
8
+ stdio: "inherit",
9
+ shell: true,
10
+ });
11
+
12
+ if (result.status !== 0) {
13
+ console.error(chalk.red("❌ Tests failed."));
14
+ process.exit(result.status ?? 1);
15
+ } else {
16
+ console.log(chalk.green("✅ Tests passed."));
17
+ }
18
+ }
19
+
20
+ module.exports = RunTest;