fragment-ts 1.0.34 ā 1.0.35
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/API.md +248 -38
- package/DOCS.md +327 -63
- package/NewCLIGENERATECOMMANDS.txt +5 -0
- package/README.md +168 -3
- package/USAGE.md +395 -2
- package/dist/cli/commands/build.command.d.ts.map +1 -1
- package/dist/cli/commands/build.command.js +20 -8
- package/dist/cli/commands/build.command.js.map +1 -1
- package/dist/cli/commands/diagnostics.command.d.ts +1 -2
- package/dist/cli/commands/diagnostics.command.d.ts.map +1 -1
- package/dist/cli/commands/diagnostics.command.js +37 -23
- package/dist/cli/commands/diagnostics.command.js.map +1 -1
- package/dist/cli/commands/generate.command.d.ts +5 -1
- package/dist/cli/commands/generate.command.d.ts.map +1 -1
- package/dist/cli/commands/generate.command.js +171 -39
- package/dist/cli/commands/generate.command.js.map +1 -1
- package/dist/cli/commands/init.command.d.ts.map +1 -1
- package/dist/cli/commands/init.command.js +98 -28
- package/dist/cli/commands/init.command.js.map +1 -1
- package/dist/cli/commands/migrate.command.d.ts +10 -17
- package/dist/cli/commands/migrate.command.d.ts.map +1 -1
- package/dist/cli/commands/migrate.command.js +133 -170
- package/dist/cli/commands/migrate.command.js.map +1 -1
- package/dist/cli/commands/serve.command.d.ts.map +1 -1
- package/dist/cli/commands/serve.command.js +9 -4
- package/dist/cli/commands/serve.command.js.map +1 -1
- package/dist/cli/commands/test.command.d.ts.map +1 -1
- package/dist/cli/commands/test.command.js +24 -6
- package/dist/cli/commands/test.command.js.map +1 -1
- package/dist/core/scanner/component-scanner.d.ts +12 -0
- package/dist/core/scanner/component-scanner.d.ts.map +1 -1
- package/dist/core/scanner/component-scanner.js +72 -14
- package/dist/core/scanner/component-scanner.js.map +1 -1
- package/dist/shared/config.utils.d.ts +58 -0
- package/dist/shared/config.utils.d.ts.map +1 -0
- package/dist/shared/config.utils.js +137 -0
- package/dist/shared/config.utils.js.map +1 -0
- package/dist/shared/env.utils.d.ts +27 -0
- package/dist/shared/env.utils.d.ts.map +1 -0
- package/dist/shared/env.utils.js +68 -0
- package/dist/shared/env.utils.js.map +1 -0
- package/dist/shared/tsconfig.utils.d.ts +122 -0
- package/dist/shared/tsconfig.utils.d.ts.map +1 -0
- package/dist/shared/tsconfig.utils.js +305 -0
- package/dist/shared/tsconfig.utils.js.map +1 -0
- package/dist/testing/runner.d.ts +9 -1
- package/dist/testing/runner.d.ts.map +1 -1
- package/dist/testing/runner.js +50 -10
- package/dist/testing/runner.js.map +1 -1
- package/dist/typeorm/typeorm-module.d.ts +1 -0
- package/dist/typeorm/typeorm-module.d.ts.map +1 -1
- package/dist/typeorm/typeorm-module.js +193 -85
- package/dist/typeorm/typeorm-module.js.map +1 -1
- package/dist/web/application.d.ts +0 -1
- package/dist/web/application.d.ts.map +1 -1
- package/dist/web/application.js +4 -26
- package/dist/web/application.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/build.command.ts +24 -9
- package/src/cli/commands/diagnostics.command.ts +42 -30
- package/src/cli/commands/generate.command.ts +212 -52
- package/src/cli/commands/init.command.ts +100 -29
- package/src/cli/commands/migrate.command.ts +145 -198
- package/src/cli/commands/serve.command.ts +181 -170
- package/src/cli/commands/test.command.ts +25 -11
- package/src/core/scanner/component-scanner.ts +100 -18
- package/src/shared/config.utils.ts +148 -0
- package/src/shared/env.utils.ts +72 -0
- package/src/shared/tsconfig.utils.ts +360 -0
- package/src/testing/runner.ts +62 -14
- package/src/typeorm/typeorm-module.ts +209 -86
- 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
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
//
|
|
206
|
-
if (
|
|
207
|
-
return
|
|
177
|
+
// In production mode, always use JavaScript
|
|
178
|
+
if (!isDevMode) {
|
|
179
|
+
return false;
|
|
208
180
|
}
|
|
209
181
|
|
|
210
|
-
//
|
|
211
|
-
return
|
|
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
|
|
214
|
+
* Get entity paths from fragment.json config
|
|
243
215
|
*/
|
|
244
|
-
private static
|
|
245
|
-
|
|
246
|
-
|
|
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
|
|
222
|
+
* Get migration paths from fragment.json config
|
|
252
223
|
*/
|
|
253
|
-
private static
|
|
254
|
-
|
|
224
|
+
private static getMigrationPathsFromConfig(): string[] {
|
|
225
|
+
const dbConfig = ConfigUtils.getDatabaseConfig();
|
|
226
|
+
return dbConfig.migrations || [];
|
|
255
227
|
}
|
|
256
228
|
|
|
257
229
|
/**
|
|
258
|
-
* Get entity paths
|
|
230
|
+
* Get resolved entity paths based on current mode
|
|
259
231
|
*/
|
|
260
|
-
private static
|
|
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
|
|
251
|
+
* Get resolved migration paths based on current mode
|
|
266
252
|
*/
|
|
267
|
-
private static
|
|
268
|
-
const
|
|
269
|
-
|
|
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
|
|
289
|
+
// Initialize DataSource with paths from fragment.json config
|
|
289
290
|
const configOverride = {
|
|
290
|
-
entities: this.
|
|
291
|
-
migrations: this.
|
|
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
|
|
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 =
|
|
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
|
|
488
|
+
// Initialize DataSource with paths from fragment.json config
|
|
487
489
|
const configOverride = {
|
|
488
|
-
entities: this.
|
|
489
|
-
migrations: this.
|
|
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
|
|
496
|
-
const
|
|
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 =
|
|
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
|
|
626
|
+
// Initialize DataSource with paths from fragment.json config
|
|
617
627
|
const configOverride = {
|
|
618
|
-
entities: this.
|
|
619
|
-
migrations: this.
|
|
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
|
|
659
|
+
// Initialize DataSource with paths from fragment.json config
|
|
650
660
|
const configOverride = {
|
|
651
|
-
entities: this.
|
|
652
|
-
migrations: this.
|
|
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
|
|
692
|
+
// Initialize DataSource with paths from fragment.json config
|
|
683
693
|
const configOverride = {
|
|
684
|
-
entities: this.
|
|
685
|
-
migrations: this.
|
|
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
|
-
|
|
712
|
-
const
|
|
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(` -
|
|
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
|
|
772
|
+
// Initialize DataSource with entity paths from config
|
|
759
773
|
const configOverride = {
|
|
760
|
-
entities: this.
|
|
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
|
|
802
|
+
// Initialize DataSource with entity paths from config
|
|
789
803
|
const configOverride = {
|
|
790
|
-
entities: this.
|
|
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
|
-
|
|
816
|
-
|
|
817
|
-
|
|
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(
|
|
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
|
-
|
|
878
|
-
|
|
879
|
-
|
|
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
|
-
|
|
927
|
-
this.registerTsNodeIfNeeded(useTypeScript);
|
|
918
|
+
if (!fs.existsSync(srcMigrationsDir)) return false;
|
|
928
919
|
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
migrations: this.getMigrationPaths(useTypeScript),
|
|
933
|
-
};
|
|
920
|
+
const tsFiles = fs
|
|
921
|
+
.readdirSync(srcMigrationsDir)
|
|
922
|
+
.filter((file) => file.endsWith(".ts"));
|
|
934
923
|
|
|
935
|
-
|
|
936
|
-
|
|
924
|
+
return tsFiles.length > 0;
|
|
925
|
+
}
|
|
937
926
|
|
|
938
|
-
|
|
939
|
-
|
|
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
|
-
|
|
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
|
-
|
|
969
|
-
|
|
970
|
-
|
|
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
|
-
|
|
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[] {
|