@famgia/omnify-cli 0.0.13 → 0.0.16

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
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli.ts
4
- import { existsSync as existsSync4 } from "fs";
5
- import { resolve as resolve6 } from "path";
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
 
@@ -455,7 +455,8 @@ async function resolveConfig(userConfig, configPath2) {
455
455
  },
456
456
  plugins,
457
457
  verbose: userConfig.verbose ?? false,
458
- lockFilePath: userConfig.lockFilePath ?? ".omnify.lock"
458
+ lockFilePath: userConfig.lockFilePath ?? ".omnify.lock",
459
+ ...userConfig.locale && { locale: userConfig.locale }
459
460
  };
460
461
  return result;
461
462
  }
@@ -886,7 +887,7 @@ function writeGeneratorOutputs(outputs, rootDir) {
886
887
  }
887
888
  return counts;
888
889
  }
889
- async function runPluginGeneration(plugins, schemas, rootDir, verbose) {
890
+ async function runPluginGeneration(plugins, schemas, rootDir, verbose, changes) {
890
891
  const pluginManager = new PluginManager({
891
892
  cwd: rootDir,
892
893
  verbose,
@@ -900,7 +901,7 @@ async function runPluginGeneration(plugins, schemas, rootDir, verbose) {
900
901
  for (const plugin of plugins) {
901
902
  await pluginManager.register(plugin);
902
903
  }
903
- const result = await pluginManager.runGenerators(schemas);
904
+ const result = await pluginManager.runGenerators(schemas, changes);
904
905
  if (!result.success) {
905
906
  for (const error of result.errors) {
906
907
  logger.error(`Generator ${error.generatorName} failed: ${error.message}`);
@@ -955,13 +956,19 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
955
956
  mkdirSync2(typesDir, { recursive: true });
956
957
  logger.debug(`Created directory: ${typesDir}`);
957
958
  }
958
- const typeFiles = generateTypeScript(schemas, {
959
- singleFile: config.output.typescript.singleFile
960
- });
959
+ const typeFiles = generateTypeScript(schemas);
961
960
  for (const file of typeFiles) {
962
- const filePath = resolve5(typesDir, file.fileName);
961
+ const filePath = resolve5(typesDir, file.filePath);
962
+ const fileDir = dirname4(filePath);
963
+ if (!existsSync3(fileDir)) {
964
+ mkdirSync2(fileDir, { recursive: true });
965
+ }
966
+ if (!file.overwrite && existsSync3(filePath)) {
967
+ logger.debug(`Skipped (exists): ${file.filePath}`);
968
+ continue;
969
+ }
963
970
  writeFileSync2(filePath, file.content);
964
- logger.debug(`Created: ${file.fileName}`);
971
+ logger.debug(`Created: ${file.filePath}`);
965
972
  typesGenerated++;
966
973
  }
967
974
  logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
@@ -984,8 +991,18 @@ async function runGenerate(options) {
984
991
  return;
985
992
  }
986
993
  logger.debug(`Found ${schemaCount} schema(s)`);
994
+ const customTypeNames = [];
995
+ for (const plugin of config.plugins) {
996
+ if (plugin.types) {
997
+ for (const typeDef of plugin.types) {
998
+ customTypeNames.push(typeDef.name);
999
+ }
1000
+ }
1001
+ }
987
1002
  logger.step("Validating schemas...");
988
- const validationResult = validateSchemas3(schemas);
1003
+ const validationResult = validateSchemas3(schemas, {
1004
+ customTypes: customTypeNames
1005
+ });
989
1006
  if (!validationResult.valid) {
990
1007
  logger.error("Schema validation failed. Fix errors before generating.");
991
1008
  for (const error of validationResult.errors) {
@@ -1019,7 +1036,8 @@ async function runGenerate(options) {
1019
1036
  config.plugins,
1020
1037
  schemas,
1021
1038
  rootDir,
1022
- options.verbose ?? false
1039
+ options.verbose ?? false,
1040
+ comparison.changes
1023
1041
  );
1024
1042
  migrationsGenerated = counts.migrations;
1025
1043
  typesGenerated = counts.types;
@@ -1092,6 +1110,191 @@ function registerGenerateCommand(program2) {
1092
1110
  });
1093
1111
  }
1094
1112
 
1113
+ // src/commands/reset.ts
1114
+ import { existsSync as existsSync4, readdirSync, rmSync, statSync } from "fs";
1115
+ import { resolve as resolve6, dirname as dirname5, join } from "path";
1116
+ import { createInterface } from "readline";
1117
+ async function confirm2(message) {
1118
+ const rl = createInterface({
1119
+ input: process.stdin,
1120
+ output: process.stdout
1121
+ });
1122
+ return new Promise((resolve8) => {
1123
+ rl.question(`${message} (y/N) `, (answer) => {
1124
+ rl.close();
1125
+ resolve8(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
1126
+ });
1127
+ });
1128
+ }
1129
+ function countFiles(dir) {
1130
+ if (!existsSync4(dir)) return 0;
1131
+ let count = 0;
1132
+ const entries = readdirSync(dir);
1133
+ for (const entry of entries) {
1134
+ const fullPath = join(dir, entry);
1135
+ const stat = statSync(fullPath);
1136
+ if (stat.isDirectory()) {
1137
+ count += countFiles(fullPath);
1138
+ } else {
1139
+ count++;
1140
+ }
1141
+ }
1142
+ return count;
1143
+ }
1144
+ function deleteDir(dir, verbose) {
1145
+ if (!existsSync4(dir)) return 0;
1146
+ const count = countFiles(dir);
1147
+ rmSync(dir, { recursive: true, force: true });
1148
+ if (verbose) {
1149
+ logger.debug(`Deleted: ${dir}`);
1150
+ }
1151
+ return count;
1152
+ }
1153
+ function deleteFilesInDir(dir, pattern, verbose) {
1154
+ if (!existsSync4(dir)) return 0;
1155
+ let count = 0;
1156
+ const entries = readdirSync(dir);
1157
+ for (const entry of entries) {
1158
+ const fullPath = join(dir, entry);
1159
+ const stat = statSync(fullPath);
1160
+ if (stat.isFile() && pattern.test(entry)) {
1161
+ rmSync(fullPath);
1162
+ if (verbose) {
1163
+ logger.debug(`Deleted: ${fullPath}`);
1164
+ }
1165
+ count++;
1166
+ }
1167
+ }
1168
+ return count;
1169
+ }
1170
+ async function runReset(options) {
1171
+ logger.setVerbose(options.verbose ?? false);
1172
+ logger.header("Reset Omnify Generated Files");
1173
+ logger.debug("Loading configuration...");
1174
+ const { config, configPath: configPath2 } = await loadConfig();
1175
+ const rootDir = configPath2 ? dirname5(configPath2) : process.cwd();
1176
+ const paths = [];
1177
+ const omnifyBasePaths = [
1178
+ "app/Models/OmnifyBase",
1179
+ "backend/app/Models/OmnifyBase",
1180
+ "src/Models/OmnifyBase"
1181
+ ];
1182
+ for (const relPath of omnifyBasePaths) {
1183
+ const omnifyBasePath = resolve6(rootDir, relPath);
1184
+ if (existsSync4(omnifyBasePath)) {
1185
+ paths.push({ name: "OmnifyBase models", path: omnifyBasePath, type: "dir" });
1186
+ break;
1187
+ }
1188
+ }
1189
+ const migrationPaths = [
1190
+ "database/migrations/omnify",
1191
+ "backend/database/migrations/omnify"
1192
+ ];
1193
+ for (const relPath of migrationPaths) {
1194
+ const migrationsPath = resolve6(rootDir, relPath);
1195
+ if (existsSync4(migrationsPath)) {
1196
+ paths.push({
1197
+ name: "Omnify migrations",
1198
+ path: migrationsPath,
1199
+ type: "files",
1200
+ pattern: /\.php$/
1201
+ });
1202
+ break;
1203
+ }
1204
+ }
1205
+ const laravelConfig = config.output.laravel;
1206
+ if (laravelConfig?.modelsPath) {
1207
+ const modelsPath = resolve6(rootDir, laravelConfig.modelsPath);
1208
+ const omnifyBasePath = join(modelsPath, "OmnifyBase");
1209
+ if (existsSync4(omnifyBasePath) && !paths.some((p) => p.path === omnifyBasePath)) {
1210
+ paths.push({ name: "OmnifyBase models", path: omnifyBasePath, type: "dir" });
1211
+ }
1212
+ }
1213
+ if (laravelConfig?.migrationsPath) {
1214
+ const migrationsPath = resolve6(rootDir, laravelConfig.migrationsPath);
1215
+ if (existsSync4(migrationsPath) && !paths.some((p) => p.path === migrationsPath)) {
1216
+ paths.push({
1217
+ name: "Omnify migrations",
1218
+ path: migrationsPath,
1219
+ type: "files",
1220
+ pattern: /\.php$/
1221
+ });
1222
+ }
1223
+ }
1224
+ const lockFilePath = resolve6(rootDir, config.lockFilePath);
1225
+ if (existsSync4(lockFilePath)) {
1226
+ paths.push({ name: "Lock file", path: lockFilePath, type: "file" });
1227
+ }
1228
+ const omnifyDir = resolve6(rootDir, ".omnify");
1229
+ if (existsSync4(omnifyDir)) {
1230
+ paths.push({ name: ".omnify directory", path: omnifyDir, type: "dir" });
1231
+ }
1232
+ if (paths.length === 0) {
1233
+ logger.info("Nothing to clean. No generated files found.");
1234
+ return;
1235
+ }
1236
+ logger.newline();
1237
+ logger.warn("The following will be deleted:");
1238
+ logger.newline();
1239
+ for (const item of paths) {
1240
+ if (item.type === "dir") {
1241
+ const count = countFiles(item.path);
1242
+ logger.info(` \u2022 ${item.name}: ${item.path} (${count} files)`);
1243
+ } else if (item.type === "files" && item.pattern) {
1244
+ const count = readdirSync(item.path).filter((f) => item.pattern.test(f)).length;
1245
+ logger.info(` \u2022 ${item.name}: ${item.path} (${count} files)`);
1246
+ } else {
1247
+ logger.info(` \u2022 ${item.name}: ${item.path}`);
1248
+ }
1249
+ }
1250
+ logger.newline();
1251
+ if (!options.yes) {
1252
+ const confirmed = await confirm2("Are you sure you want to delete these files?");
1253
+ if (!confirmed) {
1254
+ logger.info("Reset cancelled.");
1255
+ return;
1256
+ }
1257
+ }
1258
+ logger.newline();
1259
+ logger.step("Deleting files...");
1260
+ let totalDeleted = 0;
1261
+ for (const item of paths) {
1262
+ if (item.type === "dir") {
1263
+ const count = deleteDir(item.path, options.verbose ?? false);
1264
+ totalDeleted += count;
1265
+ logger.info(` \u2713 Deleted ${item.name} (${count} files)`);
1266
+ } else if (item.type === "files" && item.pattern) {
1267
+ const count = deleteFilesInDir(item.path, item.pattern, options.verbose ?? false);
1268
+ totalDeleted += count;
1269
+ logger.info(` \u2713 Deleted ${item.name} (${count} files)`);
1270
+ } else {
1271
+ rmSync(item.path, { force: true });
1272
+ if (options.verbose) {
1273
+ logger.debug(`Deleted: ${item.path}`);
1274
+ }
1275
+ totalDeleted++;
1276
+ logger.info(` \u2713 Deleted ${item.name}`);
1277
+ }
1278
+ }
1279
+ logger.newline();
1280
+ logger.success(`Reset complete! Deleted ${totalDeleted} file(s).`);
1281
+ logger.newline();
1282
+ logger.info("Run `omnify generate` to regenerate files.");
1283
+ }
1284
+ function registerResetCommand(program2) {
1285
+ 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) => {
1286
+ try {
1287
+ await runReset(options);
1288
+ } catch (error) {
1289
+ if (error instanceof Error) {
1290
+ logger.error(error.message);
1291
+ process.exit(1);
1292
+ }
1293
+ process.exit(1);
1294
+ }
1295
+ });
1296
+ }
1297
+
1095
1298
  // src/cli.ts
1096
1299
  var VERSION = "0.0.5";
1097
1300
  var program = new Command();
@@ -1100,6 +1303,7 @@ registerInitCommand(program);
1100
1303
  registerValidateCommand(program);
1101
1304
  registerDiffCommand(program);
1102
1305
  registerGenerateCommand(program);
1306
+ registerResetCommand(program);
1103
1307
  process.on("uncaughtException", (error) => {
1104
1308
  if (error instanceof OmnifyError5) {
1105
1309
  logger.formatError(error);
@@ -1123,8 +1327,8 @@ process.on("unhandledRejection", (reason) => {
1123
1327
  var args = process.argv.slice(2);
1124
1328
  var firstArg = args[0];
1125
1329
  var hasCommand = firstArg !== void 0 && !firstArg.startsWith("-");
1126
- var configPath = resolve6(process.cwd(), "omnify.config.ts");
1127
- var hasConfig = existsSync4(configPath);
1330
+ var configPath = resolve7(process.cwd(), "omnify.config.ts");
1331
+ var hasConfig = existsSync5(configPath);
1128
1332
  if (!hasCommand && !hasConfig) {
1129
1333
  runInit({}).catch((error) => {
1130
1334
  if (error instanceof Error) {