create-backlist 6.2.2 → 7.0.1
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/bin/index.js +503 -140
- package/package.json +11 -8
- package/src/ai-agent.js +171 -0
- package/src/analyzer.js +496 -436
- package/src/generators/java.js +17 -8
- package/src/generators/node.js +405 -374
- package/src/generators/template.js +23 -21
- package/src/templates/node-ts-express/partials/HexController.ts.ejs +56 -0
- package/src/templates/node-ts-express/partials/HexRepository.ts.ejs +26 -0
- package/src/templates/node-ts-express/partials/HexService.ts.ejs +27 -0
- package/src/utils.js +12 -14
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import ejs from 'ejs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
export async function renderAndWrite(templatePath, outPath, data) {
|
|
10
|
+
try {
|
|
11
|
+
const tpl = await fs.readFile(templatePath, 'utf-8');
|
|
12
|
+
const code = ejs.render(tpl, data || {}, { filename: templatePath }); // filename helps with EJS errors
|
|
13
|
+
await fs.outputFile(outPath, code);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
console.error('EJS render failed for:', templatePath);
|
|
16
|
+
console.error('Data keys:', Object.keys(data || {}));
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getTemplatePath(subpath) {
|
|
22
|
+
return path.join(__dirname, '..', 'templates', subpath);
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { <%- modelName %>Service } from '../../domain/services/<%- modelName %>.service';
|
|
3
|
+
|
|
4
|
+
<%- typeof aiValidationLogic !== 'undefined' ? aiValidationLogic : '// No external validation logic injected' %>
|
|
5
|
+
|
|
6
|
+
export class <%- modelName %>Controller {
|
|
7
|
+
|
|
8
|
+
static async getAll(req: Request, res: Response) {
|
|
9
|
+
try {
|
|
10
|
+
const data = await <%- modelName %>Service.getAll();
|
|
11
|
+
res.status(200).json(data);
|
|
12
|
+
} catch (error: any) {
|
|
13
|
+
res.status(500).json({ message: error.message });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static async getById(req: Request, res: Response) {
|
|
18
|
+
try {
|
|
19
|
+
const id = req.params.id;
|
|
20
|
+
const data = await <%- modelName %>Service.getById(id);
|
|
21
|
+
if (!data) return res.status(404).json({ message: 'Not found' });
|
|
22
|
+
res.status(200).json(data);
|
|
23
|
+
} catch (error: any) {
|
|
24
|
+
res.status(500).json({ message: error.message });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static async create(req: Request, res: Response) {
|
|
29
|
+
try {
|
|
30
|
+
const data = await <%- modelName %>Service.create(req.body);
|
|
31
|
+
res.status(201).json(data);
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
res.status(400).json({ message: error.message });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static async update(req: Request, res: Response) {
|
|
38
|
+
try {
|
|
39
|
+
const id = req.params.id;
|
|
40
|
+
const data = await <%- modelName %>Service.update(id, req.body);
|
|
41
|
+
res.status(200).json(data);
|
|
42
|
+
} catch (error: any) {
|
|
43
|
+
res.status(400).json({ message: error.message });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static async delete(req: Request, res: Response) {
|
|
48
|
+
try {
|
|
49
|
+
const id = req.params.id;
|
|
50
|
+
await <%- modelName %>Service.delete(id);
|
|
51
|
+
res.status(204).send();
|
|
52
|
+
} catch (error: any) {
|
|
53
|
+
res.status(500).json({ message: error.message });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<%- dbType === 'prisma' ? "import { prisma } from '../../infrastructure/adapters/database';" : "import " + modelName + " from '../../domain/models/" + modelName + ".model';" %>
|
|
2
|
+
|
|
3
|
+
<%- typeof aiDbRelations !== 'undefined' ? aiDbRelations : '// Default DB Relations' %>
|
|
4
|
+
|
|
5
|
+
export class <%- modelName %>Repository {
|
|
6
|
+
|
|
7
|
+
static async findAll() {
|
|
8
|
+
<%- dbType === 'prisma' ? " return prisma." + modelName.toLowerCase() + ".findMany();" : " return " + modelName + ".find();" %>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static async findById(id: string) {
|
|
12
|
+
<%- dbType === 'prisma' ? " return prisma." + modelName.toLowerCase() + ".findUnique({ where: { id } });" : " return " + modelName + ".findById(id);" %>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static async create(data: any) {
|
|
16
|
+
<%- dbType === 'prisma' ? " return prisma." + modelName.toLowerCase() + ".create({ data });" : " return " + modelName + ".create(data);" %>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static async update(id: string, data: any) {
|
|
20
|
+
<%- dbType === 'prisma' ? " return prisma." + modelName.toLowerCase() + ".update({ where: { id }, data });" : " return " + modelName + ".findByIdAndUpdate(id, data, { new: true });" %>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static async delete(id: string) {
|
|
24
|
+
<%- dbType === 'prisma' ? " return prisma." + modelName.toLowerCase() + ".delete({ where: { id } });" : " return " + modelName + ".findByIdAndDelete(id);" %>
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { <%- modelName %>Repository } from '../../infrastructure/adapters/<%- modelName %>.repository';
|
|
2
|
+
|
|
3
|
+
<%- typeof aiSecurityConfig !== 'undefined' ? aiSecurityConfig : '// Default domain logic security' %>
|
|
4
|
+
|
|
5
|
+
export class <%- modelName %>Service {
|
|
6
|
+
|
|
7
|
+
static async getAll() {
|
|
8
|
+
return <%- modelName %>Repository.findAll();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static async getById(id: string) {
|
|
12
|
+
return <%- modelName %>Repository.findById(id);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static async create(payload: any) {
|
|
16
|
+
// --- Domain Business Logic here ---
|
|
17
|
+
return <%- modelName %>Repository.create(payload);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static async update(id: string, payload: any) {
|
|
21
|
+
return <%- modelName %>Repository.update(id, payload);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static async delete(id: string) {
|
|
25
|
+
return <%- modelName %>Repository.delete(id);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
async function isCommandAvailable(command) {
|
|
4
|
-
try {
|
|
5
|
-
// Using a harmless version command to check for presence
|
|
6
|
-
const checkCommand = command === 'java' ? '-version' : '--version';
|
|
7
|
-
await execa(command, [checkCommand]);
|
|
8
|
-
return true;
|
|
9
|
-
} catch {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = { isCommandAvailable };
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
|
|
3
|
+
export async function isCommandAvailable(command) {
|
|
4
|
+
try {
|
|
5
|
+
// Using a harmless version command to check for presence
|
|
6
|
+
const checkCommand = command === 'java' ? '-version' : '--version';
|
|
7
|
+
await execa(command, [checkCommand]);
|
|
8
|
+
return true;
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|