Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/pf-codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,6 +45,7 @@ Options:
--format <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
```
Expand Down
34 changes: 26 additions & 8 deletions packages/pf-codemods/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ program
.option("--format <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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/pf-codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 2 additions & 1 deletion packages/pf-codemods/scripts/baseReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,6 +45,7 @@ Options:
--format <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
```
Expand Down
5 changes: 3 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Loading