routesync 1.0.42 → 1.0.44

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