sprint-es 0.0.80 → 0.0.81
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/dist/cjs/cli.cjs +27 -27
- package/dist/esm/cli.js +28 -28
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -117,7 +117,7 @@ function scanDirectory(dir, extensions) {
|
|
|
117
117
|
}
|
|
118
118
|
return files;
|
|
119
119
|
}
|
|
120
|
-
function extractRoutesFromFile(filePath) {
|
|
120
|
+
function extractRoutesFromFile(filePath, schemaNames) {
|
|
121
121
|
const routes = [];
|
|
122
122
|
try {
|
|
123
123
|
const content = fs.readFileSync(filePath, "utf-8");
|
|
@@ -126,42 +126,44 @@ function extractRoutesFromFile(filePath) {
|
|
|
126
126
|
for (const line of lines) {
|
|
127
127
|
const trimmed = line.trim();
|
|
128
128
|
for (const method of routerMethods) {
|
|
129
|
-
const match = trimmed.match(new RegExp(`router\\.${method}\\s*\\(\\s*['"\`]([^'"\`]+)['"\`]`));
|
|
129
|
+
const match = trimmed.match(new RegExp(`router\\.${method}\\s*\\(\\s*['"\`]([^'"\`]+)['"\`]\\s*,\\s*([^,)]+)`));
|
|
130
130
|
if (match) {
|
|
131
|
+
const routePath = match[1];
|
|
132
|
+
const firstArg = match[2].trim().split(",")[0].trim();
|
|
133
|
+
const hasSchema = schemaNames.has(firstArg);
|
|
131
134
|
routes.push({
|
|
132
135
|
file: filePath,
|
|
133
|
-
path:
|
|
136
|
+
path: routePath,
|
|
134
137
|
method: method.toUpperCase(),
|
|
135
|
-
hasSchema
|
|
138
|
+
hasSchema
|
|
136
139
|
});
|
|
137
140
|
break;
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
|
-
} catch {
|
|
144
|
+
} catch (e) {
|
|
145
|
+
console.error("Error extracting routes:", e);
|
|
142
146
|
}
|
|
143
147
|
return routes;
|
|
144
148
|
}
|
|
145
|
-
function
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
149
|
+
function extractAllSchemaNames(projectRoot2) {
|
|
150
|
+
const schemaNames = /* @__PURE__ */ new Set();
|
|
151
|
+
const schemasPath = path.join(projectRoot2, "src/schemas");
|
|
152
|
+
if (!fs.existsSync(schemasPath)) {
|
|
153
|
+
return schemaNames;
|
|
154
|
+
}
|
|
155
|
+
const schemaFiles = scanDirectory(schemasPath, [".ts", ".js"]);
|
|
156
|
+
for (const file of schemaFiles) {
|
|
157
|
+
try {
|
|
158
|
+
const content = fs.readFileSync(file, "utf-8");
|
|
159
|
+
const matches = content.matchAll(/export\s+const\s+(\w+)\s*=/g);
|
|
160
|
+
for (const match of matches) {
|
|
161
|
+
schemaNames.add(match[1]);
|
|
155
162
|
}
|
|
163
|
+
} catch {
|
|
156
164
|
}
|
|
157
|
-
const directSchemaPattern = new RegExp(`router\\.${method.toLowerCase()}\\s*\\(\\s*['"\`]${routePath.replace("/", "\\/")}['"\`]\\s*,\\s*defineRouteSchema`);
|
|
158
|
-
if (directSchemaPattern.test(content)) {
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
return false;
|
|
162
|
-
} catch {
|
|
163
|
-
return false;
|
|
164
165
|
}
|
|
166
|
+
return schemaNames;
|
|
165
167
|
}
|
|
166
168
|
function hasSchemaInMiddleware(filePath) {
|
|
167
169
|
try {
|
|
@@ -209,15 +211,13 @@ async function runDoctor() {
|
|
|
209
211
|
logger.info("🔍 Sprint Doctor - Analyzing routes and middlewares...\n");
|
|
210
212
|
const routesPath = path.join(projectRoot, "src/routes");
|
|
211
213
|
const middlewaresPath = path.join(projectRoot, "src/middlewares");
|
|
214
|
+
const schemaNames = extractAllSchemaNames(projectRoot);
|
|
212
215
|
const routeFiles = scanDirectory(routesPath, [".ts", ".js"]);
|
|
213
216
|
const middlewareFiles = scanDirectory(middlewaresPath, [".ts", ".js"]);
|
|
214
217
|
const allRoutes = [];
|
|
215
218
|
for (const file of routeFiles) {
|
|
216
|
-
const routes = extractRoutesFromFile(file);
|
|
217
|
-
|
|
218
|
-
route.hasSchema = checkRouteHasSchema(file, route.path, route.method);
|
|
219
|
-
allRoutes.push(route);
|
|
220
|
-
}
|
|
219
|
+
const routes = extractRoutesFromFile(file, schemaNames);
|
|
220
|
+
allRoutes.push(...routes);
|
|
221
221
|
}
|
|
222
222
|
const middlewares = [];
|
|
223
223
|
for (const file of middlewareFiles) {
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { existsSync, readdirSync, statSync
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "fs";
|
|
3
3
|
import * as crypto from "crypto";
|
|
4
4
|
import { join, resolve } from "path";
|
|
5
5
|
import { spawn } from "child_process";
|
|
@@ -99,7 +99,7 @@ function scanDirectory(dir, extensions) {
|
|
|
99
99
|
}
|
|
100
100
|
return files;
|
|
101
101
|
}
|
|
102
|
-
function extractRoutesFromFile(filePath) {
|
|
102
|
+
function extractRoutesFromFile(filePath, schemaNames) {
|
|
103
103
|
const routes = [];
|
|
104
104
|
try {
|
|
105
105
|
const content = readFileSync(filePath, "utf-8");
|
|
@@ -108,42 +108,44 @@ function extractRoutesFromFile(filePath) {
|
|
|
108
108
|
for (const line of lines) {
|
|
109
109
|
const trimmed = line.trim();
|
|
110
110
|
for (const method of routerMethods) {
|
|
111
|
-
const match = trimmed.match(new RegExp(`router\\.${method}\\s*\\(\\s*['"\`]([^'"\`]+)['"\`]`));
|
|
111
|
+
const match = trimmed.match(new RegExp(`router\\.${method}\\s*\\(\\s*['"\`]([^'"\`]+)['"\`]\\s*,\\s*([^,)]+)`));
|
|
112
112
|
if (match) {
|
|
113
|
+
const routePath = match[1];
|
|
114
|
+
const firstArg = match[2].trim().split(",")[0].trim();
|
|
115
|
+
const hasSchema = schemaNames.has(firstArg);
|
|
113
116
|
routes.push({
|
|
114
117
|
file: filePath,
|
|
115
|
-
path:
|
|
118
|
+
path: routePath,
|
|
116
119
|
method: method.toUpperCase(),
|
|
117
|
-
hasSchema
|
|
120
|
+
hasSchema
|
|
118
121
|
});
|
|
119
122
|
break;
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
|
-
} catch {
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.error("Error extracting routes:", e);
|
|
124
128
|
}
|
|
125
129
|
return routes;
|
|
126
130
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
function extractAllSchemaNames(projectRoot2) {
|
|
132
|
+
const schemaNames = /* @__PURE__ */ new Set();
|
|
133
|
+
const schemasPath = join(projectRoot2, "src/schemas");
|
|
134
|
+
if (!existsSync(schemasPath)) {
|
|
135
|
+
return schemaNames;
|
|
136
|
+
}
|
|
137
|
+
const schemaFiles = scanDirectory(schemasPath, [".ts", ".js"]);
|
|
138
|
+
for (const file of schemaFiles) {
|
|
139
|
+
try {
|
|
140
|
+
const content = readFileSync(file, "utf-8");
|
|
141
|
+
const matches = content.matchAll(/export\s+const\s+(\w+)\s*=/g);
|
|
142
|
+
for (const match of matches) {
|
|
143
|
+
schemaNames.add(match[1]);
|
|
137
144
|
}
|
|
145
|
+
} catch {
|
|
138
146
|
}
|
|
139
|
-
const directSchemaPattern = new RegExp(`router\\.${method.toLowerCase()}\\s*\\(\\s*['"\`]${routePath.replace("/", "\\/")}['"\`]\\s*,\\s*defineRouteSchema`);
|
|
140
|
-
if (directSchemaPattern.test(content)) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
} catch {
|
|
145
|
-
return false;
|
|
146
147
|
}
|
|
148
|
+
return schemaNames;
|
|
147
149
|
}
|
|
148
150
|
function hasSchemaInMiddleware(filePath) {
|
|
149
151
|
try {
|
|
@@ -191,15 +193,13 @@ async function runDoctor() {
|
|
|
191
193
|
logger.info("🔍 Sprint Doctor - Analyzing routes and middlewares...\n");
|
|
192
194
|
const routesPath = join(projectRoot, "src/routes");
|
|
193
195
|
const middlewaresPath = join(projectRoot, "src/middlewares");
|
|
196
|
+
const schemaNames = extractAllSchemaNames(projectRoot);
|
|
194
197
|
const routeFiles = scanDirectory(routesPath, [".ts", ".js"]);
|
|
195
198
|
const middlewareFiles = scanDirectory(middlewaresPath, [".ts", ".js"]);
|
|
196
199
|
const allRoutes = [];
|
|
197
200
|
for (const file of routeFiles) {
|
|
198
|
-
const routes = extractRoutesFromFile(file);
|
|
199
|
-
|
|
200
|
-
route.hasSchema = checkRouteHasSchema(file, route.path, route.method);
|
|
201
|
-
allRoutes.push(route);
|
|
202
|
-
}
|
|
201
|
+
const routes = extractRoutesFromFile(file, schemaNames);
|
|
202
|
+
allRoutes.push(...routes);
|
|
203
203
|
}
|
|
204
204
|
const middlewares = [];
|
|
205
205
|
for (const file of middlewareFiles) {
|