MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / detectSourceFolder

Function detectSourceFolder

packages/core/src/utils/AbstractMigrator.ts:491–512  ·  view source on GitHub ↗

* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it. * If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be * used for the TS variant (`pathTs` option). * *

(fs: { pathExists(path: string): boolean })

Source from the content-addressed store, hash-verified

489 * break existing projects, only help with the new ones.
490 */
491 private detectSourceFolder(fs: { pathExists(path: string): boolean }): void {
492 const baseDir = this.config.get('baseDir');
493 const defaultPath = './migrations';
494
495 if (!fs.pathExists(baseDir + '/src')) {
496 this.options.path ??= defaultPath;
497 return;
498 }
499
500 const exists = fs.pathExists(`${baseDir}/${defaultPath}`);
501 const distDir = fs.pathExists(baseDir + '/dist');
502 const buildDir = fs.pathExists(baseDir + '/build');
503 // if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
504 /* v8 ignore next */
505 const path = distDir ? './dist' : buildDir ? './build' : './src';
506
507 // only if the user did not provide any values and if the default path does not exist
508 if (!this.options.path && !this.options.pathTs && !exists) {
509 this.options.path = `${path}/migrations`;
510 this.options.pathTs = './src/migrations';
511 }
512 }
513
514 private registerDefaultListeners(): void {
515 /* v8 ignore else */

Callers

nothing calls this directly

Calls 2

pathExistsMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected