@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.
package/dist/index.cjs CHANGED
@@ -2215,12 +2215,14 @@ function generateModels(schemas, options) {
2215
2215
  function getModelPath(model) {
2216
2216
  return model.path;
2217
2217
  }
2218
- function generateProviderRegistration(existingContent, laravelVersion) {
2218
+ function generateProviderRegistration(existingContent, laravelVersion, laravelRoot = "") {
2219
2219
  const providerClass = "App\\Providers\\OmnifyServiceProvider::class";
2220
2220
  const providerLine = ` ${providerClass},`;
2221
+ const bootstrapPath = laravelRoot ? `${laravelRoot}/bootstrap/providers.php` : "bootstrap/providers.php";
2222
+ const configPath = laravelRoot ? `${laravelRoot}/config/app.php` : "config/app.php";
2221
2223
  if (existingContent && existingContent.includes("OmnifyServiceProvider")) {
2222
2224
  return {
2223
- path: laravelVersion === "laravel11+" ? "bootstrap/providers.php" : "config/app.php",
2225
+ path: laravelVersion === "laravel11+" ? bootstrapPath : configPath,
2224
2226
  content: existingContent,
2225
2227
  laravelVersion,
2226
2228
  alreadyRegistered: true
@@ -2240,14 +2242,14 @@ function generateProviderRegistration(existingContent, laravelVersion) {
2240
2242
  result.push(line);
2241
2243
  }
2242
2244
  return {
2243
- path: "bootstrap/providers.php",
2245
+ path: bootstrapPath,
2244
2246
  content: result.join("\n"),
2245
2247
  laravelVersion,
2246
2248
  alreadyRegistered: false
2247
2249
  };
2248
2250
  } else {
2249
2251
  return {
2250
- path: "bootstrap/providers.php",
2252
+ path: bootstrapPath,
2251
2253
  content: `<?php
2252
2254
 
2253
2255
  return [
@@ -2289,7 +2291,7 @@ ${providerLine}
2289
2291
  const lastNewline = beforeClose.lastIndexOf("\n");
2290
2292
  const content = existingContent.substring(0, lastNewline + 1) + providerLine + "\n" + existingContent.substring(lastNewline + 1);
2291
2293
  return {
2292
- path: "config/app.php",
2294
+ path: configPath,
2293
2295
  content,
2294
2296
  laravelVersion,
2295
2297
  alreadyRegistered: false
@@ -3387,6 +3389,17 @@ function getModuleName2(schema) {
3387
3389
  }
3388
3390
  return "";
3389
3391
  }
3392
+ function getFieldExpression(fieldName, propDef) {
3393
+ switch (propDef.type) {
3394
+ case "Date":
3395
+ return `$this->${fieldName}?->toDateString()`;
3396
+ case "DateTime":
3397
+ case "Timestamp":
3398
+ return `$this->${fieldName}?->toISOString()`;
3399
+ default:
3400
+ return `$this->${fieldName}`;
3401
+ }
3402
+ }
3390
3403
  function getPropertyOutput(propName, propDef, schemas, options) {
3391
3404
  const snakeName = toSnakeCase(propName);
3392
3405
  const lines = [];
@@ -3433,7 +3446,8 @@ function getPropertyOutput(propName, propDef, schemas, options) {
3433
3446
  }
3434
3447
  return lines;
3435
3448
  }
3436
- lines.push(` '${snakeName}' => $this->${snakeName},`);
3449
+ const expression = getFieldExpression(snakeName, propDef);
3450
+ lines.push(` '${snakeName}' => ${expression},`);
3437
3451
  return lines;
3438
3452
  }
3439
3453
  function generateResourceBase(schema, schemas, options) {
@@ -3582,6 +3596,18 @@ function getResourcePath(resource) {
3582
3596
  }
3583
3597
 
3584
3598
  // src/plugin.ts
3599
+ function inferLaravelRoot(providersPath) {
3600
+ const normalized = providersPath.replace(/\\/g, "/");
3601
+ const match = normalized.match(/^(.*)\/app\/Providers\/?$/i);
3602
+ if (match && match[1]) {
3603
+ return match[1];
3604
+ }
3605
+ const baseMatch = normalized.match(/^(.*)\/app\/Providers\/OmnifyBase\/?$/i);
3606
+ if (baseMatch && baseMatch[1]) {
3607
+ return baseMatch[1];
3608
+ }
3609
+ return "";
3610
+ }
3585
3611
  function getExistingMigrationTables(migrationsDir) {
3586
3612
  const existingTables = /* @__PURE__ */ new Set();
3587
3613
  if (!(0, import_node_fs.existsSync)(migrationsDir)) {
@@ -3851,8 +3877,11 @@ function laravelPlugin(options) {
3851
3877
  schemaName: model.schemaName
3852
3878
  }
3853
3879
  }));
3854
- const bootstrapProvidersPath = (0, import_node_path.join)(ctx.cwd, "bootstrap/providers.php");
3855
- const configAppPath = (0, import_node_path.join)(ctx.cwd, "config/app.php");
3880
+ const laravelRoot = inferLaravelRoot(resolved.providersPath);
3881
+ const bootstrapProvidersRelPath = laravelRoot ? `${laravelRoot}/bootstrap/providers.php` : "bootstrap/providers.php";
3882
+ const configAppRelPath = laravelRoot ? `${laravelRoot}/config/app.php` : "config/app.php";
3883
+ const bootstrapProvidersPath = (0, import_node_path.join)(ctx.cwd, bootstrapProvidersRelPath);
3884
+ const configAppPath = (0, import_node_path.join)(ctx.cwd, configAppRelPath);
3856
3885
  let existingContent = null;
3857
3886
  let laravelVersion;
3858
3887
  if ((0, import_node_fs.existsSync)(bootstrapProvidersPath)) {
@@ -3872,7 +3901,7 @@ function laravelPlugin(options) {
3872
3901
  } else {
3873
3902
  laravelVersion = "laravel11+";
3874
3903
  }
3875
- const registration = generateProviderRegistration(existingContent, laravelVersion);
3904
+ const registration = generateProviderRegistration(existingContent, laravelVersion, laravelRoot);
3876
3905
  if (registration && !registration.alreadyRegistered) {
3877
3906
  outputs.push({
3878
3907
  path: registration.path,