CLI Options
vue-metamorph provides a CLI codemod runner to faciliate running codemods against many files.
Options
Option | Description | Default |
---|---|---|
--help | Print available options | N/A |
--list-plugins | Lists all registered plugins and exists | N/A |
--files <glob> | Run transforms against these files using a glob pattern | '**/src/**/*' |
--plugins <glob> | Only run plugins matching these micromatch patterns. This option can be passed multiple times to specify multiple patterns | '*' |
API
ts
import { } from 'vue-metamorph';
const { , } = ({
: true, // suppress vue-metamorph's default output by setting silent:true
({
,
,
,
,
,
,
,
,
}) {
// called every time a file was transformed
// also called when vue-metamorph finished processing all files (with done:true)
// also called when vue-metamorph was aborted via the `abort()` function (with aborted:true)
},
// register your CodemodPlugins and/or ManualMigrationPlugins here
: [],
});
();
// call abort() to gracefully stop the runner
// process.on('SIGINT', abort);
Adding Additional Custom CLI Options
You may attach additional arguments to your vue-metamorph CLI using the additionalCliOptions
property. See the commander.js docs for info on the .option()
and .requiredOption()
functions.
Options will be passed to the CodemodPlugin transform()
and ManualMigrationPlugin find()
functions as the opts
parameter.
ts
const myCodemod: CodemodPlugin = {
name: 'myCodemod',
type: 'codemod',
transform({ opts }) {
if (opts.myCustomOption) {
// do something
} else {
// do something else
}
}
}
const {
run,
abort,
opts,
} = createVueMetamorphCli({
plugins: [
myCodemod,
// ...
],
additionalCliOptions: (program) => {
// call program.option() or program.requiredOption() to add new options
program
.option('--my-custom-option')
.option('--some-other-option');
}
});
// if you need the options outside of a codemod or manual migration, call opts()
if (opts().myCustomOption) {
console.error('do not use this option');
process.exit(1);
}