@famgia/omnify-cli 0.0.12 → 0.0.14
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 +203 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +13 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import { existsSync as
|
|
5
|
-
import { resolve as
|
|
4
|
+
import { existsSync as existsSync5 } from "fs";
|
|
5
|
+
import { resolve as resolve7 } from "path";
|
|
6
6
|
import { Command } from "commander";
|
|
7
7
|
import { OmnifyError as OmnifyError5 } from "@famgia/omnify-core";
|
|
8
8
|
|
|
@@ -864,7 +864,7 @@ function schemaChangeToVersionChange(change) {
|
|
|
864
864
|
return changes;
|
|
865
865
|
}
|
|
866
866
|
function writeGeneratorOutputs(outputs, rootDir) {
|
|
867
|
-
const counts = { migrations: 0, types: 0, other: 0 };
|
|
867
|
+
const counts = { migrations: 0, types: 0, models: 0, factories: 0, other: 0 };
|
|
868
868
|
for (const output of outputs) {
|
|
869
869
|
const filePath = resolve5(rootDir, output.path);
|
|
870
870
|
const dir = dirname4(filePath);
|
|
@@ -872,10 +872,16 @@ function writeGeneratorOutputs(outputs, rootDir) {
|
|
|
872
872
|
mkdirSync2(dir, { recursive: true });
|
|
873
873
|
logger.debug(`Created directory: ${dir}`);
|
|
874
874
|
}
|
|
875
|
+
if (output.skipIfExists && existsSync3(filePath)) {
|
|
876
|
+
logger.debug(`Skipped (exists): ${output.path}`);
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
875
879
|
writeFileSync2(filePath, output.content);
|
|
876
880
|
logger.debug(`Created: ${output.path}`);
|
|
877
881
|
if (output.type === "migration") counts.migrations++;
|
|
878
882
|
else if (output.type === "type") counts.types++;
|
|
883
|
+
else if (output.type === "model") counts.models++;
|
|
884
|
+
else if (output.type === "factory") counts.factories++;
|
|
879
885
|
else counts.other++;
|
|
880
886
|
}
|
|
881
887
|
return counts;
|
|
@@ -1023,6 +1029,12 @@ async function runGenerate(options) {
|
|
|
1023
1029
|
if (counts.types > 0) {
|
|
1024
1030
|
logger.success(`Generated ${counts.types} TypeScript file(s)`);
|
|
1025
1031
|
}
|
|
1032
|
+
if (counts.models > 0) {
|
|
1033
|
+
logger.success(`Generated ${counts.models} model(s)`);
|
|
1034
|
+
}
|
|
1035
|
+
if (counts.factories > 0) {
|
|
1036
|
+
logger.success(`Generated ${counts.factories} factory(ies)`);
|
|
1037
|
+
}
|
|
1026
1038
|
if (counts.other > 0) {
|
|
1027
1039
|
logger.success(`Generated ${counts.other} other file(s)`);
|
|
1028
1040
|
}
|
|
@@ -1080,6 +1092,191 @@ function registerGenerateCommand(program2) {
|
|
|
1080
1092
|
});
|
|
1081
1093
|
}
|
|
1082
1094
|
|
|
1095
|
+
// src/commands/reset.ts
|
|
1096
|
+
import { existsSync as existsSync4, readdirSync, rmSync, statSync } from "fs";
|
|
1097
|
+
import { resolve as resolve6, dirname as dirname5, join } from "path";
|
|
1098
|
+
import { createInterface } from "readline";
|
|
1099
|
+
async function confirm2(message) {
|
|
1100
|
+
const rl = createInterface({
|
|
1101
|
+
input: process.stdin,
|
|
1102
|
+
output: process.stdout
|
|
1103
|
+
});
|
|
1104
|
+
return new Promise((resolve8) => {
|
|
1105
|
+
rl.question(`${message} (y/N) `, (answer) => {
|
|
1106
|
+
rl.close();
|
|
1107
|
+
resolve8(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
function countFiles(dir) {
|
|
1112
|
+
if (!existsSync4(dir)) return 0;
|
|
1113
|
+
let count = 0;
|
|
1114
|
+
const entries = readdirSync(dir);
|
|
1115
|
+
for (const entry of entries) {
|
|
1116
|
+
const fullPath = join(dir, entry);
|
|
1117
|
+
const stat = statSync(fullPath);
|
|
1118
|
+
if (stat.isDirectory()) {
|
|
1119
|
+
count += countFiles(fullPath);
|
|
1120
|
+
} else {
|
|
1121
|
+
count++;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return count;
|
|
1125
|
+
}
|
|
1126
|
+
function deleteDir(dir, verbose) {
|
|
1127
|
+
if (!existsSync4(dir)) return 0;
|
|
1128
|
+
const count = countFiles(dir);
|
|
1129
|
+
rmSync(dir, { recursive: true, force: true });
|
|
1130
|
+
if (verbose) {
|
|
1131
|
+
logger.debug(`Deleted: ${dir}`);
|
|
1132
|
+
}
|
|
1133
|
+
return count;
|
|
1134
|
+
}
|
|
1135
|
+
function deleteFilesInDir(dir, pattern, verbose) {
|
|
1136
|
+
if (!existsSync4(dir)) return 0;
|
|
1137
|
+
let count = 0;
|
|
1138
|
+
const entries = readdirSync(dir);
|
|
1139
|
+
for (const entry of entries) {
|
|
1140
|
+
const fullPath = join(dir, entry);
|
|
1141
|
+
const stat = statSync(fullPath);
|
|
1142
|
+
if (stat.isFile() && pattern.test(entry)) {
|
|
1143
|
+
rmSync(fullPath);
|
|
1144
|
+
if (verbose) {
|
|
1145
|
+
logger.debug(`Deleted: ${fullPath}`);
|
|
1146
|
+
}
|
|
1147
|
+
count++;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
return count;
|
|
1151
|
+
}
|
|
1152
|
+
async function runReset(options) {
|
|
1153
|
+
logger.setVerbose(options.verbose ?? false);
|
|
1154
|
+
logger.header("Reset Omnify Generated Files");
|
|
1155
|
+
logger.debug("Loading configuration...");
|
|
1156
|
+
const { config, configPath: configPath2 } = await loadConfig();
|
|
1157
|
+
const rootDir = configPath2 ? dirname5(configPath2) : process.cwd();
|
|
1158
|
+
const paths = [];
|
|
1159
|
+
const omnifyBasePaths = [
|
|
1160
|
+
"app/Models/OmnifyBase",
|
|
1161
|
+
"backend/app/Models/OmnifyBase",
|
|
1162
|
+
"src/Models/OmnifyBase"
|
|
1163
|
+
];
|
|
1164
|
+
for (const relPath of omnifyBasePaths) {
|
|
1165
|
+
const omnifyBasePath = resolve6(rootDir, relPath);
|
|
1166
|
+
if (existsSync4(omnifyBasePath)) {
|
|
1167
|
+
paths.push({ name: "OmnifyBase models", path: omnifyBasePath, type: "dir" });
|
|
1168
|
+
break;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
const migrationPaths = [
|
|
1172
|
+
"database/migrations/omnify",
|
|
1173
|
+
"backend/database/migrations/omnify"
|
|
1174
|
+
];
|
|
1175
|
+
for (const relPath of migrationPaths) {
|
|
1176
|
+
const migrationsPath = resolve6(rootDir, relPath);
|
|
1177
|
+
if (existsSync4(migrationsPath)) {
|
|
1178
|
+
paths.push({
|
|
1179
|
+
name: "Omnify migrations",
|
|
1180
|
+
path: migrationsPath,
|
|
1181
|
+
type: "files",
|
|
1182
|
+
pattern: /\.php$/
|
|
1183
|
+
});
|
|
1184
|
+
break;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
const laravelConfig = config.output.laravel;
|
|
1188
|
+
if (laravelConfig?.modelsPath) {
|
|
1189
|
+
const modelsPath = resolve6(rootDir, laravelConfig.modelsPath);
|
|
1190
|
+
const omnifyBasePath = join(modelsPath, "OmnifyBase");
|
|
1191
|
+
if (existsSync4(omnifyBasePath) && !paths.some((p) => p.path === omnifyBasePath)) {
|
|
1192
|
+
paths.push({ name: "OmnifyBase models", path: omnifyBasePath, type: "dir" });
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
if (laravelConfig?.migrationsPath) {
|
|
1196
|
+
const migrationsPath = resolve6(rootDir, laravelConfig.migrationsPath);
|
|
1197
|
+
if (existsSync4(migrationsPath) && !paths.some((p) => p.path === migrationsPath)) {
|
|
1198
|
+
paths.push({
|
|
1199
|
+
name: "Omnify migrations",
|
|
1200
|
+
path: migrationsPath,
|
|
1201
|
+
type: "files",
|
|
1202
|
+
pattern: /\.php$/
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
const lockFilePath = resolve6(rootDir, config.lockFilePath);
|
|
1207
|
+
if (existsSync4(lockFilePath)) {
|
|
1208
|
+
paths.push({ name: "Lock file", path: lockFilePath, type: "file" });
|
|
1209
|
+
}
|
|
1210
|
+
const omnifyDir = resolve6(rootDir, ".omnify");
|
|
1211
|
+
if (existsSync4(omnifyDir)) {
|
|
1212
|
+
paths.push({ name: ".omnify directory", path: omnifyDir, type: "dir" });
|
|
1213
|
+
}
|
|
1214
|
+
if (paths.length === 0) {
|
|
1215
|
+
logger.info("Nothing to clean. No generated files found.");
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
logger.newline();
|
|
1219
|
+
logger.warn("The following will be deleted:");
|
|
1220
|
+
logger.newline();
|
|
1221
|
+
for (const item of paths) {
|
|
1222
|
+
if (item.type === "dir") {
|
|
1223
|
+
const count = countFiles(item.path);
|
|
1224
|
+
logger.info(` \u2022 ${item.name}: ${item.path} (${count} files)`);
|
|
1225
|
+
} else if (item.type === "files" && item.pattern) {
|
|
1226
|
+
const count = readdirSync(item.path).filter((f) => item.pattern.test(f)).length;
|
|
1227
|
+
logger.info(` \u2022 ${item.name}: ${item.path} (${count} files)`);
|
|
1228
|
+
} else {
|
|
1229
|
+
logger.info(` \u2022 ${item.name}: ${item.path}`);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
logger.newline();
|
|
1233
|
+
if (!options.yes) {
|
|
1234
|
+
const confirmed = await confirm2("Are you sure you want to delete these files?");
|
|
1235
|
+
if (!confirmed) {
|
|
1236
|
+
logger.info("Reset cancelled.");
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
logger.newline();
|
|
1241
|
+
logger.step("Deleting files...");
|
|
1242
|
+
let totalDeleted = 0;
|
|
1243
|
+
for (const item of paths) {
|
|
1244
|
+
if (item.type === "dir") {
|
|
1245
|
+
const count = deleteDir(item.path, options.verbose ?? false);
|
|
1246
|
+
totalDeleted += count;
|
|
1247
|
+
logger.info(` \u2713 Deleted ${item.name} (${count} files)`);
|
|
1248
|
+
} else if (item.type === "files" && item.pattern) {
|
|
1249
|
+
const count = deleteFilesInDir(item.path, item.pattern, options.verbose ?? false);
|
|
1250
|
+
totalDeleted += count;
|
|
1251
|
+
logger.info(` \u2713 Deleted ${item.name} (${count} files)`);
|
|
1252
|
+
} else {
|
|
1253
|
+
rmSync(item.path, { force: true });
|
|
1254
|
+
if (options.verbose) {
|
|
1255
|
+
logger.debug(`Deleted: ${item.path}`);
|
|
1256
|
+
}
|
|
1257
|
+
totalDeleted++;
|
|
1258
|
+
logger.info(` \u2713 Deleted ${item.name}`);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
logger.newline();
|
|
1262
|
+
logger.success(`Reset complete! Deleted ${totalDeleted} file(s).`);
|
|
1263
|
+
logger.newline();
|
|
1264
|
+
logger.info("Run `omnify generate` to regenerate files.");
|
|
1265
|
+
}
|
|
1266
|
+
function registerResetCommand(program2) {
|
|
1267
|
+
program2.command("reset").description("Delete all generated files (OmnifyBase, migrations, locks)").option("-v, --verbose", "Show detailed output").option("-y, --yes", "Skip confirmation prompt").action(async (options) => {
|
|
1268
|
+
try {
|
|
1269
|
+
await runReset(options);
|
|
1270
|
+
} catch (error) {
|
|
1271
|
+
if (error instanceof Error) {
|
|
1272
|
+
logger.error(error.message);
|
|
1273
|
+
process.exit(1);
|
|
1274
|
+
}
|
|
1275
|
+
process.exit(1);
|
|
1276
|
+
}
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1083
1280
|
// src/cli.ts
|
|
1084
1281
|
var VERSION = "0.0.5";
|
|
1085
1282
|
var program = new Command();
|
|
@@ -1088,6 +1285,7 @@ registerInitCommand(program);
|
|
|
1088
1285
|
registerValidateCommand(program);
|
|
1089
1286
|
registerDiffCommand(program);
|
|
1090
1287
|
registerGenerateCommand(program);
|
|
1288
|
+
registerResetCommand(program);
|
|
1091
1289
|
process.on("uncaughtException", (error) => {
|
|
1092
1290
|
if (error instanceof OmnifyError5) {
|
|
1093
1291
|
logger.formatError(error);
|
|
@@ -1111,8 +1309,8 @@ process.on("unhandledRejection", (reason) => {
|
|
|
1111
1309
|
var args = process.argv.slice(2);
|
|
1112
1310
|
var firstArg = args[0];
|
|
1113
1311
|
var hasCommand = firstArg !== void 0 && !firstArg.startsWith("-");
|
|
1114
|
-
var configPath =
|
|
1115
|
-
var hasConfig =
|
|
1312
|
+
var configPath = resolve7(process.cwd(), "omnify.config.ts");
|
|
1313
|
+
var hasConfig = existsSync5(configPath);
|
|
1116
1314
|
if (!hasCommand && !hasConfig) {
|
|
1117
1315
|
runInit({}).catch((error) => {
|
|
1118
1316
|
if (error instanceof Error) {
|