@gaunk/lieurjs 1.0.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/.env ADDED
@@ -0,0 +1,2 @@
1
+ PORT=3000
2
+ DB_HOST=localhost
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # LieurJS 1.0.0
2
+
3
+ **LieurJS** adalah framework backend ringan berbasis Node.js, terstruktur mirip seperti CodeIgniter namun modern:
4
+
5
+ - Routing sederhana berbasis URL
6
+ - Auto reload seperti React (tanpa refresh manual)
7
+ - CLI Generator untuk controller dan model
8
+ - Templating HTML dan favicon support
9
+ - Struktur folder rapi dan modular
10
+
11
+ ---
12
+
13
+ ## 🚀 Instalasi & Menjalankan
14
+
15
+ ```bash
16
+ npm install
17
+ npm run dev
18
+ ```
19
+
20
+ Akan:
21
+ - Menjalankan server di `http://localhost:3000`
22
+ - Membuka browser otomatis
23
+ - Auto reload saat file diubah (tanpa nodemon)
24
+
25
+ ---
26
+
27
+ ## 📁 Struktur Folder
28
+
29
+ ```
30
+ lieurjs/
31
+ ├── controllers/ # Semua controller
32
+ ├── models/ # Model ORM mini
33
+ ├── views/ # File HTML view
34
+ ├── public/ # Static file (favicon, css, js)
35
+ ├── core/ # Kernel framework
36
+ ├── .env # Konfigurasi env
37
+ ├── package.json # Konfigurasi npm
38
+ ├── lieurjs # Entry point (router + server + CLI)
39
+ ```
40
+
41
+ ---
42
+
43
+ ## ✅ Contoh Controller
44
+
45
+ ```js
46
+ // controllers/HomeController.js
47
+ export default class HomeController {
48
+ index(req, res) {
49
+ res.end("Halo dari HomeController");
50
+ }
51
+ }
52
+ ```
53
+
54
+ ## ✅ Contoh Model
55
+
56
+ ```js
57
+ // models/User.js
58
+ import Model from '../core/Model.js';
59
+
60
+ export default class User extends Model {
61
+ constructor() {
62
+ super('users');
63
+ }
64
+ }
65
+ ```
66
+
67
+ ---
68
+
69
+ ## ⚙️ CLI Generator
70
+
71
+ Buat controller atau model dengan mudah:
72
+
73
+ ```bash
74
+ node lieurjs make:controller NamaController
75
+ node lieurjs make:model NamaModel
76
+ ```
77
+ ---
78
+
79
+ ## 📄 Lisensi
80
+
81
+ MIT License © 2025 LieurCoding
@@ -0,0 +1,5 @@
1
+ export default class HomeController {
2
+ index(req, res) {
3
+ res.end("a awe");
4
+ }
5
+ }
@@ -0,0 +1,8 @@
1
+
2
+ import { WebSocketServer } from 'ws';
3
+ const wss = new WebSocketServer({ port: 35729 });
4
+ const clients = new Set();
5
+ wss.on('connection', ws => clients.add(ws));
6
+ export function reloadAllClients() {
7
+ for (const ws of clients) { if (ws.readyState === 1) ws.send('reload'); }
8
+ }
package/core/Model.js ADDED
@@ -0,0 +1 @@
1
+ export default class Model { constructor(table) { this.table = table; }}
package/core/View.js ADDED
@@ -0,0 +1 @@
1
+ export function render(view, data) { return 'Rendered HTML'; }
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ console.log("LieurJS is running!");
package/lieurjs ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import os from 'os';
6
+ import chokidar from 'chokidar';
7
+ import http from 'http';
8
+ import { fileURLToPath, pathToFileURL } from 'url';
9
+ import { exec } from 'child_process';
10
+ import './core/LiveReload.js';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+ const args = process.argv.slice(2);
15
+
16
+ // -----------------------------
17
+ // ✅ CLI Generator
18
+ // -----------------------------
19
+ const templates = {
20
+ controller: name => `export default class ${name} {
21
+ index(req, res) {
22
+ res.end("${name} Controller");
23
+ }
24
+ }`,
25
+ model: name => `import Model from '../core/Model.js';
26
+ export default class ${name} extends Model {
27
+ constructor() {
28
+ super('${name.toLowerCase()}s');
29
+ }
30
+ }`
31
+ };
32
+
33
+ if (args[0] === 'make:controller') {
34
+ const name = args[1];
35
+ const content = templates.controller(name);
36
+ fs.writeFileSync(`controllers/${name}.js`, content);
37
+ console.log(`✅ Controller ${name}.js dibuat.`);
38
+ process.exit();
39
+ }
40
+
41
+ if (args[0] === 'make:model') {
42
+ const name = args[1];
43
+ const content = templates.model(name);
44
+ fs.writeFileSync(`models/${name}.js`, content);
45
+ console.log(`✅ Model ${name}.js dibuat.`);
46
+ process.exit();
47
+ }
48
+
49
+ // -----------------------------
50
+ // ✅ Router Function
51
+ // -----------------------------
52
+ const router = async (req, res) => {
53
+ if (req.url === '/') {
54
+ const Home = await import('./controllers/HomeController.js');
55
+ return new Home.default().index(req, res);
56
+ }
57
+
58
+ if (req.url === '/favicon.ico') {
59
+ const iconPath = path.join(__dirname, 'public', 'favicon.ico');
60
+ if (fs.existsSync(iconPath)) {
61
+ const icon = fs.readFileSync(iconPath);
62
+ res.writeHead(200, { 'Content-Type': 'image/x-icon' });
63
+ return res.end(icon);
64
+ }
65
+ res.writeHead(404); return res.end();
66
+ }
67
+
68
+ res.writeHead(404);
69
+ res.end('404 Not Found');
70
+ };
71
+
72
+ // -----------------------------
73
+ // ✅ Server Init & Browser Open
74
+ // -----------------------------
75
+ let browserOpened = false;
76
+
77
+ const server = http.createServer((req, res) => router(req, res));
78
+
79
+ server.listen(3000, () => {
80
+ const url = 'http://localhost:3000';
81
+ console.log(`✅ Server berjalan di ${url}`);
82
+
83
+ if (!browserOpened && args.includes('--open')) {
84
+ const platform = os.platform();
85
+ if (platform === 'win32') exec(`start ${url}`);
86
+ else if (platform === 'darwin') exec(`open ${url}`);
87
+ else exec(`xdg-open ${url}`);
88
+ browserOpened = true;
89
+ }
90
+ });
91
+
92
+ // -----------------------------
93
+ // 🔁 Auto Reload with chokidar
94
+ // -----------------------------
95
+ chokidar.watch(['controllers/', 'models/', 'views/'], {
96
+ ignored: /node_modules/
97
+ }).on('change', file => {
98
+ console.log(`🔁 Reload karena perubahan: ${file}`);
99
+ import('./core/LiveReload.js').then(mod => mod.reloadAllClients());
100
+ });
package/models/User.js ADDED
@@ -0,0 +1,6 @@
1
+ import Model from '../core/Model.js';
2
+ export default class User extends Model {
3
+ constructor() {
4
+ super('users');
5
+ }
6
+ }
package/nodemon.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "watch": ["controllers", "models", "views"],
3
+ "ext": "js,json",
4
+ "ignore": ["node_modules"],
5
+ "exec": "node lieurjs"
6
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@gaunk/lieurjs",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "**LieurJS** adalah framework backend ringan berbasis Node.js, terstruktur mirip seperti CodeIgniter namun modern",
6
+ "main": "server.js",
7
+ "bin": {
8
+ "lieurjs": "./lieurjs.js"
9
+ },
10
+ "scripts": {
11
+ "dev": "nodemon --exec node lieurjs.js",
12
+ "start": "node server.js"
13
+ },
14
+ "dependencies": {
15
+ "chokidar": "^3.5.3",
16
+ "ws": "^8.13.0"
17
+ },
18
+ "devDependencies": {
19
+ "nodemon": "^3.1.10"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Gaunk/lieurjs.git"
24
+ },
25
+ "keywords": ["framework", "backend", "nodejs", "lieurjs"],
26
+ "author": "Your Name <your.email@example.com>",
27
+ "license": "ISC",
28
+ "bugs": {
29
+ "url": "https://github.com/Gaunk/lieurjs/issues"
30
+ },
31
+ "homepage": "https://github.com/Gaunk/lieurjs#readme"
32
+ }
Binary file
package/server.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { exec } from 'child_process';
4
+ import os from 'os';
5
+
6
+ let browserOpened = false;
7
+
8
+ server.listen(3000, () => {
9
+ console.log('✅ Server berjalan di http://localhost:3000');
10
+
11
+ // Hanya buka browser kalau belum pernah dibuka
12
+ if (!browserOpened && process.argv.includes('--open')) {
13
+ const url = 'http://localhost:3000';
14
+ if (os.platform() === 'win32') exec(`start ${url}`);
15
+ else if (os.platform() === 'darwin') exec(`open ${url}`);
16
+ else exec(`xdg-open ${url}`);
17
+
18
+ browserOpened = true;
19
+ }
20
+ });
@@ -0,0 +1 @@
1
+ <h1>Welcome to LieurJS!</h1>