UNPKG

@reliverse/rse

Version:

@reliverse/rse is your all-in-one companion for bootstrapping and improving any kind of projects (especially web apps built with frameworks like Next.js) — whether you're kicking off something new or upgrading an existing app. It is also a little AI-power

67 lines (66 loc) 1.94 kB
import { re } from "@reliverse/relico"; import { defineCommand } from "@reliverse/rempts"; import { prompt } from "enquirer"; import { runCodemods } from "../../libs/sdk/cmod/cmod-impl.js"; const sampleCodemods = [ "use-react-router-v6", "migrate-to-nextjs-14", "class-to-functional", "js-to-ts", "react/19/migration-recipe" ]; export default defineCommand({ meta: { name: "cmod", description: "Run codemods via the codemod CLI" }, args: { // List of codemod names, if user wants to directly apply them codemods: { type: "positional", required: false, array: true, description: "Names of codemods to run (e.g. react/19/migration-recipe)" }, dry: { type: "boolean", description: "Perform a dry run without applying changes", default: false, required: false }, format: { type: "boolean", description: "Enable biome formatting after codemod runs", default: false, required: false }, include: { type: "string", description: "Glob pattern for files to include", required: false }, exclude: { type: "string", description: "Glob pattern for files to exclude", required: false } }, run: async ({ args }) => { const { codemods, dry, format, include, exclude } = args; if (codemods && codemods.length > 0) { return await runCodemods([codemods], { dry, format, include, exclude }); } console.log(re.green("\n\u25C6 Rse Codemod Selection\n")); const { chosen } = await prompt({ type: "multiselect", name: "chosen", message: "Select one or more codemods to run:", choices: sampleCodemods.map((cm) => ({ name: cm })) }); if (!chosen || chosen.length === 0) { console.log(re.yellow("No codemods selected. Exiting...")); return; } await runCodemods(chosen, { dry, format, include, exclude }); } });