project-startup 1.2.0 → 1.2.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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "postman.settings.dotenv-detection-notification-visibility": false
3
+ }
package/bin/cli.js CHANGED
@@ -1,30 +1,80 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const path = require("path")
4
- const prompts = require('prompts');
5
- const fs = require('fs-extra');
3
+ const path = require("path");
4
+ const prompts = require("prompts");
5
+ const fs = require("fs-extra");
6
6
 
7
7
  async function main() {
8
- const response = await prompts({
9
- type: "text",
10
- name: "projectName",
11
- message: "Project name",
12
- initial: "project-startup"
13
- });
8
+ const response = await prompts([
9
+ {
10
+ type: "text",
11
+ name: "projectName",
12
+ message: "Project name",
13
+ initial: "project-startup"
14
+ },
15
+ {
16
+ type: "multiselect",
17
+ name: "logics",
18
+ message: "Which logic folders do you want to install?",
19
+ choices: [
20
+ { title: "Booking", value: "Booking" },
21
+ { title: "RBAC", value: "rbac" },
22
+ { title: "Stocks", value: "Stocks" },
23
+ { title: "All", value: "all" }
24
+ ],
25
+ hint: "Use space to select, enter to confirm"
26
+ }
27
+ ]);
14
28
 
15
29
  const projectName = response.projectName?.trim();
16
30
  if (!projectName) process.exit(1);
17
31
 
18
32
  const targetDir = path.resolve(process.cwd(), projectName);
19
33
  const templateDir = path.resolve(__dirname, "../template");
34
+ const logicsDir = path.join(templateDir, "Logics");
20
35
 
21
36
  if (await fs.pathExists(targetDir)) {
22
37
  console.error(`Folder already exists: ${projectName}`);
23
38
  process.exit(1);
24
39
  }
25
40
 
26
- await fs.copy(templateDir, targetDir);
41
+ await fs.copy(templateDir, targetDir, {
42
+ filter: (src) => {
43
+ const rel = path.relative(templateDir, src);
44
+ if (!rel) return true;
45
+
46
+ if (!response.logics || response.logics.length === 0) return !rel.startsWith("Logics");
47
+
48
+ if (response.logics.includes("all")) return true;
49
+
50
+ if (rel.startsWith("Logics")) {
51
+ const parts = rel.split(path.sep);
52
+ if (parts.length >= 2) {
53
+ const folder = parts[1];
54
+ return response.logics.includes(folder);
55
+ }
56
+ }
57
+
58
+ return true;
59
+ }
60
+ });
61
+
62
+ if (!response.logics.includes("all")) {
63
+ const selected = response.logics || [];
64
+ for (const item of ["Booking", "rbac", "Stocks"]) {
65
+ if (!selected.includes(item)) {
66
+ await fs.remove(path.join(targetDir, "Logics", item));
67
+ }
68
+ }
69
+ const logicPath = path.join(targetDir, "Logics");
70
+ const remaining = await fs.readdir(logicPath);
71
+ if (remaining.length === 0) {
72
+ await fs.remove(logicPath);
73
+ }
74
+ }
75
+
27
76
  console.log(`Created ${projectName}`);
77
+ console.log(`Selected logics: ${response.logics?.join(", ") || "none"}`);
28
78
  console.log(`Next: cd ${projectName} && npm install && npm run dev`);
29
79
  }
30
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-startup",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Minimal session-based auth starter using Express, MySQL, React, Vite, and React Router.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -0,0 +1,12 @@
1
+ function requireRole(...roles) {
2
+ return (req, res, next) => {
3
+ if (!roles.includes(req.user.role)) {
4
+ return res.status(403).json({
5
+ error: `Access denied. Requires role: ${roles.join(" or ")}`,
6
+ });
7
+ }
8
+ next();
9
+ };
10
+ }
11
+
12
+ module.exports = requireRole;
@@ -0,0 +1,28 @@
1
+ const express = require("express");
2
+
3
+ const router = express.Router();
4
+
5
+ const bookingController = require("../controllers/bookingController");
6
+
7
+ const {
8
+ requireAuth,
9
+ requireRole,
10
+ } = require("../middleware/authMiddleware");
11
+
12
+ router.get("/", requireAuth, bookingController.getBookings);
13
+
14
+ router.post(
15
+ "/",
16
+ requireAuth,
17
+ requireRole("customer"),
18
+ bookingController.createBooking
19
+ );
20
+
21
+ router.delete(
22
+ "/:id",
23
+ requireAuth,
24
+ requireRole("customer"),
25
+ bookingController.cancelBooking
26
+ );
27
+
28
+ module.exports = router;
@@ -0,0 +1,37 @@
1
+ const express = require("express");
2
+
3
+ const router = express.Router();
4
+
5
+ const busController = require("../controllers/busController");
6
+
7
+ const {
8
+ requireAuth,
9
+ requireRole,
10
+ } = require("../middleware/authMiddleware");
11
+
12
+ router.get("/", requireAuth, busController.getAllBuses);
13
+
14
+ router.get("/:id", requireAuth, busController.getBusById);
15
+
16
+ router.post(
17
+ "/",
18
+ requireAuth,
19
+ requireRole("manager"),
20
+ busController.createBus
21
+ );
22
+
23
+ router.put(
24
+ "/:id",
25
+ requireAuth,
26
+ requireRole("manager"),
27
+ busController.updateBus
28
+ );
29
+
30
+ router.delete(
31
+ "/:id",
32
+ requireAuth,
33
+ requireRole("manager"),
34
+ busController.deleteBus
35
+ );
36
+
37
+ module.exports = router;