kaelum 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Matheus Messias
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # Kaelum
2
+
3
+ **Kaelum** is a minimalist Node.js framework designed to simplify the creation of web pages and REST APIs, especially for beginners. Inspired by Python's clean syntax and powered by Express.js, Kaelum automates project setup and server configuration with an intuitive CLI.
4
+
5
+ ## πŸ“¦ Installation
6
+
7
+ You can create a new project with Kaelum using:
8
+
9
+ ```bash
10
+ npx kaelum create
11
+ ````
12
+
13
+ Then install dependencies and start your app:
14
+
15
+ ```bash
16
+ cd my-project
17
+ npm install
18
+ npm start
19
+ ```
20
+
21
+ > **Note:** No need to install Kaelum globally. `npx` handles it automatically!
22
+
23
+ ---
24
+
25
+ ## 🧠 Why Kaelum?
26
+
27
+ * πŸ“‚ Minimalist MVC folder structure
28
+ * βš™οΈ Auto-configured Express setup
29
+ * πŸ”’ Built-in support for CORS and Helmet
30
+ * 🧱 Easy route management
31
+ * πŸ§ͺ Great for learning and building quick prototypes
32
+
33
+ ---
34
+
35
+ ## πŸ“ Web Template Structure
36
+
37
+ After running `npx kaelum create`, the web template structure looks like this:
38
+
39
+ ```
40
+ my-web-app/
41
+ β”œβ”€β”€ public/ # Static files (e.g., CSS, JS)
42
+ β”‚ └── style.css
43
+ β”œβ”€β”€ views/ # HTML templates
44
+ β”‚ └── index.html
45
+ β”œβ”€β”€ controllers/ # Page controller logic
46
+ β”‚ └── .gitkeep
47
+ β”œβ”€β”€ middlewares/ # Custom middlewares
48
+ β”‚ └── example.js
49
+ β”œβ”€β”€ routes.js # Route definitions
50
+ β”œβ”€β”€ app.js # Server initialization
51
+ └── package.json # Project metadata and dependencies
52
+ ```
53
+
54
+ ---
55
+
56
+ ## πŸš€ Features
57
+
58
+ Kaelum exposes simple utilities that make it easy to build a web server:
59
+
60
+ ```js
61
+ const kaelum = require('kaelum');
62
+ const app = kaelum();
63
+ ```
64
+
65
+ ### 🌐 `addRoute(path, handlers)`
66
+
67
+ Add routes with GET, POST, PUT, DELETE handlers in one place.
68
+
69
+ ```js
70
+ addRoute('/home', {
71
+ get: (req, res) => res.send('GET: Welcome!'),
72
+ post: (req, res) => res.send('POST: Data received!')
73
+ });
74
+ ```
75
+
76
+ ### πŸ” `setMiddleware(middleware)`
77
+
78
+ Globally apply middleware to all routes.
79
+
80
+ ```js
81
+ setMiddleware(require('helmet')());
82
+ ```
83
+
84
+ ### πŸš€ `start(port)`
85
+
86
+ Start the server.
87
+
88
+ ```js
89
+ start(3000);
90
+ ```
91
+
92
+ ---
93
+
94
+ ## πŸ‘¨β€πŸ’» Local Development (for contributors)
95
+
96
+ If you want to test or improve Kaelum locally:
97
+
98
+ ```bash
99
+ git clone https://github.com/MatheusCampagnolo/kaelum.git
100
+ cd kaelum
101
+ npm link
102
+ ```
103
+
104
+ Now you can run the CLI from anywhere:
105
+
106
+ ```bash
107
+ npx kaelum create
108
+ ```
109
+
110
+ ---
111
+
112
+ ## πŸ“„ License
113
+
114
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/bin/.gitkeep ADDED
File without changes
package/cli/create.js ADDED
@@ -0,0 +1,52 @@
1
+ const inquirer = require("inquirer");
2
+ const inq = inquirer.default || inquirer;
3
+ const path = require("path");
4
+ const fs = require("fs-extra");
5
+ const { copyTemplate } = require("./utils");
6
+
7
+ const templatesDir = path.resolve(__dirname, "templates");
8
+
9
+ async function createProject() {
10
+ console.log("πŸš€ Bem-vindo ao Kaelum CLI!");
11
+
12
+ const answers = await inq.prompt([
13
+ {
14
+ type: "input",
15
+ name: "projectName",
16
+ message: "Qual serΓ‘ o nome do seu projeto?",
17
+ validate: (input) => (input ? true : "O nome nΓ£o pode ser vazio."),
18
+ },
19
+ {
20
+ type: "list",
21
+ name: "template",
22
+ message: "Qual template vocΓͺ deseja usar?",
23
+ choices: ["web", "api"],
24
+ },
25
+ ]);
26
+
27
+ const { projectName, template } = answers;
28
+ const targetDir = path.resolve(process.cwd(), projectName);
29
+ const templateDir = path.join(templatesDir, template);
30
+
31
+ if (template === "api") {
32
+ console.log(
33
+ '\nπŸ“¦ O template API ainda estΓ‘ em desenvolvimento. Por favor, escolha o template "web".'
34
+ );
35
+ return;
36
+ }
37
+
38
+ if (fs.existsSync(targetDir)) {
39
+ console.error(
40
+ `\n❌ A pasta "${projectName}" jÑ existe. Escolha outro nome ou apague a pasta existente.`
41
+ );
42
+ return;
43
+ }
44
+
45
+ await copyTemplate(templateDir, targetDir);
46
+
47
+ console.log(`\nβœ… Projeto "${projectName}" criado com sucesso!`);
48
+ console.log(`➑️ Acesse a pasta: cd ${projectName}`);
49
+ console.log(`➑️ Inicie o projeto com: npm install && npm start\n`);
50
+ }
51
+
52
+ module.exports = { createProject };
package/cli/index.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ const { createProject } = require('./create');
3
+
4
+ const [,, command] = process.argv;
5
+
6
+ if (command === 'create') {
7
+ createProject();
8
+ } else {
9
+ console.log(`Comando nΓ£o reconhecido: ${command}`);
10
+ console.log(`Use: kaelum create`);
11
+ }
File without changes
@@ -0,0 +1,16 @@
1
+ const kaelum = require('kaelum');
2
+ const cors = require('cors');
3
+ const helmet = require('helmet');
4
+
5
+ const app = kaelum();
6
+
7
+ // Middlewares globais (aplicados a todas as rotas)
8
+ app.setMiddleware(cors());
9
+ app.setMiddleware(helmet());
10
+
11
+ // Importa e registra as rotas
12
+ const routes = require('./routes');
13
+ routes(app);
14
+
15
+ // Inicia o servidor
16
+ app.start(3000);
File without changes
@@ -0,0 +1,6 @@
1
+ function logger(req, res, next) {
2
+ console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);
3
+ next();
4
+ }
5
+
6
+ module.exports = logger;
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "my-web-app",
3
+ "version": "1.0.0",
4
+ "description": "Project generated with Kaelum framework.",
5
+ "main": "app.js",
6
+ "scripts": {
7
+ "start": "node app.js"
8
+ },
9
+ "dependencies": {
10
+ "cors": "^2.8.5",
11
+ "helmet": "^7.0.0",
12
+ "kaelum": "^1.0.0"
13
+ },
14
+ "license": "MIT"
15
+ }
@@ -0,0 +1,54 @@
1
+ body {
2
+ margin: 0;
3
+ font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
4
+ background-color: #f9f9f9;
5
+ color: #333;
6
+ }
7
+
8
+ .container {
9
+ padding: 40px;
10
+ max-width: 800px;
11
+ margin: 0 auto;
12
+ text-align: center;
13
+ }
14
+
15
+ h1 {
16
+ font-size: 2.5rem;
17
+ margin-bottom: 10px;
18
+ color: #4a90e2;
19
+ }
20
+
21
+ p {
22
+ font-size: 1.1rem;
23
+ margin-bottom: 30px;
24
+ }
25
+
26
+ .info {
27
+ background-color: #fff;
28
+ padding: 20px;
29
+ border-radius: 8px;
30
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
31
+ }
32
+
33
+ ul {
34
+ list-style-type: none;
35
+ padding: 0;
36
+ }
37
+
38
+ li {
39
+ text-align: left;
40
+ margin-bottom: 10px;
41
+ }
42
+
43
+ code {
44
+ background-color: #eee;
45
+ padding: 2px 6px;
46
+ border-radius: 4px;
47
+ font-family: monospace;
48
+ }
49
+
50
+ footer {
51
+ margin-top: 40px;
52
+ font-size: 0.9rem;
53
+ color: #999;
54
+ }
@@ -0,0 +1,27 @@
1
+ const logger = require("./middlewares/logger");
2
+
3
+ function Routes(app) {
4
+ app.addRoute("/", {
5
+ get: (req, res) => {
6
+ res.sendFile("views/index.html", { root: __dirname });
7
+ },
8
+ post: (req, res) => res.send("POST: Dados recebidos na pΓ‘gina inicial."),
9
+ });
10
+
11
+ app.addRoute("/about", {
12
+ get: (req, res) => res.send("About page"),
13
+ });
14
+
15
+ // Rota "/secure" com middleware aplicado diretamente
16
+ app.addRoute("/secure", {
17
+ get: [
18
+ logger,
19
+ (req, res) => {
20
+ res.send("GET: Área segura! Middleware foi executado.");
21
+ },
22
+ ],
23
+ });
24
+
25
+ }
26
+
27
+ module.exports = Routes;
@@ -0,0 +1,25 @@
1
+ <html lang="en">
2
+ <head>
3
+ <meta charset="UTF-8" />
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
5
+ <title>Kaelum.js - Welcome</title>
6
+ <link rel="stylesheet" href="/style.css" />
7
+ </head>
8
+ <body>
9
+ <div class="container">
10
+ <h1>πŸš€ Welcome to Kaelum.js</h1>
11
+ <p>Your minimalist framework to build APIs and web pages easily.</p>
12
+ <div class="info">
13
+ <h2>🧭 Start exploring</h2>
14
+ <ul>
15
+ <li><strong>Global Middlewares:</strong> See <code>app.js</code></li>
16
+ <li><strong>Routing:</strong> Edit <code>routes.js</code></li>
17
+ <li><strong>Static Files:</strong> Inside <code>public/</code></li>
18
+ </ul>
19
+ </div>
20
+ <footer>
21
+ <p>Made with ❀️ using Kaelum.js</p>
22
+ </footer>
23
+ </div>
24
+ </body>
25
+ </html>
package/cli/utils.js ADDED
@@ -0,0 +1,12 @@
1
+ const fs = require("fs-extra");
2
+ const path = require("path");
3
+
4
+ async function copyTemplate(sourceDir, targetDir) {
5
+ try {
6
+ await fs.copy(sourceDir, targetDir);
7
+ } catch (err) {
8
+ console.error("Erro ao copiar o template:", err);
9
+ }
10
+ }
11
+
12
+ module.exports = { copyTemplate };
@@ -0,0 +1,11 @@
1
+ function addRoute(app, path, handlers = {}) {
2
+ const supportedMethods = ['get', 'post', 'put', 'delete', 'patch'];
3
+
4
+ for (const method of supportedMethods) {
5
+ if (handlers[method]) {
6
+ app[method](path, handlers[method]);
7
+ }
8
+ }
9
+ }
10
+
11
+ module.exports = addRoute;
@@ -0,0 +1,13 @@
1
+ function setMiddleware(app, middleware) {
2
+ if (!app || typeof app.use !== 'function') {
3
+ throw new Error("Invalid app instance: cannot apply middleware");
4
+ }
5
+
6
+ if (typeof middleware !== 'function') {
7
+ throw new Error("Middleware must be a function");
8
+ }
9
+
10
+ app.use(middleware);
11
+ }
12
+
13
+ module.exports = setMiddleware;
package/core/start.js ADDED
@@ -0,0 +1,8 @@
1
+ function start(server, port, callback) {
2
+ server.listen(port, () => {
3
+ if (callback) callback();
4
+ else console.log(`Server running at http://localhost:${port}`);
5
+ });
6
+ }
7
+
8
+ module.exports = start;
package/createApp.js ADDED
@@ -0,0 +1,21 @@
1
+ const express = require('express');
2
+ const start = require('./core/start');
3
+ const addRoute = require('./core/addRoute');
4
+ const setMiddleware = require('./core/setMiddleware');
5
+
6
+ function createApp() {
7
+ const app = express();
8
+
9
+ app.use(express.static('public'));
10
+ app.use(express.json());
11
+ app.use(express.urlencoded({ extended: true }));
12
+
13
+ // Encapsula as funΓ§Γ΅es novas dentro do objeto app
14
+ app.start = (port, callback) => start(app, port, callback);
15
+ app.addRoute = (path, handlers) => addRoute(app, path, handlers);
16
+ app.setMiddleware = (middleware) => setMiddleware(app, middleware);
17
+
18
+ return app;
19
+ }
20
+
21
+ module.exports = createApp;
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ const createApp = require("./createApp");
2
+
3
+ module.exports = createApp;
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "kaelum",
3
+ "version": "1.0.0",
4
+ "description": "A minimalist Node.js framework for building web pages and APIs with simplicity and speed.",
5
+ "main": "index.js",
6
+ "exports": {
7
+ ".": "./index.js"
8
+ },
9
+ "bin": {
10
+ "kaelum": "./cli/index.js"
11
+ },
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "keywords": [
16
+ "framework",
17
+ "nodejs",
18
+ "express",
19
+ "cli",
20
+ "kaelum",
21
+ "api",
22
+ "web",
23
+ "minimal",
24
+ "starter"
25
+ ],
26
+ "author": "Matheus Campagnolo",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "express": "^4.18.2",
30
+ "helmet": "^7.0.0",
31
+ "cors": "^2.8.5",
32
+ "fs-extra": "^11.3.0",
33
+ "inquirer": "^12.6.0"
34
+ }
35
+ }
package/utils/.gitkeep ADDED
File without changes