Skip to content

Commit 8a46215

Browse files
authored
feat: CSS vars updater package (#801)
* refactor(tokenLists): change location, use Sets * refactor(classNameUpdater utils): move to a shared helpers folder * refactor(codemods): update to use new tokenLists structure * feat: add new css-vars-updater package * update yarn.lock * refactor: move tokenLists * revert mapping paths for helpers from baseUrl * update paths in package.json files to reflect new dist folder structure * refactor: create shared-helpers package * chore: update shared-helpers package to use index.ts * chore: update yarn classic to [email protected] * chore: update yarn.lock * chore: update github action * chore: include dependencies in lerna build * docs: update README example * update test file * feat: print diff messages * chore(shared-helpers): make package private * chore: renamed shared-helpers to @patternfly/shared-codemod-helpers and make it a public package * chore: add "typescript" dev dependency
1 parent 8842c0b commit 8a46215

38 files changed

+11281
-7292
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
- uses: actions/setup-node@v1
1919
with:
2020
node-version: '18'
21+
- run: corepack enable
22+
- run: corepack prepare [email protected] --activate
2123
- uses: actions/cache@v2
2224
id: yarn-cache
2325
name: Cache npm deps
@@ -48,6 +50,8 @@ jobs:
4850
- uses: actions/setup-node@v1
4951
with:
5052
node-version: '18'
53+
- run: corepack enable
54+
- run: corepack prepare [email protected] --activate
5155
- uses: actions/cache@v2
5256
id: yarn-cache
5357
name: Cache npm deps
@@ -78,6 +82,8 @@ jobs:
7882
- uses: actions/setup-node@v1
7983
with:
8084
node-version: '18'
85+
- run: corepack enable
86+
- run: corepack prepare [email protected] --activate
8187
- uses: actions/cache@v2
8288
id: yarn-cache
8389
name: Cache npm deps

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,14 @@ test/packages/*
66
.DS_Store
77
dist
88

9+
# Yarn modern
10+
.pnp.*
11+
.yarn/*
12+
!.yarn/patches
13+
!.yarn/plugins
14+
!.yarn/releases
15+
!.yarn/sdks
16+
!.yarn/versions
17+
918
# IDE - VSCode
1019
.history

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

lerna.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"packages": [
1414
"packages/eslint-plugin-pf-codemods",
1515
"packages/pf-codemods",
16-
"packages/class-name-updater"
16+
"packages/class-name-updater",
17+
"packages/css-vars-updater",
18+
"packages/shared-codemod-helpers"
1719
],
1820
"version": "independent"
1921
}

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"build": "lerna run build",
2525
"build:generators": "tsc --build --verbose generators/tsconfig.cjs.json",
2626
"build:readme": "lerna run build:readme",
27-
"build:classnames": "lerna run build --scope=@patternfly/class-name-updater",
27+
"build:classnames": "lerna run build --scope=@patternfly/class-name-updater --include-dependencies",
2828
"clean": "lerna run clean"
2929
},
3030
"repository": {
@@ -41,13 +41,16 @@
4141
"packages/*"
4242
],
4343
"devDependencies": {
44-
"lerna": "^3.22.0",
44+
"@types/fs-extra": "^11.0.4",
45+
"@types/node": "^22.10.6",
46+
"case-anything": "^2.1.13",
47+
"fs-extra": "^11.2.0",
48+
"lerna": "^8.1.9",
4549
"mocha": "^7.2.0",
4650
"plop": "^3.1.2",
51+
"rimraf": "^6.0.1",
4752
"ts-node": "^10.9.2",
48-
"case-anything": "^2.1.13",
49-
"fs-extra": "^11.2.0",
50-
"@types/fs-extra": "^11.0.4"
53+
"typescript": "^5.4.2"
5154
},
52-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
55+
"packageManager": "yarn@4.5.1"
5356
}

packages/class-name-updater/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
"description": "Utility to update class names with Patternfly version numbers",
55
"author": "Red Hat",
66
"license": "MIT",
7-
"bin": {
8-
"class-name-updater": "./dist/cli.js"
9-
},
7+
"bin": "./dist/cli.js",
108
"engines": {
119
"node": ">=18"
1210
},
@@ -21,6 +19,7 @@
2119
"test:v6": "node ./dist/cli.js test --exclude test/largeFile.js --v6"
2220
},
2321
"dependencies": {
22+
"@patternfly/shared-codemod-helpers": "workspace:^",
2423
"colors": "^1.4.0",
2524
"commander": "^5.1.0",
2625
"diff": "^5.1.0",

packages/class-name-updater/src/classNameUpdate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { sync } from "glob";
22
import { readFileSync, writeFileSync } from "fs";
33
import { isAbsolute, join } from "path";
4-
import { isDir } from "./utils";
5-
import { printDiff } from "./printDiff";
4+
import { isDir, printDiff } from "@patternfly/shared-codemod-helpers";
65

76
export async function classNameUpdate(
87
globTarget: string,

packages/class-name-updater/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { join } from "path";
33
import { Command } from "commander";
44
const program = new Command();
55

6-
import { isDir } from "./utils";
6+
import { isDir } from "@patternfly/shared-codemod-helpers";
77
import { classNameUpdate } from "./classNameUpdate";
88

99
program
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# css-vars-updater
2+
3+
This utility automatically identifies Patternfly CSS variables in v5 that need to be updated after the introduction of new [global tokens in Patternfly v6](https://www.patternfly.org/tokens/about-tokens).
4+
5+
## Usage
6+
7+
Requires Node.js >= 10.
8+
9+
```sh
10+
npx @patternfly/css-vars-updater ./path-to-src
11+
```
12+
13+
Running this command will use default options, if you want a finer control over the updates, use an `-i` (or `--interactive`) option. It will start an interactive interface, where you can setup what files should be fixed and what tokens should be replaced:
14+
```
15+
npx @patternfly/css-vars-updater ./path-to-src -i
16+
17+
--> Enter file extensions to update (comma-separated): (scss,css,less,md)
18+
--> Do you want to exclude any files? (y/N)
19+
yes --> Enter files to exclude (comma-separated, relative paths)
20+
--> Do you want to run the fixer? (Y/n)
21+
--> Do you want to replace color variables with a temporary hot pink color variable? (Y/n)
22+
--> Do you want to replace other global variables with a matching token? (Y/n)
23+
--> Do you want to fix directional styles and how? E.g. PaddingLeft -> PaddingInlineStart (Use arrow keys)
24+
❯ Fix in left-to-right manner (English)
25+
Fix in right-to-left manner
26+
Fix in top-to-bottom manner
27+
Don’t fix
28+
```
29+
30+
Giving node more RAM can help for large codebases.
31+
32+
```sh
33+
NODE_OPTIONS=--max-old-space-size=4096 npx @patternfly/css-vars-updater ./path-to-src
34+
```
35+
36+
### Options
37+
38+
```sh
39+
Usage: @patternfly/css-vars-updater <path> [otherPaths...]
40+
41+
Options:
42+
-V, --version output the version number
43+
-i, --interactive starts an interactive interface for finer control over the updates
44+
--fix whether to run fixer
45+
-h, --help display help for command
46+
```
47+
48+
### Example
49+
50+
Using default options:
51+
52+
In:
53+
54+
```css
55+
.custom-class {
56+
/* Global non-color variables */
57+
border-radius: var(--pf-v5-global--BorderRadius--lg);
58+
row-gap: var(--pf-v5-global--spacer--md);
59+
width: var(--pf-v5-global--arrow--width);
60+
61+
/* Global color variables */
62+
color: var(--pf-v5-global--Color--100);
63+
background-color: var(--pf-v5-global--BackgroundColor--200);
64+
65+
/* Variables removed from v6 */
66+
max-width: var(--pf-v5-c-accordion__toggle-text--MaxWidth);
67+
68+
/* Variables staying in v6 */
69+
height: var(--pf-v5-c-about-modal-box--Height);
70+
box-shadow: var(--pf-v5-c-alert--BoxShadow);
71+
72+
/* Variables with direction updates */
73+
padding-inline-start: var(--pf-v5-c-about-modal-box__brand--PaddingLeft);
74+
padding-inline-end: var(--pf-v5-c-about-modal-box__brand--PaddingRight);
75+
padding-block-start: var(--pf-v5-c-about-modal-box__brand--PaddingTop);
76+
padding-block-end: var(--pf-v5-c-about-modal-box__brand--PaddingBottom);
77+
}
78+
```
79+
80+
Out:
81+
82+
```css
83+
.custom-class {
84+
/* Global non-color variables */
85+
border-radius: var(--pf-t--global--border--radius--large);
86+
row-gap: var(--pf-t--global--spacer--md);
87+
width: var(--pf-v5-global--arrow--width);
88+
89+
/* Global color variables */
90+
color: var(--pf-t--temp--dev--tbd /* CODEMODS: original v5 color was:--pf-v5-global--Color--100 */);
91+
background-color: var(--pf-t--temp--dev--tbd /* CODEMODS: original v5 color was:--pf-v5-global--BackgroundColor--200 */);
92+
93+
/* Variables removed from v6 */
94+
max-width: var(--pf-v5-c-accordion__toggle-text--MaxWidth);
95+
96+
/* Variables staying in v6 */
97+
height: var(--pf-v6-c-about-modal-box--Height);
98+
box-shadow: var(--pf-v6-c-alert--BoxShadow);
99+
100+
/* Variables with direction updates */
101+
padding-inline-start: var(--pf-v6-c-about-modal-box__brand--PaddingInlineStart);
102+
padding-inline-end: var(--pf-v6-c-about-modal-box__brand--PaddingInlineEnd);
103+
padding-block-start: var(--pf-v6-c-about-modal-box__brand--PaddingBlockStart);
104+
padding-block-end: var(--pf-v6-c-about-modal-box__brand--PaddingBlockEnd);
105+
}
106+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@patternfly/css-vars-updater",
3+
"version": "1.0.0",
4+
"description": "Utility to update Patternfly CSS variables when migrating from V5 to a new design token system in V6",
5+
"author": "Red Hat",
6+
"license": "MIT",
7+
"bin": "./dist/cli.js",
8+
"engines": {
9+
"node": ">=18"
10+
},
11+
"publishConfig": {
12+
"access": "public"
13+
},
14+
"scripts": {
15+
"build": "tsc --build --verbose ./tsconfig.json",
16+
"clean": "rimraf ./dist"
17+
},
18+
"dependencies": {
19+
"@patternfly/shared-codemod-helpers": "workspace:^",
20+
"colors": "^1.4.0",
21+
"commander": "^5.1.0",
22+
"diff": "^5.1.0",
23+
"glob": "^10.2.6",
24+
"inquirer": "^12.3.2"
25+
},
26+
"devDependencies": {
27+
"@types/diff": "^5.0.9",
28+
"@types/node": "^22.10.6",
29+
"typescript": "^5.4.2"
30+
}
31+
}

0 commit comments

Comments
 (0)