Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update class-name-updater package to support v6 #620

Merged
merged 7 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
jessiehuff marked this conversation as resolved.
Show resolved Hide resolved
"get:packages": "node getPackages.js",
"generate": "yarn build:generators && plop",
"build": "lerna run build",
Expand Down
3 changes: 2 additions & 1 deletion packages/class-name-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
jessiehuff marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"colors": "^1.4.0",
Expand Down
13 changes: 8 additions & 5 deletions packages/class-name-updater/src/classNameUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions packages/class-name-updater/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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];

Expand All @@ -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);
});
}

Expand Down
4 changes: 4 additions & 0 deletions packages/class-name-updater/test/test.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
.pf-u-screen-reader > .pf-l-stack__item{
color: red;
}

.pf-v5-c-toolbar__item {
color: green;
}
Loading