cleancode-e 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  ## Apa itu cleancode-e?
16
16
 
17
- `cleancode-e` adalah CLI generator yang men-scaffold project backend [Fastify](https://fastify.dev) secara interaktif — lengkap dengan struktur folder siap produksi, pilihan database (MongoDB / MySQL / tanpa database), dan auto-install dependency.
17
+ `cleancode-e` adalah CLI generator yang men-scaffold project backend [Fastify](https://fastify.dev) secara interaktif — lengkap dengan struktur folder siap produksi, pilihan database (MongoDB / MySQL / tanpa database), pilihan dokumentasi API (Swagger UI / Scalar), dan auto-install dependency.
18
18
 
19
19
  Terinspirasi dari Artisan (Laravel) dan Create-React-App, tapi untuk ekosistem **Node.js + Fastify**.
20
20
 
@@ -56,6 +56,10 @@ Ikuti prompt interaktifnya:
56
56
  ◇ Pakai nodemon untuk auto-reload saat development?
57
57
  │ ● Ya ○ Tidak
58
58
 
59
+ ◇ Pilih dokumentasi API:
60
+ │ ● Swagger UI (akses via /docs)
61
+ │ ○ Scalar (akses via /docs — tampilan modern)
62
+
59
63
  └ folder berhasil dibuat, Selamat berkarya! masbro 🚀
60
64
  ```
61
65
 
@@ -78,7 +82,7 @@ my-api/
78
82
  │ └── readme.txt
79
83
 
80
84
  ├── models/
81
- │ ├── example.userModel.js # Skema User (Mongoose / Sequelize)
85
+ │ ├── User.js / example.userModel.js # Skema User (Mongoose / Sequelize)
82
86
  │ └── readme.txt
83
87
 
84
88
  ├── config/
@@ -104,6 +108,8 @@ my-api/
104
108
  | MongoDB | + `mongoose` |
105
109
  | MySQL | + `sequelize`, `mysql2` |
106
110
  | Nodemon (jika Ya) | `nodemon` (devDependency) |
111
+ | Swagger UI | + `@fastify/swagger`, `@fastify/swagger-ui` |
112
+ | Scalar | + `@fastify/swagger`, `@scalar/fastify-api-reference` |
107
113
 
108
114
  ---
109
115
 
@@ -113,7 +119,7 @@ my-api/
113
119
  Langsung jalankan:
114
120
  ```bash
115
121
  cd my-api
116
- npm start
122
+ npm run dev
117
123
  # → http://localhost:3000
118
124
  ```
119
125
 
@@ -128,7 +134,7 @@ cp .env.example .env
128
134
  # atau MongoDB Atlas:
129
135
  # MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/my-api
130
136
 
131
- npm start
137
+ npm run dev
132
138
  ```
133
139
 
134
140
  ### 3. MySQL
@@ -145,12 +151,25 @@ cp .env.example .env
145
151
  # DB_USER=root
146
152
  # DB_PASS=yourpassword
147
153
 
148
- npm start
154
+ npm run dev
149
155
  # Sequelize akan auto-sync tabel saat pertama kali jalan
150
156
  ```
151
157
 
152
158
  ---
153
159
 
160
+ ## Dokumentasi API
161
+
162
+ Setelah server berjalan, buka browser dan akses:
163
+
164
+ | Pilihan | URL |
165
+ |---|---|
166
+ | Swagger UI | `http://localhost:3000/docs` |
167
+ | Scalar | `http://localhost:3000/docs` |
168
+
169
+ > Scalar menampilkan UI yang lebih modern & estetis dengan dark mode bawaan, cocok untuk project yang ingin tampilan API Reference premium.
170
+
171
+ ---
172
+
154
173
  ## Scripts
155
174
 
156
175
  | Command | Keterangan |
package/bin/index.js CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  import "../src/cli.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cleancode-e",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "CLI generator untuk project backend Fastify siap pakai",
5
5
  "keywords": ["fastify", "cli", "generator", "scaffold", "backend", "nodejs"],
6
6
  "type": "module",
package/src/cli.js CHANGED
@@ -53,6 +53,19 @@ async function main() {
53
53
  process.exit(0);
54
54
  }
55
55
 
56
+ const dokumentasi = await select({
57
+ message: "pilih dokumentasi",
58
+ options: [
59
+ { value: "swagger", label: "Swagger" },
60
+ { value: "scaler", label: "scaler" },
61
+ ],
62
+ })
63
+
64
+ if (typeof dokumentasi === "symbol") {
65
+ outro(colors.red("Dibatalkan."));
66
+ process.exit(0);
67
+ }
68
+
56
69
  const targetDir = path.resolve(projectName);
57
70
  const templateDir = path.join(__dirname, "templates");
58
71
 
@@ -88,12 +101,72 @@ async function main() {
88
101
  cp("controllers/example.userController.mongo.js", "controllers/example.userController.js");
89
102
  } else if (database === "mysql") {
90
103
  cp("config/db.mysql.js", "config/db.js");
91
- cp("models/example.userModel.mysql.js", "models/example.userModel.js");
104
+ cp("models/example.userModel.mysql.js", "models/User.js");
92
105
  cp("controllers/example.userController.mysql.js", "controllers/example.userController.js");
93
106
  } else {
94
107
  cp("controllers/example.userController.none.js", "controllers/example.userController.js");
95
108
  }
96
109
 
110
+ //ambil isi file app.js yang sudah di buat
111
+ const appJsPath = to("app.js");
112
+ let appJsContent = fs.readFileSync(appJsPath, "utf-8");
113
+
114
+ //--mempersiapkan Script DOKUMENTASI
115
+
116
+ let docsScript = "";
117
+
118
+ if (dokumentasi === "swagger") {
119
+ docsScript = `
120
+ //--DOKUMENTASI SWAGGER--
121
+ fastify.register(import("@fastify/swagger"), {
122
+ openapi: {
123
+ info: {
124
+ title: "${projectName}", // <-- Jangan lupa pakai tanda kutip untuk string!
125
+ description: "API Documentation",
126
+ version: "1.0.0",
127
+ },
128
+ servers: [
129
+ {
130
+ url: "http://localhost:3000",
131
+ description: "Development",
132
+ },
133
+ ],
134
+ },
135
+ });
136
+ fastify.register(import("@fastify/swagger-ui"), {
137
+ routePrefix: "/docs",
138
+ });
139
+ `
140
+ } else if (dokumentasi === "scaler") {
141
+ docsScript = `
142
+ //--DOKUMENTASI SCALER--
143
+ fastify.register(import("@fastify/swagger"), {
144
+ openapi: {
145
+ info: {
146
+ title: "${projectName}",
147
+ description: "API Documentation",
148
+ version: "1.0.0",
149
+ },
150
+ servers: [
151
+ {
152
+ url: "http://localhost:3000",
153
+ description: "Development",
154
+ },
155
+ ],
156
+ },
157
+ });
158
+ fastify.register(import("@scalar/fastify-api-reference"), {
159
+ routePrefix: "/docs",
160
+ });
161
+ `
162
+ }
163
+
164
+
165
+ //--ganti penanda {{DOCS_SETUP}}
166
+ appJsContent = appJsContent.replace("{{DOCS_SETUP}}", docsScript);
167
+
168
+ fs.writeFileSync(appJsPath, appJsContent);
169
+
97
170
  const deps = { fastify: "latest" };
98
171
  if (database === "mongo") deps.mongoose = "latest";
99
172
  if (database === "mysql") {
@@ -124,6 +197,8 @@ async function main() {
124
197
  const installList = ["fastify"];
125
198
  if (database === "mongo") installList.push("mongoose");
126
199
  if (database === "mysql") installList.push("sequelize", "mysql2");
200
+ if (dokumentasi === "swagger") installList.push("@fastify/swagger", "@fastify/swagger-ui");
201
+ if (dokumentasi === "scaler") installList.push("@fastify/swagger", "@scalar/fastify-api-reference");
127
202
 
128
203
  await execa("npm", ["install", ...installList], { cwd: targetDir });
129
204
 
@@ -145,6 +220,7 @@ async function main() {
145
220
  : "",
146
221
  ].filter(Boolean).join("\n"),
147
222
  "Selesai!"
223
+
148
224
  );
149
225
 
150
226
  outro(colors.green("folder berhasil dibuat, Selamat berkarya! masbro 🚀"));
@@ -5,6 +5,8 @@ import userRoutes from './routes/example.userRoute.js';
5
5
  const fastify = Fastify({ logger: true });
6
6
 
7
7
  fastify.register(userRoutes);
8
+ // ====== DOKUMENTASI API ======
9
+ // {{DOCS_SETUP}}
8
10
 
9
11
  const start = async () => {
10
12
  try {
@@ -6,6 +6,8 @@ import './models/User.js';
6
6
  const fastify = Fastify({ logger: true });
7
7
 
8
8
  fastify.register(userRoutes);
9
+ // ====== DOKUMENTASI API ======
10
+ // {{DOCS_SETUP}}
9
11
 
10
12
  const start = async () => {
11
13
  try {
@@ -4,6 +4,8 @@ import userRoutes from './routes/example.userRoute.js';
4
4
  const fastify = Fastify({ logger: true });
5
5
 
6
6
  fastify.register(userRoutes);
7
+ // ====== DOKUMENTASI API ======
8
+ // {{DOCS_SETUP}}
7
9
 
8
10
  const start = async () => {
9
11
  try {
@@ -1,4 +1,4 @@
1
- import User from '../models/example.userModel.js';
1
+ import User from '../models/User.js';
2
2
 
3
3
  export async function getUsers(request, reply) {
4
4
  const users = await User.findAll();