diff --git a/packages/pf-codemods/README.md b/packages/pf-codemods/README.md index ea5eb9dc..bf1d5ee8 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 d8700bce..85ef13f3 100644 --- a/packages/pf-codemods/package.json +++ b/packages/pf-codemods/package.json @@ -21,6 +21,7 @@ "@typescript-eslint/parser": "^7.3.1", "commander": "^5.1.0", "eslint": "^7.3.0 || ^8.29.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 2170e7d4..04f29746 100644 --- a/yarn.lock +++ b/yarn.lock @@ -155,6 +155,139 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== +"@inquirer/checkbox@^4.0.6": + version "4.0.6" + resolved "https://registry.yarnpkg.com/@inquirer/checkbox/-/checkbox-4.0.6.tgz#e71401a7e1900332f17ed68c172a89fe20225f49" + integrity sha512-PgP35JfmGjHU0LSXOyRew0zHuA9N6OJwOlos1fZ20b7j8ISeAdib3L+n0jIxBtX958UeEpte6xhG/gxJ5iUqMw== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/figures" "^1.0.9" + "@inquirer/type" "^3.0.2" + ansi-escapes "^4.3.2" + yoctocolors-cjs "^2.1.2" + +"@inquirer/confirm@^5.1.3": + version "5.1.3" + resolved "https://registry.yarnpkg.com/@inquirer/confirm/-/confirm-5.1.3.tgz#c1ad57663f54758981811ccb86f823072ddf5c1a" + integrity sha512-fuF9laMmHoOgWapF9h9hv6opA5WvmGFHsTYGCmuFxcghIhEhb3dN0CdQR4BUMqa2H506NCj8cGX4jwMsE4t6dA== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/type" "^3.0.2" + +"@inquirer/core@^10.1.4": + version "10.1.4" + resolved "https://registry.yarnpkg.com/@inquirer/core/-/core-10.1.4.tgz#02394e68d894021935caca0d10fc68fd4f3a3ead" + integrity sha512-5y4/PUJVnRb4bwWY67KLdebWOhOc7xj5IP2J80oWXa64mVag24rwQ1VAdnj7/eDY/odhguW0zQ1Mp1pj6fO/2w== + dependencies: + "@inquirer/figures" "^1.0.9" + "@inquirer/type" "^3.0.2" + ansi-escapes "^4.3.2" + cli-width "^4.1.0" + mute-stream "^2.0.0" + signal-exit "^4.1.0" + strip-ansi "^6.0.1" + wrap-ansi "^6.2.0" + yoctocolors-cjs "^2.1.2" + +"@inquirer/editor@^4.2.3": + version "4.2.3" + resolved "https://registry.yarnpkg.com/@inquirer/editor/-/editor-4.2.3.tgz#0858adcd07d9607b0614778eaa5ce8a83871c367" + integrity sha512-S9KnIOJuTZpb9upeRSBBhoDZv7aSV3pG9TECrBj0f+ZsFwccz886hzKBrChGrXMJwd4NKY+pOA9Vy72uqnd6Eg== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/type" "^3.0.2" + external-editor "^3.1.0" + +"@inquirer/expand@^4.0.6": + version "4.0.6" + resolved "https://registry.yarnpkg.com/@inquirer/expand/-/expand-4.0.6.tgz#8676e6049c6114fb306df23358375bd84fa1c92c" + integrity sha512-TRTfi1mv1GeIZGyi9PQmvAaH65ZlG4/FACq6wSzs7Vvf1z5dnNWsAAXBjWMHt76l+1hUY8teIqJFrWBk5N6gsg== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/type" "^3.0.2" + yoctocolors-cjs "^2.1.2" + +"@inquirer/figures@^1.0.9": + version "1.0.9" + resolved "https://registry.yarnpkg.com/@inquirer/figures/-/figures-1.0.9.tgz#9d8128f8274cde4ca009ca8547337cab3f37a4a3" + integrity sha512-BXvGj0ehzrngHTPTDqUoDT3NXL8U0RxUk2zJm2A66RhCEIWdtU1v6GuUqNAgArW4PQ9CinqIWyHdQgdwOj06zQ== + +"@inquirer/input@^4.1.3": + version "4.1.3" + resolved "https://registry.yarnpkg.com/@inquirer/input/-/input-4.1.3.tgz#fa0ea9a392b2ec4ddd763c504d0b0c8839a48fe2" + integrity sha512-zeo++6f7hxaEe7OjtMzdGZPHiawsfmCZxWB9X1NpmYgbeoyerIbWemvlBxxl+sQIlHC0WuSAG19ibMq3gbhaqQ== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/type" "^3.0.2" + +"@inquirer/number@^3.0.6": + version "3.0.6" + resolved "https://registry.yarnpkg.com/@inquirer/number/-/number-3.0.6.tgz#19bba46725df194bdd907762cf432a37e053b300" + integrity sha512-xO07lftUHk1rs1gR0KbqB+LJPhkUNkyzV/KhH+937hdkMazmAYHLm1OIrNKpPelppeV1FgWrgFDjdUD8mM+XUg== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/type" "^3.0.2" + +"@inquirer/password@^4.0.6": + version "4.0.6" + resolved "https://registry.yarnpkg.com/@inquirer/password/-/password-4.0.6.tgz#4bbee12fe7cd1d37435401098c296ddc4586861b" + integrity sha512-QLF0HmMpHZPPMp10WGXh6F+ZPvzWE7LX6rNoccdktv/Rov0B+0f+eyXkAcgqy5cH9V+WSpbLxu2lo3ysEVK91w== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/type" "^3.0.2" + ansi-escapes "^4.3.2" + +"@inquirer/prompts@^7.2.3": + version "7.2.3" + resolved "https://registry.yarnpkg.com/@inquirer/prompts/-/prompts-7.2.3.tgz#8a0d7cb5310d429bf815d25bbff108375fc6315b" + integrity sha512-hzfnm3uOoDySDXfDNOm9usOuYIaQvTgKp/13l1uJoe6UNY+Zpcn2RYt0jXz3yA+yemGHvDOxVzqWl3S5sQq53Q== + dependencies: + "@inquirer/checkbox" "^4.0.6" + "@inquirer/confirm" "^5.1.3" + "@inquirer/editor" "^4.2.3" + "@inquirer/expand" "^4.0.6" + "@inquirer/input" "^4.1.3" + "@inquirer/number" "^3.0.6" + "@inquirer/password" "^4.0.6" + "@inquirer/rawlist" "^4.0.6" + "@inquirer/search" "^3.0.6" + "@inquirer/select" "^4.0.6" + +"@inquirer/rawlist@^4.0.6": + version "4.0.6" + resolved "https://registry.yarnpkg.com/@inquirer/rawlist/-/rawlist-4.0.6.tgz#b55d5828d850f07bc6792bbce3b2a963e33b3ef5" + integrity sha512-QoE4s1SsIPx27FO4L1b1mUjVcoHm1pWE/oCmm4z/Hl+V1Aw5IXl8FYYzGmfXaBT0l/sWr49XmNSiq7kg3Kd/Lg== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/type" "^3.0.2" + yoctocolors-cjs "^2.1.2" + +"@inquirer/search@^3.0.6": + version "3.0.6" + resolved "https://registry.yarnpkg.com/@inquirer/search/-/search-3.0.6.tgz#5537e3f46b7d31ab65ca22b831cf546f88db1d5b" + integrity sha512-eFZ2hiAq0bZcFPuFFBmZEtXU1EarHLigE+ENCtpO+37NHCl4+Yokq1P/d09kUblObaikwfo97w+0FtG/EXl5Ng== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/figures" "^1.0.9" + "@inquirer/type" "^3.0.2" + yoctocolors-cjs "^2.1.2" + +"@inquirer/select@^4.0.6": + version "4.0.6" + resolved "https://registry.yarnpkg.com/@inquirer/select/-/select-4.0.6.tgz#3062c02c82f7bbe238972672def6d8394732bb2b" + integrity sha512-yANzIiNZ8fhMm4NORm+a74+KFYHmf7BZphSOBovIzYPVLquseTGEkU5l2UTnBOf5k0VLmTgPighNDLE9QtbViQ== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/figures" "^1.0.9" + "@inquirer/type" "^3.0.2" + ansi-escapes "^4.3.2" + yoctocolors-cjs "^2.1.2" + +"@inquirer/type@^3.0.2": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@inquirer/type/-/type-3.0.2.tgz#baff9f8d70947181deb36772cd9a5b6876d3e60c" + integrity sha512-ZhQ4TvhwHZF+lGhQ2O/rsjo80XoZR5/5qhOY3t6FJuX5XBg5Be8YzYTvaUGJnc12AUGI2nr4QSUE4PhKSigx7g== + "@isaacs/cliui@^8.0.2": version "8.0.2" resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550" @@ -1297,7 +1430,7 @@ ansi-escapes@^3.2.0: resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b" integrity sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ== -ansi-escapes@^4.2.1: +ansi-escapes@^4.2.1, ansi-escapes@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.2.tgz#6b2291d1db7d98b6521d5f1efa42d0f3a9feb65e" integrity sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ== @@ -1934,6 +2067,11 @@ cli-width@^3.0.0: resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== +cli-width@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-4.1.0.tgz#42daac41d3c254ef38ad8ac037672130173691c5" + integrity sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ== + cliui@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5" @@ -2756,7 +2894,7 @@ extend@^3.0.2, extend@~3.0.2: resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== -external-editor@^3.0.3: +external-editor@^3.0.3, external-editor@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495" integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew== @@ -3626,6 +3764,19 @@ init-package-json@^1.10.3: validate-npm-package-license "^3.0.1" validate-npm-package-name "^3.0.0" +inquirer@^12.3.2: + version "12.3.2" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-12.3.2.tgz#afa6e8573f9e9ca408335b4936ae32cbea708c22" + integrity sha512-YjQCIcDd3yyDuQrbII0FBtm/ZqNoWtvaC71yeCnd5Vbg4EgzsAGaemzfpzmqfvIZEp2roSwuZZKdM0C65hA43g== + dependencies: + "@inquirer/core" "^10.1.4" + "@inquirer/prompts" "^7.2.3" + "@inquirer/type" "^3.0.2" + ansi-escapes "^4.3.2" + mute-stream "^2.0.0" + run-async "^3.0.0" + rxjs "^7.8.1" + inquirer@^6.2.0: version "6.5.2" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.5.2.tgz#ad50942375d036d327ff528c08bd5fab089928ca" @@ -4750,6 +4901,11 @@ mute-stream@0.0.8, mute-stream@~0.0.4: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== +mute-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-2.0.0.tgz#a5446fc0c512b71c83c44d908d5c7b7b4c493b2b" + integrity sha512-WWdIxpyjEn+FhQJQQv9aQAYlHoNVdzIzUySNV1gHUPDSdZJ3yZn7pAAbQcV7B56Mvu881q9FZV+0Vx2xC44VWA== + mz@^2.5.0: version "2.7.0" resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32" @@ -5945,6 +6101,11 @@ run-async@^2.2.0, run-async@^2.4.0: resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455" integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ== +run-async@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/run-async/-/run-async-3.0.0.tgz#42a432f6d76c689522058984384df28be379daad" + integrity sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q== + run-parallel@^1.1.9: version "1.2.0" resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee" @@ -5973,6 +6134,13 @@ rxjs@^7.2.0, rxjs@^7.5.5: dependencies: tslib "^2.1.0" +rxjs@^7.8.1: + version "7.8.1" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543" + integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg== + dependencies: + tslib "^2.1.0" + safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" @@ -6077,6 +6245,11 @@ signal-exit@^4.0.1: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.0.2.tgz#ff55bb1d9ff2114c13b400688fa544ac63c36967" integrity sha512-MY2/qGx4enyjprQnFaZsHib3Yadh3IXyV2C321GY0pjGfVBu4un0uDJkwgdxqO+Rdx8JMT8IfJIRwbYVz3Ob3Q== +signal-exit@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.1.0.tgz#952188c1cbd546070e2dd20d0f41c0ae0530cb04" + integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw== + slash@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" @@ -7035,6 +7208,15 @@ wrap-ansi@^5.1.0: string-width "^3.0.0" strip-ansi "^5.0.0" +wrap-ansi@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" + integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" @@ -7194,3 +7376,8 @@ yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== + +yoctocolors-cjs@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz#f4b905a840a37506813a7acaa28febe97767a242" + integrity sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA==