@famgia/omnify-cli 0.0.56 → 0.0.58

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/cli.js CHANGED
@@ -697,7 +697,9 @@ import {
697
697
  generateMigrations,
698
698
  generateMigrationsFromChanges,
699
699
  generateModels,
700
- getModelPath
700
+ getModelPath,
701
+ generateFactories,
702
+ getFactoryPath
701
703
  } from "@famgia/omnify-laravel";
702
704
  import { generateTypeScript } from "@famgia/omnify-typescript";
703
705
 
@@ -1427,6 +1429,7 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1427
1429
  let migrationsGenerated = 0;
1428
1430
  let typesGenerated = 0;
1429
1431
  let modelsGenerated = 0;
1432
+ let factoriesGenerated = 0;
1430
1433
  const customTypesMap = /* @__PURE__ */ new Map();
1431
1434
  for (const plugin of config.plugins) {
1432
1435
  if (plugin.types) {
@@ -1512,6 +1515,32 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1512
1515
  }
1513
1516
  logger.success(`Generated ${modelsGenerated} model(s)`);
1514
1517
  }
1518
+ if (!options.typesOnly && config.output.laravel?.factoriesPath) {
1519
+ logger.step("Generating Laravel factories...");
1520
+ const factoriesPath = config.output.laravel.factoriesPath;
1521
+ const factoriesDir = resolve6(rootDir, factoriesPath);
1522
+ if (!existsSync4(factoriesDir)) {
1523
+ mkdirSync3(factoriesDir, { recursive: true });
1524
+ }
1525
+ const factories = generateFactories(schemas, {
1526
+ factoryPath: factoriesPath
1527
+ });
1528
+ for (const factory of factories) {
1529
+ const filePath = resolve6(rootDir, getFactoryPath(factory));
1530
+ const fileDir = dirname4(filePath);
1531
+ if (!existsSync4(fileDir)) {
1532
+ mkdirSync3(fileDir, { recursive: true });
1533
+ }
1534
+ if (!factory.overwrite && existsSync4(filePath)) {
1535
+ logger.debug(`Skipped (exists): ${getFactoryPath(factory)}`);
1536
+ continue;
1537
+ }
1538
+ writeFileSync3(filePath, factory.content);
1539
+ logger.debug(`Created: ${getFactoryPath(factory)}`);
1540
+ factoriesGenerated++;
1541
+ }
1542
+ logger.success(`Generated ${factoriesGenerated} factory(ies)`);
1543
+ }
1515
1544
  if (!options.migrationsOnly && config.output.typescript) {
1516
1545
  logger.step("Generating TypeScript types...");
1517
1546
  const typesDir = resolve6(rootDir, config.output.typescript.path);
@@ -1544,7 +1573,7 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1544
1573
  }
1545
1574
  logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
1546
1575
  }
1547
- return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated };
1576
+ return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated, factories: factoriesGenerated };
1548
1577
  }
1549
1578
  async function runGenerate(options) {
1550
1579
  logger.setVerbose(options.verbose ?? false);
@@ -1602,6 +1631,7 @@ async function runGenerate(options) {
1602
1631
  let migrationsGenerated = 0;
1603
1632
  let typesGenerated = 0;
1604
1633
  let modelsGenerated = 0;
1634
+ let factoriesGenerated = 0;
1605
1635
  const usePlugins = hasPluginGenerators(config.plugins);
1606
1636
  const customTypesMap = /* @__PURE__ */ new Map();
1607
1637
  for (const plugin of config.plugins) {
@@ -1674,6 +1704,7 @@ async function runGenerate(options) {
1674
1704
  migrationsGenerated = counts.migrations;
1675
1705
  typesGenerated = counts.types;
1676
1706
  modelsGenerated = counts.models;
1707
+ factoriesGenerated = counts.factories;
1677
1708
  }
1678
1709
  logger.step("Updating lock file...");
1679
1710
  const newLockFile = updateLockFile(existingLock, currentSnapshots, config.database.driver);