fragment-ts 1.0.34 → 1.0.36

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.
Files changed (72) hide show
  1. package/API.md +248 -38
  2. package/DOCS.md +327 -63
  3. package/NewCLIGENERATECOMMANDS.txt +5 -0
  4. package/README.md +168 -3
  5. package/USAGE.md +395 -2
  6. package/dist/cli/commands/build.command.d.ts.map +1 -1
  7. package/dist/cli/commands/build.command.js +20 -8
  8. package/dist/cli/commands/build.command.js.map +1 -1
  9. package/dist/cli/commands/diagnostics.command.d.ts +1 -2
  10. package/dist/cli/commands/diagnostics.command.d.ts.map +1 -1
  11. package/dist/cli/commands/diagnostics.command.js +37 -23
  12. package/dist/cli/commands/diagnostics.command.js.map +1 -1
  13. package/dist/cli/commands/generate.command.d.ts +5 -1
  14. package/dist/cli/commands/generate.command.d.ts.map +1 -1
  15. package/dist/cli/commands/generate.command.js +171 -39
  16. package/dist/cli/commands/generate.command.js.map +1 -1
  17. package/dist/cli/commands/init.command.d.ts.map +1 -1
  18. package/dist/cli/commands/init.command.js +98 -28
  19. package/dist/cli/commands/init.command.js.map +1 -1
  20. package/dist/cli/commands/migrate.command.d.ts +10 -17
  21. package/dist/cli/commands/migrate.command.d.ts.map +1 -1
  22. package/dist/cli/commands/migrate.command.js +133 -170
  23. package/dist/cli/commands/migrate.command.js.map +1 -1
  24. package/dist/cli/commands/serve.command.d.ts.map +1 -1
  25. package/dist/cli/commands/serve.command.js +9 -4
  26. package/dist/cli/commands/serve.command.js.map +1 -1
  27. package/dist/cli/commands/test.command.d.ts.map +1 -1
  28. package/dist/cli/commands/test.command.js +24 -6
  29. package/dist/cli/commands/test.command.js.map +1 -1
  30. package/dist/core/scanner/component-scanner.d.ts +12 -0
  31. package/dist/core/scanner/component-scanner.d.ts.map +1 -1
  32. package/dist/core/scanner/component-scanner.js +82 -16
  33. package/dist/core/scanner/component-scanner.js.map +1 -1
  34. package/dist/shared/config.utils.d.ts +58 -0
  35. package/dist/shared/config.utils.d.ts.map +1 -0
  36. package/dist/shared/config.utils.js +137 -0
  37. package/dist/shared/config.utils.js.map +1 -0
  38. package/dist/shared/env.utils.d.ts +27 -0
  39. package/dist/shared/env.utils.d.ts.map +1 -0
  40. package/dist/shared/env.utils.js +68 -0
  41. package/dist/shared/env.utils.js.map +1 -0
  42. package/dist/shared/tsconfig.utils.d.ts +122 -0
  43. package/dist/shared/tsconfig.utils.d.ts.map +1 -0
  44. package/dist/shared/tsconfig.utils.js +305 -0
  45. package/dist/shared/tsconfig.utils.js.map +1 -0
  46. package/dist/testing/runner.d.ts +9 -1
  47. package/dist/testing/runner.d.ts.map +1 -1
  48. package/dist/testing/runner.js +50 -10
  49. package/dist/testing/runner.js.map +1 -1
  50. package/dist/typeorm/typeorm-module.d.ts +1 -0
  51. package/dist/typeorm/typeorm-module.d.ts.map +1 -1
  52. package/dist/typeorm/typeorm-module.js +193 -85
  53. package/dist/typeorm/typeorm-module.js.map +1 -1
  54. package/dist/web/application.d.ts +0 -1
  55. package/dist/web/application.d.ts.map +1 -1
  56. package/dist/web/application.js +4 -26
  57. package/dist/web/application.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/cli/commands/build.command.ts +24 -9
  60. package/src/cli/commands/diagnostics.command.ts +42 -30
  61. package/src/cli/commands/generate.command.ts +212 -52
  62. package/src/cli/commands/init.command.ts +100 -29
  63. package/src/cli/commands/migrate.command.ts +145 -198
  64. package/src/cli/commands/serve.command.ts +181 -170
  65. package/src/cli/commands/test.command.ts +25 -11
  66. package/src/core/scanner/component-scanner.ts +110 -20
  67. package/src/shared/config.utils.ts +148 -0
  68. package/src/shared/env.utils.ts +72 -0
  69. package/src/shared/tsconfig.utils.ts +360 -0
  70. package/src/testing/runner.ts +62 -14
  71. package/src/typeorm/typeorm-module.ts +209 -86
  72. package/src/web/application.ts +4 -33
@@ -6,6 +6,8 @@ import ora from "ora";
6
6
  import { execSync, spawn } from "child_process";
7
7
  import { TypeORMModule } from "../../typeorm/typeorm-module";
8
8
  import { DataSource } from "typeorm";
9
+ import { ConfigUtils } from "../../shared/config.utils";
10
+ import { EnvUtils } from "../../shared/env.utils";
9
11
 
10
12
  export class MigrateCommand {
11
13
  private static tsNodeAvailable: boolean | null = null;
@@ -157,58 +159,28 @@ export class MigrateCommand {
157
159
  return this.hasTsConfig() ? "typescript" : "javascript";
158
160
  }
159
161
 
160
- /**
161
- * Check for TypeScript migration files
162
- */
163
- private static hasTypeScriptMigrations(): boolean {
164
- const srcMigrationsDir = path.join(process.cwd(), "src", "migrations");
165
-
166
- if (!fs.existsSync(srcMigrationsDir)) return false;
167
-
168
- const tsFiles = fs
169
- .readdirSync(srcMigrationsDir)
170
- .filter((file) => file.endsWith(".ts"));
171
-
172
- return tsFiles.length > 0;
173
- }
174
-
175
- /**
176
- * Check for JavaScript migration files
177
- */
178
- private static hasJavaScriptMigrations(): boolean {
179
- const distMigrationsDir = path.join(process.cwd(), "dist", "migrations");
180
-
181
- if (!fs.existsSync(distMigrationsDir)) return false;
182
-
183
- const jsFiles = fs
184
- .readdirSync(distMigrationsDir)
185
- .filter((file) => file.endsWith(".js"));
186
-
187
- return jsFiles.length > 0;
188
- }
189
-
190
162
  /**
191
163
  * Determine whether to use TypeScript or JavaScript for migrations
192
164
  */
193
165
  private static shouldUseTypeScript(): boolean {
194
166
  const projectType = this.detectProjectType();
195
- const hasTsMigrations = this.hasTypeScriptMigrations();
196
- const hasJsMigrations = this.hasJavaScriptMigrations();
197
167
  const tsNodeAvailable = this.isTsNodeAvailable();
198
168
 
199
- // If we have TypeScript migrations but no JavaScript migrations,
200
- // and ts-node is available, use TypeScript
201
- if (hasTsMigrations && !hasJsMigrations && tsNodeAvailable) {
169
+ // Use the same logic as EnvUtils for consistency
170
+ const isDevMode = EnvUtils.isDevelopmentMode();
171
+
172
+ // In development mode with ts-node available, use TypeScript
173
+ if (isDevMode && tsNodeAvailable) {
202
174
  return true;
203
175
  }
204
176
 
205
- // If project is clearly TypeScript-only and ts-node is available
206
- if (projectType === "typescript" && tsNodeAvailable) {
207
- return true;
177
+ // In production mode, always use JavaScript
178
+ if (!isDevMode) {
179
+ return false;
208
180
  }
209
181
 
210
- // Default to JavaScript
211
- return false;
182
+ // Fallback to project type detection
183
+ return projectType === "typescript" && tsNodeAvailable;
212
184
  }
213
185
 
214
186
  /**
@@ -239,34 +211,63 @@ export class MigrateCommand {
239
211
  }
240
212
 
241
213
  /**
242
- * Get migration directory based on project type
214
+ * Get entity paths from fragment.json config
243
215
  */
244
- private static getMigrationDirectory(useTypeScript: boolean): string {
245
- return useTypeScript
246
- ? path.join(process.cwd(), "src", "migrations")
247
- : path.join(process.cwd(), "dist", "migrations");
216
+ private static getEntityPathsFromConfig(): string[] {
217
+ const dbConfig = ConfigUtils.getDatabaseConfig();
218
+ return dbConfig.entities || [];
248
219
  }
249
220
 
250
221
  /**
251
- * Get migration file extension based on project type
222
+ * Get migration paths from fragment.json config
252
223
  */
253
- private static getMigrationExtension(useTypeScript: boolean): string {
254
- return useTypeScript ? ".ts" : ".js";
224
+ private static getMigrationPathsFromConfig(): string[] {
225
+ const dbConfig = ConfigUtils.getDatabaseConfig();
226
+ return dbConfig.migrations || [];
255
227
  }
256
228
 
257
229
  /**
258
- * Get entity paths for TypeORM configuration
230
+ * Get resolved entity paths based on current mode
259
231
  */
260
- private static getEntityPaths(useTypeScript: boolean): string[] {
232
+ private static getResolvedEntityPaths(useTypeScript: boolean): string[] {
233
+ const configPaths = this.getEntityPathsFromConfig();
234
+
235
+ if (configPaths.length > 0) {
236
+ // Use configured paths but resolve based on current mode
237
+ return configPaths.map((pattern) => {
238
+ if (useTypeScript) {
239
+ return pattern.replace(/\.js$/, ".ts");
240
+ } else {
241
+ return pattern.replace(/\.ts$/, ".js");
242
+ }
243
+ });
244
+ }
245
+
246
+ // Fallback to default paths
261
247
  return useTypeScript ? ["src/**/*.entity.ts"] : ["dist/**/*.entity.js"];
262
248
  }
263
249
 
264
250
  /**
265
- * Get migration paths for TypeORM configuration
251
+ * Get resolved migration paths based on current mode
266
252
  */
267
- private static getMigrationPaths(useTypeScript: boolean): string[] {
268
- const migrationDir = this.getMigrationDirectory(useTypeScript);
269
- return [`${migrationDir}/**/*${this.getMigrationExtension(useTypeScript)}`];
253
+ private static getResolvedMigrationPaths(useTypeScript: boolean): string[] {
254
+ const configPaths = this.getMigrationPathsFromConfig();
255
+
256
+ if (configPaths.length > 0) {
257
+ // Use configured paths but resolve based on current mode
258
+ return configPaths.map((pattern) => {
259
+ if (useTypeScript) {
260
+ return pattern.replace(/\.js$/, ".ts");
261
+ } else {
262
+ return pattern.replace(/\.ts$/, ".js");
263
+ }
264
+ });
265
+ }
266
+
267
+ // Fallback to default paths
268
+ return useTypeScript
269
+ ? ["src/migrations/**/*.ts"]
270
+ : ["dist/migrations/**/*.js"];
270
271
  }
271
272
 
272
273
  // -----------------------------------------
@@ -285,10 +286,10 @@ export class MigrateCommand {
285
286
  // Register ts-node if using TypeScript
286
287
  this.registerTsNodeIfNeeded(useTypeScript);
287
288
 
288
- // Initialize DataSource with appropriate paths
289
+ // Initialize DataSource with paths from fragment.json config
289
290
  const configOverride = {
290
- entities: this.getEntityPaths(useTypeScript),
291
- migrations: this.getMigrationPaths(useTypeScript),
291
+ entities: this.getResolvedEntityPaths(useTypeScript),
292
+ migrations: this.getResolvedMigrationPaths(useTypeScript),
292
293
  };
293
294
 
294
295
  dataSource = await TypeORMModule.initialize(configOverride);
@@ -299,16 +300,17 @@ export class MigrateCommand {
299
300
  // Verify entities are loaded
300
301
  this.verifyEntities(dataSource);
301
302
 
302
- // Setup migrations directory
303
- const migrationsDir = this.getMigrationDirectory(useTypeScript);
303
+ // Setup migrations directory from config
304
+ const migrationPaths = this.getResolvedMigrationPaths(useTypeScript);
305
+ const migrationsDir = path.dirname(
306
+ migrationPaths[0].replace("/**/*", ""),
307
+ );
304
308
  await fs.ensureDir(migrationsDir);
305
309
 
306
310
  const existingMigrations = fs.existsSync(migrationsDir)
307
311
  ? fs
308
312
  .readdirSync(migrationsDir)
309
- .filter((f) =>
310
- f.endsWith(this.getMigrationExtension(useTypeScript)),
311
- )
313
+ .filter((f) => f.endsWith(useTypeScript ? ".ts" : ".js"))
312
314
  : [];
313
315
 
314
316
  const isFirstMigration = existingMigrations.length === 0;
@@ -370,8 +372,8 @@ export class MigrateCommand {
370
372
  isFirstMigration,
371
373
  );
372
374
 
373
- // Write migration file
374
- const fileExt = this.getMigrationExtension(useTypeScript);
375
+ // Write migration file using config directory
376
+ const fileExt = useTypeScript ? ".ts" : ".js";
375
377
  const fileName = `${timestamp}-${migrationName}${fileExt}`;
376
378
  const filePath = path.join(migrationsDir, fileName);
377
379
 
@@ -483,17 +485,20 @@ export class MigrateCommand {
483
485
  // Register ts-node if using TypeScript
484
486
  this.registerTsNodeIfNeeded(useTypeScript);
485
487
 
486
- // Initialize DataSource with appropriate paths
488
+ // Initialize DataSource with paths from fragment.json config
487
489
  const configOverride = {
488
- entities: this.getEntityPaths(useTypeScript),
489
- migrations: this.getMigrationPaths(useTypeScript),
490
+ entities: this.getResolvedEntityPaths(useTypeScript),
491
+ migrations: this.getResolvedMigrationPaths(useTypeScript),
490
492
  };
491
493
 
492
494
  dataSource = await TypeORMModule.initialize(configOverride);
493
495
 
494
- // Check if migrations exist
495
- const migrationsDir = this.getMigrationDirectory(useTypeScript);
496
- const fileExt = this.getMigrationExtension(useTypeScript);
496
+ // Check if migrations exist using config paths
497
+ const migrationPaths = this.getResolvedMigrationPaths(useTypeScript);
498
+ const migrationsDir = path.dirname(
499
+ migrationPaths[0].replace("/**/*", ""),
500
+ );
501
+ const fileExt = useTypeScript ? ".ts" : ".js";
497
502
 
498
503
  const hasMigrations =
499
504
  fs.existsSync(migrationsDir) &&
@@ -569,9 +574,14 @@ export class MigrateCommand {
569
574
 
570
575
  try {
571
576
  const timestamp = Date.now();
572
- const fileExt = this.getMigrationExtension(useTypeScript);
577
+ const fileExt = useTypeScript ? ".ts" : ".js";
578
+
579
+ // Get migration directory from config
580
+ const migrationPaths = this.getResolvedMigrationPaths(useTypeScript);
581
+ const migrationsDir = path.dirname(
582
+ migrationPaths[0].replace("/**/*", ""),
583
+ );
573
584
  const fileName = `${timestamp}-${name}${fileExt}`;
574
- const migrationsDir = this.getMigrationDirectory(useTypeScript);
575
585
  const filePath = path.join(migrationsDir, fileName);
576
586
 
577
587
  const content = `import { MigrationInterface, QueryRunner } from 'typeorm';
@@ -613,10 +623,10 @@ export class ${name}${timestamp} implements MigrationInterface {
613
623
  // Register ts-node if using TypeScript
614
624
  this.registerTsNodeIfNeeded(useTypeScript);
615
625
 
616
- // Initialize DataSource with appropriate paths
626
+ // Initialize DataSource with paths from fragment.json config
617
627
  const configOverride = {
618
- entities: this.getEntityPaths(useTypeScript),
619
- migrations: this.getMigrationPaths(useTypeScript),
628
+ entities: this.getResolvedEntityPaths(useTypeScript),
629
+ migrations: this.getResolvedMigrationPaths(useTypeScript),
620
630
  };
621
631
 
622
632
  dataSource = await TypeORMModule.initialize(configOverride);
@@ -646,10 +656,10 @@ export class ${name}${timestamp} implements MigrationInterface {
646
656
  // Register ts-node if using TypeScript
647
657
  this.registerTsNodeIfNeeded(useTypeScript);
648
658
 
649
- // Initialize DataSource with appropriate paths
659
+ // Initialize DataSource with paths from fragment.json config
650
660
  const configOverride = {
651
- entities: this.getEntityPaths(useTypeScript),
652
- migrations: this.getMigrationPaths(useTypeScript),
661
+ entities: this.getResolvedEntityPaths(useTypeScript),
662
+ migrations: this.getResolvedMigrationPaths(useTypeScript),
653
663
  };
654
664
 
655
665
  dataSource = await TypeORMModule.initialize(configOverride);
@@ -679,10 +689,10 @@ export class ${name}${timestamp} implements MigrationInterface {
679
689
  // Register ts-node if using TypeScript
680
690
  this.registerTsNodeIfNeeded(useTypeScript);
681
691
 
682
- // Initialize DataSource with appropriate paths
692
+ // Initialize DataSource with paths from fragment.json config
683
693
  const configOverride = {
684
- entities: this.getEntityPaths(useTypeScript),
685
- migrations: this.getMigrationPaths(useTypeScript),
694
+ entities: this.getResolvedEntityPaths(useTypeScript),
695
+ migrations: this.getResolvedMigrationPaths(useTypeScript),
686
696
  };
687
697
 
688
698
  dataSource = await TypeORMModule.initialize(configOverride);
@@ -708,8 +718,12 @@ export class ${name}${timestamp} implements MigrationInterface {
708
718
  });
709
719
  }
710
720
 
711
- const migrationsDir = this.getMigrationDirectory(useTypeScript);
712
- const fileExt = this.getMigrationExtension(useTypeScript);
721
+ // Show migration directory from config
722
+ const migrationPaths = this.getResolvedMigrationPaths(useTypeScript);
723
+ const migrationsDir = path.dirname(
724
+ migrationPaths[0].replace("/**/*", ""),
725
+ );
726
+ const fileExt = useTypeScript ? ".ts" : ".js";
713
727
  if (fs.existsSync(migrationsDir)) {
714
728
  const files = fs
715
729
  .readdirSync(migrationsDir)
@@ -724,7 +738,7 @@ export class ${name}${timestamp} implements MigrationInterface {
724
738
  // Show detection info
725
739
  console.log(chalk.gray(`\n Mode detection:`));
726
740
  console.log(
727
- chalk.gray(` - Project type: ${this.detectProjectType()}`),
741
+ chalk.gray(` - Environment mode: ${EnvUtils.getEnvironmentMode()}`),
728
742
  );
729
743
  console.log(
730
744
  chalk.gray(` - ts-node available: ${this.isTsNodeAvailable()}`),
@@ -755,9 +769,9 @@ export class ${name}${timestamp} implements MigrationInterface {
755
769
  // Register ts-node if using TypeScript
756
770
  this.registerTsNodeIfNeeded(useTypeScript);
757
771
 
758
- // Initialize DataSource with appropriate paths
772
+ // Initialize DataSource with entity paths from config
759
773
  const configOverride = {
760
- entities: this.getEntityPaths(useTypeScript),
774
+ entities: this.getResolvedEntityPaths(useTypeScript),
761
775
  };
762
776
 
763
777
  dataSource = await TypeORMModule.initialize(configOverride);
@@ -785,9 +799,9 @@ export class ${name}${timestamp} implements MigrationInterface {
785
799
  // Register ts-node if using TypeScript
786
800
  this.registerTsNodeIfNeeded(useTypeScript);
787
801
 
788
- // Initialize DataSource with appropriate paths
802
+ // Initialize DataSource with entity paths from config
789
803
  const configOverride = {
790
- entities: this.getEntityPaths(useTypeScript),
804
+ entities: this.getResolvedEntityPaths(useTypeScript),
791
805
  };
792
806
 
793
807
  dataSource = await TypeORMModule.initialize(configOverride);
@@ -812,9 +826,21 @@ export class ${name}${timestamp} implements MigrationInterface {
812
826
  try {
813
827
  // Try TypeScript first if available
814
828
  const useTypeScript = this.shouldUseTypeScript();
815
- const seedsDir = useTypeScript
816
- ? path.join(process.cwd(), "src", "seeds")
817
- : path.join(process.cwd(), "dist", "seeds");
829
+
830
+ // Get seed directory from config or default
831
+ const dbConfig = ConfigUtils.getDatabaseConfig();
832
+ let seedsDir = "";
833
+
834
+ if (dbConfig.subscribers && dbConfig.subscribers.length > 0) {
835
+ // Infer seeds directory from subscribers or migrations
836
+ const migrationPaths = this.getResolvedMigrationPaths(useTypeScript);
837
+ seedsDir = path.join(path.dirname(migrationPaths[0]), "..", "seeds");
838
+ } else {
839
+ // seedsDir = useTypeScript
840
+ // ? path.join(process.cwd(), "src", "seeds")
841
+ // : path.join(process.cwd(), "dist", "seeds");
842
+ throw new Error("No seeds directory found");
843
+ }
818
844
 
819
845
  if (fs.existsSync(seedsDir)) {
820
846
  const files = fs.readdirSync(seedsDir);
@@ -851,8 +877,19 @@ export class ${name}${timestamp} implements MigrationInterface {
851
877
  const spinner = ora("Creating TypeScript seed...").start();
852
878
 
853
879
  try {
880
+ // Get seed directory from config or default
881
+ const dbConfig = ConfigUtils.getDatabaseConfig();
882
+ let seedsDir = "";
883
+
884
+ if (dbConfig.subscribers && dbConfig.subscribers.length > 0) {
885
+ const migrationPaths = this.getResolvedMigrationPaths(true);
886
+ seedsDir = path.join(path.dirname(migrationPaths[0]), "..", "seeds");
887
+ } else {
888
+ seedsDir = path.join(process.cwd(), "src", "seeds");
889
+ }
890
+
854
891
  const fileName = `${name}.seed.ts`;
855
- const filePath = path.join(process.cwd(), "src", "seeds", fileName);
892
+ const filePath = path.join(seedsDir, fileName);
856
893
 
857
894
  const content = `export default class ${name}Seed {
858
895
  static async run() {
@@ -874,119 +911,29 @@ export class ${name}${timestamp} implements MigrationInterface {
874
911
  }
875
912
  }
876
913
 
877
- private static async checkDatabase(): Promise<void> {
878
- console.log(chalk.blue("\nšŸ” Database Diagnostic Check\n"));
879
- let dataSource: DataSource | null = null;
880
-
881
- try {
882
- // Check fragment.json
883
- const configPath = path.join(process.cwd(), "fragment.json");
884
- if (!fs.existsSync(configPath)) {
885
- console.log(chalk.yellow("āš ļø fragment.json not found"));
886
- } else {
887
- console.log(chalk.green("āœ“ fragment.json found"));
888
- const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
889
- console.log(
890
- chalk.gray(
891
- ` Database type: ${config.database?.type || "not specified"}`,
892
- ),
893
- );
894
- console.log(
895
- chalk.gray(
896
- ` Entity paths: ${JSON.stringify(config.database?.entities || "default")}`,
897
- ),
898
- );
899
- }
900
-
901
- // Check project type
902
- const projectType = this.detectProjectType();
903
- console.log(chalk.green(`\nāœ“ Project type: ${projectType}`));
904
-
905
- // Check ts-node availability
906
- const tsNodeAvailable = this.isTsNodeAvailable();
907
- console.log(chalk.green(`āœ“ ts-node available: ${tsNodeAvailable}`));
908
-
909
- // Check what migration files exist
910
- const hasTsMigrations = this.hasTypeScriptMigrations();
911
- const hasJsMigrations = this.hasJavaScriptMigrations();
912
- console.log(chalk.green(`āœ“ TypeScript migrations: ${hasTsMigrations}`));
913
- console.log(chalk.green(`āœ“ JavaScript migrations: ${hasJsMigrations}`));
914
-
915
- // Determine what mode would be used
916
- const useTypeScript = this.shouldUseTypeScript();
917
- console.log(
918
- chalk.cyan(
919
- `\nšŸŽÆ Would use: ${useTypeScript ? "TypeScript (ts-node)" : "JavaScript"}`,
920
- ),
921
- );
922
-
923
- // Try to connect
924
- console.log(chalk.blue("\nšŸ“” Attempting database connection..."));
914
+ // Keep existing helper methods unchanged
915
+ private static hasTypeScriptMigrations(): boolean {
916
+ const srcMigrationsDir = path.join(process.cwd(), "src", "migrations");
925
917
 
926
- // Register ts-node if needed
927
- this.registerTsNodeIfNeeded(useTypeScript);
918
+ if (!fs.existsSync(srcMigrationsDir)) return false;
928
919
 
929
- // Initialize with appropriate paths
930
- const configOverride = {
931
- entities: this.getEntityPaths(useTypeScript),
932
- migrations: this.getMigrationPaths(useTypeScript),
933
- };
920
+ const tsFiles = fs
921
+ .readdirSync(srcMigrationsDir)
922
+ .filter((file) => file.endsWith(".ts"));
934
923
 
935
- dataSource = await TypeORMModule.initialize(configOverride);
936
- console.log(chalk.green("āœ“ Database connection successful"));
924
+ return tsFiles.length > 0;
925
+ }
937
926
 
938
- // Check loaded entities
939
- const entities = dataSource.entityMetadatas;
940
- console.log(chalk.blue(`\nšŸ“¦ Loaded Entities: ${entities.length}`));
927
+ private static hasJavaScriptMigrations(): boolean {
928
+ const distMigrationsDir = path.join(process.cwd(), "dist", "migrations");
941
929
 
942
- if (entities.length === 0) {
943
- console.log(chalk.red("āœ— No entities loaded by TypeORM!"));
944
- console.log(chalk.yellow("\nPossible issues:"));
945
- if (useTypeScript) {
946
- console.log(
947
- chalk.yellow(" 1. Entity files not in src/**/*.entity.ts"),
948
- );
949
- console.log(chalk.yellow(" 2. Missing @Entity() decorator"));
950
- console.log(chalk.yellow(" 3. ts-node not working properly"));
951
- } else {
952
- console.log(
953
- chalk.yellow(" 1. Entity files not compiled (run npm run build)"),
954
- );
955
- console.log(
956
- chalk.yellow(" 2. Entity paths in fragment.json incorrect"),
957
- );
958
- console.log(chalk.yellow(" 3. Missing @Entity() decorator"));
959
- }
960
- } else {
961
- entities.forEach((entity) => {
962
- console.log(chalk.cyan(`\n ${entity.name}:`));
963
- console.log(chalk.gray(` Table: ${entity.tableName}`));
964
- console.log(chalk.gray(` Columns: ${entity.columns.length}`));
965
- });
966
- }
930
+ if (!fs.existsSync(distMigrationsDir)) return false;
967
931
 
968
- // Check database tables
969
- console.log(chalk.blue("\nšŸ—„ļø Checking database tables..."));
970
- const queryRunner = dataSource.createQueryRunner();
971
- try {
972
- const tables = await queryRunner.getTables();
973
- console.log(chalk.green(`āœ“ Database has ${tables.length} table(s):`));
974
- tables.forEach((t) => console.log(chalk.gray(` - ${t.name}`)));
975
- } finally {
976
- await queryRunner.release();
977
- }
932
+ const jsFiles = fs
933
+ .readdirSync(distMigrationsDir)
934
+ .filter((file) => file.endsWith(".js"));
978
935
 
979
- console.log(chalk.green("\nāœ… Database check complete!\n"));
980
- } catch (error) {
981
- console.log(chalk.red("\nāŒ Error during check:"));
982
- console.error(
983
- chalk.red(error instanceof Error ? error.message : String(error)),
984
- );
985
- } finally {
986
- if (dataSource?.isInitialized) {
987
- await dataSource.destroy();
988
- }
989
- }
936
+ return jsFiles.length > 0;
990
937
  }
991
938
 
992
939
  private static findEntityFiles(dir: string, files: string[] = []): string[] {