kaelum 1.1.0 β 1.2.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/README.md +18 -1
- package/cli/create.js +0 -7
- package/cli/templates/api/app.js +12 -0
- package/cli/templates/api/controllers/userController.js +13 -0
- package/cli/templates/api/middlewares/logger.js +6 -0
- package/cli/templates/api/package.json +17 -0
- package/cli/templates/api/routes.js +11 -0
- package/package.json +1 -1
- package/cli/templates/api/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ npm start
|
|
|
41
41
|
|
|
42
42
|
## π Web Template Structure
|
|
43
43
|
|
|
44
|
-
After running `npx kaelum create
|
|
44
|
+
After running `npx kaelum create` using the WEB template, the structure looks like this:
|
|
45
45
|
|
|
46
46
|
```
|
|
47
47
|
my-web-app/
|
|
@@ -60,6 +60,23 @@ my-web-app/
|
|
|
60
60
|
|
|
61
61
|
---
|
|
62
62
|
|
|
63
|
+
## π API Template Structure
|
|
64
|
+
|
|
65
|
+
After running `npx kaelum create` using the API template, the structure looks like this:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
my-api-app/
|
|
69
|
+
βββ controllers/
|
|
70
|
+
β βββ userController.js
|
|
71
|
+
βββ middlewares/
|
|
72
|
+
β βββ logger.js
|
|
73
|
+
βββ routes.js
|
|
74
|
+
βββ app.js
|
|
75
|
+
βββ package.json
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
63
80
|
## π Features
|
|
64
81
|
|
|
65
82
|
Kaelum exposes simple utilities that make it easy to build a web server:
|
package/cli/create.js
CHANGED
|
@@ -28,13 +28,6 @@ async function createProject() {
|
|
|
28
28
|
const targetDir = path.resolve(process.cwd(), projectName);
|
|
29
29
|
const templateDir = path.join(templatesDir, template);
|
|
30
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
31
|
if (fs.existsSync(targetDir)) {
|
|
39
32
|
console.error(
|
|
40
33
|
`\nβ A pasta "${projectName}" jΓ‘ existe. Escolha outro nome ou apague a pasta existente.`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function getUsers(req, res) {
|
|
2
|
+
res.json([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }]);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function createUser(req, res) {
|
|
6
|
+
const newUser = req.body;
|
|
7
|
+
res.status(201).json({ message: "User created", user: newUser });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
getUsers,
|
|
12
|
+
createUser
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kaelum-api-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A basic API template generated by Kaelum.",
|
|
5
|
+
"main": "app.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node app.js",
|
|
8
|
+
"dev": "nodemon app.js"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"kaelum": "1.1.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"nodemon": "^2.0.22"
|
|
15
|
+
},
|
|
16
|
+
"type": "commonjs"
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const userController = require("./controllers/userController");
|
|
2
|
+
const logger = require("./middlewares/logger");
|
|
3
|
+
|
|
4
|
+
function Routes(app) {
|
|
5
|
+
app.addRoute("/users", {
|
|
6
|
+
get: [logger, userController.getUsers],
|
|
7
|
+
post: [logger, userController.createUser],
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = Routes;
|
package/package.json
CHANGED
|
File without changes
|