@famgia/omnify-cli 0.0.165 → 0.0.167

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
@@ -441,8 +441,8 @@ var import_node_path3 = require("path");
441
441
  function hasViteOmnifyAlias(content) {
442
442
  return content.includes("'@omnify'") || content.includes('"@omnify"') || content.includes("@omnify:") || content.includes("'@omnify/");
443
443
  }
444
- function hasViteOmnifyClientAlias(content) {
445
- return content.includes("'@omnify-client'") || content.includes('"@omnify-client"') || content.includes("@omnify-client/");
444
+ function hasViteOmnifyBaseAlias(content) {
445
+ return content.includes("'@omnify-base'") || content.includes('"@omnify-base"') || content.includes("@omnify-base/");
446
446
  }
447
447
  function hasTsconfigOmnifyPath(content) {
448
448
  return content.includes('"@omnify/*"') || content.includes("'@omnify/*'") || content.includes('"@omnify/"');
@@ -628,7 +628,7 @@ function addPluginEnumAlias(rootDir) {
628
628
  }
629
629
  try {
630
630
  let content = (0, import_node_fs3.readFileSync)(configPath, "utf-8");
631
- if (hasViteOmnifyClientAlias(content)) {
631
+ if (hasViteOmnifyBaseAlias(content)) {
632
632
  return { updated: false };
633
633
  }
634
634
  const lines = content.split("\n");
@@ -647,13 +647,13 @@ function addPluginEnumAlias(rootDir) {
647
647
  }
648
648
  if (insertIndex > 0) {
649
649
  const indent = " ";
650
- const aliasLine = `${indent}'@omnify-client': path.resolve(__dirname, 'node_modules/@omnify-client'),`;
650
+ const aliasLine = `${indent}'@omnify-base': path.resolve(__dirname, 'node_modules/@omnify-base'),`;
651
651
  lines.splice(insertIndex, 0, aliasLine);
652
652
  content = lines.join("\n");
653
653
  (0, import_node_fs3.writeFileSync)(configPath, content);
654
654
  return { updated: true };
655
655
  }
656
- return { updated: false, error: "Could not find @omnify alias to add @omnify-client after" };
656
+ return { updated: false, error: "Could not find @omnify alias to add @omnify-base after" };
657
657
  } catch (error) {
658
658
  return {
659
659
  updated: false,
@@ -668,7 +668,7 @@ function addPluginEnumTsconfigPath(rootDir) {
668
668
  }
669
669
  try {
670
670
  const content = (0, import_node_fs3.readFileSync)(configPath, "utf-8");
671
- if (content.includes("@omnify-client")) {
671
+ if (content.includes("@omnify-base")) {
672
672
  return { updated: false };
673
673
  }
674
674
  const jsonContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "");
@@ -679,7 +679,7 @@ function addPluginEnumTsconfigPath(rootDir) {
679
679
  if (!config.compilerOptions.paths) {
680
680
  config.compilerOptions.paths = {};
681
681
  }
682
- config.compilerOptions.paths["@omnify-client/*"] = ["./node_modules/@omnify-client/*"];
682
+ config.compilerOptions.paths["@omnify-base/*"] = ["./node_modules/@omnify-base/*"];
683
683
  (0, import_node_fs3.writeFileSync)(configPath, JSON.stringify(config, null, 2));
684
684
  return { updated: true };
685
685
  } catch (error) {
@@ -1253,10 +1253,8 @@ function copyOmnifyGuides(rootDir) {
1253
1253
  function generateAIGuides(rootDir, _plugins) {
1254
1254
  let filesWritten = 0;
1255
1255
  const claudeMdPath = (0, import_node_path7.resolve)(rootDir, "CLAUDE.md");
1256
- if (!(0, import_node_fs7.existsSync)(claudeMdPath)) {
1257
- (0, import_node_fs7.writeFileSync)(claudeMdPath, CLAUDE_MD);
1258
- filesWritten++;
1259
- }
1256
+ (0, import_node_fs7.writeFileSync)(claudeMdPath, CLAUDE_MD);
1257
+ filesWritten++;
1260
1258
  filesWritten += copyOmnifyGuides(rootDir);
1261
1259
  return filesWritten;
1262
1260
  }
@@ -1633,7 +1631,9 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1633
1631
  const basePath = (0, import_node_path8.resolve)(rootDir, tsConfig.path);
1634
1632
  const schemasDir = (0, import_node_path8.resolve)(basePath, tsConfig.schemasDir ?? "schemas");
1635
1633
  const enumDir = (0, import_node_path8.resolve)(basePath, tsConfig.enumDir ?? "enum");
1636
- const pluginEnumDir = (0, import_node_path8.resolve)(rootDir, "node_modules/@omnify-client/enum");
1634
+ const omnifyBaseDir = (0, import_node_path8.resolve)(rootDir, "node_modules/@omnify-base");
1635
+ const pluginEnumDir = (0, import_node_path8.resolve)(omnifyBaseDir, "enum");
1636
+ const baseSchemasDir = (0, import_node_path8.resolve)(omnifyBaseDir, "schemas");
1637
1637
  const enumImportPrefix = (0, import_node_path8.relative)(schemasDir, enumDir).replace(/\\/g, "/");
1638
1638
  if (!(0, import_node_fs8.existsSync)(schemasDir)) {
1639
1639
  (0, import_node_fs8.mkdirSync)(schemasDir, { recursive: true });
@@ -1647,16 +1647,19 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1647
1647
  (0, import_node_fs8.mkdirSync)(pluginEnumDir, { recursive: true });
1648
1648
  logger.debug(`Created directory: ${pluginEnumDir}`);
1649
1649
  }
1650
- const omnifyPkgDir = (0, import_node_path8.resolve)(rootDir, "node_modules/@omnify-client");
1651
- const omnifyPkgJson = (0, import_node_path8.resolve)(omnifyPkgDir, "package.json");
1650
+ if (!(0, import_node_fs8.existsSync)(baseSchemasDir)) {
1651
+ (0, import_node_fs8.mkdirSync)(baseSchemasDir, { recursive: true });
1652
+ logger.debug(`Created directory: ${baseSchemasDir}`);
1653
+ }
1654
+ const omnifyPkgJson = (0, import_node_path8.resolve)(omnifyBaseDir, "package.json");
1652
1655
  if (!(0, import_node_fs8.existsSync)(omnifyPkgJson)) {
1653
1656
  (0, import_node_fs8.writeFileSync)(omnifyPkgJson, JSON.stringify({
1654
- name: "@omnify-client",
1657
+ name: "@omnify-base",
1655
1658
  version: "0.0.0",
1656
1659
  private: true,
1657
- main: "./enum/index.js",
1658
1660
  exports: {
1659
- "./enum/*": "./enum/*.js"
1661
+ "./enum/*": "./enum/*.js",
1662
+ "./schemas/*": "./schemas/*.js"
1660
1663
  }
1661
1664
  }, null, 2));
1662
1665
  }
@@ -1669,18 +1672,25 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1669
1672
  generateRules: tsConfig.generateRules ?? true,
1670
1673
  validationTemplates: tsConfig.validationTemplates,
1671
1674
  enumImportPrefix,
1672
- pluginEnumImportPrefix: "@omnify-client/enum"
1675
+ pluginEnumImportPrefix: "@omnify-base/enum",
1676
+ baseImportPrefix: "@omnify-base/schemas",
1677
+ schemaEnumImportPrefix: "@omnify/enum"
1678
+ // Absolute path for node_modules base files
1673
1679
  });
1674
1680
  for (const file of typeFiles) {
1675
1681
  let outputDir;
1682
+ let outputFilePath = file.filePath;
1676
1683
  if (file.category === "plugin-enum") {
1677
1684
  outputDir = pluginEnumDir;
1685
+ } else if (file.category === "base") {
1686
+ outputDir = baseSchemasDir;
1687
+ outputFilePath = file.filePath.replace(/^base\//, "");
1678
1688
  } else if (file.category === "enum") {
1679
1689
  outputDir = enumDir;
1680
1690
  } else {
1681
1691
  outputDir = schemasDir;
1682
1692
  }
1683
- const filePath = (0, import_node_path8.resolve)(outputDir, file.filePath);
1693
+ const filePath = (0, import_node_path8.resolve)(outputDir, outputFilePath);
1684
1694
  const fileDir = (0, import_node_path8.dirname)(filePath);
1685
1695
  if (!(0, import_node_fs8.existsSync)(fileDir)) {
1686
1696
  (0, import_node_fs8.mkdirSync)(fileDir, { recursive: true });
@@ -1694,13 +1704,6 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1694
1704
  typesGenerated++;
1695
1705
  }
1696
1706
  logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
1697
- const stubsResult = (0, import_omnify_typescript.copyStubs)({
1698
- targetDir: basePath,
1699
- skipIfExists: true
1700
- });
1701
- if (stubsResult.copied.length > 0) {
1702
- logger.success(`Generated ${stubsResult.copied.length} React stub(s)`);
1703
- }
1704
1707
  const aliasResult = configureOmnifyAlias(rootDir, tsConfig.path, true);
1705
1708
  if (aliasResult.viteUpdated) {
1706
1709
  logger.success("Auto-configured @omnify alias in vite.config");
@@ -1708,15 +1711,13 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1708
1711
  if (aliasResult.tsconfigUpdated) {
1709
1712
  logger.success("Auto-configured @omnify/* path in tsconfig.json");
1710
1713
  }
1711
- if (pluginEnumsMap.size > 0) {
1712
- const pluginAliasResult = addPluginEnumAlias(rootDir);
1713
- if (pluginAliasResult.updated) {
1714
- logger.success("Auto-configured @omnify-client alias in vite.config");
1715
- }
1716
- const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
1717
- if (pluginPathResult.updated) {
1718
- logger.success("Auto-configured @omnify-client/* path in tsconfig.json");
1719
- }
1714
+ const pluginAliasResult = addPluginEnumAlias(rootDir);
1715
+ if (pluginAliasResult.updated) {
1716
+ logger.success("Auto-configured @omnify-base alias in vite.config");
1717
+ }
1718
+ const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
1719
+ if (pluginPathResult.updated) {
1720
+ logger.success("Auto-configured @omnify-base/* path in tsconfig.json");
1720
1721
  }
1721
1722
  }
1722
1723
  return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated, factories: factoriesGenerated };
@@ -1889,11 +1890,48 @@ async function runGenerate(options) {
1889
1890
  return;
1890
1891
  }
1891
1892
  }
1892
- if (migrationValidation.missingFiles.length > 0) {
1893
+ if (migrationValidation.missingFiles.length > 0 && config.output.laravel) {
1893
1894
  const toRegenerate = (0, import_omnify_atlas2.getMigrationsToRegenerate)(existingLock, migrationValidation.missingFiles);
1894
1895
  if (toRegenerate.length > 0) {
1895
- logger.info(`Will regenerate ${toRegenerate.length} missing migration(s) with original timestamps.`);
1896
- logger.warn("Auto-regeneration not yet implemented. Please restore from git or reset migrations.");
1896
+ const createMigrations = toRegenerate.filter((m) => m.type === "create");
1897
+ const alterMigrations = toRegenerate.filter((m) => m.type === "alter" || m.type === "drop");
1898
+ if (createMigrations.length > 0) {
1899
+ logger.info(`Regenerating ${createMigrations.length} missing CREATE migration(s) with original timestamps...`);
1900
+ const migrationsDir2 = (0, import_node_path8.resolve)(rootDir, config.output.laravel.migrationsPath);
1901
+ const customTypesMap2 = /* @__PURE__ */ new Map();
1902
+ for (const plugin of config.plugins) {
1903
+ if (plugin.types) {
1904
+ for (const [typeName, typeDef] of Object.entries(plugin.types)) {
1905
+ customTypesMap2.set(typeName, typeDef);
1906
+ }
1907
+ }
1908
+ }
1909
+ for (const migData of createMigrations) {
1910
+ const migrationSchemas = Object.fromEntries(
1911
+ Object.entries(schemas).filter(([name]) => migData.schemas.includes(name))
1912
+ );
1913
+ if (Object.keys(migrationSchemas).length === 0) {
1914
+ logger.warn(` Cannot regenerate ${migData.fileName}: schema not found`);
1915
+ continue;
1916
+ }
1917
+ const regenerated = (0, import_omnify_laravel.generateMigrations)(migrationSchemas, {
1918
+ timestamp: migData.timestamp,
1919
+ customTypes: customTypesMap2
1920
+ });
1921
+ for (const mig of regenerated) {
1922
+ const filePath = (0, import_node_path8.resolve)(migrationsDir2, migData.fileName);
1923
+ (0, import_node_fs8.writeFileSync)(filePath, mig.content);
1924
+ logger.success(` Regenerated: ${migData.fileName}`);
1925
+ }
1926
+ }
1927
+ }
1928
+ if (alterMigrations.length > 0) {
1929
+ logger.warn(`Cannot regenerate ${alterMigrations.length} ALTER/DROP migration(s) - original change data not available.`);
1930
+ logger.warn(" Please restore these files from git or reset migrations with: npx omnify reset");
1931
+ for (const m of alterMigrations) {
1932
+ logger.warn(` - ${m.fileName}`);
1933
+ }
1934
+ }
1897
1935
  }
1898
1936
  }
1899
1937
  }
@@ -1963,7 +2001,9 @@ async function runGenerate(options) {
1963
2001
  const basePath2 = (0, import_node_path8.resolve)(rootDir, tsConfig2.path);
1964
2002
  const schemasDir2 = (0, import_node_path8.resolve)(basePath2, tsConfig2.schemasDir ?? "schemas");
1965
2003
  const enumDir2 = (0, import_node_path8.resolve)(basePath2, tsConfig2.enumDir ?? "enum");
1966
- const pluginEnumDir2 = (0, import_node_path8.resolve)(rootDir, "node_modules/@omnify-client/enum");
2004
+ const omnifyBaseDir2 = (0, import_node_path8.resolve)(rootDir, "node_modules/@omnify-base");
2005
+ const pluginEnumDir2 = (0, import_node_path8.resolve)(omnifyBaseDir2, "enum");
2006
+ const baseSchemasDir2 = (0, import_node_path8.resolve)(omnifyBaseDir2, "schemas");
1967
2007
  const enumImportPrefix2 = (0, import_node_path8.relative)(schemasDir2, enumDir2).replace(/\\/g, "/");
1968
2008
  if (!(0, import_node_fs8.existsSync)(schemasDir2)) {
1969
2009
  (0, import_node_fs8.mkdirSync)(schemasDir2, { recursive: true });
@@ -1977,16 +2017,19 @@ async function runGenerate(options) {
1977
2017
  (0, import_node_fs8.mkdirSync)(pluginEnumDir2, { recursive: true });
1978
2018
  logger.debug(`Created directory: ${pluginEnumDir2}`);
1979
2019
  }
1980
- const omnifyPkgDir2 = (0, import_node_path8.resolve)(rootDir, "node_modules/@omnify-client");
1981
- const omnifyPkgJson2 = (0, import_node_path8.resolve)(omnifyPkgDir2, "package.json");
2020
+ if (!(0, import_node_fs8.existsSync)(baseSchemasDir2)) {
2021
+ (0, import_node_fs8.mkdirSync)(baseSchemasDir2, { recursive: true });
2022
+ logger.debug(`Created directory: ${baseSchemasDir2}`);
2023
+ }
2024
+ const omnifyPkgJson2 = (0, import_node_path8.resolve)(omnifyBaseDir2, "package.json");
1982
2025
  if (!(0, import_node_fs8.existsSync)(omnifyPkgJson2)) {
1983
2026
  (0, import_node_fs8.writeFileSync)(omnifyPkgJson2, JSON.stringify({
1984
- name: "@omnify-client",
2027
+ name: "@omnify-base",
1985
2028
  version: "0.0.0",
1986
2029
  private: true,
1987
- main: "./enum/index.js",
1988
2030
  exports: {
1989
- "./enum/*": "./enum/*.js"
2031
+ "./enum/*": "./enum/*.js",
2032
+ "./schemas/*": "./schemas/*.js"
1990
2033
  }
1991
2034
  }, null, 2));
1992
2035
  }
@@ -1999,18 +2042,25 @@ async function runGenerate(options) {
1999
2042
  generateRules: tsConfig2.generateRules ?? true,
2000
2043
  validationTemplates: tsConfig2.validationTemplates,
2001
2044
  enumImportPrefix: enumImportPrefix2,
2002
- pluginEnumImportPrefix: "@omnify-client/enum"
2045
+ pluginEnumImportPrefix: "@omnify-base/enum",
2046
+ baseImportPrefix: "@omnify-base/schemas",
2047
+ schemaEnumImportPrefix: "@omnify/enum"
2048
+ // Absolute path for node_modules base files
2003
2049
  });
2004
2050
  for (const file of typeFiles) {
2005
2051
  let outputDir2;
2052
+ let outputFilePath2 = file.filePath;
2006
2053
  if (file.category === "plugin-enum") {
2007
2054
  outputDir2 = pluginEnumDir2;
2055
+ } else if (file.category === "base") {
2056
+ outputDir2 = baseSchemasDir2;
2057
+ outputFilePath2 = file.filePath.replace(/^base\//, "");
2008
2058
  } else if (file.category === "enum") {
2009
2059
  outputDir2 = enumDir2;
2010
2060
  } else {
2011
2061
  outputDir2 = schemasDir2;
2012
2062
  }
2013
- const filePath = (0, import_node_path8.resolve)(outputDir2, file.filePath);
2063
+ const filePath = (0, import_node_path8.resolve)(outputDir2, outputFilePath2);
2014
2064
  const fileDir = (0, import_node_path8.dirname)(filePath);
2015
2065
  if (!(0, import_node_fs8.existsSync)(fileDir)) {
2016
2066
  (0, import_node_fs8.mkdirSync)(fileDir, { recursive: true });
@@ -2024,13 +2074,6 @@ async function runGenerate(options) {
2024
2074
  typesGenerated++;
2025
2075
  }
2026
2076
  logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
2027
- const stubsResult2 = (0, import_omnify_typescript.copyStubs)({
2028
- targetDir: basePath2,
2029
- skipIfExists: true
2030
- });
2031
- if (stubsResult2.copied.length > 0) {
2032
- logger.success(`Generated ${stubsResult2.copied.length} React stub(s)`);
2033
- }
2034
2077
  const aliasResult = configureOmnifyAlias(rootDir, tsConfig2.path, true);
2035
2078
  if (aliasResult.viteUpdated) {
2036
2079
  logger.success("Auto-configured @omnify alias in vite.config");
@@ -2038,15 +2081,13 @@ async function runGenerate(options) {
2038
2081
  if (aliasResult.tsconfigUpdated) {
2039
2082
  logger.success("Auto-configured @omnify/* path in tsconfig.json");
2040
2083
  }
2041
- if (pluginEnumsMap.size > 0) {
2042
- const pluginAliasResult = addPluginEnumAlias(rootDir);
2043
- if (pluginAliasResult.updated) {
2044
- logger.success("Auto-configured .omnify-generated alias in vite.config");
2045
- }
2046
- const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
2047
- if (pluginPathResult.updated) {
2048
- logger.success("Auto-configured .omnify-generated/* path in tsconfig.json");
2049
- }
2084
+ const pluginAliasResult = addPluginEnumAlias(rootDir);
2085
+ if (pluginAliasResult.updated) {
2086
+ logger.success("Auto-configured @omnify-base alias in vite.config");
2087
+ }
2088
+ const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
2089
+ if (pluginPathResult.updated) {
2090
+ logger.success("Auto-configured @omnify-base/* path in tsconfig.json");
2050
2091
  }
2051
2092
  if ((0, import_omnify_typescript.shouldGenerateAIGuides)(rootDir)) {
2052
2093
  const tsAIResult = (0, import_omnify_typescript.generateAIGuides)(rootDir, {