@comet/upgrade 1.86.0 → 1.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts_morph_1 = require("ts-morph");
4
+ async function tooltipReplaceVariantProp() {
5
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
6
+ const sourceFiles = project.getSourceFiles("admin/src/**/*.tsx");
7
+ sourceFiles.forEach((sourceFile) => {
8
+ const cometAdminImport = sourceFile.getImportDeclarations().find((importDeclaration) => {
9
+ return importDeclaration.getModuleSpecifier().getLiteralValue() === "@comet/admin";
10
+ });
11
+ if (!cometAdminImport) {
12
+ return;
13
+ }
14
+ const tooltipComponentNames = new Set();
15
+ cometAdminImport.getNamedImports().forEach((namedImport) => {
16
+ if (namedImport.getName() === "Tooltip") {
17
+ const aliasName = namedImport.getAliasNode();
18
+ tooltipComponentNames.add(aliasName ? aliasName.getText() : "Tooltip");
19
+ }
20
+ });
21
+ const jsxElements = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.JsxOpeningElement);
22
+ jsxElements.forEach((jsxElement) => {
23
+ const componentName = jsxElement.getTagNameNode().getText();
24
+ if (tooltipComponentNames.has(componentName)) {
25
+ const variantAttribute = jsxElement
26
+ .getAttributes()
27
+ .find((attribute) => attribute.getKind() === ts_morph_1.SyntaxKind.JsxAttribute &&
28
+ attribute.asKind(ts_morph_1.SyntaxKind.JsxAttribute)?.getNameNode().getText() === "variant");
29
+ if (variantAttribute) {
30
+ const jsxAttribute = variantAttribute.asKind(ts_morph_1.SyntaxKind.JsxAttribute);
31
+ if (jsxAttribute) {
32
+ const initializer = jsxAttribute.getInitializer();
33
+ let variantValue = null;
34
+ if (initializer) {
35
+ if (initializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
36
+ variantValue = initializer.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue() || null;
37
+ }
38
+ else if (initializer.getKind() === ts_morph_1.SyntaxKind.JsxExpression) {
39
+ const expression = initializer.asKind(ts_morph_1.SyntaxKind.JsxExpression)?.getExpression();
40
+ if (expression && expression.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
41
+ variantValue = expression.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue() || null;
42
+ }
43
+ }
44
+ }
45
+ if (variantValue) {
46
+ const isValueThatNoLongerExists = variantValue === "primary" || variantValue === "neutral";
47
+ if (isValueThatNoLongerExists) {
48
+ variantAttribute.remove();
49
+ }
50
+ else {
51
+ jsxAttribute.getNameNode().replaceWithText("color");
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ });
58
+ sourceFile.save();
59
+ });
60
+ }
61
+ exports.default = tooltipReplaceVariantProp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.86.0",
3
+ "version": "1.88.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {