feat(cli): add the --import option for importing modules/packages before commands are run

Can for instance be used to load environment variables using Dotenv
This commit is contained in:
Joakim Carlstein 2023-12-20 11:01:01 +01:00 committed by Joakim Carlstein
parent e6e4433018
commit 9f91bdcfa0
12 changed files with 131 additions and 40 deletions

View file

@ -1,4 +1,3 @@
import process from 'node:process';
import { getOrLoadReporter, getOrLoadStorage } from '@emigrate/plugin-tools';
import { BadOptionError, MissingOptionError, StorageInitError, toError } from '../errors.js';
import { type Config } from '../types.js';
@ -10,17 +9,21 @@ import { version } from '../get-package-info.js';
const lazyDefaultReporter = async () => import('../reporters/default.js');
type ExtraFlags = {
cwd: string;
};
export default async function listCommand({
directory,
reporter: reporterConfig,
storage: storageConfig,
color,
}: Config) {
cwd,
}: Config & ExtraFlags) {
if (!directory) {
throw MissingOptionError.fromOption('directory');
}
const cwd = process.cwd();
const storagePlugin = await getOrLoadStorage([storageConfig]);
if (!storagePlugin) {