diff --git a/package.json b/package.json index 252354455..f23caf79f 100644 --- a/package.json +++ b/package.json @@ -16,7 +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 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", "get:packages": "node getPackages.js", "generate": "yarn build:generators && plop", "build": "lerna run build", 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 diff --git a/packages/class-name-updater/package.json b/packages/class-name-updater/package.json index 5e21fc29f..26e60ccfb 100644 --- a/packages/class-name-updater/package.json +++ b/packages/class-name-updater/package.json @@ -16,7 +16,9 @@ "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": { "colors": "^1.4.0", diff --git a/packages/class-name-updater/src/classNameUpdate.ts b/packages/class-name-updater/src/classNameUpdate.ts index ef993040f..957f79026 100644 --- a/packages/class-name-updater/src/classNameUpdate.ts +++ b/packages/class-name-updater/src/classNameUpdate.ts @@ -4,11 +4,14 @@ 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: number) { const acceptedFileTypesRegex = fileTypesRegex || /\.(s?css|less|(t|j)sx?|md)$/; - - const changeNeededRegex = /(\b|\$)pf-([cul]|global|theme|color)-/g; - const version = "v5"; + const previousVersion = pfVersion ? "-v" + (pfVersion - 1) : ""; + const changeNeededRegex = new RegExp( + "(\\b|\\$)pf" + previousVersion + "-([cul]|global|theme|color)-", + "g" + ); + const newVersion = pfVersion || 5 const files = sync(globTarget, { ignore: "**/node_modules/**" }); const includedFiles = files.filter((filePath: string) => !excludeFiles.includes(filePath)) @@ -31,7 +34,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 8e4e467ed..a31eef7f1 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, pass just the version number." + ) .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: number;} ) { 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; + }