lapeh 2.1.2 → 2.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapeh",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Framework API Express yang siap pakai (Standardized)",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -9,8 +9,11 @@
9
9
  "scripts": {
10
10
  "dev": "node scripts/check-update.js && nodemon src/index.ts",
11
11
  "first": "node scripts/init-project.js",
12
+ "prebuild": "npm run prisma:generate",
12
13
  "build": "tsc",
14
+ "prestart": "npm run prisma:generate",
13
15
  "start": "node dist/src/index.js",
16
+ "prestart:prod": "npm run prisma:generate",
14
17
  "start:prod": "NODE_ENV=production node dist/src/index.js",
15
18
  "typecheck": "tsc --noEmit",
16
19
  "prisma:generate": "node scripts/compile-schema.js && prisma generate",
@@ -1,8 +1,7 @@
1
- generator client {
2
- provider = "prisma-client-js"
3
- output = "../generated/prisma"
4
- }
5
-
6
- datasource db {
7
- provider = "postgresql"
8
- }
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "postgresql"
7
+ }
@@ -1,11 +1,10 @@
1
- generator client {
2
- provider = "prisma-client-js"
3
- output = "../generated/prisma"
4
- }
5
-
6
- datasource db {
7
- provider = "postgresql"
8
- }
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "postgresql"
7
+ }
9
8
 
10
9
 
11
10
  model cache {
package/readme.md CHANGED
@@ -75,25 +75,25 @@ Jika Anda melakukan setup dengan flag `--full`, database akan terisi dengan akun
75
75
 
76
76
  ---
77
77
 
78
- ## 🔄 Upgrade Project
79
-
80
- Jika Anda memiliki project lama yang dibuat dengan versi Lapeh sebelumnya dan ingin memperbarui struktur, scripts, dan konfigurasi ke standar terbaru (termasuk keamanan Redis baru), Anda tidak perlu membuat project ulang.
81
-
82
- Cukup jalankan perintah ini di dalam folder project Anda:
83
-
84
- ```bash
85
- npx lapeh@latest upgrade
86
- ```
87
-
88
- Perintah ini akan secara otomatis:
89
-
90
- 1. Mengupdate `scripts/` (termasuk generator controller baru).
91
- 2. Mengupdate `docker-compose.yml` (keamanan Redis).
92
- 3. Mengupdate dependencies di `package.json`.
93
- 4. Menambahkan konfigurasi `.vscode` dan `tsconfig` terbaru.
94
-
95
- > **Catatan:** File `.env` Anda **tidak akan ditimpa**, namun kami akan mengupdate `.env.example` sebagai referensi konfigurasi terbaru.
96
-
78
+ ## 🔄 Upgrade Project
79
+
80
+ Jika Anda memiliki project lama yang dibuat dengan versi Lapeh sebelumnya dan ingin memperbarui struktur, scripts, dan konfigurasi ke standar terbaru (termasuk keamanan Redis baru), Anda tidak perlu membuat project ulang.
81
+
82
+ Cukup jalankan perintah ini di dalam folder project Anda:
83
+
84
+ ```bash
85
+ npx lapeh@latest upgrade
86
+ ```
87
+
88
+ Perintah ini akan secara otomatis:
89
+
90
+ 1. Mengupdate `scripts/` (termasuk generator controller baru).
91
+ 2. Mengupdate `docker-compose.yml` (keamanan Redis).
92
+ 3. Mengupdate dependencies di `package.json`.
93
+ 4. Menambahkan konfigurasi `.vscode` dan `tsconfig` terbaru.
94
+
95
+ > **Catatan:** File `.env` Anda **tidak akan ditimpa**, namun kami akan mengupdate `.env.example` sebagai referensi konfigurasi terbaru.
96
+
97
97
  ## 🧠 Zero-Config Redis
98
98
 
99
99
  Lapeh otomatis mendeteksi ketersediaan Redis.
@@ -223,23 +223,144 @@ npm run config:clear
223
223
 
224
224
  ---
225
225
 
226
- ## 📂 Struktur Folder
227
-
228
- ```text
229
- src/
230
- ├── controllers/ # Logika Request & Response
231
- ├── services/ # Business Logic
232
- ├── routes/ # Definisi Route API
233
- ├── models/ # Definisi Schema Prisma per Model
234
- ├── middleware/ # Auth, Validation, Error Handling
235
- ├── schema/ # Zod Validation Schemas
236
- ├── utils/ # Helper Functions
237
- └── index.ts # App Entry Point
238
- prisma/
239
- ├── schema.prisma # [GENERATED] Jangan edit file ini
240
- └── base.prisma.template # Konfigurasi Datasource & Generator
241
- ```
242
-
243
- ## 📝 Lisensi
244
-
245
- MIT
226
+ ## 📂 Struktur Folder
227
+
228
+ ```text
229
+ src/
230
+ ├── controllers/ # Logika Request & Response
231
+ ├── services/ # Business Logic
232
+ ├── routes/ # Definisi Route API
233
+ ├── models/ # Definisi Schema Prisma per Model
234
+ ├── middleware/ # Auth, Validation, Error Handling
235
+ ├── schema/ # Zod Validation Schemas
236
+ ├── utils/ # Helper Functions
237
+ └── index.ts # App Entry Point
238
+ prisma/
239
+ ├── schema.prisma # [GENERATED] Jangan edit file ini
240
+ └── base.prisma.template # Konfigurasi Datasource & Generator
241
+ ```
242
+
243
+ ## 📝 Lisensi
244
+
245
+ MIT
246
+
247
+ ---
248
+
249
+ ## 🚀 Deployment Guide
250
+
251
+ ### 1) Build & Generate Prisma Client (Otomatis)
252
+ - Build: `npm run build`
253
+ - Start (dev): `npm run start`
254
+ - Start (prod): `npm run start:prod`
255
+ - Hooks otomatis:
256
+ - `prebuild`, `prestart`, dan `prestart:prod` akan memanggil `npm run prisma:generate` sehingga Prisma Client selalu tersedia tanpa error.
257
+
258
+ ### 2) Production Environment
259
+ - Pastikan `.env` berisi kredensial production:
260
+ - `DATABASE_URL` dan `DATABASE_PROVIDER` (mysql/postgresql)
261
+ - `JWT_SECRET` (gunakan `npm run generate:jwt` untuk mengganti)
262
+ - Terapkan migrasi production (tanpa reset data):
263
+
264
+ ```bash
265
+ npm run prisma:deploy
266
+ ```
267
+
268
+ ### 3) Menjalankan dengan PM2
269
+ - Install PM2:
270
+
271
+ ```bash
272
+ npm i -g pm2
273
+ ```
274
+
275
+ - Jalankan aplikasi:
276
+
277
+ ```bash
278
+ pm2 start dist/src/index.js --name lapeh-api --time
279
+ ```
280
+
281
+ - Simpan proses agar auto-start saat reboot:
282
+
283
+ ```bash
284
+ pm2 save
285
+ pm2 startup
286
+ ```
287
+
288
+ - Monitoring:
289
+
290
+ ```bash
291
+ pm2 status
292
+ pm2 logs lapeh-api
293
+ pm2 restart lapeh-api
294
+ ```
295
+
296
+ ### 4) Nginx Reverse Proxy (Recommended)
297
+ - Buat server block `/etc/nginx/sites-available/lapeh`:
298
+
299
+ ```nginx
300
+ server {
301
+ listen 80;
302
+ server_name example.com;
303
+
304
+ location / {
305
+ proxy_set_header Host $host;
306
+ proxy_set_header X-Real-IP $remote_addr;
307
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
308
+ proxy_set_header X-Forwarded-Proto $scheme;
309
+ proxy_pass http://127.0.0.1:4000;
310
+ }
311
+ }
312
+ ```
313
+
314
+ - Aktifkan:
315
+
316
+ ```bash
317
+ sudo ln -s /etc/nginx/sites-available/lapeh /etc/nginx/sites-enabled/lapeh
318
+ sudo nginx -t
319
+ sudo systemctl reload nginx
320
+ ```
321
+
322
+ - SSL (opsional, Certbot):
323
+
324
+ ```bash
325
+ sudo apt install certbot python3-certbot-nginx -y
326
+ sudo certbot --nginx -d example.com
327
+ ```
328
+
329
+ ### 5) Apache 2 Reverse Proxy (Alternatif)
330
+ - Enable modul proxy:
331
+
332
+ ```bash
333
+ sudo a2enmod proxy proxy_http headers
334
+ sudo systemctl reload apache2
335
+ ```
336
+
337
+ - Buat vhost `/etc/apache2/sites-available/lapeh.conf`:
338
+
339
+ ```apache
340
+ <VirtualHost *:80>
341
+ ServerName example.com
342
+ ProxyPreserveHost On
343
+ ProxyRequests Off
344
+ <Proxy *>
345
+ Require all granted
346
+ </Proxy>
347
+ ProxyPass / http://127.0.0.1:4000/
348
+ ProxyPassReverse / http://127.0.0.1:4000/
349
+ ErrorLog ${APACHE_LOG_DIR}/lapeh-error.log
350
+ CustomLog ${APACHE_LOG_DIR}/lapeh-access.log combined
351
+ </VirtualHost>
352
+ ```
353
+
354
+ - Aktifkan:
355
+
356
+ ```bash
357
+ sudo a2ensite lapeh.conf
358
+ sudo apachectl configtest
359
+ sudo systemctl reload apache2
360
+ ```
361
+
362
+ ### 6) Checklist Produksi
363
+ - `npm run prisma:deploy` sukses dan tabel terbentuk
364
+ - `pm2 status` menunjukkan proses hidup
365
+ - Proxy (Nginx/Apache) menuju port aplikasi (default 4000)
366
+ - `.env` aman dan tidak di-commit ke repository
package/src/prisma.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { PrismaClient } from "../generated/prisma";
1
+ const { PrismaClient } = require("@prisma/client");
2
2
  import { PrismaPg } from "@prisma/adapter-pg";
3
3
  import { PrismaMariaDb } from "@prisma/adapter-mariadb";
4
4
 
5
5
  const url = process.env.DATABASE_URL || "";
6
6
  const provider = (process.env.DATABASE_PROVIDER || "").toLowerCase();
7
7
 
8
- let prisma: PrismaClient;
8
+ let prisma: any;
9
9
 
10
10
  if (provider === "postgresql" || url.startsWith("postgres")) {
11
11
  const adapter = new PrismaPg({ connectionString: url });
package/tsconfig.json CHANGED
@@ -1,12 +1,21 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2016",
4
- "module": "commonjs",
5
- "rootDir": "./",
6
- "outDir": "./dist",
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "outDir": "dist",
6
+ "rootDir": ".",
7
7
  "strict": true,
8
8
  "esModuleInterop": true,
9
9
  "skipLibCheck": true,
10
10
  "forceConsistentCasingInFileNames": true
11
- }
12
- }
11
+ },
12
+ "include": [
13
+ "src",
14
+ "prisma",
15
+ "generated"
16
+ ],
17
+ "exclude": [
18
+ "node_modules",
19
+ "dist"
20
+ ]
21
+ }