@famgia/omnify-cli 0.0.163 → 0.0.165

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 hasViteOmnifyClientAlias(content) {
150
+ return content.includes("'@omnify-client'") || content.includes('"@omnify-client"') || content.includes("@omnify-client/");
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 (hasViteOmnifyClientAlias(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-client': path.resolve(__dirname, 'node_modules/@omnify-client'),`;
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-client 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-client")) {
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-client/*"] = ["./node_modules/@omnify-client/*"];
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
@@ -1555,6 +1632,7 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1555
1632
  const basePath = resolve8(rootDir, tsConfig.path);
1556
1633
  const schemasDir = resolve8(basePath, tsConfig.schemasDir ?? "schemas");
1557
1634
  const enumDir = resolve8(basePath, tsConfig.enumDir ?? "enum");
1635
+ const pluginEnumDir = resolve8(rootDir, "node_modules/@omnify-client/enum");
1558
1636
  const enumImportPrefix = relative(schemasDir, enumDir).replace(/\\/g, "/");
1559
1637
  if (!existsSync8(schemasDir)) {
1560
1638
  mkdirSync3(schemasDir, { recursive: true });
@@ -1564,6 +1642,23 @@ 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
+ const omnifyPkgDir = resolve8(rootDir, "node_modules/@omnify-client");
1650
+ const omnifyPkgJson = resolve8(omnifyPkgDir, "package.json");
1651
+ if (!existsSync8(omnifyPkgJson)) {
1652
+ writeFileSync4(omnifyPkgJson, JSON.stringify({
1653
+ name: "@omnify-client",
1654
+ version: "0.0.0",
1655
+ private: true,
1656
+ main: "./enum/index.js",
1657
+ exports: {
1658
+ "./enum/*": "./enum/*.js"
1659
+ }
1660
+ }, null, 2));
1661
+ }
1567
1662
  const isMultiLocale = config.locale && config.locale.locales && config.locale.locales.length > 1;
1568
1663
  const typeFiles = generateTypeScript(schemas, {
1569
1664
  customTypes: customTypesMap,
@@ -1572,10 +1667,18 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1572
1667
  multiLocale: isMultiLocale,
1573
1668
  generateRules: tsConfig.generateRules ?? true,
1574
1669
  validationTemplates: tsConfig.validationTemplates,
1575
- enumImportPrefix
1670
+ enumImportPrefix,
1671
+ pluginEnumImportPrefix: "@omnify-client/enum"
1576
1672
  });
1577
1673
  for (const file of typeFiles) {
1578
- const outputDir = file.category === "enum" ? enumDir : schemasDir;
1674
+ let outputDir;
1675
+ if (file.category === "plugin-enum") {
1676
+ outputDir = pluginEnumDir;
1677
+ } else if (file.category === "enum") {
1678
+ outputDir = enumDir;
1679
+ } else {
1680
+ outputDir = schemasDir;
1681
+ }
1579
1682
  const filePath = resolve8(outputDir, file.filePath);
1580
1683
  const fileDir = dirname6(filePath);
1581
1684
  if (!existsSync8(fileDir)) {
@@ -1604,6 +1707,16 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
1604
1707
  if (aliasResult.tsconfigUpdated) {
1605
1708
  logger.success("Auto-configured @omnify/* path in tsconfig.json");
1606
1709
  }
1710
+ if (pluginEnumsMap.size > 0) {
1711
+ const pluginAliasResult = addPluginEnumAlias(rootDir);
1712
+ if (pluginAliasResult.updated) {
1713
+ logger.success("Auto-configured @omnify-client alias in vite.config");
1714
+ }
1715
+ const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
1716
+ if (pluginPathResult.updated) {
1717
+ logger.success("Auto-configured @omnify-client/* path in tsconfig.json");
1718
+ }
1719
+ }
1607
1720
  }
1608
1721
  return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated, factories: factoriesGenerated };
1609
1722
  }
@@ -1849,6 +1962,7 @@ async function runGenerate(options) {
1849
1962
  const basePath2 = resolve8(rootDir, tsConfig2.path);
1850
1963
  const schemasDir2 = resolve8(basePath2, tsConfig2.schemasDir ?? "schemas");
1851
1964
  const enumDir2 = resolve8(basePath2, tsConfig2.enumDir ?? "enum");
1965
+ const pluginEnumDir2 = resolve8(rootDir, "node_modules/@omnify-client/enum");
1852
1966
  const enumImportPrefix2 = relative(schemasDir2, enumDir2).replace(/\\/g, "/");
1853
1967
  if (!existsSync8(schemasDir2)) {
1854
1968
  mkdirSync3(schemasDir2, { recursive: true });
@@ -1858,6 +1972,23 @@ async function runGenerate(options) {
1858
1972
  mkdirSync3(enumDir2, { recursive: true });
1859
1973
  logger.debug(`Created directory: ${enumDir2}`);
1860
1974
  }
1975
+ if (!existsSync8(pluginEnumDir2)) {
1976
+ mkdirSync3(pluginEnumDir2, { recursive: true });
1977
+ logger.debug(`Created directory: ${pluginEnumDir2}`);
1978
+ }
1979
+ const omnifyPkgDir2 = resolve8(rootDir, "node_modules/@omnify-client");
1980
+ const omnifyPkgJson2 = resolve8(omnifyPkgDir2, "package.json");
1981
+ if (!existsSync8(omnifyPkgJson2)) {
1982
+ writeFileSync4(omnifyPkgJson2, JSON.stringify({
1983
+ name: "@omnify-client",
1984
+ version: "0.0.0",
1985
+ private: true,
1986
+ main: "./enum/index.js",
1987
+ exports: {
1988
+ "./enum/*": "./enum/*.js"
1989
+ }
1990
+ }, null, 2));
1991
+ }
1861
1992
  const isMultiLocale = config.locale && config.locale.locales && config.locale.locales.length > 1;
1862
1993
  const typeFiles = generateTypeScript(schemas, {
1863
1994
  customTypes: customTypesMap,
@@ -1866,10 +1997,18 @@ async function runGenerate(options) {
1866
1997
  multiLocale: isMultiLocale,
1867
1998
  generateRules: tsConfig2.generateRules ?? true,
1868
1999
  validationTemplates: tsConfig2.validationTemplates,
1869
- enumImportPrefix: enumImportPrefix2
2000
+ enumImportPrefix: enumImportPrefix2,
2001
+ pluginEnumImportPrefix: "@omnify-client/enum"
1870
2002
  });
1871
2003
  for (const file of typeFiles) {
1872
- const outputDir2 = file.category === "enum" ? enumDir2 : schemasDir2;
2004
+ let outputDir2;
2005
+ if (file.category === "plugin-enum") {
2006
+ outputDir2 = pluginEnumDir2;
2007
+ } else if (file.category === "enum") {
2008
+ outputDir2 = enumDir2;
2009
+ } else {
2010
+ outputDir2 = schemasDir2;
2011
+ }
1873
2012
  const filePath = resolve8(outputDir2, file.filePath);
1874
2013
  const fileDir = dirname6(filePath);
1875
2014
  if (!existsSync8(fileDir)) {
@@ -1898,6 +2037,16 @@ async function runGenerate(options) {
1898
2037
  if (aliasResult.tsconfigUpdated) {
1899
2038
  logger.success("Auto-configured @omnify/* path in tsconfig.json");
1900
2039
  }
2040
+ if (pluginEnumsMap.size > 0) {
2041
+ const pluginAliasResult = addPluginEnumAlias(rootDir);
2042
+ if (pluginAliasResult.updated) {
2043
+ logger.success("Auto-configured .omnify-generated alias in vite.config");
2044
+ }
2045
+ const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
2046
+ if (pluginPathResult.updated) {
2047
+ logger.success("Auto-configured .omnify-generated/* path in tsconfig.json");
2048
+ }
2049
+ }
1901
2050
  if (shouldGenerateTypescriptAIGuides(rootDir)) {
1902
2051
  const tsAIResult = generateTypescriptAIGuides(rootDir, {
1903
2052
  typescriptPath: tsConfig2.path