@famgia/omnify-laravel 0.0.121 → 0.0.123

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/index.cjs CHANGED
@@ -2225,6 +2225,7 @@ class {{CLASS_NAME}} extends {{CLASS_NAME}}BaseModel
2225
2225
 
2226
2226
  namespace App\\Providers;
2227
2227
 
2228
+ use App\\Support\\Omnify;
2228
2229
  use Illuminate\\Database\\Eloquent\\Relations\\Relation;
2229
2230
  use Illuminate\\Support\\ServiceProvider;
2230
2231
 
@@ -2236,6 +2237,7 @@ use Illuminate\\Support\\ServiceProvider;
2236
2237
  *
2237
2238
  * - Loads Omnify migrations from database/migrations/omnify
2238
2239
  * - Registers morph map for polymorphic relationships
2240
+ * - Exports schema paths for CLI consumption
2239
2241
  *
2240
2242
  * @generated by @famgia/omnify-laravel
2241
2243
  */
@@ -2261,6 +2263,11 @@ class OmnifyServiceProvider extends ServiceProvider
2261
2263
  Relation::enforceMorphMap([
2262
2264
  {{MORPH_MAP}}
2263
2265
  ]);
2266
+
2267
+ // Export registered schema paths for CLI (only when running artisan commands)
2268
+ if ($this->app->runningInConsole()) {
2269
+ Omnify::exportPaths();
2270
+ }
2264
2271
  }
2265
2272
  }
2266
2273
  `,
@@ -2389,6 +2396,148 @@ class {{CLASS_NAME}}Locales
2389
2396
  {{LOCALIZED_PROPERTY_DISPLAY_NAMES}}
2390
2397
  ];
2391
2398
  }
2399
+ `,
2400
+ "omnify-support": `<?php
2401
+
2402
+ namespace App\\Support;
2403
+
2404
+ /**
2405
+ * Omnify Support Class
2406
+ *
2407
+ * Allows Laravel packages to register their schema directories.
2408
+ *
2409
+ * DO NOT EDIT - This file is auto-generated by Omnify.
2410
+ * Any changes will be overwritten on next generation.
2411
+ *
2412
+ * @example
2413
+ * // In your package's ServiceProvider:
2414
+ * use App\\Support\\Omnify;
2415
+ *
2416
+ * public function boot()
2417
+ * {
2418
+ * Omnify::addSchemaPath(__DIR__.'/../database/schemas');
2419
+ * }
2420
+ *
2421
+ * @generated by @famgia/omnify-laravel
2422
+ */
2423
+ class Omnify
2424
+ {
2425
+ /**
2426
+ * Registered schema paths from packages.
2427
+ *
2428
+ * @var array<array{path: string, namespace: string|null}>
2429
+ */
2430
+ protected static array $schemaPaths = [];
2431
+
2432
+ /**
2433
+ * Register a schema directory path.
2434
+ *
2435
+ * @param string $path Absolute path to schema directory
2436
+ * @param string|null $namespace Optional namespace prefix for schemas
2437
+ * @return void
2438
+ */
2439
+ public static function addSchemaPath(string $path, ?string $namespace = null): void
2440
+ {
2441
+ $realPath = realpath($path);
2442
+
2443
+ if ($realPath === false) {
2444
+ $realPath = $path;
2445
+ }
2446
+
2447
+ static::$schemaPaths[] = [
2448
+ 'path' => $realPath,
2449
+ 'namespace' => $namespace,
2450
+ ];
2451
+ }
2452
+
2453
+ /**
2454
+ * Get all registered schema paths.
2455
+ *
2456
+ * @return array<array{path: string, namespace: string|null}>
2457
+ */
2458
+ public static function getSchemaPaths(): array
2459
+ {
2460
+ return static::$schemaPaths;
2461
+ }
2462
+
2463
+ /**
2464
+ * Clear all registered schema paths.
2465
+ */
2466
+ public static function clearSchemaPaths(): void
2467
+ {
2468
+ static::$schemaPaths = [];
2469
+ }
2470
+
2471
+ /**
2472
+ * Export schema paths to JSON file for CLI consumption.
2473
+ *
2474
+ * @param string|null $outputPath Path to write JSON file
2475
+ * @return string Path to the generated file
2476
+ */
2477
+ public static function exportPaths(?string $outputPath = null): string
2478
+ {
2479
+ $outputPath = $outputPath ?? storage_path('omnify/schema-paths.json');
2480
+
2481
+ $dir = dirname($outputPath);
2482
+ if (!is_dir($dir)) {
2483
+ mkdir($dir, 0755, true);
2484
+ }
2485
+
2486
+ $data = [
2487
+ 'generated_at' => date('c'),
2488
+ 'paths' => static::$schemaPaths,
2489
+ ];
2490
+
2491
+ file_put_contents($outputPath, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
2492
+
2493
+ return $outputPath;
2494
+ }
2495
+ }
2496
+ `,
2497
+ "omnify-command": `<?php
2498
+
2499
+ namespace App\\Console\\Commands;
2500
+
2501
+ use App\\Support\\Omnify;
2502
+ use Illuminate\\Console\\Command;
2503
+
2504
+ /**
2505
+ * Sync registered schema paths for Omnify CLI.
2506
+ *
2507
+ * DO NOT EDIT - This file is auto-generated by Omnify.
2508
+ * Any changes will be overwritten on next generation.
2509
+ *
2510
+ * @generated by @famgia/omnify-laravel
2511
+ */
2512
+ class OmnifySyncCommand extends Command
2513
+ {
2514
+ protected $signature = 'omnify:sync {--output= : Custom output path}';
2515
+
2516
+ protected $description = 'Export registered schema paths for Omnify CLI';
2517
+
2518
+ public function handle(): int
2519
+ {
2520
+ $this->info('Syncing Omnify schema paths...');
2521
+
2522
+ $paths = Omnify::getSchemaPaths();
2523
+
2524
+ if (empty($paths)) {
2525
+ $this->warn('No additional schema paths registered.');
2526
+ $this->line('Tip: Packages can use Omnify::addSchemaPath()');
2527
+ } else {
2528
+ $this->line('Found ' . count($paths) . ' path(s):');
2529
+ foreach ($paths as $entry) {
2530
+ $ns = $entry['namespace'] ? " [{$entry['namespace']}]" : '';
2531
+ $this->line(" \u2022 {$entry['path']}{$ns}");
2532
+ }
2533
+ }
2534
+
2535
+ $filePath = Omnify::exportPaths($this->option('output'));
2536
+ $this->info("\u2713 Exported to: {$filePath}");
2537
+
2538
+ return Command::SUCCESS;
2539
+ }
2540
+ }
2392
2541
  `
2393
2542
  };
2394
2543
  return stubs[stubName] ?? "";
@@ -2419,6 +2568,30 @@ function generateLocalizedDisplayNameTrait(options, stubContent) {
2419
2568
  schemaName: "__trait__"
2420
2569
  };
2421
2570
  }
2571
+ function generateOmnifySupport(options, stubContent) {
2572
+ const appPath = options.modelPath.replace(/\/Models$/, "");
2573
+ return {
2574
+ path: `${appPath}/Support/Omnify.php`,
2575
+ content: stubContent,
2576
+ type: "trait",
2577
+ // Use trait type for support classes
2578
+ overwrite: true,
2579
+ // Always overwrite
2580
+ schemaName: "__omnify_support__"
2581
+ };
2582
+ }
2583
+ function generateOmnifyCommand(options, stubContent) {
2584
+ const appPath = options.modelPath.replace(/\/Models$/, "");
2585
+ return {
2586
+ path: `${appPath}/Console/Commands/OmnifySyncCommand.php`,
2587
+ content: stubContent,
2588
+ type: "trait",
2589
+ // Use trait type for command classes
2590
+ overwrite: true,
2591
+ // Always overwrite
2592
+ schemaName: "__omnify_command__"
2593
+ };
2594
+ }
2422
2595
  function generateLocalesClass(schema, options, stubContent) {
2423
2596
  const className = toPascalCase(schema.name);
2424
2597
  const localizedDisplayNames = generateLocalizedDisplayNames(schema.displayName);
@@ -2439,6 +2612,8 @@ function generateModels(schemas, options) {
2439
2612
  models.push(generateBaseModel(schemas, resolved, getStubContent("base-model")));
2440
2613
  models.push(generateLocalizedDisplayNameTrait(resolved, getStubContent("has-localized-display-name")));
2441
2614
  models.push(generateServiceProvider(schemas, resolved, getStubContent("service-provider")));
2615
+ models.push(generateOmnifySupport(resolved, getStubContent("omnify-support")));
2616
+ models.push(generateOmnifyCommand(resolved, getStubContent("omnify-command")));
2442
2617
  for (const schema of Object.values(schemas)) {
2443
2618
  if (schema.kind === "enum") {
2444
2619
  continue;