@famgia/omnify-cli 0.0.144 → 0.0.146

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.js CHANGED
@@ -105,7 +105,8 @@ async function resolveConfig(userConfig, configPath) {
105
105
  plugins,
106
106
  verbose: userConfig.verbose ?? false,
107
107
  lockFilePath: userConfig.lockFilePath ?? ".omnify.lock",
108
- ...userConfig.locale && { locale: userConfig.locale }
108
+ ...userConfig.locale && { locale: userConfig.locale },
109
+ ...userConfig.additionalSchemaPaths && { additionalSchemaPaths: userConfig.additionalSchemaPaths }
109
110
  };
110
111
  return result;
111
112
  }
@@ -708,8 +709,9 @@ function registerInitCommand(program) {
708
709
  }
709
710
 
710
711
  // src/commands/validate.ts
712
+ import { existsSync as existsSync4 } from "fs";
711
713
  import { resolve as resolve4, dirname as dirname2 } from "path";
712
- import { loadSchemas, validateSchemas, OmnifyError as OmnifyError2 } from "@famgia/omnify-core";
714
+ import { loadSchemas, mergePartialSchemas, validateSchemas, OmnifyError as OmnifyError2 } from "@famgia/omnify-core";
713
715
  async function runValidate(options) {
714
716
  logger.setVerbose(options.verbose ?? false);
715
717
  logger.header("Validating Schemas");
@@ -722,14 +724,38 @@ async function runValidate(options) {
722
724
  const schemaPath = resolve4(rootDir, config.schemasDir);
723
725
  logger.step(`Loading schemas from ${schemaPath}`);
724
726
  logger.timing("Schema load start");
725
- const schemas = await loadSchemas(schemaPath);
726
- const schemaCount = Object.keys(schemas).length;
727
+ let schemas = await loadSchemas(schemaPath);
728
+ logger.debug(`Found ${Object.keys(schemas).length} schema(s) in main directory`);
729
+ const additionalPaths = config.additionalSchemaPaths ?? [];
730
+ let hasPackageSchemas = false;
731
+ if (additionalPaths.length > 0) {
732
+ logger.step(`Loading schemas from ${additionalPaths.length} additional path(s)`);
733
+ for (const entry of additionalPaths) {
734
+ const absolutePath = resolve4(rootDir, entry.path);
735
+ logger.debug(` Checking: ${entry.path} \u2192 ${absolutePath}`);
736
+ if (existsSync4(absolutePath)) {
737
+ const packageSchemas = await loadSchemas(absolutePath, { skipPartialResolution: true });
738
+ const count = Object.keys(packageSchemas).filter((k) => !k.startsWith("__partial__")).length;
739
+ const partialCount = Object.keys(packageSchemas).filter((k) => k.startsWith("__partial__")).length;
740
+ const nsInfo = entry.namespace ? ` [${entry.namespace}]` : "";
741
+ logger.info(` \u2022 ${entry.path}${nsInfo}: ${count} schema(s)${partialCount > 0 ? ` + ${partialCount} partial(s)` : ""}`);
742
+ schemas = { ...packageSchemas, ...schemas };
743
+ hasPackageSchemas = true;
744
+ } else {
745
+ logger.warn(` \u2022 ${entry.path}: directory not found (skipped)`);
746
+ }
747
+ }
748
+ }
749
+ if (hasPackageSchemas) {
750
+ schemas = mergePartialSchemas(schemas);
751
+ }
727
752
  logger.timing("Schemas loaded");
753
+ const schemaCount = Object.keys(schemas).length;
728
754
  if (schemaCount === 0) {
729
755
  logger.warn("No schema files found");
730
756
  return;
731
757
  }
732
- logger.debug(`Found ${schemaCount} schema(s)`);
758
+ logger.debug(`Total: ${schemaCount} schema(s)`);
733
759
  logger.step("Validating schemas...");
734
760
  logger.timing("Validation start");
735
761
  const result = validateSchemas(schemas);
@@ -765,8 +791,9 @@ function registerValidateCommand(program) {
765
791
  }
766
792
 
767
793
  // src/commands/diff.ts
794
+ import { existsSync as existsSync5 } from "fs";
768
795
  import { resolve as resolve5, dirname as dirname3 } from "path";
769
- import { loadSchemas as loadSchemas2, validateSchemas as validateSchemas2, OmnifyError as OmnifyError3 } from "@famgia/omnify-core";
796
+ import { loadSchemas as loadSchemas2, mergePartialSchemas as mergePartialSchemas2, validateSchemas as validateSchemas2, OmnifyError as OmnifyError3 } from "@famgia/omnify-core";
770
797
 
771
798
  // src/operations/diff.ts
772
799
  import {
@@ -805,13 +832,37 @@ async function runDiff(options) {
805
832
  requireDevUrl(config);
806
833
  const schemaPath = resolve5(rootDir, config.schemasDir);
807
834
  logger.step(`Loading schemas from ${schemaPath}`);
808
- const schemas = await loadSchemas2(schemaPath);
835
+ let schemas = await loadSchemas2(schemaPath);
836
+ logger.debug(`Found ${Object.keys(schemas).length} schema(s) in main directory`);
837
+ const additionalPaths = config.additionalSchemaPaths ?? [];
838
+ let hasPackageSchemas = false;
839
+ if (additionalPaths.length > 0) {
840
+ logger.step(`Loading schemas from ${additionalPaths.length} additional path(s)`);
841
+ for (const entry of additionalPaths) {
842
+ const absolutePath = resolve5(rootDir, entry.path);
843
+ logger.debug(` Checking: ${entry.path} \u2192 ${absolutePath}`);
844
+ if (existsSync5(absolutePath)) {
845
+ const packageSchemas = await loadSchemas2(absolutePath, { skipPartialResolution: true });
846
+ const count = Object.keys(packageSchemas).filter((k) => !k.startsWith("__partial__")).length;
847
+ const partialCount = Object.keys(packageSchemas).filter((k) => k.startsWith("__partial__")).length;
848
+ const nsInfo = entry.namespace ? ` [${entry.namespace}]` : "";
849
+ logger.info(` \u2022 ${entry.path}${nsInfo}: ${count} schema(s)${partialCount > 0 ? ` + ${partialCount} partial(s)` : ""}`);
850
+ schemas = { ...packageSchemas, ...schemas };
851
+ hasPackageSchemas = true;
852
+ } else {
853
+ logger.warn(` \u2022 ${entry.path}: directory not found (skipped)`);
854
+ }
855
+ }
856
+ }
857
+ if (hasPackageSchemas) {
858
+ schemas = mergePartialSchemas2(schemas);
859
+ }
809
860
  const schemaCount = Object.keys(schemas).length;
810
861
  if (schemaCount === 0) {
811
862
  logger.warn("No schema files found");
812
863
  return;
813
864
  }
814
- logger.debug(`Found ${schemaCount} schema(s)`);
865
+ logger.debug(`Total: ${schemaCount} schema(s)`);
815
866
  logger.step("Validating schemas...");
816
867
  const validationResult = validateSchemas2(schemas);
817
868
  if (!validationResult.valid) {
@@ -869,11 +920,11 @@ function registerDiffCommand(program) {
869
920
  }
870
921
 
871
922
  // src/commands/generate.ts
872
- import { existsSync as existsSync5, mkdirSync as mkdirSync3, writeFileSync as writeFileSync4, readdirSync as readdirSync2, readFileSync as readFileSync3 } from "fs";
923
+ import { existsSync as existsSync7, mkdirSync as mkdirSync3, writeFileSync as writeFileSync4, readdirSync as readdirSync2 } from "fs";
873
924
  import { resolve as resolve7, dirname as dirname5, relative } from "path";
874
925
  import {
875
926
  loadSchemas as loadSchemas3,
876
- mergePartialSchemas,
927
+ mergePartialSchemas as mergePartialSchemas3,
877
928
  validateSchemas as validateSchemas3,
878
929
  OmnifyError as OmnifyError4,
879
930
  PluginManager,
@@ -903,7 +954,7 @@ import {
903
954
  import { generateTypeScript, copyStubs, generateAIGuides as generateTypescriptAIGuides, shouldGenerateAIGuides as shouldGenerateTypescriptAIGuides } from "@famgia/omnify-typescript";
904
955
 
905
956
  // src/guides/index.ts
906
- import { existsSync as existsSync4, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync2 } from "fs";
957
+ import { existsSync as existsSync6, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync2 } from "fs";
907
958
  import { resolve as resolve6, dirname as dirname4, join } from "path";
908
959
  import "url";
909
960
  var CLAUDE_MD = `# Omnify Project
@@ -968,19 +1019,19 @@ function copyOmnifyGuides(rootDir) {
968
1019
  for (const pkgPath of omnifyPkgPaths) {
969
1020
  if (pkgPath.includes("*")) {
970
1021
  const parentDir = dirname4(dirname4(pkgPath));
971
- if (existsSync4(parentDir)) {
1022
+ if (existsSync6(parentDir)) {
972
1023
  const entries = readdirSync(parentDir);
973
1024
  for (const entry of entries) {
974
1025
  if (entry.startsWith("@famgia+omnify@")) {
975
1026
  const testPath = join(parentDir, entry, "node_modules", "@famgia", "omnify", "stubs", "ai-guides", "omnify");
976
- if (existsSync4(testPath)) {
1027
+ if (existsSync6(testPath)) {
977
1028
  stubsDir = testPath;
978
1029
  break;
979
1030
  }
980
1031
  }
981
1032
  }
982
1033
  }
983
- } else if (existsSync4(pkgPath)) {
1034
+ } else if (existsSync6(pkgPath)) {
984
1035
  stubsDir = pkgPath;
985
1036
  break;
986
1037
  }
@@ -989,7 +1040,7 @@ function copyOmnifyGuides(rootDir) {
989
1040
  try {
990
1041
  const omnifyPath = dirname4(__require.resolve("@famgia/omnify/package.json", { paths: [rootDir] }));
991
1042
  const testPath = join(omnifyPath, "stubs", "ai-guides", "omnify");
992
- if (existsSync4(testPath)) {
1043
+ if (existsSync6(testPath)) {
993
1044
  stubsDir = testPath;
994
1045
  }
995
1046
  } catch {
@@ -1013,7 +1064,7 @@ function copyOmnifyGuides(rootDir) {
1013
1064
  function generateAIGuides(rootDir, _plugins) {
1014
1065
  let filesWritten = 0;
1015
1066
  const claudeMdPath = resolve6(rootDir, "CLAUDE.md");
1016
- if (!existsSync4(claudeMdPath)) {
1067
+ if (!existsSync6(claudeMdPath)) {
1017
1068
  writeFileSync3(claudeMdPath, CLAUDE_MD);
1018
1069
  filesWritten++;
1019
1070
  }
@@ -1022,33 +1073,12 @@ function generateAIGuides(rootDir, _plugins) {
1022
1073
  }
1023
1074
 
1024
1075
  // src/commands/generate.ts
1025
- async function loadRegisteredSchemaPaths(rootDir) {
1026
- const schemaPathsFile = resolve7(rootDir, "storage/omnify/schema-paths.json");
1027
- logger.debug(`Checking for registered schema paths at: ${schemaPathsFile}`);
1028
- if (!existsSync5(schemaPathsFile)) {
1029
- logger.debug("No registered schema paths file found");
1030
- return [];
1031
- }
1032
- try {
1033
- const content = readFileSync3(schemaPathsFile, "utf-8");
1034
- const data = JSON.parse(content);
1035
- if (!data.paths || data.paths.length === 0) {
1036
- logger.debug("No paths defined in schema-paths.json");
1037
- return [];
1038
- }
1039
- logger.debug(`Found ${data.paths.length} registered schema path(s) in schema-paths.json`);
1040
- return data.paths;
1041
- } catch (error) {
1042
- logger.warn(`Could not read schema-paths.json: ${error.message}`);
1043
- return [];
1044
- }
1045
- }
1046
1076
  function hasPluginGenerators(plugins) {
1047
1077
  return plugins.some((p) => p.generators && p.generators.length > 0);
1048
1078
  }
1049
1079
  function getExistingMigrationTables(migrationsDir) {
1050
1080
  const existingTables = /* @__PURE__ */ new Set();
1051
- if (!existsSync5(migrationsDir)) {
1081
+ if (!existsSync7(migrationsDir)) {
1052
1082
  return existingTables;
1053
1083
  }
1054
1084
  try {
@@ -1243,11 +1273,11 @@ function writeGeneratorOutputs(outputs, rootDir) {
1243
1273
  for (const output of outputs) {
1244
1274
  const filePath = resolve7(rootDir, output.path);
1245
1275
  const dir = dirname5(filePath);
1246
- if (!existsSync5(dir)) {
1276
+ if (!existsSync7(dir)) {
1247
1277
  mkdirSync3(dir, { recursive: true });
1248
1278
  logger.debug(`Created directory: ${dir}`);
1249
1279
  }
1250
- if (output.skipIfExists && existsSync5(filePath)) {
1280
+ if (output.skipIfExists && existsSync7(filePath)) {
1251
1281
  logger.debug(`Skipped (exists): ${output.path}`);
1252
1282
  continue;
1253
1283
  }
@@ -1308,7 +1338,7 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1308
1338
  if (!options.typesOnly && config.output.laravel) {
1309
1339
  logger.step("Generating Laravel migrations...");
1310
1340
  const migrationsDir = resolve7(rootDir, config.output.laravel.migrationsPath);
1311
- if (!existsSync5(migrationsDir)) {
1341
+ if (!existsSync7(migrationsDir)) {
1312
1342
  mkdirSync3(migrationsDir, { recursive: true });
1313
1343
  logger.debug(`Created directory: ${migrationsDir}`);
1314
1344
  }
@@ -1353,10 +1383,10 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1353
1383
  const baseModelsPath = config.output.laravel.baseModelsPath ?? `${modelsPath}/OmnifyBase`;
1354
1384
  const modelsDir = resolve7(rootDir, modelsPath);
1355
1385
  const baseModelsDir = resolve7(rootDir, baseModelsPath);
1356
- if (!existsSync5(modelsDir)) {
1386
+ if (!existsSync7(modelsDir)) {
1357
1387
  mkdirSync3(modelsDir, { recursive: true });
1358
1388
  }
1359
- if (!existsSync5(baseModelsDir)) {
1389
+ if (!existsSync7(baseModelsDir)) {
1360
1390
  mkdirSync3(baseModelsDir, { recursive: true });
1361
1391
  }
1362
1392
  const providersPath = config.output.laravel.providersPath ?? "app/Providers";
@@ -1369,10 +1399,10 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1369
1399
  for (const model of models) {
1370
1400
  const filePath = resolve7(rootDir, getModelPath(model));
1371
1401
  const fileDir = dirname5(filePath);
1372
- if (!existsSync5(fileDir)) {
1402
+ if (!existsSync7(fileDir)) {
1373
1403
  mkdirSync3(fileDir, { recursive: true });
1374
1404
  }
1375
- if (!model.overwrite && existsSync5(filePath)) {
1405
+ if (!model.overwrite && existsSync7(filePath)) {
1376
1406
  logger.debug(`Skipped (exists): ${getModelPath(model)}`);
1377
1407
  continue;
1378
1408
  }
@@ -1386,7 +1416,7 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1386
1416
  logger.step("Generating Laravel factories...");
1387
1417
  const factoriesPath = config.output.laravel.factoriesPath;
1388
1418
  const factoriesDir = resolve7(rootDir, factoriesPath);
1389
- if (!existsSync5(factoriesDir)) {
1419
+ if (!existsSync7(factoriesDir)) {
1390
1420
  mkdirSync3(factoriesDir, { recursive: true });
1391
1421
  }
1392
1422
  const factories = generateFactories(schemas, {
@@ -1395,10 +1425,10 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1395
1425
  for (const factory of factories) {
1396
1426
  const filePath = resolve7(rootDir, getFactoryPath(factory));
1397
1427
  const fileDir = dirname5(filePath);
1398
- if (!existsSync5(fileDir)) {
1428
+ if (!existsSync7(fileDir)) {
1399
1429
  mkdirSync3(fileDir, { recursive: true });
1400
1430
  }
1401
- if (!factory.overwrite && existsSync5(filePath)) {
1431
+ if (!factory.overwrite && existsSync7(filePath)) {
1402
1432
  logger.debug(`Skipped (exists): ${getFactoryPath(factory)}`);
1403
1433
  continue;
1404
1434
  }
@@ -1415,11 +1445,11 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1415
1445
  const schemasDir = resolve7(basePath, tsConfig.schemasDir ?? "schemas");
1416
1446
  const enumDir = resolve7(basePath, tsConfig.enumDir ?? "enum");
1417
1447
  const enumImportPrefix = relative(schemasDir, enumDir).replace(/\\/g, "/");
1418
- if (!existsSync5(schemasDir)) {
1448
+ if (!existsSync7(schemasDir)) {
1419
1449
  mkdirSync3(schemasDir, { recursive: true });
1420
1450
  logger.debug(`Created directory: ${schemasDir}`);
1421
1451
  }
1422
- if (!existsSync5(enumDir)) {
1452
+ if (!existsSync7(enumDir)) {
1423
1453
  mkdirSync3(enumDir, { recursive: true });
1424
1454
  logger.debug(`Created directory: ${enumDir}`);
1425
1455
  }
@@ -1437,10 +1467,10 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1437
1467
  const outputDir = file.category === "enum" ? enumDir : schemasDir;
1438
1468
  const filePath = resolve7(outputDir, file.filePath);
1439
1469
  const fileDir = dirname5(filePath);
1440
- if (!existsSync5(fileDir)) {
1470
+ if (!existsSync7(fileDir)) {
1441
1471
  mkdirSync3(fileDir, { recursive: true });
1442
1472
  }
1443
- if (!file.overwrite && existsSync5(filePath)) {
1473
+ if (!file.overwrite && existsSync7(filePath)) {
1444
1474
  logger.debug(`Skipped (exists): ${file.filePath}`);
1445
1475
  continue;
1446
1476
  }
@@ -1477,18 +1507,19 @@ async function runGenerate(options) {
1477
1507
  logger.step(`Loading schemas from ${schemaPath}`);
1478
1508
  let schemas = await loadSchemas3(schemaPath);
1479
1509
  logger.debug(`Found ${Object.keys(schemas).length} schema(s) in main directory`);
1480
- const additionalPaths = await loadRegisteredSchemaPaths(rootDir);
1510
+ const additionalPaths = config.additionalSchemaPaths ?? [];
1481
1511
  let hasPackageSchemas = false;
1482
1512
  if (additionalPaths.length > 0) {
1483
- logger.step(`Loading schemas from ${additionalPaths.length} registered path(s)`);
1513
+ logger.step(`Loading schemas from ${additionalPaths.length} additional path(s)`);
1484
1514
  for (const entry of additionalPaths) {
1485
1515
  const absolutePath = resolve7(rootDir, entry.path);
1486
1516
  logger.debug(` Checking: ${entry.path} \u2192 ${absolutePath}`);
1487
- if (existsSync5(absolutePath)) {
1517
+ if (existsSync7(absolutePath)) {
1488
1518
  const packageSchemas = await loadSchemas3(absolutePath, { skipPartialResolution: true });
1489
1519
  const count = Object.keys(packageSchemas).filter((k) => !k.startsWith("__partial__")).length;
1490
1520
  const partialCount = Object.keys(packageSchemas).filter((k) => k.startsWith("__partial__")).length;
1491
- logger.info(` \u2022 ${entry.path}: ${count} schema(s)${partialCount > 0 ? ` + ${partialCount} partial(s)` : ""}`);
1521
+ const nsInfo = entry.namespace ? ` [${entry.namespace}]` : "";
1522
+ logger.info(` \u2022 ${entry.path}${nsInfo}: ${count} schema(s)${partialCount > 0 ? ` + ${partialCount} partial(s)` : ""}`);
1492
1523
  schemas = { ...packageSchemas, ...schemas };
1493
1524
  hasPackageSchemas = true;
1494
1525
  } else {
@@ -1498,7 +1529,7 @@ async function runGenerate(options) {
1498
1529
  }
1499
1530
  }
1500
1531
  if (hasPackageSchemas) {
1501
- schemas = mergePartialSchemas(schemas);
1532
+ schemas = mergePartialSchemas3(schemas);
1502
1533
  }
1503
1534
  const schemaCount = Object.keys(schemas).length;
1504
1535
  if (schemaCount === 0) {
@@ -1697,11 +1728,11 @@ async function runGenerate(options) {
1697
1728
  const schemasDir2 = resolve7(basePath2, tsConfig2.schemasDir ?? "schemas");
1698
1729
  const enumDir2 = resolve7(basePath2, tsConfig2.enumDir ?? "enum");
1699
1730
  const enumImportPrefix2 = relative(schemasDir2, enumDir2).replace(/\\/g, "/");
1700
- if (!existsSync5(schemasDir2)) {
1731
+ if (!existsSync7(schemasDir2)) {
1701
1732
  mkdirSync3(schemasDir2, { recursive: true });
1702
1733
  logger.debug(`Created directory: ${schemasDir2}`);
1703
1734
  }
1704
- if (!existsSync5(enumDir2)) {
1735
+ if (!existsSync7(enumDir2)) {
1705
1736
  mkdirSync3(enumDir2, { recursive: true });
1706
1737
  logger.debug(`Created directory: ${enumDir2}`);
1707
1738
  }
@@ -1719,10 +1750,10 @@ async function runGenerate(options) {
1719
1750
  const outputDir2 = file.category === "enum" ? enumDir2 : schemasDir2;
1720
1751
  const filePath = resolve7(outputDir2, file.filePath);
1721
1752
  const fileDir = dirname5(filePath);
1722
- if (!existsSync5(fileDir)) {
1753
+ if (!existsSync7(fileDir)) {
1723
1754
  mkdirSync3(fileDir, { recursive: true });
1724
1755
  }
1725
- if (!file.overwrite && existsSync5(filePath)) {
1756
+ if (!file.overwrite && existsSync7(filePath)) {
1726
1757
  logger.debug(`Skipped (exists): ${file.filePath}`);
1727
1758
  continue;
1728
1759
  }