* 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 })
| 55 | * break existing projects, only help with the new ones. |
| 56 | */ |
| 57 | private detectSourceFolder(fs: { pathExists(path: string): boolean }): void { |
| 58 | const baseDir = this.#config.get('baseDir'); |
| 59 | const defaultPath = './seeders'; |
| 60 | |
| 61 | if (!fs.pathExists(baseDir + '/src')) { |
| 62 | this.#options.path ??= defaultPath; |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | const exists = fs.pathExists(`${baseDir}/${defaultPath}`); |
| 67 | const distDir = fs.pathExists(baseDir + '/dist'); |
| 68 | const buildDir = fs.pathExists(baseDir + '/build'); |
| 69 | // if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder |
| 70 | const path = distDir ? './dist' : buildDir ? './build' : './src'; |
| 71 | |
| 72 | // only if the user did not provide any values and if the default path does not exist |
| 73 | if (!this.#options.path && !this.#options.pathTs && !exists) { |
| 74 | this.#options.path = `${path}/seeders`; |
| 75 | this.#options.pathTs = './src/seeders'; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | async seed(...classNames: Constructor<Seeder>[]): Promise<void> { |
| 80 | for (const SeederClass of classNames) { |
no test coverage detected