create-mb-starter 1.0.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/index.js CHANGED
@@ -1,20 +1,55 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
5
  const { execSync } = require("child_process");
6
+ const chalk = require("chalk");
6
7
 
7
8
  const projectName = process.argv[2] || "my-app";
8
9
  const targetDir = path.join(process.cwd(), projectName);
9
10
  const templateDir = path.join(__dirname, "template");
10
11
 
12
+ // Banner
13
+ console.log(
14
+ chalk.cyan(`
15
+ ╔══════════════════════════════════════╗
16
+ ║ 🚀 MB STARTER TEMPLATE ║
17
+ ╚══════════════════════════════════════╝
18
+ `)
19
+ );
20
+
21
+ console.log(chalk.yellow("📦 Creating project:"), chalk.green(projectName));
22
+ console.log(chalk.gray("--------------------------------------------------"));
23
+
24
+ // Feature list
25
+ console.log(chalk.magenta("✨ This starter includes:"));
26
+ console.log(chalk.white(" ⚛ React (Vite powered)"));
27
+ console.log(chalk.white(" 🔀 React Router"));
28
+ console.log(chalk.white(" 📡 GET / POST / DELETE examples"));
29
+ console.log(chalk.white(" ✅ Input validation"));
30
+ console.log(chalk.white(" 🎨 Bootstrap styling"));
31
+ console.log(chalk.gray("--------------------------------------------------"));
32
+
11
33
  // Copy template
34
+ if (fs.existsSync(targetDir)) {
35
+ console.log(chalk.red("❌ Folder already exists!"));
36
+ process.exit(1);
37
+ }
38
+
12
39
  fs.cpSync(templateDir, targetDir, { recursive: true });
13
40
 
14
- console.log("Installing dependencies...");
41
+ console.log(chalk.blue("\n📥 Installing dependencies...\n"));
42
+
15
43
  execSync("npm install", { cwd: targetDir, stdio: "inherit" });
16
44
 
17
- console.log(`\nProject created: ${projectName}`);
18
- console.log(`\nNext steps:`);
19
- console.log(` cd ${projectName}`);
20
- console.log(` npm run dev`);
45
+ // Success message
46
+ console.log(
47
+ chalk.green(`
48
+ 🎉 Project successfully created!
49
+ `)
50
+ );
51
+
52
+ console.log(chalk.cyan("👉 Next steps:"));
53
+ console.log(chalk.white(` cd ${projectName}`));
54
+ console.log(chalk.white(` npm run dev`));
55
+ console.log(chalk.gray("\nHappy coding! 💻🔥\n"));
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "create-mb-starter",
3
3
  "type": "commonjs",
4
- "version": "1.0.0",
4
+ "version": "1.2.0",
5
5
  "bin": {
6
6
  "create-mb-starter": "./index.js"
7
+ },
8
+ "dependencies": {
9
+ "chalk": "^4.1.2"
7
10
  }
8
- }
11
+ }
@@ -14,15 +14,25 @@ function App() {
14
14
  const fetchData = async () => {
15
15
  const res = await fetch('http://localhost:3000/api/autok')
16
16
  const data = await res.json()
17
- console.log(data);
18
17
  setAdatok(data)
19
18
  };
20
19
 
20
+ const handleDelete = async (id) => {
21
+ if (window.confirm('Biztos benne, hogy törli?')) {
22
+ const res = await fetch(`http://localhost:3000/api/autok/${id}`, {
23
+ method: 'DELETE'
24
+ });
25
+ if (res.ok) {
26
+ fetchData();
27
+ }
28
+ }
29
+ };
30
+
21
31
  return (
22
32
  <>
23
33
  <BrowserRouter>
24
34
  <Routes>
25
- <Route path='/' element={<Home data={adatok} />} />
35
+ <Route path='/' element={<Home data={adatok} handleDelete={handleDelete} />} />
26
36
  <Route path="/felvisz" element={<Felvisz onAdd={fetchData}/>}/>
27
37
  </Routes>
28
38
  </BrowserRouter>
@@ -1,5 +1,5 @@
1
- import React, { useEffect, useState } from 'react'
2
- import { href, useNavigate } from 'react-router'
1
+ import { useState } from 'react'
2
+ import { useNavigate } from 'react-router'
3
3
 
4
4
  const Felvisz = ({onAdd}) => {
5
5
  const [data, setData] = useState({
@@ -12,13 +12,31 @@ const Felvisz = ({onAdd}) => {
12
12
  "gyartas_eve": "2019-03-15"
13
13
  })
14
14
 
15
- const [error, setError] = useState()
15
+ const [errors, setErrors] = useState([])
16
16
 
17
17
  const nav = useNavigate()
18
18
 
19
+ const validate = () => {
20
+ const errs = []
21
+ if (!data.modell.trim()) errs.push('A modell megadása kötelező.')
22
+ if (!data.gyartoId || data.gyartoId <= 0) errs.push('A gyártó ID pozitív szám kell legyen.')
23
+ if (!data.kategoriaId || data.kategoriaId <= 0) errs.push('A kategória ID pozitív szám kell legyen.')
24
+ if (!data.motor.trim()) errs.push('A motor megadása kötelező.')
25
+ if (!data.teljesitmeny || data.teljesitmeny <= 0) errs.push('A teljesítmény pozitív szám kell legyen.')
26
+ if (!data.ar || data.ar <= 0) errs.push('Az ár pozitív szám kell legyen.')
27
+ if (!data.gyartas_eve) errs.push('A gyártás évének megadása kötelező.')
28
+ return errs
29
+ }
30
+
19
31
  const onSubmit = async (e) =>{
20
32
  e.preventDefault()
21
- addData()
33
+ const validationErrors = validate()
34
+ if (validationErrors.length > 0) {
35
+ setErrors(validationErrors)
36
+ return
37
+ }
38
+ setErrors([])
39
+ await addData()
22
40
  }
23
41
 
24
42
 
@@ -36,7 +54,7 @@ const Felvisz = ({onAdd}) => {
36
54
  const dataRes = await res.json()
37
55
 
38
56
  if (!res.ok) {
39
- setError(dataRes.message)
57
+ setErrors([dataRes.message || 'Hiba a felvitel során'])
40
58
  throw new Error(dataRes.message || 'Hiba a felvitel során')
41
59
  }
42
60
  console.log('Sikeres felvitel:', dataRes);
@@ -46,18 +64,22 @@ const Felvisz = ({onAdd}) => {
46
64
 
47
65
  return (
48
66
  <form onSubmit={(e)=>(onSubmit(e))}>
49
- {error && <p>{error}</p>}
67
+ {errors.length > 0 && (
68
+ <ul className="text-danger">
69
+ {errors.map((err, i) => <li key={i}>{err}</li>)}
70
+ </ul>
71
+ )}
50
72
  <div className="mb-3">
51
73
  <label htmlFor="exampleInputEmail1" className="form-label">Modell</label>
52
74
  <input type="text" value={data.modell} onChange={(e) => setData({...data, modell:e.target.value})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
53
75
  </div>
54
76
  <div className="mb-3">
55
77
  <label htmlFor="exampleInputEmail1" className="form-label">Gyarto Id</label>
56
- <input type="number" value={data.gyartoId} onChange={(e) => setData({...data, gyartoId:e.target.value})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
78
+ <input type="number" value={data.gyartoId} onChange={(e) => setData({...data, gyartoId:Number(e.target.value)})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
57
79
  </div>
58
80
  <div className="mb-3">
59
81
  <label htmlFor="exampleInputEmail1" className="form-label">Kategoria Id</label>
60
- <input type="number" value={data.kategoriaId} onChange={(e) => setData({...data, kategoriaId:e.target.value})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
82
+ <input type="number" value={data.kategoriaId} onChange={(e) => setData({...data, kategoriaId:Number(e.target.value)})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
61
83
  </div>
62
84
  <div className="mb-3">
63
85
  <label htmlFor="exampleInputEmail1" className="form-label">Motor</label>
@@ -65,11 +87,11 @@ const Felvisz = ({onAdd}) => {
65
87
  </div>
66
88
  <div className="mb-3">
67
89
  <label htmlFor="exampleInputEmail1" className="form-label">Telsejítmény</label>
68
- <input type="number" value={data.teljesitmeny} onChange={(e) => setData({...data, teljesitmeny:e.target.value})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
90
+ <input type="number" value={data.teljesitmeny} onChange={(e) => setData({...data, teljesitmeny:Number(e.target.value)})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
69
91
  </div>
70
92
  <div className="mb-3">
71
93
  <label htmlFor="exampleInputEmail1" className="form-label">Ár</label>
72
- <input type="number" value={data.ar} onChange={(e) => setData({...data, ar:e.target.value})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
94
+ <input type="number" value={data.ar} onChange={(e) => setData({...data, ar:Number(e.target.value)})} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />
73
95
  </div>
74
96
  <div className="mb-3">
75
97
  <label htmlFor="exampleInputEmail1" className="form-label">Gyártás éve</label>
@@ -1,8 +1,9 @@
1
1
  import React from 'react'
2
2
  import { Link } from 'react-router'
3
3
 
4
- const Home = ({ data }) => {
4
+ const Home = ({ data, handleDelete }) => {
5
5
  return (
6
+ <>
6
7
  <table className="table">
7
8
  <thead>
8
9
  <tr>
@@ -10,21 +11,25 @@ const Home = ({ data }) => {
10
11
  <th scope="col">Ár</th>
11
12
  <th scope="col">Motor</th>
12
13
  <th scope="col">Teljesítmény</th>
14
+ <th scope="col">Törlés</th>
13
15
  </tr>
14
16
  </thead>
15
17
  <tbody>
16
18
  {data.map((i) => (
17
- <tr>
19
+ <tr key={i.id}>
18
20
  <th scope="row">{i.modell}</th>
19
21
  <td>{i.ar} Ft</td>
20
22
  <td>{i.motor}</td>
21
23
  <td>{i.teljesitmeny}</td>
24
+ <td>
25
+ <button className="btn btn-danger" onClick={() => handleDelete(i.id)}>Törlés</button>
26
+ </td>
22
27
  </tr>
23
28
  ))}
24
29
  </tbody>
25
- <Link className='btn btn-primary' to={"/felvisz"}>Uj adat</Link>
26
30
  </table>
27
-
31
+ <Link className='btn btn-primary' to={"/felvisz"}>Uj adat</Link>
32
+ </>
28
33
  )
29
34
  }
30
35