From 2ffb4eb6df1603d590bedf00d89396ff6fb471a6 Mon Sep 17 00:00:00 2001 From: adamviktora Date: Tue, 12 Nov 2024 19:04:03 +0100 Subject: [PATCH] refactor: create shared-helpers package --- lerna.json | 3 ++- package.json | 2 +- packages/class-name-updater/package.json | 11 +++++------ .../class-name-updater/src/classNameUpdate.ts | 4 ++-- packages/class-name-updater/src/cli.ts | 2 +- packages/css-vars-updater/package.json | 7 +++---- packages/css-vars-updater/src/cli.ts | 2 +- .../css-vars-updater/src/cssVarsUpdate.ts | 4 ++-- .../eslint-plugin-pf-codemods/package.json | 3 +++ .../tokensPrefixWithT/tokens-prefix-with-t.ts | 2 +- .../rules/v6/tokensUpdate/tokens-update.ts | 2 +- packages/shared-helpers/package.json | 19 +++++++++++++++++++ .../shared-helpers/src}/printDiff.ts | 0 .../shared-helpers/src}/tokenLists/index.ts | 0 .../src}/tokenLists/oldCssVarNames.ts | 0 .../src}/tokenLists/oldGlobalCssVarNames.ts | 0 .../src}/tokenLists/oldGlobalTokens.ts | 0 .../src}/tokenLists/oldTokens.ts | 0 .../src}/tokenLists/tokensToPrefixWithT.ts | 0 .../src}/tokenLists/v6DirectionCssVars.ts | 0 .../src}/tokenLists/v6DirectionTokens.ts | 0 .../shared-helpers/src}/utils.ts | 0 packages/shared-helpers/tsconfig.json | 9 +++++++++ 23 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 packages/shared-helpers/package.json rename {helpers => packages/shared-helpers/src}/printDiff.ts (100%) rename {helpers => packages/shared-helpers/src}/tokenLists/index.ts (100%) rename {helpers => packages/shared-helpers/src}/tokenLists/oldCssVarNames.ts (100%) rename {helpers => packages/shared-helpers/src}/tokenLists/oldGlobalCssVarNames.ts (100%) rename {helpers => packages/shared-helpers/src}/tokenLists/oldGlobalTokens.ts (100%) rename {helpers => packages/shared-helpers/src}/tokenLists/oldTokens.ts (100%) rename {helpers => packages/shared-helpers/src}/tokenLists/tokensToPrefixWithT.ts (100%) rename {helpers => packages/shared-helpers/src}/tokenLists/v6DirectionCssVars.ts (100%) rename {helpers => packages/shared-helpers/src}/tokenLists/v6DirectionTokens.ts (100%) rename {helpers => packages/shared-helpers/src}/utils.ts (100%) create mode 100644 packages/shared-helpers/tsconfig.json diff --git a/lerna.json b/lerna.json index ad95c0379..c987102f2 100644 --- a/lerna.json +++ b/lerna.json @@ -14,7 +14,8 @@ "packages/eslint-plugin-pf-codemods", "packages/pf-codemods", "packages/class-name-updater", - "packages/css-vars-updater" + "packages/css-vars-updater", + "packages/shared-helpers" ], "version": "independent" } diff --git a/package.json b/package.json index 04faec3b3..15fdac786 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "yarn test:v4 && yarn test:v5 && yarn test:v6", "test:v4": "mocha packages/eslint-plugin-pf-codemods/test/rules/v4", "test:v5": "mocha packages/eslint-plugin-pf-codemods/test/rules/v5", - "test:v6": "yarn build && mocha packages/eslint-plugin-pf-codemods/dist/js/packages/eslint-plugin-pf-codemods/src/rules/v6/*/*.test.js", + "test:v6": "yarn build && mocha packages/eslint-plugin-pf-codemods/dist/js/rules/v6/*/*.test.js", "test:v4:single": "pf-codemods --v4 --no-cache test/v4test.tsx", "test:v5:single": "pf-codemods --no-cache test/test.tsx", "test:v6:single": "yarn build && pf-codemods --v6 --no-cache packages/eslint-plugin-pf-codemods/src/rules/v6/*/*Input.tsx", diff --git a/packages/class-name-updater/package.json b/packages/class-name-updater/package.json index 782bd77f7..5a20ecfec 100644 --- a/packages/class-name-updater/package.json +++ b/packages/class-name-updater/package.json @@ -4,9 +4,7 @@ "description": "Utility to update class names with Patternfly version numbers", "author": "Red Hat", "license": "MIT", - "bin": { - "class-name-updater": "./dist/packages/class-name-updater/src/cli.js" - }, + "bin": "./dist/cli.js", "engines": { "node": ">=18" }, @@ -17,14 +15,15 @@ "build": "tsc --build --verbose ./tsconfig.json", "clean": "rimraf ./dist", "test": "yarn build && yarn test:v5 && yarn test:v6", - "test:v5": "node ./dist/packages/class-name-updater/src/cli.js test --exclude test/largeFile.js", - "test:v6": "node ./dist/packages/class-name-updater/src/cli.js test --exclude test/largeFile.js --v6" + "test:v5": "node ./dist/cli.js test --exclude test/largeFile.js", + "test:v6": "node ./dist/cli.js test --exclude test/largeFile.js --v6" }, "dependencies": { "colors": "^1.4.0", "commander": "^5.1.0", "diff": "^5.1.0", - "glob": "^10.2.6" + "glob": "^10.2.6", + "shared-helpers": "^1.0.0" }, "devDependencies": { "@types/diff": "^5.0.9", diff --git a/packages/class-name-updater/src/classNameUpdate.ts b/packages/class-name-updater/src/classNameUpdate.ts index 5af932d1d..42ee43876 100644 --- a/packages/class-name-updater/src/classNameUpdate.ts +++ b/packages/class-name-updater/src/classNameUpdate.ts @@ -1,8 +1,8 @@ import { sync } from "glob"; import { readFileSync, writeFileSync } from "fs"; import { join } from "path"; -import { isDir } from "../../../helpers/utils"; -import { printDiff } from "../../../helpers/printDiff"; +import { isDir } from "shared-helpers/dist/utils"; +import { printDiff } from "shared-helpers/dist/printDiff"; export async function classNameUpdate( globTarget: string, diff --git a/packages/class-name-updater/src/cli.ts b/packages/class-name-updater/src/cli.ts index 09639803b..aa1a65c37 100755 --- a/packages/class-name-updater/src/cli.ts +++ b/packages/class-name-updater/src/cli.ts @@ -3,7 +3,7 @@ import { join } from "path"; import { Command } from "commander"; const program = new Command(); -import { isDir } from "../../../helpers/utils"; +import { isDir } from "shared-helpers/dist/utils"; import { classNameUpdate } from "./classNameUpdate"; program diff --git a/packages/css-vars-updater/package.json b/packages/css-vars-updater/package.json index 6e4f92039..71dea25c3 100644 --- a/packages/css-vars-updater/package.json +++ b/packages/css-vars-updater/package.json @@ -4,9 +4,7 @@ "description": "Utility to update Patternfly CSS variables when migrating from V5 to a new design token system in V6", "author": "Red Hat", "license": "MIT", - "bin": { - "css-vars-updater": "./dist/packages/css-vars-updater/src/cli.js" - }, + "bin": "./dist/cli.js", "engines": { "node": ">=18" }, @@ -22,7 +20,8 @@ "commander": "^5.1.0", "diff": "^5.1.0", "glob": "^10.2.6", - "inquirer": "^12.0.1" + "inquirer": "^12.0.1", + "shared-helpers": "^1.0.0" }, "devDependencies": { "@types/diff": "^5.0.9", diff --git a/packages/css-vars-updater/src/cli.ts b/packages/css-vars-updater/src/cli.ts index 5189b15b6..b8f219617 100644 --- a/packages/css-vars-updater/src/cli.ts +++ b/packages/css-vars-updater/src/cli.ts @@ -4,7 +4,7 @@ import { Command } from "commander"; const program = new Command(); import inquirer from "inquirer"; -import { isDir } from "../../../helpers/utils"; +import { isDir } from "shared-helpers/dist/utils"; import { cssVarsUpdate } from "./cssVarsUpdate"; import { Answers } from "./answers"; diff --git a/packages/css-vars-updater/src/cssVarsUpdate.ts b/packages/css-vars-updater/src/cssVarsUpdate.ts index a4cac8fe3..0bf4d2250 100644 --- a/packages/css-vars-updater/src/cssVarsUpdate.ts +++ b/packages/css-vars-updater/src/cssVarsUpdate.ts @@ -1,7 +1,7 @@ import { sync } from "glob"; import { readFileSync, writeFileSync } from "fs"; import { join } from "path"; -import { isDir } from "../../../helpers/utils"; +import { isDir } from "shared-helpers/dist/utils"; // import { printDiff } from "../../../helpers/printDiff"; import { globalNonColorCssVarNamesMap, @@ -9,7 +9,7 @@ import { oldGlobalColorCssVarNames, oldGlobalNonColorCssVarNames, v6DirectionCssVars, -} from "../../../helpers/tokenLists"; +} from "shared-helpers/dist/tokenLists"; import { Answers } from "./answers"; import { getDirectionMap } from "./directionalStyles"; diff --git a/packages/eslint-plugin-pf-codemods/package.json b/packages/eslint-plugin-pf-codemods/package.json index 13d6a9d86..20f091184 100644 --- a/packages/eslint-plugin-pf-codemods/package.json +++ b/packages/eslint-plugin-pf-codemods/package.json @@ -17,6 +17,9 @@ "test": "eslint . --ext .ts", "clean": "rimraf ./dist" }, + "dependencies": { + "shared-helpers": "^1.0.0" + }, "peerDependencies": { "@typescript-eslint/parser": ">=5.58.0", "eslint": ">=0.8.0", diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensPrefixWithT/tokens-prefix-with-t.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensPrefixWithT/tokens-prefix-with-t.ts index 850ea1f8c..ae893b1ad 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensPrefixWithT/tokens-prefix-with-t.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensPrefixWithT/tokens-prefix-with-t.ts @@ -8,7 +8,7 @@ import { getImportPath, } from "../../helpers"; import { Identifier, ImportSpecifier } from "estree-jsx"; -import { tokensToPrefixWithT } from "../../../../../../helpers/tokenLists"; +import { tokensToPrefixWithT } from "shared-helpers/dist/tokenLists"; module.exports = { meta: { fixable: "code" }, diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.ts index 5945627ce..11d2fbba6 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.ts @@ -16,7 +16,7 @@ import { globalNonColorCssVarNamesMap, oldGlobalColorCssVarNames, oldGlobalColorTokens, -} from "../../../../../../helpers/tokenLists"; +} from "shared-helpers/dist/tokenLists"; module.exports = { meta: { fixable: "code" }, diff --git a/packages/shared-helpers/package.json b/packages/shared-helpers/package.json new file mode 100644 index 000000000..ec1698237 --- /dev/null +++ b/packages/shared-helpers/package.json @@ -0,0 +1,19 @@ +{ + "name": "shared-helpers", + "version": "1.0.0", + "description": "Shared helpers for the monorepo", + "scripts": { + "build": "tsc --build --verbose ./tsconfig.json", + "clean": "rimraf ./dist" + }, + "author": "Red Hat", + "license": "MIT", + "dependencies": { + "colors": "^1.4.0", + "diff": "^5.1.0" + }, + "devDependencies": { + "@types/diff": "^5.0.9", + "typescript": "^5.4.2" + } +} diff --git a/helpers/printDiff.ts b/packages/shared-helpers/src/printDiff.ts similarity index 100% rename from helpers/printDiff.ts rename to packages/shared-helpers/src/printDiff.ts diff --git a/helpers/tokenLists/index.ts b/packages/shared-helpers/src/tokenLists/index.ts similarity index 100% rename from helpers/tokenLists/index.ts rename to packages/shared-helpers/src/tokenLists/index.ts diff --git a/helpers/tokenLists/oldCssVarNames.ts b/packages/shared-helpers/src/tokenLists/oldCssVarNames.ts similarity index 100% rename from helpers/tokenLists/oldCssVarNames.ts rename to packages/shared-helpers/src/tokenLists/oldCssVarNames.ts diff --git a/helpers/tokenLists/oldGlobalCssVarNames.ts b/packages/shared-helpers/src/tokenLists/oldGlobalCssVarNames.ts similarity index 100% rename from helpers/tokenLists/oldGlobalCssVarNames.ts rename to packages/shared-helpers/src/tokenLists/oldGlobalCssVarNames.ts diff --git a/helpers/tokenLists/oldGlobalTokens.ts b/packages/shared-helpers/src/tokenLists/oldGlobalTokens.ts similarity index 100% rename from helpers/tokenLists/oldGlobalTokens.ts rename to packages/shared-helpers/src/tokenLists/oldGlobalTokens.ts diff --git a/helpers/tokenLists/oldTokens.ts b/packages/shared-helpers/src/tokenLists/oldTokens.ts similarity index 100% rename from helpers/tokenLists/oldTokens.ts rename to packages/shared-helpers/src/tokenLists/oldTokens.ts diff --git a/helpers/tokenLists/tokensToPrefixWithT.ts b/packages/shared-helpers/src/tokenLists/tokensToPrefixWithT.ts similarity index 100% rename from helpers/tokenLists/tokensToPrefixWithT.ts rename to packages/shared-helpers/src/tokenLists/tokensToPrefixWithT.ts diff --git a/helpers/tokenLists/v6DirectionCssVars.ts b/packages/shared-helpers/src/tokenLists/v6DirectionCssVars.ts similarity index 100% rename from helpers/tokenLists/v6DirectionCssVars.ts rename to packages/shared-helpers/src/tokenLists/v6DirectionCssVars.ts diff --git a/helpers/tokenLists/v6DirectionTokens.ts b/packages/shared-helpers/src/tokenLists/v6DirectionTokens.ts similarity index 100% rename from helpers/tokenLists/v6DirectionTokens.ts rename to packages/shared-helpers/src/tokenLists/v6DirectionTokens.ts diff --git a/helpers/utils.ts b/packages/shared-helpers/src/utils.ts similarity index 100% rename from helpers/utils.ts rename to packages/shared-helpers/src/utils.ts diff --git a/packages/shared-helpers/tsconfig.json b/packages/shared-helpers/tsconfig.json new file mode 100644 index 000000000..d0f268fbe --- /dev/null +++ b/packages/shared-helpers/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "CommonJS", + "outDir": "./dist" + }, + "include": ["src/**/*"], + "exclude": ["dist"] +}