refactor(cli): introduce the migration-runner helper for less code duplication and fewer return paths
Thanks to the migration-runner the "up" and "list" commands are now very similar code wise
This commit is contained in:
parent
5307e87242
commit
8cc43a8f83
9 changed files with 332 additions and 294 deletions
30
packages/cli/src/to-migration-metadata.ts
Normal file
30
packages/cli/src/to-migration-metadata.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import path from 'node:path';
|
||||
import { type MigrationHistoryEntry, type MigrationMetadataFinished } from '@emigrate/plugin-tools/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);
|
||||
const finishedMigration: MigrationMetadataFinished = {
|
||||
name: entry.name,
|
||||
status: entry.status,
|
||||
filePath,
|
||||
relativeFilePath: path.relative(cwd, filePath),
|
||||
extension: withLeadingPeriod(path.extname(entry.name)),
|
||||
directory,
|
||||
cwd,
|
||||
duration: 0,
|
||||
};
|
||||
|
||||
if (entry.status === 'failed') {
|
||||
finishedMigration.error = new MigrationHistoryError(
|
||||
`Migration ${entry.name} is in a failed state, it should be fixed and removed`,
|
||||
entry,
|
||||
);
|
||||
}
|
||||
|
||||
return finishedMigration;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue