Skip to content

Commit 6c8752a

Browse files
authored
chore: update CLI to force choosing PF version (#814)
1 parent 3bacbc6 commit 6c8752a

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

packages/pf-codemods/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Requires Node.js >= 10.
1616
npx @patternfly/pf-codemods ./path-to-src
1717
```
1818

19-
Note: when updating from PatternFly 5 to 6, add the `--v6` flag.
19+
Use the interactive menu to choose a PatternFly version to update to. Or you can specify the version directly with a flag:
2020

2121
```sh
2222
npx @patternfly/pf-codemods --v6 ./path-to-src
@@ -45,6 +45,7 @@ Options:
4545
--format <format> What eslint report format to use (default: "stylish")
4646
--no-cache Disables eslint caching
4747
--v4 Run v3 to v4 codemods
48+
--v5 Run v4 to v5 codemods
4849
--v6 Run v5 to v6 codemods
4950
-h, --help display help for command
5051
```

packages/pf-codemods/index.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ program
2323
.option("--format <format>", "What eslint report format to use", "stylish")
2424
.option("--no-cache", "Disables eslint caching")
2525
.option("--v4", "Run v3 to v4 codemods")
26+
.option("--v5", "Run v4 to v5 codemods")
2627
.option("--v6", "Run v5 to v6 codemods")
2728
.action(runCodemods);
2829

@@ -68,14 +69,31 @@ async function printResults(eslint, results, format) {
6869
return true;
6970
}
7071

71-
function getRulesToRemove(options) {
72-
if (options.v4) {
73-
return [...ruleVersionMapping["v5"], ...ruleVersionMapping["v6"]];
74-
} else if (options.v6) {
75-
return [...ruleVersionMapping["v4"], ...ruleVersionMapping["v5"]];
76-
} else {
77-
return [...ruleVersionMapping["v4"], ...ruleVersionMapping["v6"]];
72+
async function getRulesToRemove(options) {
73+
const pfVersions = ["v6", "v5", "v4"];
74+
let selectedVersion = pfVersions.find((version) => options[version]);
75+
76+
if (!selectedVersion) {
77+
const inquirer = await import("inquirer");
78+
const answer = await inquirer.default.prompt([
79+
{
80+
type: "list",
81+
name: "version",
82+
message: "What PatternFly version are you updating to?",
83+
choices: [
84+
{ name: "V5 -> V6", value: "v6" },
85+
{ name: "V4 -> V5", value: "v5" },
86+
{ name: "V3 -> V4", value: "v4" },
87+
],
88+
},
89+
]);
90+
91+
selectedVersion = answer.version;
7892
}
93+
94+
return pfVersions.flatMap((version) =>
95+
version === selectedVersion ? [] : ruleVersionMapping[version]
96+
);
7997
}
8098

8199
async function runCodemods(path, otherPaths, options) {
@@ -95,7 +113,7 @@ async function runCodemods(path, otherPaths, options) {
95113
.forEach((rule) => delete configs.recommended.rules[prefix + rule]);
96114
}
97115

98-
const rulesToRemove = getRulesToRemove(options);
116+
const rulesToRemove = await getRulesToRemove(options);
99117

100118
rulesToRemove.forEach((rule) => {
101119
// data-codemods-cleanup rule should exist for any version of codemods

packages/pf-codemods/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@typescript-eslint/parser": "^7.3.1",
2020
"commander": "^5.1.0",
2121
"eslint": "^7.3.0 || ^8.56.0",
22+
"inquirer": "^12.3.2",
2223
"typescript": "^5.4.2"
2324
}
2425
}

packages/pf-codemods/scripts/baseReadMe.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Requires Node.js >= 10.
1616
npx @patternfly/pf-codemods ./path-to-src
1717
```
1818

19-
Note: when updating from PatternFly 5 to 6, add the `--v6` flag.
19+
Use the interactive menu to choose a PatternFly version to update to. Or you can specify the version directly with a flag:
2020

2121
```sh
2222
npx @patternfly/pf-codemods --v6 ./path-to-src
@@ -45,6 +45,7 @@ Options:
4545
--format <format> What eslint report format to use (default: "stylish")
4646
--no-cache Disables eslint caching
4747
--v4 Run v3 to v4 codemods
48+
--v5 Run v4 to v5 codemods
4849
--v6 Run v5 to v6 codemods
4950
-h, --help display help for command
5051
```

yarn.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ __metadata:
977977
languageName: unknown
978978
linkType: soft
979979

980-
"@patternfly/eslint-plugin-pf-codemods@npm:^1.139.1, @patternfly/eslint-plugin-pf-codemods@workspace:packages/eslint-plugin-pf-codemods":
980+
"@patternfly/eslint-plugin-pf-codemods@npm:^1.139.4, @patternfly/eslint-plugin-pf-codemods@workspace:packages/eslint-plugin-pf-codemods":
981981
version: 0.0.0-use.local
982982
resolution: "@patternfly/eslint-plugin-pf-codemods@workspace:packages/eslint-plugin-pf-codemods"
983983
dependencies:
@@ -996,10 +996,11 @@ __metadata:
996996
version: 0.0.0-use.local
997997
resolution: "@patternfly/pf-codemods@workspace:packages/pf-codemods"
998998
dependencies:
999-
"@patternfly/eslint-plugin-pf-codemods": "npm:^1.139.1"
999+
"@patternfly/eslint-plugin-pf-codemods": "npm:^1.139.4"
10001000
"@typescript-eslint/parser": "npm:^7.3.1"
10011001
commander: "npm:^5.1.0"
10021002
eslint: "npm:^7.3.0 || ^8.56.0"
1003+
inquirer: "npm:^12.3.2"
10031004
typescript: "npm:^5.4.2"
10041005
bin:
10051006
pf-codemods: ./index.js

0 commit comments

Comments
 (0)