@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/cli.js +105 -64
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +103 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +104 -63
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -405,8 +405,8 @@ import { resolve as resolve3 } from "path";
|
|
|
405
405
|
function hasViteOmnifyAlias(content) {
|
|
406
406
|
return content.includes("'@omnify'") || content.includes('"@omnify"') || content.includes("@omnify:") || content.includes("'@omnify/");
|
|
407
407
|
}
|
|
408
|
-
function
|
|
409
|
-
return content.includes("'@omnify-
|
|
408
|
+
function hasViteOmnifyBaseAlias(content) {
|
|
409
|
+
return content.includes("'@omnify-base'") || content.includes('"@omnify-base"') || content.includes("@omnify-base/");
|
|
410
410
|
}
|
|
411
411
|
function hasTsconfigOmnifyPath(content) {
|
|
412
412
|
return content.includes('"@omnify/*"') || content.includes("'@omnify/*'") || content.includes('"@omnify/"');
|
|
@@ -592,7 +592,7 @@ function addPluginEnumAlias(rootDir) {
|
|
|
592
592
|
}
|
|
593
593
|
try {
|
|
594
594
|
let content = readFileSync2(configPath, "utf-8");
|
|
595
|
-
if (
|
|
595
|
+
if (hasViteOmnifyBaseAlias(content)) {
|
|
596
596
|
return { updated: false };
|
|
597
597
|
}
|
|
598
598
|
const lines = content.split("\n");
|
|
@@ -611,13 +611,13 @@ function addPluginEnumAlias(rootDir) {
|
|
|
611
611
|
}
|
|
612
612
|
if (insertIndex > 0) {
|
|
613
613
|
const indent = " ";
|
|
614
|
-
const aliasLine = `${indent}'@omnify-
|
|
614
|
+
const aliasLine = `${indent}'@omnify-base': path.resolve(__dirname, 'node_modules/@omnify-base'),`;
|
|
615
615
|
lines.splice(insertIndex, 0, aliasLine);
|
|
616
616
|
content = lines.join("\n");
|
|
617
617
|
writeFileSync(configPath, content);
|
|
618
618
|
return { updated: true };
|
|
619
619
|
}
|
|
620
|
-
return { updated: false, error: "Could not find @omnify alias to add @omnify-
|
|
620
|
+
return { updated: false, error: "Could not find @omnify alias to add @omnify-base after" };
|
|
621
621
|
} catch (error) {
|
|
622
622
|
return {
|
|
623
623
|
updated: false,
|
|
@@ -632,7 +632,7 @@ function addPluginEnumTsconfigPath(rootDir) {
|
|
|
632
632
|
}
|
|
633
633
|
try {
|
|
634
634
|
const content = readFileSync2(configPath, "utf-8");
|
|
635
|
-
if (content.includes("@omnify-
|
|
635
|
+
if (content.includes("@omnify-base")) {
|
|
636
636
|
return { updated: false };
|
|
637
637
|
}
|
|
638
638
|
const jsonContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "");
|
|
@@ -643,7 +643,7 @@ function addPluginEnumTsconfigPath(rootDir) {
|
|
|
643
643
|
if (!config.compilerOptions.paths) {
|
|
644
644
|
config.compilerOptions.paths = {};
|
|
645
645
|
}
|
|
646
|
-
config.compilerOptions.paths["@omnify-
|
|
646
|
+
config.compilerOptions.paths["@omnify-base/*"] = ["./node_modules/@omnify-base/*"];
|
|
647
647
|
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
648
648
|
return { updated: true };
|
|
649
649
|
} catch (error) {
|
|
@@ -1133,7 +1133,7 @@ import {
|
|
|
1133
1133
|
generateFactories,
|
|
1134
1134
|
getFactoryPath
|
|
1135
1135
|
} from "@famgia/omnify-laravel";
|
|
1136
|
-
import { generateTypeScript,
|
|
1136
|
+
import { generateTypeScript, generateAIGuides as generateTypescriptAIGuides, shouldGenerateAIGuides as shouldGenerateTypescriptAIGuides } from "@famgia/omnify-typescript";
|
|
1137
1137
|
|
|
1138
1138
|
// src/guides/index.ts
|
|
1139
1139
|
import { existsSync as existsSync7, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3 } from "fs";
|
|
@@ -1246,10 +1246,8 @@ function copyOmnifyGuides(rootDir) {
|
|
|
1246
1246
|
function generateAIGuides(rootDir, _plugins) {
|
|
1247
1247
|
let filesWritten = 0;
|
|
1248
1248
|
const claudeMdPath = resolve7(rootDir, "CLAUDE.md");
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
filesWritten++;
|
|
1252
|
-
}
|
|
1249
|
+
writeFileSync3(claudeMdPath, CLAUDE_MD);
|
|
1250
|
+
filesWritten++;
|
|
1253
1251
|
filesWritten += copyOmnifyGuides(rootDir);
|
|
1254
1252
|
return filesWritten;
|
|
1255
1253
|
}
|
|
@@ -1626,7 +1624,9 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1626
1624
|
const basePath = resolve8(rootDir, tsConfig.path);
|
|
1627
1625
|
const schemasDir = resolve8(basePath, tsConfig.schemasDir ?? "schemas");
|
|
1628
1626
|
const enumDir = resolve8(basePath, tsConfig.enumDir ?? "enum");
|
|
1629
|
-
const
|
|
1627
|
+
const omnifyBaseDir = resolve8(rootDir, "node_modules/@omnify-base");
|
|
1628
|
+
const pluginEnumDir = resolve8(omnifyBaseDir, "enum");
|
|
1629
|
+
const baseSchemasDir = resolve8(omnifyBaseDir, "schemas");
|
|
1630
1630
|
const enumImportPrefix = relative(schemasDir, enumDir).replace(/\\/g, "/");
|
|
1631
1631
|
if (!existsSync8(schemasDir)) {
|
|
1632
1632
|
mkdirSync3(schemasDir, { recursive: true });
|
|
@@ -1640,16 +1640,19 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1640
1640
|
mkdirSync3(pluginEnumDir, { recursive: true });
|
|
1641
1641
|
logger.debug(`Created directory: ${pluginEnumDir}`);
|
|
1642
1642
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1643
|
+
if (!existsSync8(baseSchemasDir)) {
|
|
1644
|
+
mkdirSync3(baseSchemasDir, { recursive: true });
|
|
1645
|
+
logger.debug(`Created directory: ${baseSchemasDir}`);
|
|
1646
|
+
}
|
|
1647
|
+
const omnifyPkgJson = resolve8(omnifyBaseDir, "package.json");
|
|
1645
1648
|
if (!existsSync8(omnifyPkgJson)) {
|
|
1646
1649
|
writeFileSync4(omnifyPkgJson, JSON.stringify({
|
|
1647
|
-
name: "@omnify-
|
|
1650
|
+
name: "@omnify-base",
|
|
1648
1651
|
version: "0.0.0",
|
|
1649
1652
|
private: true,
|
|
1650
|
-
main: "./enum/index.js",
|
|
1651
1653
|
exports: {
|
|
1652
|
-
"./enum/*": "./enum/*.js"
|
|
1654
|
+
"./enum/*": "./enum/*.js",
|
|
1655
|
+
"./schemas/*": "./schemas/*.js"
|
|
1653
1656
|
}
|
|
1654
1657
|
}, null, 2));
|
|
1655
1658
|
}
|
|
@@ -1662,18 +1665,25 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1662
1665
|
generateRules: tsConfig.generateRules ?? true,
|
|
1663
1666
|
validationTemplates: tsConfig.validationTemplates,
|
|
1664
1667
|
enumImportPrefix,
|
|
1665
|
-
pluginEnumImportPrefix: "@omnify-
|
|
1668
|
+
pluginEnumImportPrefix: "@omnify-base/enum",
|
|
1669
|
+
baseImportPrefix: "@omnify-base/schemas",
|
|
1670
|
+
schemaEnumImportPrefix: "@omnify/enum"
|
|
1671
|
+
// Absolute path for node_modules base files
|
|
1666
1672
|
});
|
|
1667
1673
|
for (const file of typeFiles) {
|
|
1668
1674
|
let outputDir;
|
|
1675
|
+
let outputFilePath = file.filePath;
|
|
1669
1676
|
if (file.category === "plugin-enum") {
|
|
1670
1677
|
outputDir = pluginEnumDir;
|
|
1678
|
+
} else if (file.category === "base") {
|
|
1679
|
+
outputDir = baseSchemasDir;
|
|
1680
|
+
outputFilePath = file.filePath.replace(/^base\//, "");
|
|
1671
1681
|
} else if (file.category === "enum") {
|
|
1672
1682
|
outputDir = enumDir;
|
|
1673
1683
|
} else {
|
|
1674
1684
|
outputDir = schemasDir;
|
|
1675
1685
|
}
|
|
1676
|
-
const filePath = resolve8(outputDir,
|
|
1686
|
+
const filePath = resolve8(outputDir, outputFilePath);
|
|
1677
1687
|
const fileDir = dirname6(filePath);
|
|
1678
1688
|
if (!existsSync8(fileDir)) {
|
|
1679
1689
|
mkdirSync3(fileDir, { recursive: true });
|
|
@@ -1687,13 +1697,6 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1687
1697
|
typesGenerated++;
|
|
1688
1698
|
}
|
|
1689
1699
|
logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
|
|
1690
|
-
const stubsResult = copyStubs({
|
|
1691
|
-
targetDir: basePath,
|
|
1692
|
-
skipIfExists: true
|
|
1693
|
-
});
|
|
1694
|
-
if (stubsResult.copied.length > 0) {
|
|
1695
|
-
logger.success(`Generated ${stubsResult.copied.length} React stub(s)`);
|
|
1696
|
-
}
|
|
1697
1700
|
const aliasResult = configureOmnifyAlias(rootDir, tsConfig.path, true);
|
|
1698
1701
|
if (aliasResult.viteUpdated) {
|
|
1699
1702
|
logger.success("Auto-configured @omnify alias in vite.config");
|
|
@@ -1701,15 +1704,13 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1701
1704
|
if (aliasResult.tsconfigUpdated) {
|
|
1702
1705
|
logger.success("Auto-configured @omnify/* path in tsconfig.json");
|
|
1703
1706
|
}
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
logger.success("Auto-configured @omnify-client/* path in tsconfig.json");
|
|
1712
|
-
}
|
|
1707
|
+
const pluginAliasResult = addPluginEnumAlias(rootDir);
|
|
1708
|
+
if (pluginAliasResult.updated) {
|
|
1709
|
+
logger.success("Auto-configured @omnify-base alias in vite.config");
|
|
1710
|
+
}
|
|
1711
|
+
const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
|
|
1712
|
+
if (pluginPathResult.updated) {
|
|
1713
|
+
logger.success("Auto-configured @omnify-base/* path in tsconfig.json");
|
|
1713
1714
|
}
|
|
1714
1715
|
}
|
|
1715
1716
|
return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated, factories: factoriesGenerated };
|
|
@@ -1882,11 +1883,48 @@ async function runGenerate(options) {
|
|
|
1882
1883
|
return;
|
|
1883
1884
|
}
|
|
1884
1885
|
}
|
|
1885
|
-
if (migrationValidation.missingFiles.length > 0) {
|
|
1886
|
+
if (migrationValidation.missingFiles.length > 0 && config.output.laravel) {
|
|
1886
1887
|
const toRegenerate = getMigrationsToRegenerate(existingLock, migrationValidation.missingFiles);
|
|
1887
1888
|
if (toRegenerate.length > 0) {
|
|
1888
|
-
|
|
1889
|
-
|
|
1889
|
+
const createMigrations = toRegenerate.filter((m) => m.type === "create");
|
|
1890
|
+
const alterMigrations = toRegenerate.filter((m) => m.type === "alter" || m.type === "drop");
|
|
1891
|
+
if (createMigrations.length > 0) {
|
|
1892
|
+
logger.info(`Regenerating ${createMigrations.length} missing CREATE migration(s) with original timestamps...`);
|
|
1893
|
+
const migrationsDir2 = resolve8(rootDir, config.output.laravel.migrationsPath);
|
|
1894
|
+
const customTypesMap2 = /* @__PURE__ */ new Map();
|
|
1895
|
+
for (const plugin of config.plugins) {
|
|
1896
|
+
if (plugin.types) {
|
|
1897
|
+
for (const [typeName, typeDef] of Object.entries(plugin.types)) {
|
|
1898
|
+
customTypesMap2.set(typeName, typeDef);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
for (const migData of createMigrations) {
|
|
1903
|
+
const migrationSchemas = Object.fromEntries(
|
|
1904
|
+
Object.entries(schemas).filter(([name]) => migData.schemas.includes(name))
|
|
1905
|
+
);
|
|
1906
|
+
if (Object.keys(migrationSchemas).length === 0) {
|
|
1907
|
+
logger.warn(` Cannot regenerate ${migData.fileName}: schema not found`);
|
|
1908
|
+
continue;
|
|
1909
|
+
}
|
|
1910
|
+
const regenerated = generateMigrations(migrationSchemas, {
|
|
1911
|
+
timestamp: migData.timestamp,
|
|
1912
|
+
customTypes: customTypesMap2
|
|
1913
|
+
});
|
|
1914
|
+
for (const mig of regenerated) {
|
|
1915
|
+
const filePath = resolve8(migrationsDir2, migData.fileName);
|
|
1916
|
+
writeFileSync4(filePath, mig.content);
|
|
1917
|
+
logger.success(` Regenerated: ${migData.fileName}`);
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
if (alterMigrations.length > 0) {
|
|
1922
|
+
logger.warn(`Cannot regenerate ${alterMigrations.length} ALTER/DROP migration(s) - original change data not available.`);
|
|
1923
|
+
logger.warn(" Please restore these files from git or reset migrations with: npx omnify reset");
|
|
1924
|
+
for (const m of alterMigrations) {
|
|
1925
|
+
logger.warn(` - ${m.fileName}`);
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1890
1928
|
}
|
|
1891
1929
|
}
|
|
1892
1930
|
}
|
|
@@ -1956,7 +1994,9 @@ async function runGenerate(options) {
|
|
|
1956
1994
|
const basePath2 = resolve8(rootDir, tsConfig2.path);
|
|
1957
1995
|
const schemasDir2 = resolve8(basePath2, tsConfig2.schemasDir ?? "schemas");
|
|
1958
1996
|
const enumDir2 = resolve8(basePath2, tsConfig2.enumDir ?? "enum");
|
|
1959
|
-
const
|
|
1997
|
+
const omnifyBaseDir2 = resolve8(rootDir, "node_modules/@omnify-base");
|
|
1998
|
+
const pluginEnumDir2 = resolve8(omnifyBaseDir2, "enum");
|
|
1999
|
+
const baseSchemasDir2 = resolve8(omnifyBaseDir2, "schemas");
|
|
1960
2000
|
const enumImportPrefix2 = relative(schemasDir2, enumDir2).replace(/\\/g, "/");
|
|
1961
2001
|
if (!existsSync8(schemasDir2)) {
|
|
1962
2002
|
mkdirSync3(schemasDir2, { recursive: true });
|
|
@@ -1970,16 +2010,19 @@ async function runGenerate(options) {
|
|
|
1970
2010
|
mkdirSync3(pluginEnumDir2, { recursive: true });
|
|
1971
2011
|
logger.debug(`Created directory: ${pluginEnumDir2}`);
|
|
1972
2012
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
2013
|
+
if (!existsSync8(baseSchemasDir2)) {
|
|
2014
|
+
mkdirSync3(baseSchemasDir2, { recursive: true });
|
|
2015
|
+
logger.debug(`Created directory: ${baseSchemasDir2}`);
|
|
2016
|
+
}
|
|
2017
|
+
const omnifyPkgJson2 = resolve8(omnifyBaseDir2, "package.json");
|
|
1975
2018
|
if (!existsSync8(omnifyPkgJson2)) {
|
|
1976
2019
|
writeFileSync4(omnifyPkgJson2, JSON.stringify({
|
|
1977
|
-
name: "@omnify-
|
|
2020
|
+
name: "@omnify-base",
|
|
1978
2021
|
version: "0.0.0",
|
|
1979
2022
|
private: true,
|
|
1980
|
-
main: "./enum/index.js",
|
|
1981
2023
|
exports: {
|
|
1982
|
-
"./enum/*": "./enum/*.js"
|
|
2024
|
+
"./enum/*": "./enum/*.js",
|
|
2025
|
+
"./schemas/*": "./schemas/*.js"
|
|
1983
2026
|
}
|
|
1984
2027
|
}, null, 2));
|
|
1985
2028
|
}
|
|
@@ -1992,18 +2035,25 @@ async function runGenerate(options) {
|
|
|
1992
2035
|
generateRules: tsConfig2.generateRules ?? true,
|
|
1993
2036
|
validationTemplates: tsConfig2.validationTemplates,
|
|
1994
2037
|
enumImportPrefix: enumImportPrefix2,
|
|
1995
|
-
pluginEnumImportPrefix: "@omnify-
|
|
2038
|
+
pluginEnumImportPrefix: "@omnify-base/enum",
|
|
2039
|
+
baseImportPrefix: "@omnify-base/schemas",
|
|
2040
|
+
schemaEnumImportPrefix: "@omnify/enum"
|
|
2041
|
+
// Absolute path for node_modules base files
|
|
1996
2042
|
});
|
|
1997
2043
|
for (const file of typeFiles) {
|
|
1998
2044
|
let outputDir2;
|
|
2045
|
+
let outputFilePath2 = file.filePath;
|
|
1999
2046
|
if (file.category === "plugin-enum") {
|
|
2000
2047
|
outputDir2 = pluginEnumDir2;
|
|
2048
|
+
} else if (file.category === "base") {
|
|
2049
|
+
outputDir2 = baseSchemasDir2;
|
|
2050
|
+
outputFilePath2 = file.filePath.replace(/^base\//, "");
|
|
2001
2051
|
} else if (file.category === "enum") {
|
|
2002
2052
|
outputDir2 = enumDir2;
|
|
2003
2053
|
} else {
|
|
2004
2054
|
outputDir2 = schemasDir2;
|
|
2005
2055
|
}
|
|
2006
|
-
const filePath = resolve8(outputDir2,
|
|
2056
|
+
const filePath = resolve8(outputDir2, outputFilePath2);
|
|
2007
2057
|
const fileDir = dirname6(filePath);
|
|
2008
2058
|
if (!existsSync8(fileDir)) {
|
|
2009
2059
|
mkdirSync3(fileDir, { recursive: true });
|
|
@@ -2017,13 +2067,6 @@ async function runGenerate(options) {
|
|
|
2017
2067
|
typesGenerated++;
|
|
2018
2068
|
}
|
|
2019
2069
|
logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
|
|
2020
|
-
const stubsResult2 = copyStubs({
|
|
2021
|
-
targetDir: basePath2,
|
|
2022
|
-
skipIfExists: true
|
|
2023
|
-
});
|
|
2024
|
-
if (stubsResult2.copied.length > 0) {
|
|
2025
|
-
logger.success(`Generated ${stubsResult2.copied.length} React stub(s)`);
|
|
2026
|
-
}
|
|
2027
2070
|
const aliasResult = configureOmnifyAlias(rootDir, tsConfig2.path, true);
|
|
2028
2071
|
if (aliasResult.viteUpdated) {
|
|
2029
2072
|
logger.success("Auto-configured @omnify alias in vite.config");
|
|
@@ -2031,15 +2074,13 @@ async function runGenerate(options) {
|
|
|
2031
2074
|
if (aliasResult.tsconfigUpdated) {
|
|
2032
2075
|
logger.success("Auto-configured @omnify/* path in tsconfig.json");
|
|
2033
2076
|
}
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
logger.success("Auto-configured .omnify-generated/* path in tsconfig.json");
|
|
2042
|
-
}
|
|
2077
|
+
const pluginAliasResult = addPluginEnumAlias(rootDir);
|
|
2078
|
+
if (pluginAliasResult.updated) {
|
|
2079
|
+
logger.success("Auto-configured @omnify-base alias in vite.config");
|
|
2080
|
+
}
|
|
2081
|
+
const pluginPathResult = addPluginEnumTsconfigPath(rootDir);
|
|
2082
|
+
if (pluginPathResult.updated) {
|
|
2083
|
+
logger.success("Auto-configured @omnify-base/* path in tsconfig.json");
|
|
2043
2084
|
}
|
|
2044
2085
|
if (shouldGenerateTypescriptAIGuides(rootDir)) {
|
|
2045
2086
|
const tsAIResult = generateTypescriptAIGuides(rootDir, {
|