feat(cli): implement the "list" command for listing migration history and pending migrations
This commit is contained in:
parent
e79dd4bca9
commit
53cdb23237
8 changed files with 199 additions and 38 deletions
28
packages/cli/src/get-migrations.ts
Normal file
28
packages/cli/src/get-migrations.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import path from 'node:path';
|
||||
import fs from 'node:fs/promises';
|
||||
import { type MigrationMetadata } from '@emigrate/plugin-tools/types';
|
||||
import { withLeadingPeriod } from './with-leading-period.js';
|
||||
|
||||
export const getMigrations = async (cwd: string, directory: string): Promise<MigrationMetadata[]> => {
|
||||
const allFilesInMigrationDirectory = await fs.readdir(path.resolve(cwd, directory), {
|
||||
withFileTypes: true,
|
||||
});
|
||||
|
||||
const migrationFiles: MigrationMetadata[] = allFilesInMigrationDirectory
|
||||
.filter((file) => file.isFile() && !file.name.startsWith('.') && !file.name.startsWith('_'))
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
.map(({ name }) => {
|
||||
const filePath = path.resolve(cwd, directory, name);
|
||||
|
||||
return {
|
||||
name,
|
||||
filePath,
|
||||
relativeFilePath: path.relative(cwd, filePath),
|
||||
extension: withLeadingPeriod(path.extname(name)),
|
||||
directory,
|
||||
cwd,
|
||||
};
|
||||
});
|
||||
|
||||
return migrationFiles;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue