@famgia/omnify-cli 0.0.164 → 0.0.166

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
@@ -146,6 +146,9 @@ import { resolve } from "path";
146
146
  function hasViteOmnifyAlias(content) {
147
147
  return content.includes("'@omnify'") || content.includes('"@omnify"') || content.includes("@omnify:") || content.includes("'@omnify/");
148
148
  }
149
+ function hasViteOmnifyBaseAlias(content) {
150
+ return content.includes("'@omnify-base'") || content.includes('"@omnify-base"') || content.includes("@omnify-base/");
151
+ }
149
152
  function hasTsconfigOmnifyPath(content) {
150
153
  return content.includes('"@omnify/*"') || content.includes("'@omnify/*'") || content.includes('"@omnify/"');
151
154
  }
@@ -317,6 +320,80 @@ function configureOmnifyAlias(rootDir, omnifyPath = "omnify", silent = false) {
317
320
  }
318
321
  return result;
319
322
  }
323
+ function addPluginEnumAlias(rootDir) {
324
+ const configPaths = [
325
+ resolve(rootDir, "vite.config.ts"),
326
+ resolve(rootDir, "vite.config.js"),
327
+ resolve(rootDir, "vite.config.mts"),
328
+ resolve(rootDir, "vite.config.mjs")
329
+ ];
330
+ const configPath2 = configPaths.find((p) => existsSync(p));
331
+ if (!configPath2) {
332
+ return { updated: false };
333
+ }
334
+ try {
335
+ let content = readFileSync(configPath2, "utf-8");
336
+ if (hasViteOmnifyBaseAlias(content)) {
337
+ return { updated: false };
338
+ }
339
+ const lines = content.split("\n");
340
+ let insertIndex = -1;
341
+ for (let i = 0; i < lines.length; i++) {
342
+ const line = lines[i];
343
+ if ((line.includes("'@omnify'") || line.includes('"@omnify"')) && line.includes(":")) {
344
+ for (let j = i; j < lines.length; j++) {
345
+ if (lines[j].includes("),") || lines[j].trim().endsWith(",") && lines[j].includes(")")) {
346
+ insertIndex = j + 1;
347
+ break;
348
+ }
349
+ }
350
+ break;
351
+ }
352
+ }
353
+ if (insertIndex > 0) {
354
+ const indent = " ";
355
+ const aliasLine = `${indent}'@omnify-base': path.resolve(__dirname, 'node_modules/@omnify-base'),`;
356
+ lines.splice(insertIndex, 0, aliasLine);
357
+ content = lines.join("\n");
358
+ writeFileSync(configPath2, content);
359
+ return { updated: true };
360
+ }
361
+ return { updated: false, error: "Could not find @omnify alias to add @omnify-base after" };
362
+ } catch (error) {
363
+ return {
364
+ updated: false,
365
+ error: `Failed to add plugin enum alias: ${error instanceof Error ? error.message : String(error)}`
366
+ };
367
+ }
368
+ }
369
+ function addPluginEnumTsconfigPath(rootDir) {
370
+ const configPath2 = resolve(rootDir, "tsconfig.json");
371
+ if (!existsSync(configPath2)) {
372
+ return { updated: false };
373
+ }
374
+ try {
375
+ const content = readFileSync(configPath2, "utf-8");
376
+ if (content.includes("@omnify-base")) {
377
+ return { updated: false };
378
+ }
379
+ const jsonContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "");
380
+ const config = JSON.parse(jsonContent);
381
+ if (!config.compilerOptions) {
382
+ config.compilerOptions = {};
383
+ }
384
+ if (!config.compilerOptions.paths) {
385
+ config.compilerOptions.paths = {};
386
+ }
387
+ config.compilerOptions.paths["@omnify-base/*"] = ["./node_modules/@omnify-base/*"];
388
+ writeFileSync(configPath2, JSON.stringify(config, null, 2));
389
+ return { updated: true };
390
+ } catch (error) {
391
+ return {
392
+ updated: false,
393
+ error: `Failed to add plugin enum tsconfig path: ${error instanceof Error ? error.message : String(error)}`
394
+ };
395
+ }
396
+ }
320
397
 
321
398
  // src/commands/init.ts
322
399
  var EXAMPLE_SCHEMA = `# Example User schema
@@ -1062,7 +1139,7 @@ import {
1062
1139
  generateFactories,
1063
1140
  getFactoryPath
1064
1141
  } from "@famgia/omnify-laravel";
1065
- import { generateTypeScript, copyStubs, generateAIGuides as generateTypescriptAIGuides, shouldGenerateAIGuides as shouldGenerateTypescriptAIGuides } from "@famgia/omnify-typescript";
1142
+ import { generateTypeScript, generateAIGuides as generateTypescriptAIGuides, shouldGenerateAIGuides as shouldGenerateTypescriptAIGuides } from "@famgia/omnify-typescript";
1066
1143
 
1067
1144
  // src/guides/index.ts
1068
1145
  import { existsSync as existsSync7, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3 } from "fs";
@@ -1175,10 +1252,8 @@ function copyOmnifyGuides(rootDir) {
1175
1252
  function generateAIGuides(rootDir, _plugins) {
1176
1253
  let filesWritten = 0;
1177
1254
  const claudeMdPath = resolve7(rootDir, "CLAUDE.md");
1178
- if (!existsSync7(claudeMdPath)) {
1179
- writeFileSync3(claudeMdPath, CLAUDE_MD);
1180
- filesWritten++;
1181
- }
1255
+ writeFileSync3(claudeMdPath, CLAUDE_MD);
1256
+ filesWritten++;
1182
1257
  filesWritten += copyOmnifyGuides(rootDir);
1183
1258
  return filesWritten;
1184
1259
  }
@@ -1555,6 +1630,9 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1555
1630
  const basePath = resolve8(rootDir, tsConfig.path);
1556
1631
  const schemasDir = resolve8(basePath, tsConfig.schemasDir ?? "schemas");
1557
1632
  const enumDir = resolve8(basePath, tsConfig.enumDir ?? "enum");
1633
+ const omnifyBaseDir = resolve8(rootDir, "node_modules/@omnify-base");
1634
+ const pluginEnumDir = resolve8(omnifyBaseDir, "enum");
1635
+ const baseSchemasDir = resolve8(omnifyBaseDir, "schemas");
1558
1636
  const enumImportPrefix = relative(schemasDir, enumDir).replace(/\\/g, "/");
1559
1637
  if (!existsSync8(schemasDir)) {
1560
1638
  mkdirSync3(schemasDir, { recursive: true });
@@ -1564,6 +1642,26 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1564
1642
  mkdirSync3(enumDir, { recursive: true });
1565
1643
  logger.debug(`Created directory: ${enumDir}`);
1566
1644
  }
1645
+ if (!existsSync8(pluginEnumDir)) {
1646
+ mkdirSync3(pluginEnumDir, { recursive: true });
1647
+ logger.debug(`Created directory: ${pluginEnumDir}`);
1648
+ }
1649
+ if (!existsSync8(baseSchemasDir)) {
1650
+ mkdirSync3(baseSchemasDir, { recursive: true });
1651
+ logger.debug(`Created directory: ${baseSchemasDir}`);
1652
+ }
1653
+ const omnifyPkgJson = resolve8(omnifyBaseDir, "package.json");
1654
+ if (!existsSync8(omnifyPkgJson)) {
1655
+ writeFileSync4(omnifyPkgJson, JSON.stringify({
1656
+ name: "@omnify-base",
1657
+ version: "0.0.0",
1658
+ private: true,
1659
+ exports: {
1660
+ "./enum/*": "./enum/*.js",
1661
+ "./schemas/*": "./schemas/*.js"
1662
+ }
1663
+ }, null, 2));
1664
+ }
1567
1665
  const isMultiLocale = config.locale && config.locale.locales && config.locale.locales.length > 1;
1568
1666
  const typeFiles = generateTypeScript(schemas, {
1569
1667
  customTypes: customTypesMap,
@@ -1572,11 +1670,26 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1572
1670
  multiLocale: isMultiLocale,
1573
1671
  generateRules: tsConfig.generateRules ?? true,
1574
1672
  validationTemplates: tsConfig.validationTemplates,
1575
- enumImportPrefix
1673
+ enumImportPrefix,
1674
+ pluginEnumImportPrefix: "@omnify-base/enum",
1675
+ baseImportPrefix: "@omnify-base/schemas",
1676
+ schemaEnumImportPrefix: "@omnify/enum"
1677
+ // Absolute path for node_modules base files
1576
1678
  });
1577
1679
  for (const file of typeFiles) {
1578
- const outputDir = file.category === "enum" ? enumDir : schemasDir;
1579
- const filePath = resolve8(outputDir, file.filePath);
1680
+ let outputDir;
1681
+ let outputFilePath = file.filePath;
1682
+ if (file.category === "plugin-enum") {
1683
+ outputDir = pluginEnumDir;
1684
+ } else if (file.category === "base") {
1685
+ outputDir = baseSchemasDir;
1686
+ outputFilePath = file.filePath.replace(/^base\//, "");
1687
+ } else if (file.category === "enum") {
1688
+ outputDir = enumDir;
1689
+ } else {
1690
+ outputDir = schemasDir;
1691
+ }
1692
+ const filePath = resolve8(outputDir, outputFilePath);
1580
1693
  const fileDir = dirname6(filePath);
1581
1694
  if (!existsSync8(fileDir)) {
1582
1695
  mkdirSync3(fileDir, { recursive: true });
@@ -1590,13 +1703,6 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1590
1703
  typesGenerated++;
1591
1704
  }
1592
1705
  logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
1593
- const stubsResult = copyStubs({
1594
- targetDir: basePath,
1595
- skipIfExists: true
1596
- });
1597
- if (stubsResult.copied.length > 0) {
1598
- logger.success(`Generated ${stubsResult.copied.length} React stub(s)`);
1599
- }
1600
1706
  const aliasResult = configureOmnifyAlias(rootDir, tsConfig.path, true);
1601
1707
  if (aliasResult.viteUpdated) {
1602
1708
  logger.success("Auto-configured @omnify alias in vite.config");
@@ -1604,6 +1710,14 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1604
1710
  if (aliasResult.tsconfigUpdated) {
1605
1711
  logger.success("Auto-configured @omnify/* path in tsconfig.json");
1606
1712
  }
1713
+ const pluginAliasResult = addPluginEnumAlias(rootDir);
1714
+ if (pluginAliasResult.updated) {
1715
+ logger.success("Auto-configured @omnify-base alias in vite.config");
1716
+ }
1717
+ const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
1718
+ if (pluginPathResult.updated) {
1719
+ logger.success("Auto-configured @omnify-base/* path in tsconfig.json");
1720
+ }
1607
1721
  }
1608
1722
  return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated, factories: factoriesGenerated };
1609
1723
  }
@@ -1775,11 +1889,48 @@ async function runGenerate(options) {
1775
1889
  return;
1776
1890
  }
1777
1891
  }
1778
- if (migrationValidation.missingFiles.length > 0) {
1892
+ if (migrationValidation.missingFiles.length > 0 && config.output.laravel) {
1779
1893
  const toRegenerate = getMigrationsToRegenerate(existingLock, migrationValidation.missingFiles);
1780
1894
  if (toRegenerate.length > 0) {
1781
- logger.info(`Will regenerate ${toRegenerate.length} missing migration(s) with original timestamps.`);
1782
- logger.warn("Auto-regeneration not yet implemented. Please restore from git or reset migrations.");
1895
+ const createMigrations = toRegenerate.filter((m) => m.type === "create");
1896
+ const alterMigrations = toRegenerate.filter((m) => m.type === "alter" || m.type === "drop");
1897
+ if (createMigrations.length > 0) {
1898
+ logger.info(`Regenerating ${createMigrations.length} missing CREATE migration(s) with original timestamps...`);
1899
+ const migrationsDir2 = resolve8(rootDir, config.output.laravel.migrationsPath);
1900
+ const customTypesMap2 = /* @__PURE__ */ new Map();
1901
+ for (const plugin of config.plugins) {
1902
+ if (plugin.types) {
1903
+ for (const [typeName, typeDef] of Object.entries(plugin.types)) {
1904
+ customTypesMap2.set(typeName, typeDef);
1905
+ }
1906
+ }
1907
+ }
1908
+ for (const migData of createMigrations) {
1909
+ const migrationSchemas = Object.fromEntries(
1910
+ Object.entries(schemas).filter(([name]) => migData.schemas.includes(name))
1911
+ );
1912
+ if (Object.keys(migrationSchemas).length === 0) {
1913
+ logger.warn(` Cannot regenerate ${migData.fileName}: schema not found`);
1914
+ continue;
1915
+ }
1916
+ const regenerated = generateMigrations(migrationSchemas, {
1917
+ timestamp: migData.timestamp,
1918
+ customTypes: customTypesMap2
1919
+ });
1920
+ for (const mig of regenerated) {
1921
+ const filePath = resolve8(migrationsDir2, migData.fileName);
1922
+ writeFileSync4(filePath, mig.content);
1923
+ logger.success(` Regenerated: ${migData.fileName}`);
1924
+ }
1925
+ }
1926
+ }
1927
+ if (alterMigrations.length > 0) {
1928
+ logger.warn(`Cannot regenerate ${alterMigrations.length} ALTER/DROP migration(s) - original change data not available.`);
1929
+ logger.warn(" Please restore these files from git or reset migrations with: npx omnify reset");
1930
+ for (const m of alterMigrations) {
1931
+ logger.warn(` - ${m.fileName}`);
1932
+ }
1933
+ }
1783
1934
  }
1784
1935
  }
1785
1936
  }
@@ -1849,6 +2000,9 @@ async function runGenerate(options) {
1849
2000
  const basePath2 = resolve8(rootDir, tsConfig2.path);
1850
2001
  const schemasDir2 = resolve8(basePath2, tsConfig2.schemasDir ?? "schemas");
1851
2002
  const enumDir2 = resolve8(basePath2, tsConfig2.enumDir ?? "enum");
2003
+ const omnifyBaseDir2 = resolve8(rootDir, "node_modules/@omnify-base");
2004
+ const pluginEnumDir2 = resolve8(omnifyBaseDir2, "enum");
2005
+ const baseSchemasDir2 = resolve8(omnifyBaseDir2, "schemas");
1852
2006
  const enumImportPrefix2 = relative(schemasDir2, enumDir2).replace(/\\/g, "/");
1853
2007
  if (!existsSync8(schemasDir2)) {
1854
2008
  mkdirSync3(schemasDir2, { recursive: true });
@@ -1858,6 +2012,26 @@ async function runGenerate(options) {
1858
2012
  mkdirSync3(enumDir2, { recursive: true });
1859
2013
  logger.debug(`Created directory: ${enumDir2}`);
1860
2014
  }
2015
+ if (!existsSync8(pluginEnumDir2)) {
2016
+ mkdirSync3(pluginEnumDir2, { recursive: true });
2017
+ logger.debug(`Created directory: ${pluginEnumDir2}`);
2018
+ }
2019
+ if (!existsSync8(baseSchemasDir2)) {
2020
+ mkdirSync3(baseSchemasDir2, { recursive: true });
2021
+ logger.debug(`Created directory: ${baseSchemasDir2}`);
2022
+ }
2023
+ const omnifyPkgJson2 = resolve8(omnifyBaseDir2, "package.json");
2024
+ if (!existsSync8(omnifyPkgJson2)) {
2025
+ writeFileSync4(omnifyPkgJson2, JSON.stringify({
2026
+ name: "@omnify-base",
2027
+ version: "0.0.0",
2028
+ private: true,
2029
+ exports: {
2030
+ "./enum/*": "./enum/*.js",
2031
+ "./schemas/*": "./schemas/*.js"
2032
+ }
2033
+ }, null, 2));
2034
+ }
1861
2035
  const isMultiLocale = config.locale && config.locale.locales && config.locale.locales.length > 1;
1862
2036
  const typeFiles = generateTypeScript(schemas, {
1863
2037
  customTypes: customTypesMap,
@@ -1866,11 +2040,26 @@ async function runGenerate(options) {
1866
2040
  multiLocale: isMultiLocale,
1867
2041
  generateRules: tsConfig2.generateRules ?? true,
1868
2042
  validationTemplates: tsConfig2.validationTemplates,
1869
- enumImportPrefix: enumImportPrefix2
2043
+ enumImportPrefix: enumImportPrefix2,
2044
+ pluginEnumImportPrefix: "@omnify-base/enum",
2045
+ baseImportPrefix: "@omnify-base/schemas",
2046
+ schemaEnumImportPrefix: "@omnify/enum"
2047
+ // Absolute path for node_modules base files
1870
2048
  });
1871
2049
  for (const file of typeFiles) {
1872
- const outputDir2 = file.category === "enum" ? enumDir2 : schemasDir2;
1873
- const filePath = resolve8(outputDir2, file.filePath);
2050
+ let outputDir2;
2051
+ let outputFilePath2 = file.filePath;
2052
+ if (file.category === "plugin-enum") {
2053
+ outputDir2 = pluginEnumDir2;
2054
+ } else if (file.category === "base") {
2055
+ outputDir2 = baseSchemasDir2;
2056
+ outputFilePath2 = file.filePath.replace(/^base\//, "");
2057
+ } else if (file.category === "enum") {
2058
+ outputDir2 = enumDir2;
2059
+ } else {
2060
+ outputDir2 = schemasDir2;
2061
+ }
2062
+ const filePath = resolve8(outputDir2, outputFilePath2);
1874
2063
  const fileDir = dirname6(filePath);
1875
2064
  if (!existsSync8(fileDir)) {
1876
2065
  mkdirSync3(fileDir, { recursive: true });
@@ -1884,13 +2073,6 @@ async function runGenerate(options) {
1884
2073
  typesGenerated++;
1885
2074
  }
1886
2075
  logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
1887
- const stubsResult2 = copyStubs({
1888
- targetDir: basePath2,
1889
- skipIfExists: true
1890
- });
1891
- if (stubsResult2.copied.length > 0) {
1892
- logger.success(`Generated ${stubsResult2.copied.length} React stub(s)`);
1893
- }
1894
2076
  const aliasResult = configureOmnifyAlias(rootDir, tsConfig2.path, true);
1895
2077
  if (aliasResult.viteUpdated) {
1896
2078
  logger.success("Auto-configured @omnify alias in vite.config");
@@ -1898,6 +2080,14 @@ async function runGenerate(options) {
1898
2080
  if (aliasResult.tsconfigUpdated) {
1899
2081
  logger.success("Auto-configured @omnify/* path in tsconfig.json");
1900
2082
  }
2083
+ const pluginAliasResult = addPluginEnumAlias(rootDir);
2084
+ if (pluginAliasResult.updated) {
2085
+ logger.success("Auto-configured @omnify-base alias in vite.config");
2086
+ }
2087
+ const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
2088
+ if (pluginPathResult.updated) {
2089
+ logger.success("Auto-configured @omnify-base/* path in tsconfig.json");
2090
+ }
1901
2091
  if (shouldGenerateTypescriptAIGuides(rootDir)) {
1902
2092
  const tsAIResult = generateTypescriptAIGuides(rootDir, {
1903
2093
  typescriptPath: tsConfig2.path