@famgia/omnify-cli 0.0.111 → 0.0.112
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 +97 -37
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +54 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +85 -24
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
2
8
|
|
|
3
9
|
// src/cli.ts
|
|
4
10
|
import { existsSync as existsSync7 } from "fs";
|
|
@@ -679,8 +685,8 @@ function registerDiffCommand(program2) {
|
|
|
679
685
|
}
|
|
680
686
|
|
|
681
687
|
// src/commands/generate.ts
|
|
682
|
-
import { existsSync as existsSync4, mkdirSync as
|
|
683
|
-
import { resolve as resolve6, dirname as
|
|
688
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3, readdirSync as readdirSync2 } from "fs";
|
|
689
|
+
import { resolve as resolve6, dirname as dirname5, relative } from "path";
|
|
684
690
|
import {
|
|
685
691
|
loadSchemas as loadSchemas3,
|
|
686
692
|
validateSchemas as validateSchemas3,
|
|
@@ -709,8 +715,9 @@ import {
|
|
|
709
715
|
import { generateTypeScript, copyStubs, generateAIGuides as generateTypescriptAIGuides, shouldGenerateAIGuides as shouldGenerateTypescriptAIGuides } from "@famgia/omnify-typescript";
|
|
710
716
|
|
|
711
717
|
// src/guides/index.ts
|
|
712
|
-
import { existsSync as existsSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
713
|
-
import { resolve as resolve5 } from "path";
|
|
718
|
+
import { existsSync as existsSync3, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2, readdirSync, readFileSync } from "fs";
|
|
719
|
+
import { resolve as resolve5, dirname as dirname4, join } from "path";
|
|
720
|
+
import "url";
|
|
714
721
|
var CLAUDE_MD = `## Omnify
|
|
715
722
|
|
|
716
723
|
This project uses Omnify for schema-driven code generation.
|
|
@@ -727,6 +734,58 @@ This project uses Omnify for schema-driven code generation.
|
|
|
727
734
|
- \`npx omnify generate\` - Generate code from schemas
|
|
728
735
|
- \`npx omnify validate\` - Validate schemas
|
|
729
736
|
`;
|
|
737
|
+
function copyOmnifyGuides(rootDir) {
|
|
738
|
+
let filesWritten = 0;
|
|
739
|
+
const omnifyPkgPaths = [
|
|
740
|
+
resolve5(rootDir, "node_modules", "@famgia", "omnify", "stubs", "ai-guides", "omnify"),
|
|
741
|
+
resolve5(rootDir, "node_modules", ".pnpm", "@famgia+omnify@*", "node_modules", "@famgia", "omnify", "stubs", "ai-guides", "omnify")
|
|
742
|
+
];
|
|
743
|
+
let stubsDir = null;
|
|
744
|
+
for (const pkgPath of omnifyPkgPaths) {
|
|
745
|
+
if (pkgPath.includes("*")) {
|
|
746
|
+
const parentDir = dirname4(dirname4(pkgPath));
|
|
747
|
+
if (existsSync3(parentDir)) {
|
|
748
|
+
const entries = readdirSync(parentDir);
|
|
749
|
+
for (const entry of entries) {
|
|
750
|
+
if (entry.startsWith("@famgia+omnify@")) {
|
|
751
|
+
const testPath = join(parentDir, entry, "node_modules", "@famgia", "omnify", "stubs", "ai-guides", "omnify");
|
|
752
|
+
if (existsSync3(testPath)) {
|
|
753
|
+
stubsDir = testPath;
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
} else if (existsSync3(pkgPath)) {
|
|
760
|
+
stubsDir = pkgPath;
|
|
761
|
+
break;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
if (!stubsDir) {
|
|
765
|
+
try {
|
|
766
|
+
const omnifyPath = dirname4(__require.resolve("@famgia/omnify/package.json", { paths: [rootDir] }));
|
|
767
|
+
const testPath = join(omnifyPath, "stubs", "ai-guides", "omnify");
|
|
768
|
+
if (existsSync3(testPath)) {
|
|
769
|
+
stubsDir = testPath;
|
|
770
|
+
}
|
|
771
|
+
} catch {
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
if (!stubsDir) {
|
|
775
|
+
return 0;
|
|
776
|
+
}
|
|
777
|
+
const destDir = resolve5(rootDir, ".claude", "omnify", "guides", "omnify");
|
|
778
|
+
mkdirSync2(destDir, { recursive: true });
|
|
779
|
+
const files = readdirSync(stubsDir).filter((f) => f.endsWith(".stub"));
|
|
780
|
+
for (const file of files) {
|
|
781
|
+
const srcPath = join(stubsDir, file);
|
|
782
|
+
const destPath = join(destDir, file.replace(".stub", ""));
|
|
783
|
+
const content = readFileSync(srcPath, "utf8");
|
|
784
|
+
writeFileSync2(destPath, content);
|
|
785
|
+
filesWritten++;
|
|
786
|
+
}
|
|
787
|
+
return filesWritten;
|
|
788
|
+
}
|
|
730
789
|
function generateAIGuides(rootDir, _plugins) {
|
|
731
790
|
let filesWritten = 0;
|
|
732
791
|
const claudeMdPath = resolve5(rootDir, "CLAUDE.md");
|
|
@@ -734,6 +793,7 @@ function generateAIGuides(rootDir, _plugins) {
|
|
|
734
793
|
writeFileSync2(claudeMdPath, CLAUDE_MD);
|
|
735
794
|
filesWritten++;
|
|
736
795
|
}
|
|
796
|
+
filesWritten += copyOmnifyGuides(rootDir);
|
|
737
797
|
return filesWritten;
|
|
738
798
|
}
|
|
739
799
|
|
|
@@ -747,7 +807,7 @@ function getExistingMigrationTables(migrationsDir) {
|
|
|
747
807
|
return existingTables;
|
|
748
808
|
}
|
|
749
809
|
try {
|
|
750
|
-
const files =
|
|
810
|
+
const files = readdirSync2(migrationsDir);
|
|
751
811
|
const createMigrationPattern = /^\d{4}_\d{2}_\d{2}_\d{6}_create_(.+)_table\.php$/;
|
|
752
812
|
for (const file of files) {
|
|
753
813
|
const match = file.match(createMigrationPattern);
|
|
@@ -937,9 +997,9 @@ function writeGeneratorOutputs(outputs, rootDir) {
|
|
|
937
997
|
const counts = { migrations: 0, types: 0, models: 0, factories: 0, other: 0 };
|
|
938
998
|
for (const output of outputs) {
|
|
939
999
|
const filePath = resolve6(rootDir, output.path);
|
|
940
|
-
const dir =
|
|
1000
|
+
const dir = dirname5(filePath);
|
|
941
1001
|
if (!existsSync4(dir)) {
|
|
942
|
-
|
|
1002
|
+
mkdirSync3(dir, { recursive: true });
|
|
943
1003
|
logger.debug(`Created directory: ${dir}`);
|
|
944
1004
|
}
|
|
945
1005
|
if (output.skipIfExists && existsSync4(filePath)) {
|
|
@@ -1004,7 +1064,7 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1004
1064
|
logger.step("Generating Laravel migrations...");
|
|
1005
1065
|
const migrationsDir = resolve6(rootDir, config.output.laravel.migrationsPath);
|
|
1006
1066
|
if (!existsSync4(migrationsDir)) {
|
|
1007
|
-
|
|
1067
|
+
mkdirSync3(migrationsDir, { recursive: true });
|
|
1008
1068
|
logger.debug(`Created directory: ${migrationsDir}`);
|
|
1009
1069
|
}
|
|
1010
1070
|
const addedSchemaNames = new Set(
|
|
@@ -1049,10 +1109,10 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1049
1109
|
const modelsDir = resolve6(rootDir, modelsPath);
|
|
1050
1110
|
const baseModelsDir = resolve6(rootDir, baseModelsPath);
|
|
1051
1111
|
if (!existsSync4(modelsDir)) {
|
|
1052
|
-
|
|
1112
|
+
mkdirSync3(modelsDir, { recursive: true });
|
|
1053
1113
|
}
|
|
1054
1114
|
if (!existsSync4(baseModelsDir)) {
|
|
1055
|
-
|
|
1115
|
+
mkdirSync3(baseModelsDir, { recursive: true });
|
|
1056
1116
|
}
|
|
1057
1117
|
const providersPath = config.output.laravel.providersPath ?? "app/Providers";
|
|
1058
1118
|
const models = generateModels(schemas, {
|
|
@@ -1063,9 +1123,9 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1063
1123
|
});
|
|
1064
1124
|
for (const model of models) {
|
|
1065
1125
|
const filePath = resolve6(rootDir, getModelPath(model));
|
|
1066
|
-
const fileDir =
|
|
1126
|
+
const fileDir = dirname5(filePath);
|
|
1067
1127
|
if (!existsSync4(fileDir)) {
|
|
1068
|
-
|
|
1128
|
+
mkdirSync3(fileDir, { recursive: true });
|
|
1069
1129
|
}
|
|
1070
1130
|
if (!model.overwrite && existsSync4(filePath)) {
|
|
1071
1131
|
logger.debug(`Skipped (exists): ${getModelPath(model)}`);
|
|
@@ -1082,16 +1142,16 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1082
1142
|
const factoriesPath = config.output.laravel.factoriesPath;
|
|
1083
1143
|
const factoriesDir = resolve6(rootDir, factoriesPath);
|
|
1084
1144
|
if (!existsSync4(factoriesDir)) {
|
|
1085
|
-
|
|
1145
|
+
mkdirSync3(factoriesDir, { recursive: true });
|
|
1086
1146
|
}
|
|
1087
1147
|
const factories = generateFactories(schemas, {
|
|
1088
1148
|
factoryPath: factoriesPath
|
|
1089
1149
|
});
|
|
1090
1150
|
for (const factory of factories) {
|
|
1091
1151
|
const filePath = resolve6(rootDir, getFactoryPath(factory));
|
|
1092
|
-
const fileDir =
|
|
1152
|
+
const fileDir = dirname5(filePath);
|
|
1093
1153
|
if (!existsSync4(fileDir)) {
|
|
1094
|
-
|
|
1154
|
+
mkdirSync3(fileDir, { recursive: true });
|
|
1095
1155
|
}
|
|
1096
1156
|
if (!factory.overwrite && existsSync4(filePath)) {
|
|
1097
1157
|
logger.debug(`Skipped (exists): ${getFactoryPath(factory)}`);
|
|
@@ -1111,11 +1171,11 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1111
1171
|
const enumDir = resolve6(basePath, tsConfig.enumDir ?? "enum");
|
|
1112
1172
|
const enumImportPrefix = relative(schemasDir, enumDir).replace(/\\/g, "/");
|
|
1113
1173
|
if (!existsSync4(schemasDir)) {
|
|
1114
|
-
|
|
1174
|
+
mkdirSync3(schemasDir, { recursive: true });
|
|
1115
1175
|
logger.debug(`Created directory: ${schemasDir}`);
|
|
1116
1176
|
}
|
|
1117
1177
|
if (!existsSync4(enumDir)) {
|
|
1118
|
-
|
|
1178
|
+
mkdirSync3(enumDir, { recursive: true });
|
|
1119
1179
|
logger.debug(`Created directory: ${enumDir}`);
|
|
1120
1180
|
}
|
|
1121
1181
|
const isMultiLocale = config.locale && config.locale.locales && config.locale.locales.length > 1;
|
|
@@ -1131,9 +1191,9 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1131
1191
|
for (const file of typeFiles) {
|
|
1132
1192
|
const outputDir = file.category === "enum" ? enumDir : schemasDir;
|
|
1133
1193
|
const filePath = resolve6(outputDir, file.filePath);
|
|
1134
|
-
const fileDir =
|
|
1194
|
+
const fileDir = dirname5(filePath);
|
|
1135
1195
|
if (!existsSync4(fileDir)) {
|
|
1136
|
-
|
|
1196
|
+
mkdirSync3(fileDir, { recursive: true });
|
|
1137
1197
|
}
|
|
1138
1198
|
if (!file.overwrite && existsSync4(filePath)) {
|
|
1139
1199
|
logger.debug(`Skipped (exists): ${file.filePath}`);
|
|
@@ -1159,7 +1219,7 @@ async function runGenerate(options) {
|
|
|
1159
1219
|
logger.header("Generating Outputs");
|
|
1160
1220
|
logger.debug("Loading configuration...");
|
|
1161
1221
|
const { config, configPath: configPath2 } = await loadConfig();
|
|
1162
|
-
const rootDir = configPath2 ?
|
|
1222
|
+
const rootDir = configPath2 ? dirname5(configPath2) : process.cwd();
|
|
1163
1223
|
validateConfig(config, rootDir);
|
|
1164
1224
|
const schemaPath = resolve6(rootDir, config.schemasDir);
|
|
1165
1225
|
logger.step(`Loading schemas from ${schemaPath}`);
|
|
@@ -1326,11 +1386,11 @@ async function runGenerate(options) {
|
|
|
1326
1386
|
const enumDir2 = resolve6(basePath2, tsConfig2.enumDir ?? "enum");
|
|
1327
1387
|
const enumImportPrefix2 = relative(schemasDir2, enumDir2).replace(/\\/g, "/");
|
|
1328
1388
|
if (!existsSync4(schemasDir2)) {
|
|
1329
|
-
|
|
1389
|
+
mkdirSync3(schemasDir2, { recursive: true });
|
|
1330
1390
|
logger.debug(`Created directory: ${schemasDir2}`);
|
|
1331
1391
|
}
|
|
1332
1392
|
if (!existsSync4(enumDir2)) {
|
|
1333
|
-
|
|
1393
|
+
mkdirSync3(enumDir2, { recursive: true });
|
|
1334
1394
|
logger.debug(`Created directory: ${enumDir2}`);
|
|
1335
1395
|
}
|
|
1336
1396
|
const isMultiLocale = config.locale && config.locale.locales && config.locale.locales.length > 1;
|
|
@@ -1346,9 +1406,9 @@ async function runGenerate(options) {
|
|
|
1346
1406
|
for (const file of typeFiles) {
|
|
1347
1407
|
const outputDir2 = file.category === "enum" ? enumDir2 : schemasDir2;
|
|
1348
1408
|
const filePath = resolve6(outputDir2, file.filePath);
|
|
1349
|
-
const fileDir =
|
|
1409
|
+
const fileDir = dirname5(filePath);
|
|
1350
1410
|
if (!existsSync4(fileDir)) {
|
|
1351
|
-
|
|
1411
|
+
mkdirSync3(fileDir, { recursive: true });
|
|
1352
1412
|
}
|
|
1353
1413
|
if (!file.overwrite && existsSync4(filePath)) {
|
|
1354
1414
|
logger.debug(`Skipped (exists): ${file.filePath}`);
|
|
@@ -1446,8 +1506,8 @@ function registerGenerateCommand(program2) {
|
|
|
1446
1506
|
}
|
|
1447
1507
|
|
|
1448
1508
|
// src/commands/reset.ts
|
|
1449
|
-
import { existsSync as existsSync5, readdirSync as
|
|
1450
|
-
import { resolve as resolve7, dirname as
|
|
1509
|
+
import { existsSync as existsSync5, readdirSync as readdirSync3, rmSync, statSync } from "fs";
|
|
1510
|
+
import { resolve as resolve7, dirname as dirname6, join as join2 } from "path";
|
|
1451
1511
|
import { createInterface } from "readline";
|
|
1452
1512
|
async function confirm2(message) {
|
|
1453
1513
|
const rl = createInterface({
|
|
@@ -1464,9 +1524,9 @@ async function confirm2(message) {
|
|
|
1464
1524
|
function countFiles(dir) {
|
|
1465
1525
|
if (!existsSync5(dir)) return 0;
|
|
1466
1526
|
let count = 0;
|
|
1467
|
-
const entries =
|
|
1527
|
+
const entries = readdirSync3(dir);
|
|
1468
1528
|
for (const entry of entries) {
|
|
1469
|
-
const fullPath =
|
|
1529
|
+
const fullPath = join2(dir, entry);
|
|
1470
1530
|
const stat = statSync(fullPath);
|
|
1471
1531
|
if (stat.isDirectory()) {
|
|
1472
1532
|
count += countFiles(fullPath);
|
|
@@ -1488,9 +1548,9 @@ function deleteDir(dir, verbose) {
|
|
|
1488
1548
|
function deleteFilesInDir(dir, pattern, verbose) {
|
|
1489
1549
|
if (!existsSync5(dir)) return 0;
|
|
1490
1550
|
let count = 0;
|
|
1491
|
-
const entries =
|
|
1551
|
+
const entries = readdirSync3(dir);
|
|
1492
1552
|
for (const entry of entries) {
|
|
1493
|
-
const fullPath =
|
|
1553
|
+
const fullPath = join2(dir, entry);
|
|
1494
1554
|
const stat = statSync(fullPath);
|
|
1495
1555
|
if (stat.isFile() && pattern.test(entry)) {
|
|
1496
1556
|
rmSync(fullPath);
|
|
@@ -1507,7 +1567,7 @@ async function runReset(options) {
|
|
|
1507
1567
|
logger.header("Reset Omnify Generated Files");
|
|
1508
1568
|
logger.debug("Loading configuration...");
|
|
1509
1569
|
const { config, configPath: configPath2 } = await loadConfig();
|
|
1510
|
-
const rootDir = configPath2 ?
|
|
1570
|
+
const rootDir = configPath2 ? dirname6(configPath2) : process.cwd();
|
|
1511
1571
|
const paths = [];
|
|
1512
1572
|
const omnifyBasePaths = [
|
|
1513
1573
|
{ name: "OmnifyBase models", paths: ["app/Models/OmnifyBase", "backend/app/Models/OmnifyBase"] },
|
|
@@ -1542,7 +1602,7 @@ async function runReset(options) {
|
|
|
1542
1602
|
const laravelConfig = config.output.laravel;
|
|
1543
1603
|
if (laravelConfig?.modelsPath) {
|
|
1544
1604
|
const modelsPath = resolve7(rootDir, laravelConfig.modelsPath);
|
|
1545
|
-
const omnifyBasePath =
|
|
1605
|
+
const omnifyBasePath = join2(modelsPath, "OmnifyBase");
|
|
1546
1606
|
if (existsSync5(omnifyBasePath) && !paths.some((p) => p.path === omnifyBasePath)) {
|
|
1547
1607
|
paths.push({ name: "OmnifyBase models", path: omnifyBasePath, type: "dir" });
|
|
1548
1608
|
}
|
|
@@ -1581,14 +1641,14 @@ async function runReset(options) {
|
|
|
1581
1641
|
if (foundTsPath && existsSync5(foundTsPath)) {
|
|
1582
1642
|
const autoGeneratedDirs = ["base", "enum", "rules", "hooks", "lib"];
|
|
1583
1643
|
for (const subDir of autoGeneratedDirs) {
|
|
1584
|
-
const subPath =
|
|
1644
|
+
const subPath = join2(foundTsPath, subDir);
|
|
1585
1645
|
if (existsSync5(subPath)) {
|
|
1586
1646
|
paths.push({ name: `TypeScript ${subDir}`, path: subPath, type: "dir" });
|
|
1587
1647
|
}
|
|
1588
1648
|
}
|
|
1589
1649
|
const autoGeneratedFiles = ["common.ts", "index.ts", "i18n.ts"];
|
|
1590
1650
|
for (const fileName of autoGeneratedFiles) {
|
|
1591
|
-
const filePath =
|
|
1651
|
+
const filePath = join2(foundTsPath, fileName);
|
|
1592
1652
|
if (existsSync5(filePath)) {
|
|
1593
1653
|
paths.push({ name: `TypeScript ${fileName}`, path: filePath, type: "file" });
|
|
1594
1654
|
}
|
|
@@ -1622,7 +1682,7 @@ async function runReset(options) {
|
|
|
1622
1682
|
const count = countFiles(item.path);
|
|
1623
1683
|
logger.info(` \u2022 ${item.name}: ${item.path} (${count} files)`);
|
|
1624
1684
|
} else if (item.type === "files" && item.pattern) {
|
|
1625
|
-
const count =
|
|
1685
|
+
const count = readdirSync3(item.path).filter((f) => item.pattern.test(f)).length;
|
|
1626
1686
|
logger.info(` \u2022 ${item.name}: ${item.path} (${count} files)`);
|
|
1627
1687
|
} else {
|
|
1628
1688
|
logger.info(` \u2022 ${item.name}: ${item.path}`);
|
|
@@ -1678,7 +1738,7 @@ function registerResetCommand(program2) {
|
|
|
1678
1738
|
|
|
1679
1739
|
// src/commands/create-project.ts
|
|
1680
1740
|
import { execSync, spawn } from "child_process";
|
|
1681
|
-
import { existsSync as existsSync6, rmSync as rmSync2, readFileSync, writeFileSync as writeFileSync4 } from "fs";
|
|
1741
|
+
import { existsSync as existsSync6, rmSync as rmSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
1682
1742
|
import { resolve as resolve8 } from "path";
|
|
1683
1743
|
var BOILERPLATE_REPO = "https://github.com/omnifyjp/omnify-laravel-boilerplate.git";
|
|
1684
1744
|
var IS_WINDOWS = process.platform === "win32";
|
|
@@ -1782,7 +1842,7 @@ var GITIGNORE_ENTRIES_TO_REMOVE = [
|
|
|
1782
1842
|
function cleanupGitignore(targetDir) {
|
|
1783
1843
|
const gitignorePath = resolve8(targetDir, ".gitignore");
|
|
1784
1844
|
if (!existsSync6(gitignorePath)) return;
|
|
1785
|
-
const content =
|
|
1845
|
+
const content = readFileSync2(gitignorePath, "utf-8");
|
|
1786
1846
|
const lines = content.split("\n");
|
|
1787
1847
|
const cleanedLines = lines.filter((line) => {
|
|
1788
1848
|
const trimmed = line.trim();
|