@famgia/omnify-laravel 0.0.122 → 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/{chunk-NMX3TLZT.js → chunk-C3AGVZB4.js} +176 -1
- package/dist/chunk-C3AGVZB4.js.map +1 -0
- package/dist/index.cjs +175 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin.cjs +175 -0
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/package.json +4 -4
- package/stubs/Omnify.php.stub +94 -0
- package/stubs/commands/OmnifySyncCommand.php.stub +65 -0
- package/dist/chunk-NMX3TLZT.js.map +0 -1
package/dist/index.js
CHANGED
package/dist/plugin.cjs
CHANGED
|
@@ -2020,6 +2020,7 @@ class {{CLASS_NAME}} extends {{CLASS_NAME}}BaseModel
|
|
|
2020
2020
|
|
|
2021
2021
|
namespace App\\Providers;
|
|
2022
2022
|
|
|
2023
|
+
use App\\Support\\Omnify;
|
|
2023
2024
|
use Illuminate\\Database\\Eloquent\\Relations\\Relation;
|
|
2024
2025
|
use Illuminate\\Support\\ServiceProvider;
|
|
2025
2026
|
|
|
@@ -2031,6 +2032,7 @@ use Illuminate\\Support\\ServiceProvider;
|
|
|
2031
2032
|
*
|
|
2032
2033
|
* - Loads Omnify migrations from database/migrations/omnify
|
|
2033
2034
|
* - Registers morph map for polymorphic relationships
|
|
2035
|
+
* - Exports schema paths for CLI consumption
|
|
2034
2036
|
*
|
|
2035
2037
|
* @generated by @famgia/omnify-laravel
|
|
2036
2038
|
*/
|
|
@@ -2056,6 +2058,11 @@ class OmnifyServiceProvider extends ServiceProvider
|
|
|
2056
2058
|
Relation::enforceMorphMap([
|
|
2057
2059
|
{{MORPH_MAP}}
|
|
2058
2060
|
]);
|
|
2061
|
+
|
|
2062
|
+
// Export registered schema paths for CLI (only when running artisan commands)
|
|
2063
|
+
if ($this->app->runningInConsole()) {
|
|
2064
|
+
Omnify::exportPaths();
|
|
2065
|
+
}
|
|
2059
2066
|
}
|
|
2060
2067
|
}
|
|
2061
2068
|
`,
|
|
@@ -2184,6 +2191,148 @@ class {{CLASS_NAME}}Locales
|
|
|
2184
2191
|
{{LOCALIZED_PROPERTY_DISPLAY_NAMES}}
|
|
2185
2192
|
];
|
|
2186
2193
|
}
|
|
2194
|
+
`,
|
|
2195
|
+
"omnify-support": `<?php
|
|
2196
|
+
|
|
2197
|
+
namespace App\\Support;
|
|
2198
|
+
|
|
2199
|
+
/**
|
|
2200
|
+
* Omnify Support Class
|
|
2201
|
+
*
|
|
2202
|
+
* Allows Laravel packages to register their schema directories.
|
|
2203
|
+
*
|
|
2204
|
+
* DO NOT EDIT - This file is auto-generated by Omnify.
|
|
2205
|
+
* Any changes will be overwritten on next generation.
|
|
2206
|
+
*
|
|
2207
|
+
* @example
|
|
2208
|
+
* // In your package's ServiceProvider:
|
|
2209
|
+
* use App\\Support\\Omnify;
|
|
2210
|
+
*
|
|
2211
|
+
* public function boot()
|
|
2212
|
+
* {
|
|
2213
|
+
* Omnify::addSchemaPath(__DIR__.'/../database/schemas');
|
|
2214
|
+
* }
|
|
2215
|
+
*
|
|
2216
|
+
* @generated by @famgia/omnify-laravel
|
|
2217
|
+
*/
|
|
2218
|
+
class Omnify
|
|
2219
|
+
{
|
|
2220
|
+
/**
|
|
2221
|
+
* Registered schema paths from packages.
|
|
2222
|
+
*
|
|
2223
|
+
* @var array<array{path: string, namespace: string|null}>
|
|
2224
|
+
*/
|
|
2225
|
+
protected static array $schemaPaths = [];
|
|
2226
|
+
|
|
2227
|
+
/**
|
|
2228
|
+
* Register a schema directory path.
|
|
2229
|
+
*
|
|
2230
|
+
* @param string $path Absolute path to schema directory
|
|
2231
|
+
* @param string|null $namespace Optional namespace prefix for schemas
|
|
2232
|
+
* @return void
|
|
2233
|
+
*/
|
|
2234
|
+
public static function addSchemaPath(string $path, ?string $namespace = null): void
|
|
2235
|
+
{
|
|
2236
|
+
$realPath = realpath($path);
|
|
2237
|
+
|
|
2238
|
+
if ($realPath === false) {
|
|
2239
|
+
$realPath = $path;
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
static::$schemaPaths[] = [
|
|
2243
|
+
'path' => $realPath,
|
|
2244
|
+
'namespace' => $namespace,
|
|
2245
|
+
];
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
/**
|
|
2249
|
+
* Get all registered schema paths.
|
|
2250
|
+
*
|
|
2251
|
+
* @return array<array{path: string, namespace: string|null}>
|
|
2252
|
+
*/
|
|
2253
|
+
public static function getSchemaPaths(): array
|
|
2254
|
+
{
|
|
2255
|
+
return static::$schemaPaths;
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
/**
|
|
2259
|
+
* Clear all registered schema paths.
|
|
2260
|
+
*/
|
|
2261
|
+
public static function clearSchemaPaths(): void
|
|
2262
|
+
{
|
|
2263
|
+
static::$schemaPaths = [];
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
/**
|
|
2267
|
+
* Export schema paths to JSON file for CLI consumption.
|
|
2268
|
+
*
|
|
2269
|
+
* @param string|null $outputPath Path to write JSON file
|
|
2270
|
+
* @return string Path to the generated file
|
|
2271
|
+
*/
|
|
2272
|
+
public static function exportPaths(?string $outputPath = null): string
|
|
2273
|
+
{
|
|
2274
|
+
$outputPath = $outputPath ?? storage_path('omnify/schema-paths.json');
|
|
2275
|
+
|
|
2276
|
+
$dir = dirname($outputPath);
|
|
2277
|
+
if (!is_dir($dir)) {
|
|
2278
|
+
mkdir($dir, 0755, true);
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
$data = [
|
|
2282
|
+
'generated_at' => date('c'),
|
|
2283
|
+
'paths' => static::$schemaPaths,
|
|
2284
|
+
];
|
|
2285
|
+
|
|
2286
|
+
file_put_contents($outputPath, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
|
2287
|
+
|
|
2288
|
+
return $outputPath;
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
`,
|
|
2292
|
+
"omnify-command": `<?php
|
|
2293
|
+
|
|
2294
|
+
namespace App\\Console\\Commands;
|
|
2295
|
+
|
|
2296
|
+
use App\\Support\\Omnify;
|
|
2297
|
+
use Illuminate\\Console\\Command;
|
|
2298
|
+
|
|
2299
|
+
/**
|
|
2300
|
+
* Sync registered schema paths for Omnify CLI.
|
|
2301
|
+
*
|
|
2302
|
+
* DO NOT EDIT - This file is auto-generated by Omnify.
|
|
2303
|
+
* Any changes will be overwritten on next generation.
|
|
2304
|
+
*
|
|
2305
|
+
* @generated by @famgia/omnify-laravel
|
|
2306
|
+
*/
|
|
2307
|
+
class OmnifySyncCommand extends Command
|
|
2308
|
+
{
|
|
2309
|
+
protected $signature = 'omnify:sync {--output= : Custom output path}';
|
|
2310
|
+
|
|
2311
|
+
protected $description = 'Export registered schema paths for Omnify CLI';
|
|
2312
|
+
|
|
2313
|
+
public function handle(): int
|
|
2314
|
+
{
|
|
2315
|
+
$this->info('Syncing Omnify schema paths...');
|
|
2316
|
+
|
|
2317
|
+
$paths = Omnify::getSchemaPaths();
|
|
2318
|
+
|
|
2319
|
+
if (empty($paths)) {
|
|
2320
|
+
$this->warn('No additional schema paths registered.');
|
|
2321
|
+
$this->line('Tip: Packages can use Omnify::addSchemaPath()');
|
|
2322
|
+
} else {
|
|
2323
|
+
$this->line('Found ' . count($paths) . ' path(s):');
|
|
2324
|
+
foreach ($paths as $entry) {
|
|
2325
|
+
$ns = $entry['namespace'] ? " [{$entry['namespace']}]" : '';
|
|
2326
|
+
$this->line(" \u2022 {$entry['path']}{$ns}");
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
$filePath = Omnify::exportPaths($this->option('output'));
|
|
2331
|
+
$this->info("\u2713 Exported to: {$filePath}");
|
|
2332
|
+
|
|
2333
|
+
return Command::SUCCESS;
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2187
2336
|
`
|
|
2188
2337
|
};
|
|
2189
2338
|
return stubs[stubName] ?? "";
|
|
@@ -2214,6 +2363,30 @@ function generateLocalizedDisplayNameTrait(options, stubContent) {
|
|
|
2214
2363
|
schemaName: "__trait__"
|
|
2215
2364
|
};
|
|
2216
2365
|
}
|
|
2366
|
+
function generateOmnifySupport(options, stubContent) {
|
|
2367
|
+
const appPath = options.modelPath.replace(/\/Models$/, "");
|
|
2368
|
+
return {
|
|
2369
|
+
path: `${appPath}/Support/Omnify.php`,
|
|
2370
|
+
content: stubContent,
|
|
2371
|
+
type: "trait",
|
|
2372
|
+
// Use trait type for support classes
|
|
2373
|
+
overwrite: true,
|
|
2374
|
+
// Always overwrite
|
|
2375
|
+
schemaName: "__omnify_support__"
|
|
2376
|
+
};
|
|
2377
|
+
}
|
|
2378
|
+
function generateOmnifyCommand(options, stubContent) {
|
|
2379
|
+
const appPath = options.modelPath.replace(/\/Models$/, "");
|
|
2380
|
+
return {
|
|
2381
|
+
path: `${appPath}/Console/Commands/OmnifySyncCommand.php`,
|
|
2382
|
+
content: stubContent,
|
|
2383
|
+
type: "trait",
|
|
2384
|
+
// Use trait type for command classes
|
|
2385
|
+
overwrite: true,
|
|
2386
|
+
// Always overwrite
|
|
2387
|
+
schemaName: "__omnify_command__"
|
|
2388
|
+
};
|
|
2389
|
+
}
|
|
2217
2390
|
function generateLocalesClass(schema, options, stubContent) {
|
|
2218
2391
|
const className = toPascalCase(schema.name);
|
|
2219
2392
|
const localizedDisplayNames = generateLocalizedDisplayNames(schema.displayName);
|
|
@@ -2234,6 +2407,8 @@ function generateModels(schemas, options) {
|
|
|
2234
2407
|
models.push(generateBaseModel(schemas, resolved, getStubContent("base-model")));
|
|
2235
2408
|
models.push(generateLocalizedDisplayNameTrait(resolved, getStubContent("has-localized-display-name")));
|
|
2236
2409
|
models.push(generateServiceProvider(schemas, resolved, getStubContent("service-provider")));
|
|
2410
|
+
models.push(generateOmnifySupport(resolved, getStubContent("omnify-support")));
|
|
2411
|
+
models.push(generateOmnifyCommand(resolved, getStubContent("omnify-command")));
|
|
2237
2412
|
for (const schema of Object.values(schemas)) {
|
|
2238
2413
|
if (schema.kind === "enum") {
|
|
2239
2414
|
continue;
|