lapeh 1.0.1 → 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.
package/.env.example CHANGED
@@ -1,16 +1,16 @@
1
- PORT=4000
2
- DATABASE_PROVIDER="postgresql"
3
- DATABASE_URL="postgresql://roby:12341234@localhost:5432/db_contact?schema=public"
4
- JWT_SECRET="replace_this_with_a_secure_random_string"
5
-
6
- # redis example:
7
- REDIS_URL="redis://localhost:6379"
8
-
9
- # mysql example:
10
- # DATABASE_PROVIDER="mysql"
11
- # DATABASE_URL="mysql://user:password@localhost:3306/news_db"
12
- # DATABASE_HOST="localhost"
13
- # DATABASE_PORT=3306
14
- # DATABASE_USER="user"
15
- # DATABASE_PASSWORD="password"
16
- # DATABASE_NAME="news_db"
1
+ PORT=4000
2
+ DATABASE_PROVIDER="postgresql"
3
+ DATABASE_URL="postgresql://roby:12341234@localhost:5432/db_contact?schema=public"
4
+ JWT_SECRET="replace_this_with_a_secure_random_string"
5
+
6
+ # redis example:
7
+ REDIS_URL="redis://localhost:6379"
8
+
9
+ # mysql example:
10
+ # DATABASE_PROVIDER="mysql"
11
+ # DATABASE_URL="mysql://user:password@localhost:3306/news_db"
12
+ # DATABASE_HOST="localhost"
13
+ # DATABASE_PORT=3306
14
+ # DATABASE_USER="user"
15
+ # DATABASE_PASSWORD="password"
16
+ # DATABASE_NAME="news_db"
package/bin/index.js CHANGED
@@ -1,105 +1,105 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { execSync } = require('child_process');
6
-
7
- const projectName = process.argv[2];
8
-
9
- if (!projectName) {
10
- console.error('❌ Please specify the project name:');
11
- console.error(' npx lapeh-cli <project-name>');
12
- process.exit(1);
13
- }
14
-
15
- const currentDir = process.cwd();
16
- const projectDir = path.join(currentDir, projectName);
17
- const templateDir = path.join(__dirname, '..');
18
-
19
- if (fs.existsSync(projectDir)) {
20
- console.error(`❌ Directory ${projectName} already exists.`);
21
- process.exit(1);
22
- }
23
-
24
- console.log(`🚀 Creating a new API Lapeh project in ${projectDir}...`);
25
- fs.mkdirSync(projectDir);
26
-
27
- // List of files/folders to exclude
28
- const ignoreList = [
29
- 'node_modules',
30
- 'dist',
31
- '.git',
32
- '.env',
33
- 'bin', // Don't copy the CLI script itself
34
- 'package-lock.json',
35
- '.DS_Store',
36
- projectName // Don't copy the destination folder itself if creating inside the template
37
- ];
38
-
39
- function copyDir(src, dest) {
40
- const entries = fs.readdirSync(src, { withFileTypes: true });
41
-
42
- for (const entry of entries) {
43
- const srcPath = path.join(src, entry.name);
44
- const destPath = path.join(dest, entry.name);
45
-
46
- if (ignoreList.includes(entry.name)) {
47
- continue;
48
- }
49
-
50
- if (entry.isDirectory()) {
51
- fs.mkdirSync(destPath);
52
- copyDir(srcPath, destPath);
53
- } else {
54
- fs.copyFileSync(srcPath, destPath);
55
- }
56
- }
57
- }
58
-
59
- console.log('📂 Copying template files...');
60
- copyDir(templateDir, projectDir);
61
-
62
- // Update package.json
63
- console.log('📝 Updating package.json...');
64
- const packageJsonPath = path.join(projectDir, 'package.json');
65
- const packageJson = require(packageJsonPath);
66
-
67
- packageJson.name = projectName;
68
- packageJson.version = '1.0.0';
69
- packageJson.description = 'Generated by lapeh';
70
- delete packageJson.bin; // Remove the bin entry from the generated project
71
- delete packageJson.repository; // Remove repository info if specific to the template
72
-
73
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
74
-
75
- // Create .env from .env.example
76
- console.log('⚙️ Configuring environment...');
77
- const envExamplePath = path.join(projectDir, '.env.example');
78
- const envPath = path.join(projectDir, '.env');
79
-
80
- if (fs.existsSync(envExamplePath)) {
81
- fs.copyFileSync(envExamplePath, envPath);
82
- }
83
-
84
- // Install dependencies
85
- console.log('📦 Installing dependencies (this might take a while)...');
86
- try {
87
- execSync('npm install', { cwd: projectDir, stdio: 'inherit' });
88
- } catch (error) {
89
- console.error('❌ Error installing dependencies.');
90
- process.exit(1);
91
- }
92
-
93
- // Generate JWT Secret
94
- console.log('🔑 Generating JWT Secret...');
95
- try {
96
- execSync('npm run generate:jwt', { cwd: projectDir, stdio: 'inherit' });
97
- } catch (error) {
98
- console.warn('⚠️ Could not generate JWT secret automatically. Please run "npm run generate:jwt" manually.');
99
- }
100
-
101
- console.log('\n✅ Project created successfully!');
102
- console.log(`\nNext steps:\n`);
103
- console.log(` cd ${projectName}`);
104
- console.log(` npm run dev`);
105
- console.log('\nHappy coding! 🚀\n');
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { execSync } = require('child_process');
6
+
7
+ const projectName = process.argv[2];
8
+
9
+ if (!projectName) {
10
+ console.error('❌ Please specify the project name:');
11
+ console.error(' npx lapeh-cli <project-name>');
12
+ process.exit(1);
13
+ }
14
+
15
+ const currentDir = process.cwd();
16
+ const projectDir = path.join(currentDir, projectName);
17
+ const templateDir = path.join(__dirname, '..');
18
+
19
+ if (fs.existsSync(projectDir)) {
20
+ console.error(`❌ Directory ${projectName} already exists.`);
21
+ process.exit(1);
22
+ }
23
+
24
+ console.log(`🚀 Creating a new API Lapeh project in ${projectDir}...`);
25
+ fs.mkdirSync(projectDir);
26
+
27
+ // List of files/folders to exclude
28
+ const ignoreList = [
29
+ 'node_modules',
30
+ 'dist',
31
+ '.git',
32
+ '.env',
33
+ 'bin', // Don't copy the CLI script itself
34
+ 'package-lock.json',
35
+ '.DS_Store',
36
+ projectName // Don't copy the destination folder itself if creating inside the template
37
+ ];
38
+
39
+ function copyDir(src, dest) {
40
+ const entries = fs.readdirSync(src, { withFileTypes: true });
41
+
42
+ for (const entry of entries) {
43
+ const srcPath = path.join(src, entry.name);
44
+ const destPath = path.join(dest, entry.name);
45
+
46
+ if (ignoreList.includes(entry.name)) {
47
+ continue;
48
+ }
49
+
50
+ if (entry.isDirectory()) {
51
+ fs.mkdirSync(destPath);
52
+ copyDir(srcPath, destPath);
53
+ } else {
54
+ fs.copyFileSync(srcPath, destPath);
55
+ }
56
+ }
57
+ }
58
+
59
+ console.log('📂 Copying template files...');
60
+ copyDir(templateDir, projectDir);
61
+
62
+ // Update package.json
63
+ console.log('📝 Updating package.json...');
64
+ const packageJsonPath = path.join(projectDir, 'package.json');
65
+ const packageJson = require(packageJsonPath);
66
+
67
+ packageJson.name = projectName;
68
+ packageJson.version = '1.0.0';
69
+ packageJson.description = 'Generated by lapeh';
70
+ delete packageJson.bin; // Remove the bin entry from the generated project
71
+ delete packageJson.repository; // Remove repository info if specific to the template
72
+
73
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
74
+
75
+ // Create .env from .env.example
76
+ console.log('⚙️ Configuring environment...');
77
+ const envExamplePath = path.join(projectDir, '.env.example');
78
+ const envPath = path.join(projectDir, '.env');
79
+
80
+ if (fs.existsSync(envExamplePath)) {
81
+ fs.copyFileSync(envExamplePath, envPath);
82
+ }
83
+
84
+ // Install dependencies
85
+ console.log('📦 Installing dependencies (this might take a while)...');
86
+ try {
87
+ execSync('npm install', { cwd: projectDir, stdio: 'inherit' });
88
+ } catch (error) {
89
+ console.error('❌ Error installing dependencies.');
90
+ process.exit(1);
91
+ }
92
+
93
+ // Generate JWT Secret
94
+ console.log('🔑 Generating JWT Secret...');
95
+ try {
96
+ execSync('npm run generate:jwt', { cwd: projectDir, stdio: 'inherit' });
97
+ } catch (error) {
98
+ console.warn('⚠️ Could not generate JWT secret automatically. Please run "npm run generate:jwt" manually.');
99
+ }
100
+
101
+ console.log('\n✅ Project created successfully!');
102
+ console.log(`\nNext steps:\n`);
103
+ console.log(` cd ${projectName}`);
104
+ console.log(` npm run dev`);
105
+ console.log('\nHappy coding! 🚀\n');
package/framework.md ADDED
@@ -0,0 +1,105 @@
1
+ # Lapeh Framework
2
+
3
+ ## Quick Start
4
+
5
+ Untuk memulai project ini (Setup awal):
6
+
7
+ ```bash
8
+ npm i
9
+ ```
10
+
11
+ ```bash
12
+ npm run first
13
+ ```
14
+
15
+ Perintah di atas akan secara otomatis melakukan:
16
+
17
+ 1. Copy `.env.example` ke `.env`
18
+ 2. Install dependencies (`npm install`)
19
+ 3. Generate JWT Secret baru di `.env`
20
+ 4. Setup database (Migrate)
21
+ 5. Menjalankan Database Seeder
22
+
23
+ Setelah selesai, Anda bisa langsung menjalankan project:
24
+
25
+ ```bash
26
+ npm run dev
27
+ ```
28
+
29
+ ## Database Workflow (Prisma)
30
+
31
+ Framework ini menggunakan **Prisma ORM** dengan struktur schema yang modular (dipecah per file). Berikut adalah panduan lengkap dari Development hingga Deployment.
32
+
33
+ ### 1. Development (Lokal)
34
+
35
+ Saat mengembangkan aplikasi di local environment:
36
+
37
+ **a. Mengupdate Schema Database**
38
+ Jika Anda mengubah file schema di `src/models/*.prisma` atau `prisma/schema.prisma`:
39
+
40
+ ```bash
41
+ npm run prisma:migrate
42
+ ```
43
+
44
+ _Perintah ini akan menggabungkan semua file schema, membuat file migrasi baru, menerapkan ke database lokal, dan men-generate ulang Prisma Client._
45
+
46
+ **b. Melihat/Edit Data (GUI)**
47
+ Untuk membuka dashboard visual database:
48
+
49
+ ```bash
50
+ npm run db:studio
51
+ ```
52
+
53
+ **c. Mengisi Data Awal (Seeding)**
54
+ Jika Anda butuh data dummy atau data awal (seperti roles/permissions):
55
+
56
+ ```bash
57
+ npm run db:seed
58
+ ```
59
+
60
+ **d. Reset Database Total**
61
+ Jika database berantakan dan ingin mengulang dari awal (HATI-HATI: Menghapus semua data):
62
+
63
+ ```bash
64
+ npm run db:reset
65
+ ```
66
+
67
+ _Perintah ini akan menghapus database, membuat ulang schema dari awal, dan otomatis menjalankan seeder._
68
+
69
+ ---
70
+
71
+ ### 2. Deployment (Production)
72
+
73
+ Saat deploy ke server production:
74
+
75
+ **a. Setup Awal**
76
+ Pastikan `.env` di production sudah disetup dengan benar (DATABASE_URL, dll).
77
+
78
+ **b. Menerapkan Migrasi**
79
+ Jangan gunakan `migrate dev` di production. Gunakan perintah ini:
80
+
81
+ ```bash
82
+ npm run prisma:deploy
83
+ ```
84
+
85
+ _Perintah ini hanya akan menerapkan file migrasi yang sudah ada ke database production tanpa mereset data atau meminta konfirmasi interaktif._
86
+
87
+ **c. Generate Client (Opsional)**
88
+ Biasanya dilakukan otomatis saat `npm install` (karena `postinstall`), tapi jika perlu manual:
89
+
90
+ ```bash
91
+ npm run prisma:generate
92
+ ```
93
+
94
+ ---
95
+
96
+ ### Ringkasan Command
97
+
98
+ | Command | Fungsi | Environment |
99
+ | ------------------------- | -------------------------------------------------------- | ------------ |
100
+ | `npm run prisma:migrate` | Compile schema + Create Migration + Apply to DB | **Dev** |
101
+ | `npm run prisma:deploy` | Compile schema + Apply Migration only | **Prod** |
102
+ | `npm run prisma:generate` | Compile schema + Update Prisma Client (Type Definitions) | Dev/Prod |
103
+ | `npm run db:seed` | Menjalankan script `prisma/seed.ts` | Dev/Prod |
104
+ | `npm run db:reset` | Hapus DB + Migrate ulang + Seed | **Dev Only** |
105
+ | `npm run db:studio` | Buka GUI database di browser | Dev |
package/nodemon.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "watch": ["src", ".env"],
3
+ "ext": "ts,json",
4
+ "ignore": ["src/**/*.test.ts"],
5
+ "exec": "ts-node src/index.ts"
6
+ }
package/package.json CHANGED
@@ -1,70 +1,73 @@
1
- {
2
- "name": "lapeh",
3
- "version": "1.0.1",
4
- "description": "Framework API Express yang siap pakai (Standardized)",
5
- "main": "index.js",
6
- "bin": {
7
- "lapeh": "bin/index.js"
8
- },
9
- "scripts": {
10
- "dev": "nodemon",
11
- "build": "tsc",
12
- "start": "node dist/src/index.js",
13
- "start:prod": "NODE_ENV=production node dist/src/index.js",
14
- "typecheck": "tsc --noEmit",
15
- "prisma:generate": "node scripts/compile-schema.js && prisma generate",
16
- "prisma:migrate": "node scripts/compile-schema.js && prisma migrate dev",
17
- "prisma:deploy": "node scripts/compile-schema.js && prisma migrate deploy",
18
- "db:seed": "prisma db seed",
19
- "generate:jwt": "node scripts/generate-jwt-secret.js",
20
- "make:module": "node scripts/make-module.js",
21
- "make:model": "node scripts/make-model.js"
22
- },
23
- "keywords": [
24
- "express",
25
- "api",
26
- "framework",
27
- "cli",
28
- "generator",
29
- "boilerplate",
30
- "typescript",
31
- "prisma",
32
- "lapeh-cli"
33
- ],
34
- "author": "",
35
- "license": "ISC",
36
- "type": "commonjs",
37
- "dependencies": {
38
- "@prisma/adapter-mariadb": "^7.2.0",
39
- "@prisma/adapter-pg": "^7.2.0",
40
- "@prisma/client": "^7.2.0",
41
- "bcryptjs": "^3.0.3",
42
- "cors": "^2.8.5",
43
- "dotenv": "^17.2.3",
44
- "express": "^5.2.1",
45
- "express-rate-limit": "^8.2.1",
46
- "helmet": "^8.1.0",
47
- "ioredis": "^5.8.2",
48
- "jsonwebtoken": "^9.0.3",
49
- "multer": "^2.0.2",
50
- "pg": "^8.16.3",
51
- "slugify": "^1.6.6",
52
- "socket.io": "^4.8.3",
53
- "uuid": "^13.0.0",
54
- "zod": "^4.2.1"
55
- },
56
- "devDependencies": {
57
- "@types/bcryptjs": "^2.4.6",
58
- "@types/cors": "^2.8.19",
59
- "@types/express": "^5.0.6",
60
- "@types/jsonwebtoken": "^9.0.10",
61
- "@types/node": "^25.0.3",
62
- "@types/pg": "^8.16.0",
63
- "@types/uuid": "^10.0.0",
64
- "nodemon": "^3.1.11",
65
- "prisma": "^7.2.0",
66
- "ts-node": "^10.9.2",
67
- "ts-node-dev": "^2.0.0",
68
- "typescript": "^5.9.3"
69
- }
70
- }
1
+ {
2
+ "name": "lapeh",
3
+ "version": "1.0.2",
4
+ "description": "Framework API Express yang siap pakai (Standardized)",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "lapeh": "bin/index.js"
8
+ },
9
+ "scripts": {
10
+ "dev": "nodemon src/index.ts",
11
+ "first": "node scripts/init-project.js",
12
+ "build": "tsc",
13
+ "start": "node dist/src/index.js",
14
+ "start:prod": "NODE_ENV=production node dist/src/index.js",
15
+ "typecheck": "tsc --noEmit",
16
+ "prisma:generate": "node scripts/compile-schema.js && prisma generate",
17
+ "prisma:migrate": "node scripts/compile-schema.js && prisma migrate dev",
18
+ "prisma:deploy": "node scripts/compile-schema.js && prisma migrate deploy",
19
+ "db:seed": "prisma db seed",
20
+ "db:reset": "prisma migrate reset",
21
+ "db:studio": "prisma studio",
22
+ "generate:jwt": "node scripts/generate-jwt-secret.js",
23
+ "make:module": "node scripts/make-module.js",
24
+ "make:model": "node scripts/make-model.js"
25
+ },
26
+ "keywords": [
27
+ "express",
28
+ "api",
29
+ "framework",
30
+ "cli",
31
+ "generator",
32
+ "boilerplate",
33
+ "typescript",
34
+ "prisma",
35
+ "lapeh-cli"
36
+ ],
37
+ "author": "",
38
+ "license": "ISC",
39
+ "type": "commonjs",
40
+ "dependencies": {
41
+ "@prisma/adapter-mariadb": "^7.2.0",
42
+ "@prisma/adapter-pg": "^7.2.0",
43
+ "@prisma/client": "^7.2.0",
44
+ "bcryptjs": "^3.0.3",
45
+ "cors": "^2.8.5",
46
+ "dotenv": "^17.2.3",
47
+ "express": "^5.2.1",
48
+ "express-rate-limit": "^8.2.1",
49
+ "helmet": "^8.1.0",
50
+ "ioredis": "^5.8.2",
51
+ "jsonwebtoken": "^9.0.3",
52
+ "multer": "^2.0.2",
53
+ "pg": "^8.16.3",
54
+ "slugify": "^1.6.6",
55
+ "socket.io": "^4.8.3",
56
+ "uuid": "^13.0.0",
57
+ "zod": "^3.23.8"
58
+ },
59
+ "devDependencies": {
60
+ "@types/bcryptjs": "^2.4.6",
61
+ "@types/cors": "^2.8.19",
62
+ "@types/express": "^5.0.6",
63
+ "@types/jsonwebtoken": "^9.0.10",
64
+ "@types/node": "^25.0.3",
65
+ "@types/pg": "^8.16.0",
66
+ "@types/uuid": "^10.0.0",
67
+ "nodemon": "^3.1.11",
68
+ "prisma": "^7.2.0",
69
+ "ts-node": "^10.9.2",
70
+ "ts-node-dev": "^2.0.0",
71
+ "typescript": "^5.9.3"
72
+ }
73
+ }
@@ -1,8 +1,8 @@
1
- generator client {
2
- provider = "prisma-client"
3
- output = "../generated/prisma"
4
- }
5
-
6
- datasource db {
7
- provider = "postgresql"
8
- }
1
+ generator client {
2
+ provider = "prisma-client"
3
+ output = "../generated/prisma"
4
+ }
5
+
6
+ datasource db {
7
+ provider = "postgresql"
8
+ }