kaelum 1.3.2 → 1.3.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/README.md CHANGED
@@ -1,9 +1,22 @@
1
- # Kaelum
1
+ <div align="center">
2
2
 
3
- **Kaelum.JS** — Minimalist Node.js framework to simplify creation of web pages and REST APIs.
3
+ <h1>Kaelum</h1>
4
+
5
+ [![npm version](https://img.shields.io/npm/v/kaelum)](https://www.npmjs.com/package/kaelum)
6
+ [![Build Status](https://github.com/MatheusCampagnolo/kaelum/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/MatheusCampagnolo/kaelum/actions)
7
+ [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
8
+ [![Docs](https://img.shields.io/badge/docs-online-blue)](https://matheuscampagnolo.github.io/kaelum/)
9
+
10
+ **Kaelum.js** — Minimalist Node.js framework to simplify creation of web pages and REST APIs.
4
11
  Designed for students and developers who want a fast, opinionated project scaffold and a small, friendly API that encapsulates common Express.js boilerplate.
5
12
 
6
- ---
13
+ 👉 [**Read the full documentation here**](https://matheuscampagnolo.github.io/kaelum/)
14
+
15
+ **If Kaelum helps you, consider supporting its development:**
16
+
17
+ <a href='https://ko-fi.com/Z8Z51NK4KT' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi6.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
18
+
19
+ </div>
7
20
 
8
21
  ## 🚀 Quick start
9
22
 
@@ -11,7 +24,7 @@ Create a new project (interactive):
11
24
 
12
25
  ```bash
13
26
  npx kaelum create
14
- ````
27
+ ```
15
28
 
16
29
  Or create non-interactively (project name + template):
17
30
 
@@ -35,13 +48,14 @@ npm start
35
48
 
36
49
  ## 📦 What Kaelum provides
37
50
 
38
- * CLI that scaffolds a ready-to-run project (Web or API template) using an opinionated **MVC** structure.
39
- * Thin abstraction layer over **Express.js** that:
51
+ - CLI that scaffolds a ready-to-run project (Web or API template) using an opinionated **MVC** structure.
52
+ - Thin abstraction layer over **Express.js** that:
53
+
54
+ - automates JSON / URL-encoded parsing by default,
55
+ - automatically configures common security middlewares via `setConfig` (CORS, Helmet),
56
+ - exposes a small, easy-to-learn API for routes, middleware and configuration.
40
57
 
41
- * automates JSON / URL-encoded parsing by default,
42
- * automatically configures common security middlewares via `setConfig` (CORS, Helmet),
43
- * exposes a small, easy-to-learn API for routes, middleware and configuration.
44
- * Small set of helpers for common tasks: `start`, `addRoute`, `apiRoute`, `setConfig`, `static`, `redirect`, `healthCheck`, `useErrorHandler`, and more.
58
+ - Small set of helpers for common tasks: `start`, `addRoute`, `apiRoute`, `setConfig`, `static`, `redirect`, `healthCheck`, `useErrorHandler`, and more.
45
59
 
46
60
  Kaelum aims to reduce the initial setup burden while keeping flexibility for advanced users.
47
61
 
@@ -49,7 +63,7 @@ Kaelum aims to reduce the initial setup burden while keeping flexibility for adv
49
63
 
50
64
  ## 📁 Template structures
51
65
 
52
- ### Web template (created by `npx kaelum create <name>` with template `web`)
66
+ ### Web template (`--template web`)
53
67
 
54
68
  ```
55
69
  my-web-app/
@@ -81,12 +95,12 @@ my-api-app/
81
95
 
82
96
  ---
83
97
 
84
- ## 🧩 Core API (examples — CommonJS)
98
+ ## 🧩 Core API
85
99
 
86
100
  > Kaelum exposes a factory — use `require('kaelum')` and call it to get an app instance:
87
101
 
88
102
  ```js
89
- const kaelum = require('kaelum');
103
+ const kaelum = require("kaelum");
90
104
  const app = kaelum();
91
105
  ```
92
106
 
@@ -96,17 +110,17 @@ Enable/disable common features:
96
110
 
97
111
  ```js
98
112
  app.setConfig({
99
- cors: true, // apply CORS (requires cors package in dependencies)
100
- helmet: true, // apply Helmet
101
- static: "public", // serve static files from "public"
102
- bodyParser: true, // default: enabled (JSON + urlencoded)
103
- logs: false, // enable request logging via morgan (if installed)
104
- port: 3000 // prefered port (used when calling app.start() without port)
113
+ cors: true, // apply CORS (requires cors package in dependencies)
114
+ helmet: true, // apply Helmet
115
+ static: "public", // serve static files from "public"
116
+ bodyParser: true, // default: enabled (JSON + urlencoded)
117
+ logs: false, // enable request logging via morgan (if installed)
118
+ port: 3000, // prefered port (used when calling app.start() without port)
105
119
  });
106
120
  ```
107
121
 
108
- * `setConfig` persists settings to the Kaelum config and will install/remove Kaelum-managed middlewares.
109
- * Kaelum enables JSON/urlencoded parsing by default so beginners won't forget to parse request bodies.
122
+ - `setConfig` persists settings to the Kaelum config and will install/remove Kaelum-managed middlewares.
123
+ - Kaelum enables JSON/urlencoded parsing by default so beginners won't forget to parse request bodies.
110
124
 
111
125
  ---
112
126
 
@@ -115,7 +129,7 @@ app.setConfig({
115
129
  Starts the HTTP server. If `port` is omitted, Kaelum reads `port` from `setConfig` or falls back to `3000`.
116
130
 
117
131
  ```js
118
- app.start(3000, () => console.log('Running'));
132
+ app.start(3000, () => console.log("Running"));
119
133
  ```
120
134
 
121
135
  ---
@@ -125,20 +139,20 @@ app.start(3000, () => console.log('Running'));
125
139
  Register routes easily:
126
140
 
127
141
  ```js
128
- app.addRoute('/home', {
129
- get: (req, res) => res.send('Welcome!'),
130
- post: (req, res) => res.send('Posted!')
142
+ app.addRoute("/home", {
143
+ get: (req, res) => res.send("Welcome!"),
144
+ post: (req, res) => res.send("Posted!"),
131
145
  });
132
146
 
133
147
  // apiRoute builds RESTy resources with nested subpaths:
134
- app.apiRoute('users', {
148
+ app.apiRoute("users", {
135
149
  get: listUsers,
136
150
  post: createUser,
137
- '/:id': {
151
+ "/:id": {
138
152
  get: getUserById,
139
153
  put: updateUser,
140
- delete: deleteUser
141
- }
154
+ delete: deleteUser,
155
+ },
142
156
  });
143
157
  ```
144
158
 
@@ -152,13 +166,13 @@ Flexible helper to register middleware(s):
152
166
 
153
167
  ```js
154
168
  // single middleware
155
- app.setMiddleware(require('helmet')());
169
+ app.setMiddleware(require("helmet")());
156
170
 
157
171
  // array of middlewares
158
172
  app.setMiddleware([mw1, mw2]);
159
173
 
160
174
  // mount middleware on a path
161
- app.setMiddleware('/admin', authMiddleware);
175
+ app.setMiddleware("/admin", authMiddleware);
162
176
  ```
163
177
 
164
178
  ---
@@ -168,7 +182,7 @@ app.setMiddleware('/admin', authMiddleware);
168
182
  Register a redirect route:
169
183
 
170
184
  ```js
171
- app.redirect('/old-url', '/new-url', 302);
185
+ app.redirect("/old-url", "/new-url", 302);
172
186
  ```
173
187
 
174
188
  ---
@@ -193,45 +207,42 @@ It will return standardized JSON for errors and log server-side errors (5xx) to
193
207
 
194
208
  ## 🔧 Local development & contributing
195
209
 
196
- To develop Kaelum locally and test the CLI:
197
-
198
210
  ```bash
199
- # clone
200
211
  git clone https://github.com/MatheusCampagnolo/kaelum.git
201
212
  cd kaelum
202
-
203
- # install & link locally
204
213
  npm install
205
214
  npm link
215
+ ```
216
+
217
+ Now you can test the CLI locally:
206
218
 
207
- # from any folder you can now run the CLI
219
+ ```bash
208
220
  npx kaelum create my-test --template web
209
- # or
210
- kaelum create my-test # if linked globally
211
221
  ```
212
222
 
213
223
  ---
214
224
 
215
-
216
225
  ## 📝 Why Kaelum?
217
226
 
218
- * Reduces repetitive boilerplate required to start Node/Express web projects.
219
- * Opinionated scaffolding (MVC) helps beginners adopt better structure.
220
- * Keeps a small API surface: easy to teach and document.
221
- * Extensible — `setConfig` and middleware helpers allow adding features without exposing Express internals.
227
+ - Reduces repetitive boilerplate required to start Node/Express web projects.
228
+ - Opinionated scaffolding (MVC) helps beginners adopt better structure.
229
+ - Keeps a small API surface: easy to teach and document.
230
+ - Extensible — `setConfig` and middleware helpers allow adding features without exposing Express internals.
222
231
 
223
232
  ---
224
233
 
225
234
  ## ✅ Current status
226
235
 
227
- > Kaelum is under active development. The CLI scaffolds web and API templates and the framework already includes the MVP helpers (`start`, `addRoute`, `apiRoute`, `setConfig`, `static`, `redirect`, `healthCheck`, `useErrorHandler`) and security toggles for `cors` and `helmet`.
236
+ > Kaelum is under active development.
237
+ > CLI scaffolds web and API templates, and the framework includes the MVP helpers (`start`, `addRoute`, `apiRoute`, `setConfig`, `static`, `redirect`, `healthCheck`, `useErrorHandler`) and security toggles for `cors` and `helmet`.
228
238
 
229
239
  ---
230
240
 
231
241
  ## 📚 Links
232
242
 
233
- * GitHub: `https://github.com/MatheusCampagnolo/kaelum`
234
- * npm: `https://www.npmjs.com/package/kaelum`
243
+ - [GitHub](https://github.com/MatheusCampagnolo/kaelum)
244
+ - [npm](https://www.npmjs.com/package/kaelum)
245
+ - [Documentation](https://matheuscampagnolo.github.io/kaelum/)
235
246
 
236
247
  ---
237
248
 
@@ -243,6 +254,5 @@ MIT — see [LICENSE](LICENSE).
243
254
 
244
255
  ## ✍️ Notes for maintainers
245
256
 
246
- * Templates include `package.json` configured as `commonjs` for now (uses `require`/`module.exports`).
247
- * Update template `package.json` dependencies to reference Kaelum version when releasing new npm versions.
248
- * We plan to add full JSDoc for the public API, unit tests (Jest + Supertest) and a docs site in future iterations.
257
+ - Templates use `commonjs` (`require` / `module.exports`).
258
+ - Update template dependencies to reference the correct Kaelum version when releasing new npm versions.
package/cli/create.js CHANGED
@@ -3,12 +3,42 @@ const inq = inquirer.default || inquirer;
3
3
  const path = require("path");
4
4
  const fs = require("fs-extra");
5
5
  const { copyTemplate } = require("./utils");
6
+ const { spawn } = require("child_process");
6
7
 
7
8
  const templatesDir = path.resolve(__dirname, "templates");
8
9
 
10
+ /**
11
+ * runInstall - runs `npm ci` if package-lock exists, otherwise `npm install`
12
+ * @param {string} cwd - target directory where install runs
13
+ * @returns {Promise<void>}
14
+ */
15
+ function runInstall(cwd) {
16
+ return new Promise((resolve, reject) => {
17
+ const lockExists = fs.existsSync(path.join(cwd, "package-lock.json"));
18
+ const cmd = "npm";
19
+ const args = lockExists ? ["ci"] : ["install"];
20
+
21
+ // Spawn child process and inherit stdio so user sees progress
22
+ const child = spawn(cmd, args, {
23
+ cwd,
24
+ stdio: "inherit",
25
+ shell: process.platform === "win32", // improves compatibility on Windows
26
+ });
27
+
28
+ child.on("error", (err) => {
29
+ reject(err);
30
+ });
31
+
32
+ child.on("exit", (code) => {
33
+ if (code === 0) return resolve();
34
+ reject(new Error(`${cmd} ${args.join(" ")} exited with code ${code}`));
35
+ });
36
+ });
37
+ }
38
+
9
39
  /**
10
40
  * createProject - create project from template
11
- * @param {Object} defaults - optional { projectName, template }
41
+ * @param {Object} defaults - optional { projectName, template, autoInstall }
12
42
  */
13
43
  async function createProject(defaults = {}) {
14
44
  console.log("🚀 Bem-vindo ao Kaelum CLI!");
@@ -47,9 +77,19 @@ async function createProject(defaults = {}) {
47
77
  },
48
78
  default: defaults.template || "web",
49
79
  },
80
+ {
81
+ type: "confirm",
82
+ name: "autoInstall",
83
+ message:
84
+ "Deseja que eu execute 'npm install' agora (recomendado)?",
85
+ default:
86
+ typeof defaults.autoInstall === "boolean"
87
+ ? defaults.autoInstall
88
+ : true,
89
+ },
50
90
  ]);
51
91
 
52
- const { projectName, template } = answers;
92
+ const { projectName, template, autoInstall } = answers;
53
93
  const targetDir = path.resolve(process.cwd(), projectName);
54
94
  const templateDir = path.join(templatesDir, template);
55
95
 
@@ -76,10 +116,26 @@ async function createProject(defaults = {}) {
76
116
 
77
117
  console.log(`\n✅ Projeto "${projectName}" criado com sucesso!`);
78
118
  console.log(`➡️ Acesse a pasta: cd ${projectName}`);
79
- console.log(`➡️ Inicie o projeto com: npm install && npm start\n`);
119
+
120
+ if (autoInstall) {
121
+ console.log("⬇️ Instalando dependências (npm)... (isso pode levar alguns minutos)");
122
+ try {
123
+ await runInstall(targetDir);
124
+ console.log("\n✅ Dependências instaladas com sucesso!");
125
+ console.log("➡️ Para iniciar o projeto, execute: npm start\n");
126
+ } catch (installErr) {
127
+ console.error(
128
+ "\n❌ Falha ao instalar dependências automaticamente:",
129
+ installErr.message || installErr
130
+ );
131
+ console.log(`➡️ Tente manualmente: cd ${projectName} && npm install`);
132
+ }
133
+ } else {
134
+ console.log(`➡️ Inicie o projeto com: cd ${projectName} && npm install && npm start\n`);
135
+ }
80
136
  } catch (err) {
81
137
  console.error("❌ Erro inesperado:", err.message || err);
82
138
  }
83
139
  }
84
140
 
85
- module.exports = { createProject };
141
+ module.exports = { createProject };
package/cli/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const { createProject } = require("./create");
3
3
  const argv = process.argv.slice(2);
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaelum",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "A minimalist Node.js framework for building web pages and APIs with simplicity and speed.",
5
5
  "main": "index.js",
6
6
  "exports": {