Skip to content

Commit

Permalink
CLI: add --list to automigrate command
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Dec 19, 2022
1 parent eb88800 commit f04aca8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
26 changes: 16 additions & 10 deletions code/lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type FixId = string;

interface FixOptions {
fixId?: FixId;
list?: boolean;
yes?: boolean;
dryRun?: boolean;
useNpm?: boolean;
Expand All @@ -37,22 +38,27 @@ type FixSummary = {
failed: Record<FixId, string>;
};

export const automigrate = async ({ fixId, dryRun, yes, useNpm, force }: FixOptions = {}) => {
const packageManager = JsPackageManagerFactory.getPackageManager({ useNpm, force });
const logAvailableMigrations = () => {
const availableFixes = allFixes.map((f) => chalk.yellow(f.id)).join(', ');
logger.info(`\nThe following migrations are available: ${availableFixes}`);
};

export const automigrate = async ({ fixId, dryRun, yes, useNpm, force, list }: FixOptions = {}) => {
if (list) {
logAvailableMigrations();
return;
}

const fixes = fixId ? allFixes.filter((f) => f.id === fixId) : allFixes;

if (fixId && fixes.length === 0) {
const availableFixes = allFixes.map((f) => chalk.yellow(f.id)).join(', ');
logger.info(
dedent`
📭 No migrations found for ${chalk.magenta(fixId)}.
The following migrations are available: ${availableFixes}
`
);
logger.info(`📭 No migrations found for ${chalk.magenta(fixId)}.`);
logAvailableMigrations();
return;
}

const packageManager = JsPackageManagerFactory.getPackageManager({ useNpm, force });

logger.info('🔎 checking possible migrations..');
const fixResults = {} as Record<FixId, FixStatus>;
const fixSummary: FixSummary = { succeeded: [], failed: {}, manual: [], skipped: [] };
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ program
.option('-n --dry-run', 'Only check for fixes, do not actually run them')
.option('--package-manager <npm|pnpm|yarn1|yarn2>', 'Force package manager')
.option('-N --use-npm', 'Use npm as package manager (deprecated)')
.option('-l --list', 'List available migrations')
.action(async (fixId, options) => {
await automigrate({ fixId, ...options }).catch((e) => {
logger.error(e);
Expand Down

0 comments on commit f04aca8

Please sign in to comment.