create-backlist 5.0.5 → 5.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-backlist",
3
- "version": "5.0.5",
3
+ "version": "5.0.6",
4
4
  "description": "An advanced, multi-language backend generator based on frontend analysis.",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -1,11 +1,17 @@
1
- const ejs = require('ejs');
2
1
  const fs = require('fs-extra');
2
+ const ejs = require('ejs');
3
3
  const path = require('path');
4
4
 
5
- async function renderAndWrite(templatePath, destinationPath, data) {
6
- const template = await fs.readFile(templatePath, 'utf-8');
7
- const content = ejs.render(template, data);
8
- await fs.outputFile(destinationPath, content);
5
+ async function renderAndWrite(templatePath, outPath, data) {
6
+ try {
7
+ const tpl = await fs.readFile(templatePath, 'utf-8');
8
+ const code = ejs.render(tpl, data || {}, { filename: templatePath }); // filename helps with EJS errors
9
+ await fs.outputFile(outPath, code);
10
+ } catch (err) {
11
+ console.error('EJS render failed for:', templatePath);
12
+ console.error('Data keys:', Object.keys(data || {}));
13
+ throw err;
14
+ }
9
15
  }
10
16
 
11
17
  function getTemplatePath(subpath) {
@@ -1,125 +1,50 @@
1
- // Auto-generated by create-backlist v5.0
2
- using Microsoft.AspNetCore.Mvc;
3
- using Microsoft.EntityFrameworkCore;
4
- using <%= projectName %>.Data;
5
- using <%= projectName %>.Models;
6
-
7
- namespace <%= projectName %>.Controllers
8
- {
9
- [ApiController]
10
- [Route("api/[controller]")]
11
- public class <%= controllerName %>Controller : ControllerBase
12
- {
13
- private readonly ApplicationDbContext _context;
14
-
15
- public <%= controllerName %>Controller(ApplicationDbContext context)
16
- {
17
- _context = context;
18
- }
19
-
20
- // GET: api/<%= controllerName.toLowerCase() %>
21
- // Retrieves all items.
22
- [HttpGet]
23
- public async Task<ActionResult<IEnumerable<<%= controllerName %>>>> Get<%= controllerName %>s()
24
- {
25
- if (_context.<%= controllerName %>s == null)
26
- {
27
- return NotFound("Entity set '<%= controllerName %>s' is null.");
28
- }
29
- return await _context.<%= controllerName %>s.ToListAsync();
30
- }
31
-
32
- // GET: api/<%= controllerName.toLowerCase() %>/{id}
33
- // Retrieves a specific item by its ID.
34
- [HttpGet("{id}")]
35
- public async Task<ActionResult<<%= controllerName %>>> Get<%= controllerName %>(Guid id)
36
- {
37
- if (_context.<%= controllerName %>s == null)
38
- {
39
- return NotFound();
40
- }
41
- var item = await _context.<%= controllerName %>s.FindAsync(id);
42
-
43
- if (item == null)
44
- {
45
- return NotFound();
46
- }
47
-
48
- return item;
49
- }
50
-
51
- // PUT: api/<%= controllerName.toLowerCase() %>/{id}
52
- // Updates a specific item.
53
- [HttpPut("{id}")]
54
- public async Task<IActionResult> Put<%= controllerName %>(Guid id, <%= controllerName %> item)
55
- {
56
- if (id != item.Id)
57
- {
58
- return BadRequest();
59
- }
60
-
61
- _context.Entry(item).State = EntityState.Modified;
62
-
63
- try
64
- {
65
- await _context.SaveChangesAsync();
66
- }
67
- catch (DbUpdateConcurrencyException)
68
- {
69
- if (!ItemExists(id))
70
- {
71
- return NotFound();
72
- }
73
- else
74
- {
75
- throw;
76
- }
77
- }
78
-
79
- return NoContent();
80
- }
81
-
82
- // POST: api/<%= controllerName.toLowerCase() %>
83
- // Creates a new item.
84
- [HttpPost]
85
- public async Task<ActionResult<<%= controllerName %>>> Post<%= controllerName %>(<%= controllerName %> item)
86
- {
87
- if (_context.<%= controllerName %>s == null)
88
- {
89
- return Problem("Entity set '<%= controllerName %>s' is null.");
90
- }
91
- // Ensure a new Guid is created for the new item
92
- item.Id = Guid.NewGuid();
93
- _context.<%= controllerName %>s.Add(item);
94
- await _context.SaveChangesAsync();
95
-
96
- return CreatedAtAction(nameof(Get<%= controllerName %>), new { id = item.Id }, item);
97
- }
98
-
99
- // DELETE: api/<%= controllerName.toLowerCase() %>/{id}
100
- // Deletes a specific item.
101
- [HttpDelete("{id}")]
102
- public async Task<IActionResult> Delete<%= controllerName %>(Guid id)
103
- {
104
- if (_context.<%= controllerName %>s == null)
105
- {
106
- return NotFound();
107
- }
108
- var item = await _context.<%= controllerName %>s.FindAsync(id);
109
- if (item == null)
110
- {
111
- return NotFound();
112
- }
113
-
114
- _context.<%= controllerName %>s.Remove(item);
115
- await _context.SaveChangesAsync();
116
-
117
- return NoContent();
118
- }
119
-
120
- private bool ItemExists(Guid id)
121
- {
122
- return (_context.<%= controllerName %>s?.Any(e => e.Id == id)).GetValueOrDefault();
123
- }
124
- }
125
- }
1
+ // Auto-generated by create-backlist on <%= new Date().toISOString() %>
2
+ import { Request, Response } from 'express';
3
+
4
+ export const create<%= modelName %> = async (req: Request, res: Response) => {
5
+ try {
6
+ // TODO: implement create logic
7
+ res.status(201).json({ message: '<%= modelName %> created', data: req.body });
8
+ } catch (error) {
9
+ res.status(500).json({ message: 'Error creating <%= modelName %>', error });
10
+ }
11
+ };
12
+
13
+ export const getAll<%= modelName %>s = async (_req: Request, res: Response) => {
14
+ try {
15
+ // TODO: implement list logic
16
+ res.status(200).json([]);
17
+ } catch (error) {
18
+ res.status(500).json({ message: 'Error fetching <%= modelName %>s', error });
19
+ }
20
+ };
21
+
22
+ export const get<%= modelName %>ById = async (req: Request, res: Response) => {
23
+ try {
24
+ const { id } = req.params;
25
+ // TODO: implement get by id logic
26
+ res.status(200).json({ id });
27
+ } catch (error) {
28
+ res.status(500).json({ message: 'Error fetching <%= modelName %>', error });
29
+ }
30
+ };
31
+
32
+ export const update<%= modelName %>ById = async (req: Request, res: Response) => {
33
+ try {
34
+ const { id } = req.params;
35
+ // TODO: implement update logic
36
+ res.status(200).json({ id, ...req.body });
37
+ } catch (error) {
38
+ res.status(500).json({ message: 'Error updating <%= modelName %>', error });
39
+ }
40
+ };
41
+
42
+ export const delete<%= modelName %>ById = async (req: Request, res: Response) => {
43
+ try {
44
+ const { id } = req.params;
45
+ // TODO: implement delete logic
46
+ res.status(204).send();
47
+ } catch (error) {
48
+ res.status(500).json({ message: 'Error deleting <%= modelName %>', error });
49
+ }
50
+ };