* feat(types): move Emigrate types to separate package Also refactor the types to use discriminating unions for easier error handling and such. Errors passed to storage plugins should now be serialized and storage plugins are expected to return already serialized errors on failed history entries. * fix(mysql): handle the new type changes * fix(storage-fs): handle the new type changes * feat(cli): better error handling and types Adapt to the new types from the @emigrate/types package, like discriminating union types and serializing and deserializing errors
36 lines
1 KiB
TypeScript
36 lines
1 KiB
TypeScript
import path from 'node:path';
|
|
import { type MigrationHistoryEntry, type MigrationMetadataFinished } from '@emigrate/types';
|
|
import { withLeadingPeriod } from './with-leading-period.js';
|
|
import { MigrationHistoryError } from './errors.js';
|
|
|
|
export const toMigrationMetadata = (
|
|
entry: MigrationHistoryEntry,
|
|
{ cwd, directory }: { cwd: string; directory: string },
|
|
): MigrationMetadataFinished => {
|
|
const filePath = path.resolve(cwd, directory, entry.name);
|
|
|
|
if (entry.status === 'failed') {
|
|
return {
|
|
name: entry.name,
|
|
status: entry.status,
|
|
filePath,
|
|
relativeFilePath: path.relative(cwd, filePath),
|
|
extension: withLeadingPeriod(path.extname(entry.name)),
|
|
directory,
|
|
cwd,
|
|
duration: 0,
|
|
error: MigrationHistoryError.fromHistoryEntry(entry),
|
|
};
|
|
}
|
|
|
|
return {
|
|
name: entry.name,
|
|
status: entry.status,
|
|
filePath,
|
|
relativeFilePath: path.relative(cwd, filePath),
|
|
extension: withLeadingPeriod(path.extname(entry.name)),
|
|
directory,
|
|
cwd,
|
|
duration: 0,
|
|
};
|
|
};
|