diff --git a/packages/pf-codemods/README.md b/packages/pf-codemods/README.md index 66612183..269409eb 100644 --- a/packages/pf-codemods/README.md +++ b/packages/pf-codemods/README.md @@ -16,7 +16,7 @@ Requires Node.js >= 10. npx @patternfly/pf-codemods ./path-to-src ``` -Note: when updating from PatternFly 5 to 6, add the `--v6` flag. +Use the interactive menu to choose a PatternFly version to update to. Or you can specify the version directly with a flag: ```sh npx @patternfly/pf-codemods --v6 ./path-to-src @@ -45,6 +45,7 @@ Options: --format What eslint report format to use (default: "stylish") --no-cache Disables eslint caching --v4 Run v3 to v4 codemods + --v5 Run v4 to v5 codemods --v6 Run v5 to v6 codemods -h, --help display help for command ``` diff --git a/packages/pf-codemods/index.js b/packages/pf-codemods/index.js index 63e4bdb9..f368bb9f 100755 --- a/packages/pf-codemods/index.js +++ b/packages/pf-codemods/index.js @@ -23,6 +23,7 @@ program .option("--format ", "What eslint report format to use", "stylish") .option("--no-cache", "Disables eslint caching") .option("--v4", "Run v3 to v4 codemods") + .option("--v5", "Run v4 to v5 codemods") .option("--v6", "Run v5 to v6 codemods") .action(runCodemods); @@ -68,14 +69,31 @@ async function printResults(eslint, results, format) { return true; } -function getRulesToRemove(options) { - if (options.v4) { - return [...ruleVersionMapping["v5"], ...ruleVersionMapping["v6"]]; - } else if (options.v6) { - return [...ruleVersionMapping["v4"], ...ruleVersionMapping["v5"]]; - } else { - return [...ruleVersionMapping["v4"], ...ruleVersionMapping["v6"]]; +async function getRulesToRemove(options) { + const pfVersions = ["v6", "v5", "v4"]; + let selectedVersion = pfVersions.find((version) => options[version]); + + if (!selectedVersion) { + const inquirer = await import("inquirer"); + const answer = await inquirer.default.prompt([ + { + type: "list", + name: "version", + message: "What PatternFly version are you updating to?", + choices: [ + { name: "V5 -> V6", value: "v6" }, + { name: "V4 -> V5", value: "v5" }, + { name: "V3 -> V4", value: "v4" }, + ], + }, + ]); + + selectedVersion = answer.version; } + + return pfVersions.flatMap((version) => + version === selectedVersion ? [] : ruleVersionMapping[version] + ); } async function runCodemods(path, otherPaths, options) { @@ -95,7 +113,7 @@ async function runCodemods(path, otherPaths, options) { .forEach((rule) => delete configs.recommended.rules[prefix + rule]); } - const rulesToRemove = getRulesToRemove(options); + const rulesToRemove = await getRulesToRemove(options); rulesToRemove.forEach((rule) => { // data-codemods-cleanup rule should exist for any version of codemods diff --git a/packages/pf-codemods/package.json b/packages/pf-codemods/package.json index 4762cf8a..cc3426af 100644 --- a/packages/pf-codemods/package.json +++ b/packages/pf-codemods/package.json @@ -19,6 +19,7 @@ "@typescript-eslint/parser": "^7.3.1", "commander": "^5.1.0", "eslint": "^7.3.0 || ^8.56.0", + "inquirer": "^12.3.2", "typescript": "^5.4.2" } } diff --git a/packages/pf-codemods/scripts/baseReadMe.md b/packages/pf-codemods/scripts/baseReadMe.md index 5cab0762..214d3441 100644 --- a/packages/pf-codemods/scripts/baseReadMe.md +++ b/packages/pf-codemods/scripts/baseReadMe.md @@ -16,7 +16,7 @@ Requires Node.js >= 10. npx @patternfly/pf-codemods ./path-to-src ``` -Note: when updating from PatternFly 5 to 6, add the `--v6` flag. +Use the interactive menu to choose a PatternFly version to update to. Or you can specify the version directly with a flag: ```sh npx @patternfly/pf-codemods --v6 ./path-to-src @@ -45,6 +45,7 @@ Options: --format What eslint report format to use (default: "stylish") --no-cache Disables eslint caching --v4 Run v3 to v4 codemods + --v5 Run v4 to v5 codemods --v6 Run v5 to v6 codemods -h, --help display help for command ``` diff --git a/yarn.lock b/yarn.lock index 552ef9d2..732029ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -977,7 +977,7 @@ __metadata: languageName: unknown linkType: soft -"@patternfly/eslint-plugin-pf-codemods@npm:^1.139.1, @patternfly/eslint-plugin-pf-codemods@workspace:packages/eslint-plugin-pf-codemods": +"@patternfly/eslint-plugin-pf-codemods@npm:^1.139.4, @patternfly/eslint-plugin-pf-codemods@workspace:packages/eslint-plugin-pf-codemods": version: 0.0.0-use.local resolution: "@patternfly/eslint-plugin-pf-codemods@workspace:packages/eslint-plugin-pf-codemods" dependencies: @@ -996,10 +996,11 @@ __metadata: version: 0.0.0-use.local resolution: "@patternfly/pf-codemods@workspace:packages/pf-codemods" dependencies: - "@patternfly/eslint-plugin-pf-codemods": "npm:^1.139.1" + "@patternfly/eslint-plugin-pf-codemods": "npm:^1.139.4" "@typescript-eslint/parser": "npm:^7.3.1" commander: "npm:^5.1.0" eslint: "npm:^7.3.0 || ^8.56.0" + inquirer: "npm:^12.3.2" typescript: "npm:^5.4.2" bin: pf-codemods: ./index.js