Installation
There are two ways to use vue-metamorph. You can use the scaffolding tool to create a vue-metamorph CLI project, or you can import vue-metamorph into an app or library that you already have.
Scaffold and run a codemod project
The scaffolding command copies a sample project. The generated CLI runs your plugins. To create the project and try its sample plugin, follow these steps:
Create the project and install its dependencies:
bashnpx vue-metamorph my-codemod-name cd my-codemod-name npm installOpen
src/plugins/hello-world.tsto inspect the sample plugin. It replaces script string literals withHello, world!. Thesrc/main.tsfile registers the plugin.Create a file named
sample.jsin the project directory with this content:jsconst message = 'Goodbye';Build the CLI and check that the plugin is registered:
bashnpm run build node dist/cli.js --list-pluginsThe output includes
hello-world. Rebuild after changing a plugin or its registration.Run the plugin on the sample file:
bashnode dist/cli.js --files 'sample.js' --plugins 'hello-world'The CLI writes changes directly to matching files. After this command,
sample.jscontains:jsconst message = 'Hello, world!';
To apply the CLI to your own project, replace 'sample.js' with a quoted file pattern, such as '../my-app/src/**/*.vue'. Relative patterns start from your terminal's working directory. Review the plugin before running it on your source files.
For plugin authoring, see Write a codemod. For runner options, see Command-line interface.
Install vue-metamorph in an existing package
To add vue-metamorph to a package that you already have, install it as a development dependency:
# npm
npm install -D vue-metamorph
# yarn
yarn add -D vue-metamorph
# pnpm
pnpm add -D vue-metamorph