create-bdpa-react-scaffold 1.7.0 → 1.7.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.
Files changed (3) hide show
  1. package/create-ui-lib.js +182 -2
  2. package/package.json +2 -3
  3. package/HOWTO.md +0 -166
package/create-ui-lib.js CHANGED
@@ -62,9 +62,20 @@ function installDependencies(pm, cwd) {
62
62
  const pmCmd = pm === "yarn" ? "yarn" : pm === "pnpm" ? "pnpm" : "npm";
63
63
  console.log(`\nšŸ“¦ Installing dependencies with ${pmCmd}...`);
64
64
  const args = pmCmd === "npm" ? ["install"] : ["install"];
65
- const result = spawnSync(pmCmd, args, { stdio: "inherit", cwd });
65
+ const result = spawnSync(pmCmd, args, {
66
+ stdio: "inherit",
67
+ cwd,
68
+ shell: true,
69
+ maxBuffer: 10 * 1024 * 1024
70
+ });
66
71
  if (result.status !== 0) {
67
- console.error(`\nāŒ ${pmCmd} install failed.`);
72
+ console.error(`\nāŒ ${pmCmd} install failed with status code ${result.status}.`);
73
+ console.error(`\nTroubleshooting tips:`);
74
+ console.error(` 1. Try again: cd ${cwd} && ${pmCmd} install`);
75
+ console.error(` 2. Check Node.js version: node --version (requires v18+)`);
76
+ console.error(` 3. Clear cache: ${pmCmd} cache clean --force`);
77
+ console.error(` 4. Check internet connection`);
78
+ console.error(` 5. Delete node_modules and package-lock.json, then retry`);
68
79
  process.exit(result.status || 1);
69
80
  }
70
81
  console.log("\nāœ… Dependencies installed.");
@@ -160,6 +171,175 @@ write("index.html", `
160
171
  </html>
161
172
  `);
162
173
 
174
+ write("HOWTO.md", `
175
+ # How-To Guides
176
+
177
+ ## How to Add a New Page
178
+
179
+ 1. **Create the page component** in \`src/pages/\`:
180
+
181
+ \`\`\`jsx
182
+ // src/pages/Dashboard.jsx
183
+ import React from "react";
184
+ import Container from "../components/layout/Container";
185
+ import Card from "../components/ui/Card";
186
+
187
+ export default function Dashboard() {
188
+ return (
189
+ <Container>
190
+ <h1 className="text-3xl font-bold mb-6">Dashboard</h1>
191
+ <Card>
192
+ <p>Welcome to your dashboard!</p>
193
+ </Card>
194
+ </Container>
195
+ );
196
+ }
197
+ \`\`\`
198
+
199
+ 2. **Add the route** in \`src/App.jsx\`:
200
+
201
+ \`\`\`jsx
202
+ import { BrowserRouter, Routes, Route } from "react-router-dom";
203
+ import Dashboard from "./pages/Dashboard";
204
+ // ... other imports
205
+
206
+ function App() {
207
+ return (
208
+ <BrowserRouter>
209
+ <Routes>
210
+ <Route path="/" element={<Home />} />
211
+ <Route path="/dashboard" element={<Dashboard />} />
212
+ {/* Add your new route here */}
213
+ </Routes>
214
+ </BrowserRouter>
215
+ );
216
+ }
217
+ \`\`\`
218
+
219
+ 3. **Add navigation link** (optional) in \`src/components/ui/Navbar.jsx\` or \`Sidebar.jsx\`:
220
+
221
+ \`\`\`jsx
222
+ import { Link } from "react-router-dom";
223
+
224
+ <Link to="/dashboard" className="text-gray-700 hover:text-blue-600">
225
+ Dashboard
226
+ </Link>
227
+ \`\`\`
228
+
229
+ ## How to Make a REST API Call
230
+
231
+ The scaffold includes an Axios-based API client in \`src/utils/api.js\` with built-in CRUD methods.
232
+
233
+ ### Basic API Configuration
234
+
235
+ Set your API base URL in a \`.env\` file:
236
+
237
+ \`\`\`bash
238
+ VITE_API_BASE_URL=https://api.example.com
239
+ \`\`\`
240
+
241
+ ### Making API Calls
242
+
243
+ \`\`\`jsx
244
+ import { useState, useEffect } from "react";
245
+ import api from "../utils/api";
246
+
247
+ function MyComponent() {
248
+ const [data, setData] = useState([]);
249
+ const [loading, setLoading] = useState(false);
250
+ const [error, setError] = useState(null);
251
+
252
+ // GET request - Fetch all items
253
+ useEffect(() => {
254
+ const fetchData = async () => {
255
+ setLoading(true);
256
+ try {
257
+ const response = await api.getAll("/students");
258
+ setData(response.data);
259
+ } catch (err) {
260
+ setError(err.message);
261
+ } finally {
262
+ setLoading(false);
263
+ }
264
+ };
265
+ fetchData();
266
+ }, []);
267
+
268
+ // GET request - Fetch single item
269
+ const fetchStudent = async (id) => {
270
+ try {
271
+ const response = await api.getById("/students", id);
272
+ console.log(response.data);
273
+ } catch (err) {
274
+ console.error(err);
275
+ }
276
+ };
277
+
278
+ // POST request - Create new item
279
+ const createStudent = async () => {
280
+ try {
281
+ const newStudent = { name: "Ada Lovelace", grade: "A" };
282
+ const response = await api.create("/students", newStudent);
283
+ setData([...data, response.data]);
284
+ } catch (err) {
285
+ setError(err.message);
286
+ }
287
+ };
288
+
289
+ // PUT request - Update item
290
+ const updateStudent = async (id) => {
291
+ try {
292
+ const updates = { name: "Grace Hopper" };
293
+ const response = await api.update(\`/students/\${id}\`, updates);
294
+ setData(data.map(item => item.id === id ? response.data : item));
295
+ } catch (err) {
296
+ setError(err.message);
297
+ }
298
+ };
299
+
300
+ // DELETE request - Remove item
301
+ const deleteStudent = async (id) => {
302
+ try {
303
+ await api.delete(\`/students/\${id}\`);
304
+ setData(data.filter(item => item.id !== id));
305
+ } catch (err) {
306
+ setError(err.message);
307
+ }
308
+ };
309
+
310
+ return (
311
+ <div>
312
+ {loading && <p>Loading...</p>}
313
+ {error && <p className="text-red-500">Error: {error}</p>}
314
+ {/* Render your data here */}
315
+ </div>
316
+ );
317
+ }
318
+ \`\`\`
319
+
320
+ ### Available API Methods
321
+
322
+ - \`api.getAll(endpoint)\` - GET all items
323
+ - \`api.getById(endpoint, id)\` - GET single item
324
+ - \`api.create(endpoint, data)\` - POST new item
325
+ - \`api.update(endpoint, data)\` - PUT update item
326
+ - \`api.delete(endpoint)\` - DELETE item
327
+ - \`api.setToken(token)\` - Set authorization token
328
+
329
+ ### Custom API Client
330
+
331
+ Create a custom client for different base URLs:
332
+
333
+ \`\`\`js
334
+ import { ApiClient } from "./utils/api";
335
+
336
+ const adminApi = new ApiClient("https://admin.example.com");
337
+ adminApi.setToken("your-jwt-token");
338
+
339
+ const response = await adminApi.getAll("/users");
340
+ \`\`\`
341
+ `);
342
+
163
343
  // -------------------------------
164
344
  // src root
165
345
  // -------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-bdpa-react-scaffold",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
 
5
5
  "description": "Scaffold a React + Tailwind UI library demo via Vite.",
6
6
  "bin": {
@@ -8,8 +8,7 @@
8
8
  },
9
9
  "files": [
10
10
  "create-ui-lib.js",
11
- "README.md",
12
- "HOWTO.md"
11
+ "README.md"
13
12
  ],
14
13
  "keywords": [
15
14
  "create",
package/HOWTO.md DELETED
@@ -1,166 +0,0 @@
1
- # How-To Guides
2
-
3
- ## How to Add a New Page
4
-
5
- 1. **Create the page component** in `src/pages/`:
6
-
7
- ```jsx
8
- // src/pages/Dashboard.jsx
9
- import React from "react";
10
- import Container from "../components/layout/Container";
11
- import Card from "../components/ui/Card";
12
-
13
- export default function Dashboard() {
14
- return (
15
- <Container>
16
- <h1 className="text-3xl font-bold mb-6">Dashboard</h1>
17
- <Card>
18
- <p>Welcome to your dashboard!</p>
19
- </Card>
20
- </Container>
21
- );
22
- }
23
- ```
24
-
25
- 2. **Add the route** in `src/App.jsx`:
26
-
27
- ```jsx
28
- import { BrowserRouter, Routes, Route } from "react-router-dom";
29
- import Dashboard from "./pages/Dashboard";
30
- // ... other imports
31
-
32
- function App() {
33
- return (
34
- <BrowserRouter>
35
- <Routes>
36
- <Route path="/" element={<Home />} />
37
- <Route path="/dashboard" element={<Dashboard />} />
38
- {/* Add your new route here */}
39
- </Routes>
40
- </BrowserRouter>
41
- );
42
- }
43
- ```
44
-
45
- 3. **Add navigation link** (optional) in `src/components/ui/Navbar.jsx` or `Sidebar.jsx`:
46
-
47
- ```jsx
48
- import { Link } from "react-router-dom";
49
-
50
- <Link to="/dashboard" className="text-gray-700 hover:text-blue-600">
51
- Dashboard
52
- </Link>
53
- ```
54
-
55
- ## How to Make a REST API Call
56
-
57
- The scaffold includes an Axios-based API client in `src/utils/api.js` with built-in CRUD methods.
58
-
59
- ### Basic API Configuration
60
-
61
- Set your API base URL in a `.env` file:
62
-
63
- ```bash
64
- VITE_API_BASE_URL=https://api.example.com
65
- ```
66
-
67
- ### Making API Calls
68
-
69
- ```jsx
70
- import { useState, useEffect } from "react";
71
- import api from "../utils/api";
72
-
73
- function MyComponent() {
74
- const [data, setData] = useState([]);
75
- const [loading, setLoading] = useState(false);
76
- const [error, setError] = useState(null);
77
-
78
- // GET request - Fetch all items
79
- useEffect(() => {
80
- const fetchData = async () => {
81
- setLoading(true);
82
- try {
83
- const response = await api.getAll("/students");
84
- setData(response.data);
85
- } catch (err) {
86
- setError(err.message);
87
- } finally {
88
- setLoading(false);
89
- }
90
- };
91
- fetchData();
92
- }, []);
93
-
94
- // GET request - Fetch single item
95
- const fetchStudent = async (id) => {
96
- try {
97
- const response = await api.getById("/students", id);
98
- console.log(response.data);
99
- } catch (err) {
100
- console.error(err);
101
- }
102
- };
103
-
104
- // POST request - Create new item
105
- const createStudent = async () => {
106
- try {
107
- const newStudent = { name: "Ada Lovelace", grade: "A" };
108
- const response = await api.create("/students", newStudent);
109
- setData([...data, response.data]);
110
- } catch (err) {
111
- setError(err.message);
112
- }
113
- };
114
-
115
- // PUT request - Update item
116
- const updateStudent = async (id) => {
117
- try {
118
- const updates = { name: "Grace Hopper" };
119
- const response = await api.update(`/students/${id}`, updates);
120
- setData(data.map(item => item.id === id ? response.data : item));
121
- } catch (err) {
122
- setError(err.message);
123
- }
124
- };
125
-
126
- // DELETE request - Remove item
127
- const deleteStudent = async (id) => {
128
- try {
129
- await api.delete(`/students/${id}`);
130
- setData(data.filter(item => item.id !== id));
131
- } catch (err) {
132
- setError(err.message);
133
- }
134
- };
135
-
136
- return (
137
- <div>
138
- {loading && <p>Loading...</p>}
139
- {error && <p className="text-red-500">Error: {error}</p>}
140
- {/* Render your data here */}
141
- </div>
142
- );
143
- }
144
- ```
145
-
146
- ### Available API Methods
147
-
148
- - `api.getAll(endpoint)` - GET all items
149
- - `api.getById(endpoint, id)` - GET single item
150
- - `api.create(endpoint, data)` - POST new item
151
- - `api.update(endpoint, data)` - PUT update item
152
- - `api.delete(endpoint)` - DELETE item
153
- - `api.setToken(token)` - Set authorization token
154
-
155
- ### Custom API Client
156
-
157
- Create a custom client for different base URLs:
158
-
159
- ```js
160
- import { ApiClient } from "./utils/api";
161
-
162
- const adminApi = new ApiClient("https://admin.example.com");
163
- adminApi.setToken("your-jwt-token");
164
-
165
- const response = await adminApi.getAll("/users");
166
- ```