create-backlist 6.0.4 → 6.0.5

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": "6.0.4",
3
+ "version": "6.0.5",
4
4
  "description": "An advanced, multi-language backend generator based on frontend analysis.",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -0,0 +1,117 @@
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 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
+ * Analyze frontend source to extract API endpoints
45
+ * (axios / fetch based – simple & safe)
46
+ */
47
+ function analyzeFrontend(frontendDir) {
48
+ const endpoints = [];
49
+
50
+ function walk(dir) {
51
+ const files = fs.readdirSync(dir);
52
+
53
+ for (const file of files) {
54
+ const fullPath = path.join(dir, file);
55
+
56
+ if (fs.statSync(fullPath).isDirectory()) {
57
+ walk(fullPath);
58
+ } else if (
59
+ file.endsWith(".js") ||
60
+ file.endsWith(".ts") ||
61
+ file.endsWith(".jsx") ||
62
+ file.endsWith(".tsx")
63
+ ) {
64
+ const content = fs.readFileSync(fullPath, "utf8");
65
+
66
+ // axios.get('/api/xxx')
67
+ const axiosRegex = /axios\.(get|post|put|delete|patch)\(\s*['"`](.*?)['"`]/g;
68
+ let match;
69
+ while ((match = axiosRegex.exec(content)) !== null) {
70
+ endpoints.push({
71
+ method: match[1].toUpperCase(),
72
+ path: match[2],
73
+ source: normalizeSlashes(fullPath)
74
+ });
75
+ }
76
+
77
+ // fetch('/api/xxx')
78
+ const fetchRegex = /fetch\(\s*['"`](.*?)['"`]/g;
79
+ while ((match = fetchRegex.exec(content)) !== null) {
80
+ endpoints.push({
81
+ method: "GET",
82
+ path: match[1],
83
+ source: normalizeSlashes(fullPath)
84
+ });
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ walk(frontendDir);
91
+ return endpoints;
92
+ }
93
+
94
+ /**
95
+ * MAIN analyzer function (used by CLI)
96
+ */
97
+ function analyze(projectRoot = process.cwd()) {
98
+ const rootDir = path.resolve(projectRoot);
99
+
100
+ const frontendSrc = ["src", "app", "pages"]
101
+ .map(d => path.join(rootDir, d))
102
+ .find(d => fs.existsSync(d));
103
+
104
+ const endpoints = frontendSrc ? analyzeFrontend(frontendSrc) : [];
105
+
106
+ return {
107
+ rootDir: normalizeSlashes(rootDir),
108
+ hasAuth: findAuthUsageInRepo(rootDir),
109
+ addAuth: findAuthUsageInRepo(rootDir),
110
+ endpoints
111
+ };
112
+ }
113
+
114
+ module.exports = {
115
+ analyze,
116
+ analyzeFrontend
117
+ };
@@ -26,4 +26,4 @@ const PORT: number | string = process.env.PORT || 8000;
26
26
 
27
27
  app.listen(PORT, () => {
28
28
  console.log(`Server running on http://localhost:${PORT}`);
29
- });
29
+ });