@famgia/omnify-cli 0.0.165 → 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 +104 -63
- 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/cli.js
CHANGED
|
@@ -146,8 +146,8 @@ 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
|
|
150
|
-
return content.includes("'@omnify-
|
|
149
|
+
function hasViteOmnifyBaseAlias(content) {
|
|
150
|
+
return content.includes("'@omnify-base'") || content.includes('"@omnify-base"') || content.includes("@omnify-base/");
|
|
151
151
|
}
|
|
152
152
|
function hasTsconfigOmnifyPath(content) {
|
|
153
153
|
return content.includes('"@omnify/*"') || content.includes("'@omnify/*'") || content.includes('"@omnify/"');
|
|
@@ -333,7 +333,7 @@ function addPluginEnumAlias(rootDir) {
|
|
|
333
333
|
}
|
|
334
334
|
try {
|
|
335
335
|
let content = readFileSync(configPath2, "utf-8");
|
|
336
|
-
if (
|
|
336
|
+
if (hasViteOmnifyBaseAlias(content)) {
|
|
337
337
|
return { updated: false };
|
|
338
338
|
}
|
|
339
339
|
const lines = content.split("\n");
|
|
@@ -352,13 +352,13 @@ function addPluginEnumAlias(rootDir) {
|
|
|
352
352
|
}
|
|
353
353
|
if (insertIndex > 0) {
|
|
354
354
|
const indent = " ";
|
|
355
|
-
const aliasLine = `${indent}'@omnify-
|
|
355
|
+
const aliasLine = `${indent}'@omnify-base': path.resolve(__dirname, 'node_modules/@omnify-base'),`;
|
|
356
356
|
lines.splice(insertIndex, 0, aliasLine);
|
|
357
357
|
content = lines.join("\n");
|
|
358
358
|
writeFileSync(configPath2, content);
|
|
359
359
|
return { updated: true };
|
|
360
360
|
}
|
|
361
|
-
return { updated: false, error: "Could not find @omnify alias to add @omnify-
|
|
361
|
+
return { updated: false, error: "Could not find @omnify alias to add @omnify-base after" };
|
|
362
362
|
} catch (error) {
|
|
363
363
|
return {
|
|
364
364
|
updated: false,
|
|
@@ -373,7 +373,7 @@ function addPluginEnumTsconfigPath(rootDir) {
|
|
|
373
373
|
}
|
|
374
374
|
try {
|
|
375
375
|
const content = readFileSync(configPath2, "utf-8");
|
|
376
|
-
if (content.includes("@omnify-
|
|
376
|
+
if (content.includes("@omnify-base")) {
|
|
377
377
|
return { updated: false };
|
|
378
378
|
}
|
|
379
379
|
const jsonContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "");
|
|
@@ -384,7 +384,7 @@ function addPluginEnumTsconfigPath(rootDir) {
|
|
|
384
384
|
if (!config.compilerOptions.paths) {
|
|
385
385
|
config.compilerOptions.paths = {};
|
|
386
386
|
}
|
|
387
|
-
config.compilerOptions.paths["@omnify-
|
|
387
|
+
config.compilerOptions.paths["@omnify-base/*"] = ["./node_modules/@omnify-base/*"];
|
|
388
388
|
writeFileSync(configPath2, JSON.stringify(config, null, 2));
|
|
389
389
|
return { updated: true };
|
|
390
390
|
} catch (error) {
|
|
@@ -1139,7 +1139,7 @@ import {
|
|
|
1139
1139
|
generateFactories,
|
|
1140
1140
|
getFactoryPath
|
|
1141
1141
|
} from "@famgia/omnify-laravel";
|
|
1142
|
-
import { generateTypeScript,
|
|
1142
|
+
import { generateTypeScript, generateAIGuides as generateTypescriptAIGuides, shouldGenerateAIGuides as shouldGenerateTypescriptAIGuides } from "@famgia/omnify-typescript";
|
|
1143
1143
|
|
|
1144
1144
|
// src/guides/index.ts
|
|
1145
1145
|
import { existsSync as existsSync7, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3 } from "fs";
|
|
@@ -1252,10 +1252,8 @@ function copyOmnifyGuides(rootDir) {
|
|
|
1252
1252
|
function generateAIGuides(rootDir, _plugins) {
|
|
1253
1253
|
let filesWritten = 0;
|
|
1254
1254
|
const claudeMdPath = resolve7(rootDir, "CLAUDE.md");
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
filesWritten++;
|
|
1258
|
-
}
|
|
1255
|
+
writeFileSync3(claudeMdPath, CLAUDE_MD);
|
|
1256
|
+
filesWritten++;
|
|
1259
1257
|
filesWritten += copyOmnifyGuides(rootDir);
|
|
1260
1258
|
return filesWritten;
|
|
1261
1259
|
}
|
|
@@ -1632,7 +1630,9 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1632
1630
|
const basePath = resolve8(rootDir, tsConfig.path);
|
|
1633
1631
|
const schemasDir = resolve8(basePath, tsConfig.schemasDir ?? "schemas");
|
|
1634
1632
|
const enumDir = resolve8(basePath, tsConfig.enumDir ?? "enum");
|
|
1635
|
-
const
|
|
1633
|
+
const omnifyBaseDir = resolve8(rootDir, "node_modules/@omnify-base");
|
|
1634
|
+
const pluginEnumDir = resolve8(omnifyBaseDir, "enum");
|
|
1635
|
+
const baseSchemasDir = resolve8(omnifyBaseDir, "schemas");
|
|
1636
1636
|
const enumImportPrefix = relative(schemasDir, enumDir).replace(/\\/g, "/");
|
|
1637
1637
|
if (!existsSync8(schemasDir)) {
|
|
1638
1638
|
mkdirSync3(schemasDir, { recursive: true });
|
|
@@ -1646,16 +1646,19 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1646
1646
|
mkdirSync3(pluginEnumDir, { recursive: true });
|
|
1647
1647
|
logger.debug(`Created directory: ${pluginEnumDir}`);
|
|
1648
1648
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1649
|
+
if (!existsSync8(baseSchemasDir)) {
|
|
1650
|
+
mkdirSync3(baseSchemasDir, { recursive: true });
|
|
1651
|
+
logger.debug(`Created directory: ${baseSchemasDir}`);
|
|
1652
|
+
}
|
|
1653
|
+
const omnifyPkgJson = resolve8(omnifyBaseDir, "package.json");
|
|
1651
1654
|
if (!existsSync8(omnifyPkgJson)) {
|
|
1652
1655
|
writeFileSync4(omnifyPkgJson, JSON.stringify({
|
|
1653
|
-
name: "@omnify-
|
|
1656
|
+
name: "@omnify-base",
|
|
1654
1657
|
version: "0.0.0",
|
|
1655
1658
|
private: true,
|
|
1656
|
-
main: "./enum/index.js",
|
|
1657
1659
|
exports: {
|
|
1658
|
-
"./enum/*": "./enum/*.js"
|
|
1660
|
+
"./enum/*": "./enum/*.js",
|
|
1661
|
+
"./schemas/*": "./schemas/*.js"
|
|
1659
1662
|
}
|
|
1660
1663
|
}, null, 2));
|
|
1661
1664
|
}
|
|
@@ -1668,18 +1671,25 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1668
1671
|
generateRules: tsConfig.generateRules ?? true,
|
|
1669
1672
|
validationTemplates: tsConfig.validationTemplates,
|
|
1670
1673
|
enumImportPrefix,
|
|
1671
|
-
pluginEnumImportPrefix: "@omnify-
|
|
1674
|
+
pluginEnumImportPrefix: "@omnify-base/enum",
|
|
1675
|
+
baseImportPrefix: "@omnify-base/schemas",
|
|
1676
|
+
schemaEnumImportPrefix: "@omnify/enum"
|
|
1677
|
+
// Absolute path for node_modules base files
|
|
1672
1678
|
});
|
|
1673
1679
|
for (const file of typeFiles) {
|
|
1674
1680
|
let outputDir;
|
|
1681
|
+
let outputFilePath = file.filePath;
|
|
1675
1682
|
if (file.category === "plugin-enum") {
|
|
1676
1683
|
outputDir = pluginEnumDir;
|
|
1684
|
+
} else if (file.category === "base") {
|
|
1685
|
+
outputDir = baseSchemasDir;
|
|
1686
|
+
outputFilePath = file.filePath.replace(/^base\//, "");
|
|
1677
1687
|
} else if (file.category === "enum") {
|
|
1678
1688
|
outputDir = enumDir;
|
|
1679
1689
|
} else {
|
|
1680
1690
|
outputDir = schemasDir;
|
|
1681
1691
|
}
|
|
1682
|
-
const filePath = resolve8(outputDir,
|
|
1692
|
+
const filePath = resolve8(outputDir, outputFilePath);
|
|
1683
1693
|
const fileDir = dirname6(filePath);
|
|
1684
1694
|
if (!existsSync8(fileDir)) {
|
|
1685
1695
|
mkdirSync3(fileDir, { recursive: true });
|
|
@@ -1693,13 +1703,6 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1693
1703
|
typesGenerated++;
|
|
1694
1704
|
}
|
|
1695
1705
|
logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
|
|
1696
|
-
const stubsResult = copyStubs({
|
|
1697
|
-
targetDir: basePath,
|
|
1698
|
-
skipIfExists: true
|
|
1699
|
-
});
|
|
1700
|
-
if (stubsResult.copied.length > 0) {
|
|
1701
|
-
logger.success(`Generated ${stubsResult.copied.length} React stub(s)`);
|
|
1702
|
-
}
|
|
1703
1706
|
const aliasResult = configureOmnifyAlias(rootDir, tsConfig.path, true);
|
|
1704
1707
|
if (aliasResult.viteUpdated) {
|
|
1705
1708
|
logger.success("Auto-configured @omnify alias in vite.config");
|
|
@@ -1707,15 +1710,13 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1707
1710
|
if (aliasResult.tsconfigUpdated) {
|
|
1708
1711
|
logger.success("Auto-configured @omnify/* path in tsconfig.json");
|
|
1709
1712
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
logger.success("Auto-configured @omnify-client/* path in tsconfig.json");
|
|
1718
|
-
}
|
|
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");
|
|
1719
1720
|
}
|
|
1720
1721
|
}
|
|
1721
1722
|
return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated, factories: factoriesGenerated };
|
|
@@ -1888,11 +1889,48 @@ async function runGenerate(options) {
|
|
|
1888
1889
|
return;
|
|
1889
1890
|
}
|
|
1890
1891
|
}
|
|
1891
|
-
if (migrationValidation.missingFiles.length > 0) {
|
|
1892
|
+
if (migrationValidation.missingFiles.length > 0 && config.output.laravel) {
|
|
1892
1893
|
const toRegenerate = getMigrationsToRegenerate(existingLock, migrationValidation.missingFiles);
|
|
1893
1894
|
if (toRegenerate.length > 0) {
|
|
1894
|
-
|
|
1895
|
-
|
|
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
|
+
}
|
|
1896
1934
|
}
|
|
1897
1935
|
}
|
|
1898
1936
|
}
|
|
@@ -1962,7 +2000,9 @@ async function runGenerate(options) {
|
|
|
1962
2000
|
const basePath2 = resolve8(rootDir, tsConfig2.path);
|
|
1963
2001
|
const schemasDir2 = resolve8(basePath2, tsConfig2.schemasDir ?? "schemas");
|
|
1964
2002
|
const enumDir2 = resolve8(basePath2, tsConfig2.enumDir ?? "enum");
|
|
1965
|
-
const
|
|
2003
|
+
const omnifyBaseDir2 = resolve8(rootDir, "node_modules/@omnify-base");
|
|
2004
|
+
const pluginEnumDir2 = resolve8(omnifyBaseDir2, "enum");
|
|
2005
|
+
const baseSchemasDir2 = resolve8(omnifyBaseDir2, "schemas");
|
|
1966
2006
|
const enumImportPrefix2 = relative(schemasDir2, enumDir2).replace(/\\/g, "/");
|
|
1967
2007
|
if (!existsSync8(schemasDir2)) {
|
|
1968
2008
|
mkdirSync3(schemasDir2, { recursive: true });
|
|
@@ -1976,16 +2016,19 @@ async function runGenerate(options) {
|
|
|
1976
2016
|
mkdirSync3(pluginEnumDir2, { recursive: true });
|
|
1977
2017
|
logger.debug(`Created directory: ${pluginEnumDir2}`);
|
|
1978
2018
|
}
|
|
1979
|
-
|
|
1980
|
-
|
|
2019
|
+
if (!existsSync8(baseSchemasDir2)) {
|
|
2020
|
+
mkdirSync3(baseSchemasDir2, { recursive: true });
|
|
2021
|
+
logger.debug(`Created directory: ${baseSchemasDir2}`);
|
|
2022
|
+
}
|
|
2023
|
+
const omnifyPkgJson2 = resolve8(omnifyBaseDir2, "package.json");
|
|
1981
2024
|
if (!existsSync8(omnifyPkgJson2)) {
|
|
1982
2025
|
writeFileSync4(omnifyPkgJson2, JSON.stringify({
|
|
1983
|
-
name: "@omnify-
|
|
2026
|
+
name: "@omnify-base",
|
|
1984
2027
|
version: "0.0.0",
|
|
1985
2028
|
private: true,
|
|
1986
|
-
main: "./enum/index.js",
|
|
1987
2029
|
exports: {
|
|
1988
|
-
"./enum/*": "./enum/*.js"
|
|
2030
|
+
"./enum/*": "./enum/*.js",
|
|
2031
|
+
"./schemas/*": "./schemas/*.js"
|
|
1989
2032
|
}
|
|
1990
2033
|
}, null, 2));
|
|
1991
2034
|
}
|
|
@@ -1998,18 +2041,25 @@ async function runGenerate(options) {
|
|
|
1998
2041
|
generateRules: tsConfig2.generateRules ?? true,
|
|
1999
2042
|
validationTemplates: tsConfig2.validationTemplates,
|
|
2000
2043
|
enumImportPrefix: enumImportPrefix2,
|
|
2001
|
-
pluginEnumImportPrefix: "@omnify-
|
|
2044
|
+
pluginEnumImportPrefix: "@omnify-base/enum",
|
|
2045
|
+
baseImportPrefix: "@omnify-base/schemas",
|
|
2046
|
+
schemaEnumImportPrefix: "@omnify/enum"
|
|
2047
|
+
// Absolute path for node_modules base files
|
|
2002
2048
|
});
|
|
2003
2049
|
for (const file of typeFiles) {
|
|
2004
2050
|
let outputDir2;
|
|
2051
|
+
let outputFilePath2 = file.filePath;
|
|
2005
2052
|
if (file.category === "plugin-enum") {
|
|
2006
2053
|
outputDir2 = pluginEnumDir2;
|
|
2054
|
+
} else if (file.category === "base") {
|
|
2055
|
+
outputDir2 = baseSchemasDir2;
|
|
2056
|
+
outputFilePath2 = file.filePath.replace(/^base\//, "");
|
|
2007
2057
|
} else if (file.category === "enum") {
|
|
2008
2058
|
outputDir2 = enumDir2;
|
|
2009
2059
|
} else {
|
|
2010
2060
|
outputDir2 = schemasDir2;
|
|
2011
2061
|
}
|
|
2012
|
-
const filePath = resolve8(outputDir2,
|
|
2062
|
+
const filePath = resolve8(outputDir2, outputFilePath2);
|
|
2013
2063
|
const fileDir = dirname6(filePath);
|
|
2014
2064
|
if (!existsSync8(fileDir)) {
|
|
2015
2065
|
mkdirSync3(fileDir, { recursive: true });
|
|
@@ -2023,13 +2073,6 @@ async function runGenerate(options) {
|
|
|
2023
2073
|
typesGenerated++;
|
|
2024
2074
|
}
|
|
2025
2075
|
logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
|
|
2026
|
-
const stubsResult2 = copyStubs({
|
|
2027
|
-
targetDir: basePath2,
|
|
2028
|
-
skipIfExists: true
|
|
2029
|
-
});
|
|
2030
|
-
if (stubsResult2.copied.length > 0) {
|
|
2031
|
-
logger.success(`Generated ${stubsResult2.copied.length} React stub(s)`);
|
|
2032
|
-
}
|
|
2033
2076
|
const aliasResult = configureOmnifyAlias(rootDir, tsConfig2.path, true);
|
|
2034
2077
|
if (aliasResult.viteUpdated) {
|
|
2035
2078
|
logger.success("Auto-configured @omnify alias in vite.config");
|
|
@@ -2037,15 +2080,13 @@ async function runGenerate(options) {
|
|
|
2037
2080
|
if (aliasResult.tsconfigUpdated) {
|
|
2038
2081
|
logger.success("Auto-configured @omnify/* path in tsconfig.json");
|
|
2039
2082
|
}
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
logger.success("Auto-configured .omnify-generated/* path in tsconfig.json");
|
|
2048
|
-
}
|
|
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");
|
|
2049
2090
|
}
|
|
2050
2091
|
if (shouldGenerateTypescriptAIGuides(rootDir)) {
|
|
2051
2092
|
const tsAIResult = generateTypescriptAIGuides(rootDir, {
|