routesync 1.0.42 → 1.0.43
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/cli.js +31 -29
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8361,7 +8361,9 @@ var import_path = __toESM(require("path"));
|
|
|
8361
8361
|
var LaravelRouteParser = class {
|
|
8362
8362
|
async parse(filePath, options = {}) {
|
|
8363
8363
|
const projectRoot = import_path.default.resolve(import_path.default.dirname(filePath), "..");
|
|
8364
|
+
const extractModels = options.extractModels ? "true" : "false";
|
|
8364
8365
|
const phpScript = `<?php
|
|
8366
|
+
error_reporting(0);
|
|
8365
8367
|
require __DIR__.'/vendor/autoload.php';
|
|
8366
8368
|
$app = require_once __DIR__.'/bootstrap/app.php';
|
|
8367
8369
|
$kernel = $app->make(Illuminate\\Contracts\\Console\\Kernel::class);
|
|
@@ -8376,10 +8378,10 @@ $result = [
|
|
|
8376
8378
|
$routes = app('router')->getRoutes();
|
|
8377
8379
|
foreach ($routes as $route) {
|
|
8378
8380
|
if (!str_starts_with($route->uri(), 'api/')) continue;
|
|
8379
|
-
|
|
8381
|
+
|
|
8380
8382
|
$methods = array_diff($route->methods(), ['HEAD']);
|
|
8381
8383
|
$middlewares = $route->gatherMiddleware();
|
|
8382
|
-
|
|
8384
|
+
|
|
8383
8385
|
$auth = false;
|
|
8384
8386
|
foreach ($middlewares as $mw) {
|
|
8385
8387
|
if (is_string($mw) && (str_contains($mw, 'auth') || str_contains($mw, 'sanctum'))) {
|
|
@@ -8398,7 +8400,7 @@ foreach ($routes as $route) {
|
|
|
8398
8400
|
$type = $param->getType();
|
|
8399
8401
|
if ($type && !$type->isBuiltin()) {
|
|
8400
8402
|
$className = $type->getName();
|
|
8401
|
-
if (is_subclass_of($className, 'Illuminate
|
|
8403
|
+
if (is_subclass_of($className, 'Illuminate\\\\Foundation\\\\Http\\\\FormRequest')) {
|
|
8402
8404
|
$request = new $className();
|
|
8403
8405
|
if (method_exists($request, 'rules')) {
|
|
8404
8406
|
$schema = $request->rules();
|
|
@@ -8406,17 +8408,17 @@ foreach ($routes as $route) {
|
|
|
8406
8408
|
}
|
|
8407
8409
|
}
|
|
8408
8410
|
}
|
|
8409
|
-
|
|
8411
|
+
|
|
8410
8412
|
// Parse PHP 8 Attributes for Response Metadata
|
|
8411
8413
|
$responseMetadata = null;
|
|
8412
8414
|
$attributes = $reflector->getAttributes();
|
|
8413
8415
|
foreach ($attributes as $attr) {
|
|
8414
8416
|
$attrName = $attr->getName();
|
|
8415
8417
|
$shortName = class_basename($attrName);
|
|
8416
|
-
|
|
8418
|
+
|
|
8417
8419
|
if (in_array($shortName, ['Response', 'RouteSyncResponse'])) {
|
|
8418
8420
|
$args = $attr->getArguments();
|
|
8419
|
-
|
|
8421
|
+
|
|
8420
8422
|
$type = null;
|
|
8421
8423
|
if (isset($args[0])) {
|
|
8422
8424
|
$type = $args[0];
|
|
@@ -8427,14 +8429,14 @@ foreach ($routes as $route) {
|
|
|
8427
8429
|
} elseif (isset($args['response'])) {
|
|
8428
8430
|
$type = $args['response'];
|
|
8429
8431
|
}
|
|
8430
|
-
|
|
8432
|
+
|
|
8431
8433
|
$collection = false;
|
|
8432
8434
|
if (isset($args[1])) {
|
|
8433
8435
|
$collection = (bool) $args[1];
|
|
8434
8436
|
} elseif (isset($args['collection'])) {
|
|
8435
8437
|
$collection = (bool) $args['collection'];
|
|
8436
8438
|
}
|
|
8437
|
-
|
|
8439
|
+
|
|
8438
8440
|
if ($type) {
|
|
8439
8441
|
$responseMetadata = [
|
|
8440
8442
|
'type' => class_basename($type),
|
|
@@ -8444,8 +8446,7 @@ foreach ($routes as $route) {
|
|
|
8444
8446
|
}
|
|
8445
8447
|
}
|
|
8446
8448
|
}
|
|
8447
|
-
|
|
8448
|
-
|
|
8449
|
+
|
|
8449
8450
|
$fileName = $reflector->getFileName();
|
|
8450
8451
|
$startLine = $reflector->getStartLine();
|
|
8451
8452
|
$endLine = $reflector->getEndLine();
|
|
@@ -8460,14 +8461,14 @@ foreach ($routes as $route) {
|
|
|
8460
8461
|
if (!$responseMetadata && $methodSource) {
|
|
8461
8462
|
$resourceName = null;
|
|
8462
8463
|
$collection = false;
|
|
8463
|
-
|
|
8464
|
+
|
|
8464
8465
|
if (preg_match('/return\\s+new\\s+([a-zA-Z0-9_]+Resource)/', $methodSource, $matches)) {
|
|
8465
8466
|
$resourceName = $matches[1];
|
|
8466
8467
|
} elseif (preg_match('/return\\s+([a-zA-Z0-9_]+Resource)::collection/', $methodSource, $matches)) {
|
|
8467
8468
|
$resourceName = $matches[1];
|
|
8468
8469
|
$collection = true;
|
|
8469
8470
|
}
|
|
8470
|
-
|
|
8471
|
+
|
|
8471
8472
|
if ($resourceName) {
|
|
8472
8473
|
$resourceClass = 'App\\\\Http\\\\Resources\\\\' . $resourceName;
|
|
8473
8474
|
if (class_exists($resourceClass)) {
|
|
@@ -8486,10 +8487,10 @@ foreach ($routes as $route) {
|
|
|
8486
8487
|
}
|
|
8487
8488
|
}
|
|
8488
8489
|
}
|
|
8489
|
-
|
|
8490
|
+
|
|
8490
8491
|
if (!$responseMetadata) {
|
|
8491
8492
|
$docComment = $resReflector->getDocComment();
|
|
8492
|
-
if ($docComment && preg_match('/@mixin\\s+([
|
|
8493
|
+
if ($docComment && preg_match('/@mixin\\s+([\\\\a-zA-Z0-9_]+)/', $docComment, $mixinMatches)) {
|
|
8493
8494
|
$responseMetadata = [
|
|
8494
8495
|
'type' => class_basename($mixinMatches[1]),
|
|
8495
8496
|
'collection' => $collection
|
|
@@ -8499,14 +8500,12 @@ foreach ($routes as $route) {
|
|
|
8499
8500
|
}
|
|
8500
8501
|
}
|
|
8501
8502
|
}
|
|
8502
|
-
|
|
8503
|
+
|
|
8503
8504
|
// Fallback: Try to parse $request->validate([...]) from source code
|
|
8504
8505
|
if (empty($schema) && $methodSource) {
|
|
8505
|
-
|
|
8506
|
-
if (preg_match('/\\\\$request->validate\\\\s*\\\\(\\\\s*\\\\[(.*?)\\\\]\\\\s*\\\\)/s', $methodSource, $matches)) {
|
|
8506
|
+
if (preg_match('/\\$request->validate\\s*\\(\\s*\\[(.*?)\\]\\s*\\)/s', $methodSource, $matches)) {
|
|
8507
8507
|
$rulesString = $matches[1];
|
|
8508
|
-
|
|
8509
|
-
preg_match_all('~[\\'"]([a-zA-Z0-9_.*]+)[\\'"]\\\\s*=>\\\\s*[\\'"](.*?)[\\'"]~', $rulesString, $ruleMatches);
|
|
8508
|
+
preg_match_all('/[\\'"]([a-zA-Z0-9_.*]+)[\\'"]\\s*=>\\s*[\\'"](.*?)[\\'"]/', $rulesString, $ruleMatches);
|
|
8510
8509
|
if (!empty($ruleMatches[1])) {
|
|
8511
8510
|
foreach ($ruleMatches[1] as $index => $field) {
|
|
8512
8511
|
$schema[$field] = $ruleMatches[2][$index];
|
|
@@ -8522,9 +8521,9 @@ foreach ($routes as $route) {
|
|
|
8522
8521
|
$nameParts = explode('/', preg_replace('/^api\\//', '', $route->uri()));
|
|
8523
8522
|
$resource = preg_replace('/\\{.*\\}/', '', $nameParts[0]);
|
|
8524
8523
|
if (empty($resource)) $resource = 'api';
|
|
8525
|
-
|
|
8524
|
+
|
|
8526
8525
|
$name = $resource . '.' . strtolower($method);
|
|
8527
|
-
|
|
8526
|
+
|
|
8528
8527
|
$result['routes'][] = [
|
|
8529
8528
|
'name' => $route->getName() ?: $name,
|
|
8530
8529
|
'method' => $method,
|
|
@@ -8538,7 +8537,7 @@ foreach ($routes as $route) {
|
|
|
8538
8537
|
}
|
|
8539
8538
|
|
|
8540
8539
|
// Extract Models if requested
|
|
8541
|
-
$extractModels = ${
|
|
8540
|
+
$extractModels = ${extractModels};
|
|
8542
8541
|
if ($extractModels) {
|
|
8543
8542
|
$modelsPath = app_path('Models');
|
|
8544
8543
|
if (is_dir($modelsPath)) {
|
|
@@ -8546,25 +8545,25 @@ if ($extractModels) {
|
|
|
8546
8545
|
foreach ($files as $file) {
|
|
8547
8546
|
$class = 'App\\\\Models\\\\' . str_replace('/', '\\\\', $file->getRelativePathname());
|
|
8548
8547
|
$class = preg_replace('/\\.php$/', '', $class);
|
|
8549
|
-
|
|
8548
|
+
|
|
8550
8549
|
if (class_exists($class) && is_subclass_of($class, 'Illuminate\\\\Database\\\\Eloquent\\\\Model')) {
|
|
8551
8550
|
try {
|
|
8552
8551
|
$reflection = new ReflectionClass($class);
|
|
8553
8552
|
if ($reflection->isAbstract()) continue;
|
|
8554
|
-
|
|
8553
|
+
|
|
8555
8554
|
$model = new $class();
|
|
8556
8555
|
$table = $model->getTable();
|
|
8557
8556
|
$columns = \\Illuminate\\Support\\Facades\\Schema::getColumns($table);
|
|
8558
|
-
|
|
8557
|
+
|
|
8559
8558
|
$parsedColumns = [];
|
|
8560
8559
|
foreach ($columns as $col) {
|
|
8561
8560
|
$parsedColumns[] = [
|
|
8562
8561
|
'name' => $col['name'],
|
|
8563
|
-
'type' => $col['type'],
|
|
8562
|
+
'type' => $col['type'],
|
|
8564
8563
|
'nullable' => $col['nullable']
|
|
8565
8564
|
];
|
|
8566
8565
|
}
|
|
8567
|
-
|
|
8566
|
+
|
|
8568
8567
|
$result['models'][] = [
|
|
8569
8568
|
'name' => class_basename($class),
|
|
8570
8569
|
'table' => $table,
|
|
@@ -8584,13 +8583,16 @@ echo json_encode($result);
|
|
|
8584
8583
|
const scriptPath = import_path.default.join(projectRoot, "routesync-extractor-temp.php");
|
|
8585
8584
|
try {
|
|
8586
8585
|
await import_fs_extra.default.writeFile(scriptPath, phpScript);
|
|
8587
|
-
const stdout = (0, import_child_process.execSync)(`php routesync-extractor-temp.php`, {
|
|
8586
|
+
const stdout = (0, import_child_process.execSync)(`php routesync-extractor-temp.php 2>/dev/null`, {
|
|
8588
8587
|
cwd: projectRoot,
|
|
8589
8588
|
encoding: "utf-8",
|
|
8590
8589
|
maxBuffer: 1024 * 1024 * 10
|
|
8591
8590
|
});
|
|
8592
8591
|
await import_fs_extra.default.remove(scriptPath);
|
|
8593
|
-
const
|
|
8592
|
+
const trimmed = stdout.trim();
|
|
8593
|
+
const jsonStart = trimmed.indexOf("{");
|
|
8594
|
+
if (jsonStart === -1) throw new Error("No JSON output from PHP script");
|
|
8595
|
+
const parsed = JSON.parse(trimmed.slice(jsonStart));
|
|
8594
8596
|
return {
|
|
8595
8597
|
routes: parsed.routes || [],
|
|
8596
8598
|
models: parsed.models || []
|