@famgia/omnify-laravel 0.0.81 → 0.0.83

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.
@@ -2169,12 +2169,14 @@ function generateModels(schemas, options) {
2169
2169
  function getModelPath(model) {
2170
2170
  return model.path;
2171
2171
  }
2172
- function generateProviderRegistration(existingContent, laravelVersion) {
2172
+ function generateProviderRegistration(existingContent, laravelVersion, laravelRoot = "") {
2173
2173
  const providerClass = "App\\Providers\\OmnifyServiceProvider::class";
2174
2174
  const providerLine = ` ${providerClass},`;
2175
+ const bootstrapPath = laravelRoot ? `${laravelRoot}/bootstrap/providers.php` : "bootstrap/providers.php";
2176
+ const configPath = laravelRoot ? `${laravelRoot}/config/app.php` : "config/app.php";
2175
2177
  if (existingContent && existingContent.includes("OmnifyServiceProvider")) {
2176
2178
  return {
2177
- path: laravelVersion === "laravel11+" ? "bootstrap/providers.php" : "config/app.php",
2179
+ path: laravelVersion === "laravel11+" ? bootstrapPath : configPath,
2178
2180
  content: existingContent,
2179
2181
  laravelVersion,
2180
2182
  alreadyRegistered: true
@@ -2194,14 +2196,14 @@ function generateProviderRegistration(existingContent, laravelVersion) {
2194
2196
  result.push(line);
2195
2197
  }
2196
2198
  return {
2197
- path: "bootstrap/providers.php",
2199
+ path: bootstrapPath,
2198
2200
  content: result.join("\n"),
2199
2201
  laravelVersion,
2200
2202
  alreadyRegistered: false
2201
2203
  };
2202
2204
  } else {
2203
2205
  return {
2204
- path: "bootstrap/providers.php",
2206
+ path: bootstrapPath,
2205
2207
  content: `<?php
2206
2208
 
2207
2209
  return [
@@ -2243,7 +2245,7 @@ ${providerLine}
2243
2245
  const lastNewline = beforeClose.lastIndexOf("\n");
2244
2246
  const content = existingContent.substring(0, lastNewline + 1) + providerLine + "\n" + existingContent.substring(lastNewline + 1);
2245
2247
  return {
2246
- path: "config/app.php",
2248
+ path: configPath,
2247
2249
  content,
2248
2250
  laravelVersion,
2249
2251
  alreadyRegistered: false
@@ -3337,6 +3339,17 @@ function getModuleName2(schema) {
3337
3339
  }
3338
3340
  return "";
3339
3341
  }
3342
+ function getFieldExpression(fieldName, propDef) {
3343
+ switch (propDef.type) {
3344
+ case "Date":
3345
+ return `$this->${fieldName}?->toDateString()`;
3346
+ case "DateTime":
3347
+ case "Timestamp":
3348
+ return `$this->${fieldName}?->toISOString()`;
3349
+ default:
3350
+ return `$this->${fieldName}`;
3351
+ }
3352
+ }
3340
3353
  function getPropertyOutput(propName, propDef, schemas, options) {
3341
3354
  const snakeName = toSnakeCase(propName);
3342
3355
  const lines = [];
@@ -3383,7 +3396,8 @@ function getPropertyOutput(propName, propDef, schemas, options) {
3383
3396
  }
3384
3397
  return lines;
3385
3398
  }
3386
- lines.push(` '${snakeName}' => $this->${snakeName},`);
3399
+ const expression = getFieldExpression(snakeName, propDef);
3400
+ lines.push(` '${snakeName}' => ${expression},`);
3387
3401
  return lines;
3388
3402
  }
3389
3403
  function generateResourceBase(schema, schemas, options) {
@@ -3532,6 +3546,18 @@ function getResourcePath(resource) {
3532
3546
  }
3533
3547
 
3534
3548
  // src/plugin.ts
3549
+ function inferLaravelRoot(providersPath) {
3550
+ const normalized = providersPath.replace(/\\/g, "/");
3551
+ const match = normalized.match(/^(.*)\/app\/Providers\/?$/i);
3552
+ if (match && match[1]) {
3553
+ return match[1];
3554
+ }
3555
+ const baseMatch = normalized.match(/^(.*)\/app\/Providers\/OmnifyBase\/?$/i);
3556
+ if (baseMatch && baseMatch[1]) {
3557
+ return baseMatch[1];
3558
+ }
3559
+ return "";
3560
+ }
3535
3561
  function getExistingMigrationTables(migrationsDir) {
3536
3562
  const existingTables = /* @__PURE__ */ new Set();
3537
3563
  if (!existsSync(migrationsDir)) {
@@ -3801,8 +3827,11 @@ function laravelPlugin(options) {
3801
3827
  schemaName: model.schemaName
3802
3828
  }
3803
3829
  }));
3804
- const bootstrapProvidersPath = join(ctx.cwd, "bootstrap/providers.php");
3805
- const configAppPath = join(ctx.cwd, "config/app.php");
3830
+ const laravelRoot = inferLaravelRoot(resolved.providersPath);
3831
+ const bootstrapProvidersRelPath = laravelRoot ? `${laravelRoot}/bootstrap/providers.php` : "bootstrap/providers.php";
3832
+ const configAppRelPath = laravelRoot ? `${laravelRoot}/config/app.php` : "config/app.php";
3833
+ const bootstrapProvidersPath = join(ctx.cwd, bootstrapProvidersRelPath);
3834
+ const configAppPath = join(ctx.cwd, configAppRelPath);
3806
3835
  let existingContent = null;
3807
3836
  let laravelVersion;
3808
3837
  if (existsSync(bootstrapProvidersPath)) {
@@ -3822,7 +3851,7 @@ function laravelPlugin(options) {
3822
3851
  } else {
3823
3852
  laravelVersion = "laravel11+";
3824
3853
  }
3825
- const registration = generateProviderRegistration(existingContent, laravelVersion);
3854
+ const registration = generateProviderRegistration(existingContent, laravelVersion, laravelRoot);
3826
3855
  if (registration && !registration.alreadyRegistered) {
3827
3856
  outputs.push({
3828
3857
  path: registration.path,
@@ -3967,4 +3996,4 @@ export {
3967
3996
  getFactoryPath,
3968
3997
  laravelPlugin
3969
3998
  };
3970
- //# sourceMappingURL=chunk-WFEVU3LX.js.map
3999
+ //# sourceMappingURL=chunk-TBXCIKK7.js.map