"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.classNameUpdate = void 0; const glob_1 = require("glob"); const fs_1 = require("fs"); const path_1 = require("path"); const shared_codemod_helpers_1 = require("@patternfly/shared-codemod-helpers"); function classNameUpdate(globTarget_1, makeChange_1, fileTypesRegex_1) { return __awaiter(this, arguments, void 0, function* (globTarget, makeChange, fileTypesRegex, excludeFiles = [], pfVersion) { const acceptedFileTypesRegex = fileTypesRegex || /\.(s?css|less|(t|j)sx?|md)$/; const isPostV5 = pfVersion > 5; const previousVersion = isPostV5 ? "-v" + (pfVersion - 1) : ""; const classNameMatches = "[cul]"; const cssVarMatches = `${classNameMatches}|global|theme|color|chart`; const bodyMatches = isPostV5 ? classNameMatches : cssVarMatches; const cssVarStart = isPostV5 ? "[^-]" : ""; const changeNeededRegex = new RegExp(`(${cssVarStart})` + "(\\b|\\$)pf" + previousVersion + `-(${bodyMatches})-`, "g"); const newVersion = pfVersion || 5; const files = (0, glob_1.sync)(globTarget, { ignore: "**/node_modules/**" }); const includedFiles = files.filter((filePath) => !excludeFiles.includes(filePath)); includedFiles.forEach((file) => __awaiter(this, void 0, void 0, function* () { const filePath = (0, path_1.isAbsolute)(file) ? file : (0, path_1.join)(process.cwd(), file); const isDirectory = yield (0, shared_codemod_helpers_1.isDir)(filePath); const isUnexpectedFile = !acceptedFileTypesRegex.test(filePath); if (isDirectory || isUnexpectedFile) { return; } const fileContent = (0, fs_1.readFileSync)(filePath, "utf8"); const needsChange = changeNeededRegex.test(fileContent); if (!needsChange) { return; } const newContent = fileContent.replace(changeNeededRegex, `$1$2pf-v${newVersion}-$3-`); (0, shared_codemod_helpers_1.printDiff)(file, fileContent, newContent, changeNeededRegex); if (makeChange) { (0, fs_1.writeFileSync)(filePath, newContent); } })); }); } exports.classNameUpdate = classNameUpdate; //# sourceMappingURL=classNameUpdate.js.map