@emigrate/cli
Version:
Emigrate is a tool for managing database migrations. It is designed to be simple yet support advanced setups, modular and extensible.
30 lines • 1.03 kB
JavaScript
import path from 'node:path';
import fs from 'node:fs/promises';
import { withLeadingPeriod } from './with-leading-period.js';
import { OptionNeededError } from './errors.js';
const checkMigrationFile = async (name, filePath) => {
try {
const stats = await fs.stat(filePath);
if (!stats.isFile()) {
throw new Error('Not a file');
}
}
catch {
throw OptionNeededError.fromOption('force', `The given migration name "${name}" does not exist or is not a file. Use the "force" option to ignore this error`);
}
};
export const getMigration = async (cwd, directory, name, requireExists = true) => {
const filePath = path.resolve(cwd, directory, name);
if (requireExists) {
await checkMigrationFile(name, filePath);
}
return {
name,
filePath,
relativeFilePath: path.relative(cwd, filePath),
extension: withLeadingPeriod(path.extname(name)),
directory,
cwd,
};
};
//# sourceMappingURL=get-migration.js.map