@famgia/omnify-laravel 2.0.14 → 2.0.16

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.
@@ -1,6 +1,6 @@
1
1
  // src/plugin.ts
2
- import { readFileSync as readFileSync2, existsSync as existsSync2, readdirSync as readdirSync2 } from "fs";
3
- import { join as join2 } from "path";
2
+ import { readFileSync, existsSync, readdirSync } from "fs";
3
+ import { join } from "path";
4
4
 
5
5
  // src/migration/schema-builder.ts
6
6
  import { resolveLocalizedString } from "@famgia/omnify-types";
@@ -1373,12 +1373,23 @@ function formatDropColumn(columnName, prop) {
1373
1373
  lines.push(`$table->dropColumn('${snakeColumn}');`);
1374
1374
  return lines;
1375
1375
  }
1376
- function formatRenameColumn(oldName, newName) {
1376
+ function formatRenameColumn(oldName, newName, prop) {
1377
+ if (prop && isAssociationWithFkColumn(prop)) {
1378
+ const oldFkColumn = getAssociationFkColumnName(oldName);
1379
+ const newFkColumn = getAssociationFkColumnName(newName);
1380
+ return `$table->renameColumn('${oldFkColumn}', '${newFkColumn}');`;
1381
+ }
1377
1382
  const oldSnake = toColumnName(oldName);
1378
1383
  const newSnake = toColumnName(newName);
1379
1384
  return `$table->renameColumn('${oldSnake}', '${newSnake}');`;
1380
1385
  }
1381
1386
  function formatModifyColumn(columnName, _prevProp, currProp) {
1387
+ if (isAssociationWithFkColumn(currProp)) {
1388
+ const fkColumn = getAssociationFkColumnName(columnName);
1389
+ let code2 = `$table->unsignedBigInteger('${fkColumn}')`;
1390
+ if (currProp.nullable) code2 += "->nullable()";
1391
+ return code2 + "->change();";
1392
+ }
1382
1393
  const snakeColumn = toColumnName(columnName);
1383
1394
  const method = TYPE_METHOD_MAP2[currProp.type] ?? "string";
1384
1395
  let code;
@@ -1437,8 +1448,8 @@ function generateAlterMigrationContent(tableName, change, options = {}) {
1437
1448
  upLines.push(` ${formatModifyColumn(col.column, col.previousDef, col.currentDef)}`);
1438
1449
  downLines.push(` ${formatModifyColumn(col.column, col.currentDef, col.previousDef)}`);
1439
1450
  } else if (col.changeType === "renamed" && col.previousColumn) {
1440
- upLines.push(` ${formatRenameColumn(col.previousColumn, col.column)}`);
1441
- downLines.push(` ${formatRenameColumn(col.column, col.previousColumn)}`);
1451
+ upLines.push(` ${formatRenameColumn(col.previousColumn, col.column, col.currentDef)}`);
1452
+ downLines.push(` ${formatRenameColumn(col.column, col.previousColumn, col.currentDef)}`);
1442
1453
  if (col.modifications && col.modifications.length > 0 && col.previousDef && col.currentDef) {
1443
1454
  upLines.push(` ${formatModifyColumn(col.column, col.previousDef, col.currentDef)}`);
1444
1455
  downLines.push(` ${formatModifyColumn(col.column, col.currentDef, col.previousDef)}`);
@@ -4701,173 +4712,17 @@ function getResourcePath(resource) {
4701
4712
  return resource.path;
4702
4713
  }
4703
4714
 
4704
- // src/ai-guides/generator.ts
4705
- import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs";
4706
- import { resolve, join } from "path";
4707
- import {
4708
- generateAIGuides as coreGenerateAIGuides
4709
- } from "@famgia/omnify-core";
4710
- function extractLaravelBasePath(modelsPath) {
4711
- if (!modelsPath) return "app";
4712
- const normalized = modelsPath.replace(/\\/g, "/");
4713
- const match = normalized.match(/^(.+?)\/Models(?:\/.*)?$/);
4714
- if (match && match[1]) {
4715
- return match[1];
4716
- }
4717
- const parts = normalized.split("/").filter(Boolean);
4718
- if (parts.length > 1) {
4719
- return parts.slice(0, -1).join("/");
4720
- }
4721
- return "app";
4722
- }
4723
- function extractLaravelRoot(basePath) {
4724
- const normalized = basePath.replace(/\\/g, "/");
4725
- const match = normalized.match(/^(.+?)\/app$/);
4726
- if (match && match[1]) {
4727
- return match[1];
4728
- }
4729
- return "";
4730
- }
4731
- function expandPackageGlobs(cursorRulesDir, basePath, packagePaths) {
4732
- if (!packagePaths.length || !existsSync(cursorRulesDir)) {
4733
- return;
4734
- }
4735
- const files = readdirSync(cursorRulesDir).filter((f) => f.endsWith(".mdc"));
4736
- for (const file of files) {
4737
- const filePath = join(cursorRulesDir, file);
4738
- let content = readFileSync(filePath, "utf-8");
4739
- if (!content.startsWith("---")) continue;
4740
- const endIndex = content.indexOf("---", 3);
4741
- if (endIndex === -1) continue;
4742
- const frontmatter = content.substring(0, endIndex + 3);
4743
- const body = content.substring(endIndex + 3);
4744
- const globsMatch = frontmatter.match(/globs:\s*\[([^\]]*)\]/);
4745
- if (!globsMatch) continue;
4746
- const originalGlobs = globsMatch[1].split(",").map((g) => g.trim().replace(/["']/g, "")).filter(Boolean);
4747
- const specificPatterns = [
4748
- { pattern: `${basePath}/Models/OmnifyBase/`, suffix: "Models/OmnifyBase/" },
4749
- { pattern: `${basePath}/Models/`, suffix: "Models/" }
4750
- ];
4751
- const generalAppPattern = `${basePath}/**/*.php`;
4752
- const newGlobs = [];
4753
- for (const glob of originalGlobs) {
4754
- newGlobs.push(glob);
4755
- if (glob === generalAppPattern) {
4756
- for (const pkg of packagePaths) {
4757
- const pkgBase = pkg.base.replace(/^\.\//, "");
4758
- const pkgGlob = `${pkgBase}/src/**/*.php`;
4759
- if (!newGlobs.includes(pkgGlob)) {
4760
- newGlobs.push(pkgGlob);
4761
- }
4762
- }
4763
- continue;
4764
- }
4765
- for (const { pattern, suffix } of specificPatterns) {
4766
- if (glob.includes(pattern)) {
4767
- for (const pkg of packagePaths) {
4768
- const pkgBase = pkg.base.replace(/^\.\//, "");
4769
- const pkgModelsPath = pkg.modelsPath ?? "src/Models";
4770
- const afterModels = glob.split(pattern)[1] || "";
4771
- const modelsSuffix = suffix.replace("Models/", "");
4772
- const pkgGlob = `${pkgBase}/${pkgModelsPath}/${modelsSuffix}${afterModels}`;
4773
- if (!newGlobs.includes(pkgGlob)) {
4774
- newGlobs.push(pkgGlob);
4775
- }
4776
- }
4777
- break;
4778
- }
4779
- }
4780
- }
4781
- if (newGlobs.length > originalGlobs.length) {
4782
- const newGlobsStr = newGlobs.map((g) => `"${g}"`).join(", ");
4783
- const newFrontmatter = frontmatter.replace(
4784
- /globs:\s*\[[^\]]*\]/,
4785
- `globs: [${newGlobsStr}]`
4786
- );
4787
- writeFileSync(filePath, newFrontmatter + body);
4788
- }
4789
- }
4790
- }
4791
- function generateAIGuides(rootDir, options = {}) {
4792
- const basePath = options.laravelBasePath || extractLaravelBasePath(options.modelsPath);
4793
- const laravelRoot = extractLaravelRoot(basePath);
4794
- const tsPath = options.typescriptBasePath || "resources/ts";
4795
- const coreResult = coreGenerateAIGuides(rootDir, {
4796
- placeholders: {
4797
- LARAVEL_BASE: basePath,
4798
- LARAVEL_ROOT: laravelRoot ? laravelRoot + "/" : "",
4799
- TYPESCRIPT_BASE: tsPath
4800
- }
4801
- });
4802
- if (options.packagePaths?.length) {
4803
- const cursorRulesDir = resolve(rootDir, ".cursor/rules/omnify");
4804
- expandPackageGlobs(cursorRulesDir, basePath, options.packagePaths);
4805
- }
4806
- const result = {
4807
- claudeGuides: 0,
4808
- claudeRules: 0,
4809
- claudeChecklists: 0,
4810
- claudeWorkflows: 0,
4811
- claudeAgents: 0,
4812
- claudeOmnify: 0,
4813
- cursorRules: 0,
4814
- antigravityRules: 0,
4815
- files: coreResult.files
4816
- };
4817
- const claudeCount = coreResult.counts["claude"] || 0;
4818
- const cursorCount = coreResult.counts["cursor"] || 0;
4819
- const antigravityCount = coreResult.counts["antigravity"] || 0;
4820
- result.claudeGuides = Math.floor(claudeCount * 0.4);
4821
- result.claudeRules = Math.floor(claudeCount * 0.2);
4822
- result.claudeChecklists = Math.floor(claudeCount * 0.1);
4823
- result.claudeWorkflows = Math.floor(claudeCount * 0.1);
4824
- result.claudeAgents = Math.floor(claudeCount * 0.1);
4825
- result.claudeOmnify = claudeCount - result.claudeGuides - result.claudeRules - result.claudeChecklists - result.claudeWorkflows - result.claudeAgents;
4826
- result.cursorRules = cursorCount;
4827
- result.antigravityRules = antigravityCount;
4828
- return result;
4829
- }
4830
- function shouldGenerateAIGuides(rootDir) {
4831
- const claudeDir = resolve(rootDir, ".claude/omnify/guides/laravel");
4832
- const cursorDir = resolve(rootDir, ".cursor/rules/omnify");
4833
- if (!existsSync(claudeDir) || !existsSync(cursorDir)) {
4834
- return true;
4835
- }
4836
- try {
4837
- const claudeFiles = readdirSync(claudeDir);
4838
- const cursorFiles = readdirSync(cursorDir);
4839
- const hasLaravelRules = cursorFiles.some((f) => f.startsWith("laravel"));
4840
- return claudeFiles.length === 0 || !hasLaravelRules;
4841
- } catch {
4842
- return true;
4843
- }
4844
- }
4845
-
4846
4715
  // src/plugin.ts
4847
4716
  function getPluginVersion() {
4848
4717
  try {
4849
4718
  const pkgPath = new URL("../package.json", import.meta.url);
4850
- const pkgContent = readFileSync2(pkgPath, "utf-8");
4719
+ const pkgContent = readFileSync(pkgPath, "utf-8");
4851
4720
  const pkg = JSON.parse(pkgContent);
4852
4721
  return pkg.version;
4853
4722
  } catch {
4854
4723
  return "unknown";
4855
4724
  }
4856
4725
  }
4857
- function extractPackagePaths(schemas) {
4858
- const packageMap = /* @__PURE__ */ new Map();
4859
- for (const schema of Object.values(schemas)) {
4860
- const pkg = schema.packageOutput?.laravel;
4861
- if (pkg?.base && !packageMap.has(pkg.base)) {
4862
- packageMap.set(pkg.base, {
4863
- base: pkg.base,
4864
- modelsPath: pkg.modelsPath ?? "src/Models",
4865
- migrationsPath: pkg.migrationsPath ?? "database/migrations"
4866
- });
4867
- }
4868
- }
4869
- return Array.from(packageMap.values());
4870
- }
4871
4726
  function getMigrationPathForSchema(migration, schemas, defaultPath) {
4872
4727
  if (migration.schemaName) {
4873
4728
  const schema = schemas[migration.schemaName];
@@ -4893,11 +4748,11 @@ function inferLaravelRoot(providersPath) {
4893
4748
  }
4894
4749
  function getExistingMigrationTables(migrationsDir) {
4895
4750
  const existingTables = /* @__PURE__ */ new Set();
4896
- if (!existsSync2(migrationsDir)) {
4751
+ if (!existsSync(migrationsDir)) {
4897
4752
  return existingTables;
4898
4753
  }
4899
4754
  try {
4900
- const files = readdirSync2(migrationsDir);
4755
+ const files = readdirSync(migrationsDir);
4901
4756
  const createMigrationPattern = /^\d{4}_\d{2}_\d{2}_\d{6}_create_(.+)_table\.php$/;
4902
4757
  for (const file of files) {
4903
4758
  const match = file.match(createMigrationPattern);
@@ -4909,25 +4764,17 @@ function getExistingMigrationTables(migrationsDir) {
4909
4764
  }
4910
4765
  return existingTables;
4911
4766
  }
4912
- function getMigrationsDirForSchema(schema, cwd, defaultMigrationsPath) {
4913
- if (schema?.packageOutput?.laravel) {
4914
- const pkg = schema.packageOutput.laravel;
4915
- const migrationsPath = pkg.migrationsPath ?? "database/migrations";
4916
- return join2(cwd, pkg.base, migrationsPath);
4917
- }
4918
- return join2(cwd, defaultMigrationsPath);
4919
- }
4920
4767
  function buildExistingTablesMap(schemas, cwd, defaultMigrationsPath) {
4921
4768
  const tablesMap = /* @__PURE__ */ new Map();
4922
4769
  const checkedDirs = /* @__PURE__ */ new Set();
4923
- const defaultDir = join2(cwd, defaultMigrationsPath);
4770
+ const defaultDir = join(cwd, defaultMigrationsPath);
4924
4771
  tablesMap.set(defaultDir, getExistingMigrationTables(defaultDir));
4925
4772
  checkedDirs.add(defaultDir);
4926
4773
  for (const schema of Object.values(schemas)) {
4927
4774
  if (schema.packageOutput?.laravel) {
4928
4775
  const pkg = schema.packageOutput.laravel;
4929
4776
  const migrationsPath = pkg.migrationsPath ?? "database/migrations";
4930
- const pkgDir = join2(cwd, pkg.base, migrationsPath);
4777
+ const pkgDir = join(cwd, pkg.base, migrationsPath);
4931
4778
  if (!checkedDirs.has(pkgDir)) {
4932
4779
  tablesMap.set(pkgDir, getExistingMigrationTables(pkgDir));
4933
4780
  checkedDirs.add(pkgDir);
@@ -4936,11 +4783,13 @@ function buildExistingTablesMap(schemas, cwd, defaultMigrationsPath) {
4936
4783
  }
4937
4784
  return tablesMap;
4938
4785
  }
4939
- function tableHasMigration(tableName, schemaName, schemas, existingTablesMap, cwd, defaultMigrationsPath) {
4940
- const schema = schemaName ? schemas[schemaName] : void 0;
4941
- const migrationsDir = getMigrationsDirForSchema(schema, cwd, defaultMigrationsPath);
4942
- const existingTables = existingTablesMap.get(migrationsDir);
4943
- return existingTables?.has(tableName) ?? false;
4786
+ function tableHasMigration(tableName, _schemaName, _schemas, existingTablesMap, _cwd, _defaultMigrationsPath) {
4787
+ for (const existingTables of existingTablesMap.values()) {
4788
+ if (existingTables.has(tableName)) {
4789
+ return true;
4790
+ }
4791
+ }
4792
+ return false;
4944
4793
  }
4945
4794
  var LARAVEL_CONFIG_SCHEMA = {
4946
4795
  fields: [
@@ -5148,7 +4997,8 @@ function laravelPlugin(options) {
5148
4997
  type: "migration",
5149
4998
  metadata: {
5150
4999
  tableName,
5151
- migrationType: "create"
5000
+ migrationType: "create",
5001
+ schemaName: migration.schemaName
5152
5002
  }
5153
5003
  });
5154
5004
  }
@@ -5168,7 +5018,8 @@ function laravelPlugin(options) {
5168
5018
  type: "migration",
5169
5019
  metadata: {
5170
5020
  tableName: migration.tables[0],
5171
- migrationType: migration.type
5021
+ migrationType: migration.type,
5022
+ schemaName: migration.schemaName
5172
5023
  }
5173
5024
  });
5174
5025
  }
@@ -5187,7 +5038,8 @@ function laravelPlugin(options) {
5187
5038
  type: "migration",
5188
5039
  metadata: {
5189
5040
  tableName,
5190
- migrationType: migration.type
5041
+ migrationType: migration.type,
5042
+ schemaName: migration.schemaName
5191
5043
  }
5192
5044
  });
5193
5045
  }
@@ -5222,20 +5074,20 @@ function laravelPlugin(options) {
5222
5074
  const laravelRoot = inferLaravelRoot(resolved.providersPath);
5223
5075
  const bootstrapProvidersRelPath = laravelRoot ? `${laravelRoot}/bootstrap/providers.php` : "bootstrap/providers.php";
5224
5076
  const configAppRelPath = laravelRoot ? `${laravelRoot}/config/app.php` : "config/app.php";
5225
- const bootstrapProvidersPath = join2(ctx.cwd, bootstrapProvidersRelPath);
5226
- const configAppPath = join2(ctx.cwd, configAppRelPath);
5077
+ const bootstrapProvidersPath = join(ctx.cwd, bootstrapProvidersRelPath);
5078
+ const configAppPath = join(ctx.cwd, configAppRelPath);
5227
5079
  let existingContent = null;
5228
5080
  let laravelVersion;
5229
- if (existsSync2(bootstrapProvidersPath)) {
5081
+ if (existsSync(bootstrapProvidersPath)) {
5230
5082
  laravelVersion = "laravel11+";
5231
5083
  try {
5232
- existingContent = readFileSync2(bootstrapProvidersPath, "utf-8");
5084
+ existingContent = readFileSync(bootstrapProvidersPath, "utf-8");
5233
5085
  } catch {
5234
5086
  existingContent = null;
5235
5087
  }
5236
- } else if (existsSync2(configAppPath)) {
5088
+ } else if (existsSync(configAppPath)) {
5237
5089
  try {
5238
- const configContent = readFileSync2(configAppPath, "utf-8");
5090
+ const configContent = readFileSync(configAppPath, "utf-8");
5239
5091
  if (/'providers'\s*=>\s*\[/.test(configContent)) {
5240
5092
  laravelVersion = "laravel10-";
5241
5093
  existingContent = configContent;
@@ -5349,24 +5201,6 @@ function laravelPlugin(options) {
5349
5201
  }));
5350
5202
  }
5351
5203
  };
5352
- const aiGuidesGenerator = {
5353
- name: "laravel-ai-guides",
5354
- description: "Generate AI assistant guides (Claude, Cursor) for Laravel development",
5355
- generate: async (ctx) => {
5356
- const packagePaths = extractPackagePaths(ctx.schemas);
5357
- const result = generateAIGuides(ctx.cwd, {
5358
- modelsPath: resolved.modelsPath,
5359
- migrationsPath: resolved.migrationsPath,
5360
- laravelBasePath: "app",
5361
- packagePaths
5362
- });
5363
- const claudeTotal = result.claudeGuides + result.claudeRules + result.claudeChecklists + result.claudeWorkflows + result.claudeAgents + result.claudeOmnify;
5364
- const antigravityTotal = result.antigravityRules || 0;
5365
- const antigravityInfo = antigravityTotal > 0 ? `, ${antigravityTotal} Antigravity rules` : "";
5366
- ctx.logger.info(`Generated ${claudeTotal} Claude files, ${result.cursorRules} Cursor rules${antigravityInfo}`);
5367
- return [];
5368
- }
5369
- };
5370
5204
  const generators = [migrationGenerator];
5371
5205
  if (resolved.generateModels) {
5372
5206
  generators.push(modelGenerator);
@@ -5380,7 +5214,6 @@ function laravelPlugin(options) {
5380
5214
  if (resolved.generateResources) {
5381
5215
  generators.push(resourceGenerator);
5382
5216
  }
5383
- generators.push(aiGuidesGenerator);
5384
5217
  return {
5385
5218
  name: "@famgia/omnify-laravel",
5386
5219
  version: getPluginVersion(),
@@ -5419,8 +5252,6 @@ export {
5419
5252
  generateProviderRegistration,
5420
5253
  generateFactories,
5421
5254
  getFactoryPath,
5422
- generateAIGuides,
5423
- shouldGenerateAIGuides,
5424
5255
  laravelPlugin
5425
5256
  };
5426
- //# sourceMappingURL=chunk-ILDRIQLW.js.map
5257
+ //# sourceMappingURL=chunk-F2VU73BX.js.map