Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
40 lines
1.2 KiB
Plaintext
40 lines
1.2 KiB
Plaintext
import fs from 'fs';
|
|
import path from 'path';
|
|
/**
|
|
* Attempt to find migrations directory.
|
|
*
|
|
* Checks for the following directories in order:
|
|
* - `migrationDir` argument from Payload config
|
|
* - `src/migrations`
|
|
* - `dist/migrations`
|
|
* - `migrations`
|
|
*
|
|
* @param migrationDir
|
|
* @default src/migrations`, if the src folder does not exists - migrations.
|
|
* @returns
|
|
*/ export const findMigrationDir = (migrationDir)=>{
|
|
const cwd = process.cwd();
|
|
const srcMigrationsDir = path.resolve(cwd, 'src/migrations');
|
|
const distMigrationsDir = path.resolve(cwd, 'dist/migrations');
|
|
const relativeMigrations = path.resolve(cwd, 'migrations');
|
|
// Use arg if provided
|
|
if (migrationDir) {
|
|
return migrationDir;
|
|
}
|
|
// Check other common locations
|
|
if (fs.existsSync(srcMigrationsDir)) {
|
|
return srcMigrationsDir;
|
|
}
|
|
if (fs.existsSync(distMigrationsDir)) {
|
|
return distMigrationsDir;
|
|
}
|
|
if (fs.existsSync(relativeMigrations)) {
|
|
return relativeMigrations;
|
|
}
|
|
if (fs.existsSync(path.resolve(cwd, 'src'))) {
|
|
return srcMigrationsDir;
|
|
}
|
|
return relativeMigrations;
|
|
};
|
|
|
|
//# sourceMappingURL=findMigrationDir.js.map |