create-backlist 6.0.7 → 6.0.9
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 +141 -0
- package/package.json +4 -10
- package/src/analyzer.js +104 -315
- package/src/generators/dotnet.js +94 -120
- package/src/generators/java.js +109 -157
- package/src/generators/node.js +157 -261
- package/src/generators/template.js +2 -38
- package/src/templates/dotnet/partials/Controller.cs.ejs +14 -7
- package/src/templates/java-spring/partials/ApplicationSeeder.java.ejs +2 -7
- package/src/templates/java-spring/partials/AuthController.java.ejs +10 -23
- package/src/templates/java-spring/partials/Controller.java.ejs +6 -17
- package/src/templates/java-spring/partials/Dockerfile.ejs +1 -6
- package/src/templates/java-spring/partials/Entity.java.ejs +5 -15
- package/src/templates/java-spring/partials/JwtAuthFilter.java.ejs +7 -30
- package/src/templates/java-spring/partials/JwtService.java.ejs +10 -38
- package/src/templates/java-spring/partials/Repository.java.ejs +1 -10
- package/src/templates/java-spring/partials/Service.java.ejs +7 -45
- package/src/templates/java-spring/partials/User.java.ejs +4 -17
- package/src/templates/java-spring/partials/UserDetailsServiceImpl.java.ejs +4 -10
- package/src/templates/java-spring/partials/UserRepository.java.ejs +0 -8
- package/src/templates/java-spring/partials/docker-compose.yml.ejs +8 -16
- package/src/templates/node-ts-express/base/server.ts +6 -13
- package/src/templates/node-ts-express/base/tsconfig.json +3 -13
- package/src/templates/node-ts-express/partials/ApiDocs.ts.ejs +7 -17
- package/src/templates/node-ts-express/partials/App.test.ts.ejs +26 -49
- package/src/templates/node-ts-express/partials/Auth.controller.ts.ejs +62 -56
- package/src/templates/node-ts-express/partials/Auth.middleware.ts.ejs +10 -21
- package/src/templates/node-ts-express/partials/Controller.ts.ejs +40 -40
- package/src/templates/node-ts-express/partials/DbContext.cs.ejs +3 -3
- package/src/templates/node-ts-express/partials/Dockerfile.ejs +11 -9
- package/src/templates/node-ts-express/partials/Model.cs.ejs +7 -25
- package/src/templates/node-ts-express/partials/Model.ts.ejs +12 -20
- package/src/templates/node-ts-express/partials/PrismaController.ts.ejs +55 -72
- package/src/templates/node-ts-express/partials/PrismaSchema.prisma.ejs +12 -27
- package/src/templates/node-ts-express/partials/README.md.ejs +12 -9
- package/src/templates/node-ts-express/partials/Seeder.ts.ejs +64 -44
- package/src/templates/node-ts-express/partials/docker-compose.yml.ejs +16 -31
- package/src/templates/node-ts-express/partials/package.json.ejs +1 -3
- package/src/templates/node-ts-express/partials/routes.ts.ejs +24 -35
- package/src/utils.js +5 -17
- package/bin/backlist.js +0 -228
- package/src/db/prisma.ts +0 -4
- package/src/scanner/analyzeFrontend.js +0 -146
- package/src/scanner/index.js +0 -99
- package/src/templates/dotnet/partials/Dto.cs.ejs +0 -8
- package/src/templates/node-ts-express/partials/prismaClient.ts.ejs +0 -4
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
const fs = require("fs-extra");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Normalize paths (Windows → Unix style)
|
|
7
|
-
*/
|
|
8
|
-
function normalizeSlashes(p) {
|
|
9
|
-
return String(p || "").replace(/\\/g, "/");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Detect auth usage in entire repo
|
|
14
|
-
* (basic heuristic – good enough for competition demo)
|
|
15
|
-
*/
|
|
16
|
-
function findAuthUsageInRepo(rootDir) {
|
|
17
|
-
const keywords = ["auth", "jwt", "token", "passport", "oauth"];
|
|
18
|
-
let found = false;
|
|
19
|
-
|
|
20
|
-
function walk(dir) {
|
|
21
|
-
if (found) return;
|
|
22
|
-
|
|
23
|
-
const files = fs.readdirSync(dir);
|
|
24
|
-
for (const file of files) {
|
|
25
|
-
const fullPath = path.join(dir, file);
|
|
26
|
-
|
|
27
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
28
|
-
walk(fullPath);
|
|
29
|
-
} else if (file.endsWith(".js") || file.endsWith(".ts")) {
|
|
30
|
-
const content = fs.readFileSync(fullPath, "utf8").toLowerCase();
|
|
31
|
-
if (keywords.some(k => content.includes(k))) {
|
|
32
|
-
found = true;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
walk(rootDir);
|
|
40
|
-
return found;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Derive a controller name from URL
|
|
45
|
-
*/
|
|
46
|
-
function deriveControllerName(urlPath) {
|
|
47
|
-
if (!urlPath) return "Default";
|
|
48
|
-
const parts = urlPath.split("/").filter(Boolean);
|
|
49
|
-
const apiIndex = parts.indexOf("api");
|
|
50
|
-
if (apiIndex >= 0) return parts[apiIndex + 1] || "Default";
|
|
51
|
-
return parts[0] || "Default";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Derive an action name from method + URL
|
|
56
|
-
*/
|
|
57
|
-
function deriveActionName(method, urlPath) {
|
|
58
|
-
if (!urlPath) return `${method.toLowerCase()}Action`;
|
|
59
|
-
const cleaned = urlPath.replace(/^\/api\//, "/").replace(/[/:{}-]/g, " ");
|
|
60
|
-
const lastSegment = cleaned.trim().split(/\s+/).filter(Boolean).pop() || "Action";
|
|
61
|
-
return `${method.toLowerCase()}${lastSegment.charAt(0).toUpperCase()}${lastSegment.slice(1)}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Analyze frontend source to extract API endpoints
|
|
66
|
-
* (axios / fetch based – simple & safe)
|
|
67
|
-
*/
|
|
68
|
-
function analyzeFrontend(frontendDir) {
|
|
69
|
-
const endpoints = [];
|
|
70
|
-
|
|
71
|
-
function walk(dir) {
|
|
72
|
-
const files = fs.readdirSync(dir);
|
|
73
|
-
|
|
74
|
-
for (const file of files) {
|
|
75
|
-
const fullPath = path.join(dir, file);
|
|
76
|
-
|
|
77
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
78
|
-
walk(fullPath);
|
|
79
|
-
} else if (
|
|
80
|
-
file.endsWith(".js") ||
|
|
81
|
-
file.endsWith(".ts") ||
|
|
82
|
-
file.endsWith(".jsx") ||
|
|
83
|
-
file.endsWith(".tsx")
|
|
84
|
-
) {
|
|
85
|
-
const content = fs.readFileSync(fullPath, "utf8");
|
|
86
|
-
|
|
87
|
-
// --- axios ---
|
|
88
|
-
const axiosRegex = /axios\.(get|post|put|delete|patch)\(\s*['"`](.*?)['"`]/g;
|
|
89
|
-
let match;
|
|
90
|
-
while ((match = axiosRegex.exec(content)) !== null) {
|
|
91
|
-
const url = match[2].startsWith("/") ? match[2] : "/" + match[2];
|
|
92
|
-
const method = match[1].toUpperCase();
|
|
93
|
-
endpoints.push({
|
|
94
|
-
method,
|
|
95
|
-
path: url,
|
|
96
|
-
controllerName: deriveControllerName(url),
|
|
97
|
-
actionName: deriveActionName(method, url),
|
|
98
|
-
source: normalizeSlashes(fullPath)
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// --- fetch ---
|
|
103
|
-
const fetchRegex = /fetch\(\s*['"`](.*?)['"`]/g;
|
|
104
|
-
while ((match = fetchRegex.exec(content)) !== null) {
|
|
105
|
-
const url = match[1].startsWith("/") ? match[1] : "/" + match[1];
|
|
106
|
-
const method = "GET";
|
|
107
|
-
endpoints.push({
|
|
108
|
-
method,
|
|
109
|
-
path: url,
|
|
110
|
-
controllerName: deriveControllerName(url),
|
|
111
|
-
actionName: deriveActionName(method, url),
|
|
112
|
-
source: normalizeSlashes(fullPath)
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
walk(frontendDir);
|
|
120
|
-
return endpoints;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* MAIN analyzer function (used by CLI)
|
|
125
|
-
*/
|
|
126
|
-
function analyze(projectRoot = process.cwd()) {
|
|
127
|
-
const rootDir = path.resolve(projectRoot);
|
|
128
|
-
|
|
129
|
-
const frontendSrc = ["src", "app", "pages"]
|
|
130
|
-
.map(d => path.join(rootDir, d))
|
|
131
|
-
.find(d => fs.existsSync(d));
|
|
132
|
-
|
|
133
|
-
const endpoints = frontendSrc ? analyzeFrontend(frontendSrc) : [];
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
rootDir: normalizeSlashes(rootDir),
|
|
137
|
-
hasAuth: findAuthUsageInRepo(rootDir),
|
|
138
|
-
addAuth: findAuthUsageInRepo(rootDir),
|
|
139
|
-
endpoints
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
module.exports = {
|
|
144
|
-
analyze,
|
|
145
|
-
analyzeFrontend
|
|
146
|
-
};
|
package/src/scanner/index.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fg = require('fast-glob');
|
|
3
|
-
const { Project, SyntaxKind } = require('ts-morph');
|
|
4
|
-
const fs = require('fs-extra');
|
|
5
|
-
|
|
6
|
-
function normalizeMethod(name) {
|
|
7
|
-
const m = String(name).toUpperCase();
|
|
8
|
-
return ['GET','POST','PUT','PATCH','DELETE'].includes(m) ? m : null;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Very first-pass extractor: axios.<method>('url') OR fetch('url', { method: 'POST' })
|
|
12
|
-
async function scanFrontend({ frontendSrcDir }) {
|
|
13
|
-
const patterns = [
|
|
14
|
-
'**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
const files = await fg(patterns, {
|
|
18
|
-
cwd: frontendSrcDir,
|
|
19
|
-
absolute: true,
|
|
20
|
-
ignore: ['**/node_modules/**', '**/dist/**', '**/.next/**', '**/build/**']
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const project = new Project({
|
|
24
|
-
tsConfigFilePath: fs.existsSync(path.join(frontendSrcDir, '../tsconfig.json'))
|
|
25
|
-
? path.join(frontendSrcDir, '../tsconfig.json')
|
|
26
|
-
: undefined,
|
|
27
|
-
skipAddingFilesFromTsConfig: true
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
files.forEach(f => project.addSourceFileAtPathIfExists(f));
|
|
31
|
-
|
|
32
|
-
const endpoints = [];
|
|
33
|
-
|
|
34
|
-
for (const sf of project.getSourceFiles()) {
|
|
35
|
-
// axios.get('/x') | axios.post('/x')
|
|
36
|
-
const callExprs = sf.getDescendantsOfKind(SyntaxKind.CallExpression);
|
|
37
|
-
|
|
38
|
-
for (const call of callExprs) {
|
|
39
|
-
const expr = call.getExpression();
|
|
40
|
-
|
|
41
|
-
// axios.<method>(...)
|
|
42
|
-
if (expr.getKind() === SyntaxKind.PropertyAccessExpression) {
|
|
43
|
-
const pae = expr;
|
|
44
|
-
const method = normalizeMethod(pae.getName());
|
|
45
|
-
const target = pae.getExpression().getText(); // axios / api / client etc (basic)
|
|
46
|
-
const args = call.getArguments();
|
|
47
|
-
if (method && args.length >= 1 && args[0].getKind() === SyntaxKind.StringLiteral) {
|
|
48
|
-
const url = args[0].getText().slice(1, -1);
|
|
49
|
-
endpoints.push({
|
|
50
|
-
source: sf.getFilePath(),
|
|
51
|
-
kind: 'axios',
|
|
52
|
-
client: target,
|
|
53
|
-
method,
|
|
54
|
-
url
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// fetch('/x', { method: 'POST' })
|
|
60
|
-
if (expr.getText() === 'fetch') {
|
|
61
|
-
const args = call.getArguments();
|
|
62
|
-
if (args.length >= 1 && args[0].getKind() === SyntaxKind.StringLiteral) {
|
|
63
|
-
const url = args[0].getText().slice(1, -1);
|
|
64
|
-
let method = 'GET';
|
|
65
|
-
if (args[1] && args[1].getKind() === SyntaxKind.ObjectLiteralExpression) {
|
|
66
|
-
const obj = args[1];
|
|
67
|
-
const methodProp = obj.getProperty('method');
|
|
68
|
-
if (methodProp && methodProp.getKind() === SyntaxKind.PropertyAssignment) {
|
|
69
|
-
const init = methodProp.getInitializer();
|
|
70
|
-
if (init && init.getKind() === SyntaxKind.StringLiteral) {
|
|
71
|
-
method = init.getText().slice(1, -1).toUpperCase();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
endpoints.push({
|
|
76
|
-
source: sf.getFilePath(),
|
|
77
|
-
kind: 'fetch',
|
|
78
|
-
method,
|
|
79
|
-
url
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
version: 1,
|
|
88
|
-
generatedAt: new Date().toISOString(),
|
|
89
|
-
frontendSrcDir,
|
|
90
|
-
endpoints
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function writeContracts(outFile, contracts) {
|
|
95
|
-
await fs.ensureDir(path.dirname(outFile));
|
|
96
|
-
await fs.writeJson(outFile, contracts, { spaces: 2 });
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
module.exports = { scanFrontend, writeContracts };
|