From 3cc6393a62f938ab9400029aa5964086fc511bb3 Mon Sep 17 00:00:00 2001 From: Jessie Date: Tue, 19 Mar 2024 17:40:54 -0400 Subject: [PATCH 1/7] Add pfVersion option --- packages/class-name-updater/src/classNameUpdate.ts | 4 ++-- packages/class-name-updater/src/cli.ts | 8 ++++++-- packages/class-name-updater/test/test.css | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/class-name-updater/src/classNameUpdate.ts b/packages/class-name-updater/src/classNameUpdate.ts index ef993040f..8d7f266f2 100644 --- a/packages/class-name-updater/src/classNameUpdate.ts +++ b/packages/class-name-updater/src/classNameUpdate.ts @@ -4,11 +4,11 @@ import { join } from "path"; import { isDir } from "./utils"; import { printDiff } from "./printDiff"; -export async function classNameUpdate(globTarget: string, makeChange: boolean, fileTypesRegex: RegExp, excludeFiles: string[] = []) { +export async function classNameUpdate(globTarget: string, makeChange: boolean, fileTypesRegex: RegExp, excludeFiles: string[] = [], pfVersion: string) { const acceptedFileTypesRegex = fileTypesRegex || /\.(s?css|less|(t|j)sx?|md)$/; const changeNeededRegex = /(\b|\$)pf-([cul]|global|theme|color)-/g; - const version = "v5"; + const version = "v5" || pfVersion; const files = sync(globTarget, { ignore: "**/node_modules/**" }); const includedFiles = files.filter((filePath: string) => !excludeFiles.includes(filePath)) diff --git a/packages/class-name-updater/src/cli.ts b/packages/class-name-updater/src/cli.ts index 8e4e467ed..8a51e945e 100755 --- a/packages/class-name-updater/src/cli.ts +++ b/packages/class-name-updater/src/cli.ts @@ -21,12 +21,16 @@ program "Comma-delineated list of files to exclude, files should include their path relative to where this utility is being called" ) .option("--fix", "Whether to run fixer") + .option( + "--pfVersion ", + "Version of PatternFly to use" + ) .action(runClassNameUpdate); async function runClassNameUpdate( path: string, otherPaths: string, - options: { extensions: string; fix: boolean; exclude: string[] | undefined } + options: { extensions: string; fix: boolean; exclude: string[] | undefined; pfVersion: string;} ) { let allPaths = [path, ...otherPaths]; @@ -45,7 +49,7 @@ async function runClassNameUpdate( } allPaths.forEach(async (path) => { - await classNameUpdate(path, options.fix, fileTypes, options.exclude); + await classNameUpdate(path, options.fix, fileTypes, options.exclude, options.pfVersion); }); } diff --git a/packages/class-name-updater/test/test.css b/packages/class-name-updater/test/test.css index b6972c05a..b4b1b7172 100644 --- a/packages/class-name-updater/test/test.css +++ b/packages/class-name-updater/test/test.css @@ -20,3 +20,7 @@ .pf-u-screen-reader > .pf-l-stack__item{ color: red; } + + .pf-v5-c-toolbar__item { + color: green; + } From 254afedbdad9e76135d89b1feb5df919ca484447 Mon Sep 17 00:00:00 2001 From: Jessie Date: Wed, 20 Mar 2024 12:11:55 -0400 Subject: [PATCH 2/7] Update regex --- .../class-name-updater/src/classNameUpdate.ts | 15 ++++++++++----- packages/class-name-updater/src/cli.ts | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/class-name-updater/src/classNameUpdate.ts b/packages/class-name-updater/src/classNameUpdate.ts index 8d7f266f2..9764cf104 100644 --- a/packages/class-name-updater/src/classNameUpdate.ts +++ b/packages/class-name-updater/src/classNameUpdate.ts @@ -4,11 +4,16 @@ import { join } from "path"; import { isDir } from "./utils"; import { printDiff } from "./printDiff"; -export async function classNameUpdate(globTarget: string, makeChange: boolean, fileTypesRegex: RegExp, excludeFiles: string[] = [], pfVersion: string) { +export async function classNameUpdate(globTarget: string, makeChange: boolean, fileTypesRegex: RegExp, excludeFiles: string[] = [], pfVersion: number) { const acceptedFileTypesRegex = fileTypesRegex || /\.(s?css|less|(t|j)sx?|md)$/; - - const changeNeededRegex = /(\b|\$)pf-([cul]|global|theme|color)-/g; - const version = "v5" || pfVersion; + // const changeNeededRegex = /(\b|\$)pf-([cul]|global|theme|color)-/g; + const previousVersion = pfVersion ? ("v" + (pfVersion - 1)) : "" + const changeNeededRegex = new RegExp( + "(\b|\$)pf-" + + previousVersion + + "([cul]|global|theme|color)" + ) + const newVersion = pfVersion || 5 const files = sync(globTarget, { ignore: "**/node_modules/**" }); const includedFiles = files.filter((filePath: string) => !excludeFiles.includes(filePath)) @@ -31,7 +36,7 @@ export async function classNameUpdate(globTarget: string, makeChange: boolean, f const newContent = fileContent.replace( changeNeededRegex, - `$1pf-${version}-$2-` + `$1pf-v${newVersion}-$2-` ); printDiff(file, fileContent, newContent, changeNeededRegex); diff --git a/packages/class-name-updater/src/cli.ts b/packages/class-name-updater/src/cli.ts index 8a51e945e..a31eef7f1 100755 --- a/packages/class-name-updater/src/cli.ts +++ b/packages/class-name-updater/src/cli.ts @@ -23,14 +23,14 @@ program .option("--fix", "Whether to run fixer") .option( "--pfVersion ", - "Version of PatternFly to use" + "Version of PatternFly to use, pass just the version number." ) .action(runClassNameUpdate); async function runClassNameUpdate( path: string, otherPaths: string, - options: { extensions: string; fix: boolean; exclude: string[] | undefined; pfVersion: string;} + options: { extensions: string; fix: boolean; exclude: string[] | undefined; pfVersion: number;} ) { let allPaths = [path, ...otherPaths]; From f6a7bd24fbc1e55fcd52f10b61391191a997f6cc Mon Sep 17 00:00:00 2001 From: Jessie Date: Thu, 21 Mar 2024 09:48:39 -0400 Subject: [PATCH 3/7] Fix regex --- packages/class-name-updater/src/classNameUpdate.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/class-name-updater/src/classNameUpdate.ts b/packages/class-name-updater/src/classNameUpdate.ts index 9764cf104..3735fe39c 100644 --- a/packages/class-name-updater/src/classNameUpdate.ts +++ b/packages/class-name-updater/src/classNameUpdate.ts @@ -7,12 +7,11 @@ import { printDiff } from "./printDiff"; export async function classNameUpdate(globTarget: string, makeChange: boolean, fileTypesRegex: RegExp, excludeFiles: string[] = [], pfVersion: number) { const acceptedFileTypesRegex = fileTypesRegex || /\.(s?css|less|(t|j)sx?|md)$/; // const changeNeededRegex = /(\b|\$)pf-([cul]|global|theme|color)-/g; - const previousVersion = pfVersion ? ("v" + (pfVersion - 1)) : "" + const previousVersion = pfVersion ? "-v" + (pfVersion - 1) : ""; const changeNeededRegex = new RegExp( - "(\b|\$)pf-" + - previousVersion + - "([cul]|global|theme|color)" - ) + "(\\b|\\$)pf" + previousVersion + "-([cul]|global|theme|color)-", + "g" + ); const newVersion = pfVersion || 5 const files = sync(globTarget, { ignore: "**/node_modules/**" }); From 00f9e54fc73a906784579076d95ebe67744d8568 Mon Sep 17 00:00:00 2001 From: Jessie Date: Tue, 26 Mar 2024 14:47:21 -0400 Subject: [PATCH 4/7] Update test scripts --- packages/class-name-updater/package.json | 3 ++- packages/class-name-updater/src/classNameUpdate.ts | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/class-name-updater/package.json b/packages/class-name-updater/package.json index 5e21fc29f..edf486fb2 100644 --- a/packages/class-name-updater/package.json +++ b/packages/class-name-updater/package.json @@ -16,7 +16,8 @@ "scripts": { "build": "tsc --build --verbose ./tsconfig.json", "clean": "rimraf ./dist", - "test": "node ./dist/cli.js test --exclude test/largeFile.js" + "test": "node ./dist/cli.js test --exclude test/largeFile.js", + "test:v6": "node ./dist/cli.js test --exclude test/largeFile.js --pfVersion 6" }, "dependencies": { "colors": "^1.4.0", diff --git a/packages/class-name-updater/src/classNameUpdate.ts b/packages/class-name-updater/src/classNameUpdate.ts index 3735fe39c..957f79026 100644 --- a/packages/class-name-updater/src/classNameUpdate.ts +++ b/packages/class-name-updater/src/classNameUpdate.ts @@ -6,7 +6,6 @@ import { printDiff } from "./printDiff"; export async function classNameUpdate(globTarget: string, makeChange: boolean, fileTypesRegex: RegExp, excludeFiles: string[] = [], pfVersion: number) { const acceptedFileTypesRegex = fileTypesRegex || /\.(s?css|less|(t|j)sx?|md)$/; - // const changeNeededRegex = /(\b|\$)pf-([cul]|global|theme|color)-/g; const previousVersion = pfVersion ? "-v" + (pfVersion - 1) : ""; const changeNeededRegex = new RegExp( "(\\b|\\$)pf" + previousVersion + "-([cul]|global|theme|color)-", From 5259c9a92eae603089d18a8c2e08c5c597f7dbca Mon Sep 17 00:00:00 2001 From: Jessie Date: Tue, 26 Mar 2024 15:15:27 -0400 Subject: [PATCH 5/7] Top level scripts --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 252354455..1194f2406 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,10 @@ "test:console": "pf-codemods --v6 --no-cache test/console/frontend", "test:integreatly": "pf-codemods --v6 --no-cache test/tutorial-web-app", "test:packages": "yarn get:packages && node --unhandled-rejections=strict packages/pf-codemods/index.js --v6 --no-cache test/packages", - "test:classnames": "yarn build:classnames && lerna run test --scope=@patternfly/class-name-updater --stream", + "test:classnames": "yarn test:classnames:v5 && test:classnames:v6:nobuild", + "test:classnames:v5": "yarn build:classnames && lerna run test --scope=@patternfly/class-name-updater --stream", + "test:classnames:v6": "yarn build:classnames && lerna run test:v6 --scope=@patternfly/class-name-updater --stream", + "test:classnames:v6:nobuild": "lerna run test:v6 --scope=@patternfly/class-name-updater --stream", "get:packages": "node getPackages.js", "generate": "yarn build:generators && plop", "build": "lerna run build", From ab9b2a51f6919efefbde5cd7ac75d212730dd703 Mon Sep 17 00:00:00 2001 From: Jessie Date: Tue, 26 Mar 2024 15:24:07 -0400 Subject: [PATCH 6/7] Refactor scripts based on feedback --- package.json | 5 ++--- packages/class-name-updater/package.json | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1194f2406..f23caf79f 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,9 @@ "test:console": "pf-codemods --v6 --no-cache test/console/frontend", "test:integreatly": "pf-codemods --v6 --no-cache test/tutorial-web-app", "test:packages": "yarn get:packages && node --unhandled-rejections=strict packages/pf-codemods/index.js --v6 --no-cache test/packages", - "test:classnames": "yarn test:classnames:v5 && test:classnames:v6:nobuild", - "test:classnames:v5": "yarn build:classnames && lerna run test --scope=@patternfly/class-name-updater --stream", + "test:classnames": "lerna run test --scope=@patternfly/class-name-updater --stream", + "test:classnames:v5": "yarn build:classnames && lerna run test:v5 --scope=@patternfly/class-name-updater --stream", "test:classnames:v6": "yarn build:classnames && lerna run test:v6 --scope=@patternfly/class-name-updater --stream", - "test:classnames:v6:nobuild": "lerna run test:v6 --scope=@patternfly/class-name-updater --stream", "get:packages": "node getPackages.js", "generate": "yarn build:generators && plop", "build": "lerna run build", diff --git a/packages/class-name-updater/package.json b/packages/class-name-updater/package.json index edf486fb2..26e60ccfb 100644 --- a/packages/class-name-updater/package.json +++ b/packages/class-name-updater/package.json @@ -16,7 +16,8 @@ "scripts": { "build": "tsc --build --verbose ./tsconfig.json", "clean": "rimraf ./dist", - "test": "node ./dist/cli.js test --exclude test/largeFile.js", + "test": "yarn build && yarn test:v5 && yarn test:v6", + "test:v5": "node ./dist/cli.js test --exclude test/largeFile.js", "test:v6": "node ./dist/cli.js test --exclude test/largeFile.js --pfVersion 6" }, "dependencies": { From e07f9c84d1a823cf7db769374f417db671ba0982 Mon Sep 17 00:00:00 2001 From: Jessie Date: Tue, 26 Mar 2024 15:30:22 -0400 Subject: [PATCH 7/7] Update README --- packages/class-name-updater/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/class-name-updater/README.md b/packages/class-name-updater/README.md index 7f4cb7b07..1018c98ab 100644 --- a/packages/class-name-updater/README.md +++ b/packages/class-name-updater/README.md @@ -1,6 +1,6 @@ # class-name-updater -This utility automatically identifies Patternfly class names that need to be updated after the introduction of versioned class names in Patternfly v5. +This utility automatically identifies Patternfly class names that need to be updated after the introduction of versioned class names in Patternfly v5 or v6. Currently v5 is set at the default so if you are updating to v6, please use the `--pfVersion 6` option. ## Usage @@ -25,6 +25,7 @@ Usage: @patternfly/class-name-updater [options] [otherPaths...] Options: -V, --version output the version number + --pfVersion version of PatternFly you are upgrading to, pass as number (i.e. 6) --extensions comma-delineated list of file extensions to update, by default includes css, scss, less, ts, tsx, js, jsx and md --exclude comma-delineated list of files to exclude, files should include their path relative to where this utility is being called --fix whether to run fixer