Skip to content

Commit

Permalink
add --list-plugins and --plugins options to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrefinedBrain committed Sep 30, 2024
1 parent 70075a8 commit c872204
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@types/cli-progress": "^3.11.5",
"@types/deep-diff": "^1.0.5",
"@types/lodash-es": "^4.17.12",
"@types/micromatch": "^4.0.9",
"@types/node": "^22.0.0",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
Expand All @@ -77,6 +78,7 @@
"glob": "^11.0.0",
"lodash-es": "^4.17.21",
"magic-string": "^0.30.10",
"micromatch": "^4.0.8",
"node-html-parser": "^6.1.13",
"postcss": "^8.4.38",
"postcss-less": "^6.0.0",
Expand Down
26 changes: 22 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Command } from 'commander';
import { globSync } from 'glob';
import { promises as fs } from 'fs';
import micromatch from 'micromatch';
import type { CodemodPlugin, ManualMigrationPlugin, Plugin } from './types';
import { transform } from './transform';
import { ManualMigrationReport, findManualMigrations } from './manual';
Expand Down Expand Up @@ -100,6 +101,8 @@ export interface CreateVueMetamorphCliOptions {

type ProgramOptions = {
files: string;
plugins: string[];
listPlugins: boolean;
};

/**
Expand All @@ -111,7 +114,9 @@ export function createVueMetamorphCli(options: CreateVueMetamorphCliOptions) {
const defaultCliProgressHandler = createDefaultCliProgressHandler(console);

program
.requiredOption('--files <glob>', 'Run transforms against these files', '**/src/**/*');
.requiredOption('--files <glob>', 'Run transforms against these files', '**/src/**/*')
.requiredOption('--plugins <glob...>', 'Run only these plugins using micromatch queries', '*')
.option('--list-plugins', 'Print a list of plugins.');

options.additionalCliOptions?.(program);

Expand All @@ -122,6 +127,11 @@ export function createVueMetamorphCli(options: CreateVueMetamorphCliOptions) {
const opts = program.opts<ProgramOptions>();
const stats: Record<string, number> = {};

if (opts.listPlugins) {
process.stdout.write(`${options.plugins.flat().map((plugin) => plugin.name).join('\n')}\n`);
process.exit(0);
}

const files = globSync(opts.files, {
absolute: true,
nodir: true,
Expand All @@ -140,7 +150,11 @@ export function createVueMetamorphCli(options: CreateVueMetamorphCliOptions) {
},
});

const plugins = options.plugins.flat();
const plugins = options
.plugins
.flat()
.filter((plugin) => micromatch.isMatch(plugin.name, opts.plugins));

const codemodPlugins = plugins.filter((plugin): plugin is CodemodPlugin => plugin.type === 'codemod');
const manualMigrationPlugins = plugins.filter((plugin): plugin is ManualMigrationPlugin => plugin.type === 'manual');
const manualMigrationReports: ManualMigrationReport[] = [];
Expand Down

0 comments on commit c872204

Please sign in to comment.