@comet/upgrade 1.53.0 → 1.54.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,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts_morph_1 = require("ts-morph");
4
+ async function addDialogContentToEditDialog() {
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 importDeclarations = sourceFile.getImportDeclarations();
9
+ const muiImport = importDeclarations.find((importDeclaration) => importDeclaration.getModuleSpecifier().getLiteralValue() === "@mui/material");
10
+ if (!muiImport) {
11
+ sourceFile.addImportDeclaration({
12
+ moduleSpecifier: "@mui/material",
13
+ namedImports: ["DialogContent"],
14
+ });
15
+ }
16
+ else if (!muiImport.getNamedImports().some((namedImport) => namedImport.getName() === "DialogContent")) {
17
+ muiImport.addNamedImport("DialogContent");
18
+ }
19
+ const jsxElements = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.JsxElement);
20
+ const elementsToReplace = [];
21
+ jsxElements.forEach((jsxElement) => {
22
+ const tagName = jsxElement.getOpeningElement().getTagNameNode().getText();
23
+ if (tagName !== "EditDialog")
24
+ return;
25
+ const children = jsxElement.getJsxChildren();
26
+ const functionAsChild = children.find((child) => ts_morph_1.Node.isJsxExpression(child) && ts_morph_1.Node.isArrowFunction(child.getExpression()));
27
+ if (functionAsChild && ts_morph_1.Node.isJsxExpression(functionAsChild)) {
28
+ const expression = functionAsChild.getExpression();
29
+ if (!expression || !ts_morph_1.Node.isArrowFunction(expression))
30
+ return;
31
+ const body = expression.getBody();
32
+ const parameters = expression.getParameters();
33
+ let wrappedContent;
34
+ if (ts_morph_1.Node.isBlock(body)) {
35
+ const returnStatement = body.getStatements().find((statement) => ts_morph_1.Node.isReturnStatement(statement));
36
+ if (!returnStatement || !ts_morph_1.Node.isReturnStatement(returnStatement))
37
+ return;
38
+ let returnedExpression = returnStatement.getExpression();
39
+ if (returnedExpression && ts_morph_1.Node.isParenthesizedExpression(returnedExpression)) {
40
+ returnedExpression = returnedExpression.getExpression();
41
+ }
42
+ if (!returnedExpression)
43
+ return;
44
+ if (ts_morph_1.Node.isJsxFragment(returnedExpression)) {
45
+ const fragmentChildren = returnedExpression.getChildrenOfKind(ts_morph_1.SyntaxKind.JsxElement);
46
+ const fragmentText = fragmentChildren.map((child) => child.getText()).join("\n");
47
+ wrappedContent = `(<DialogContent>\n${fragmentText}\n</DialogContent>)`;
48
+ }
49
+ else {
50
+ const innerContent = returnedExpression.getText().replace(/\n/g, "\n");
51
+ wrappedContent = `(<DialogContent>\n${innerContent}\n</DialogContent>)`;
52
+ }
53
+ const newFunction = `{(${parameters.map((param) => param.getText()).join(", ")}) => {
54
+ return ${wrappedContent};}}`;
55
+ elementsToReplace.push({ node: functionAsChild, newText: newFunction });
56
+ }
57
+ }
58
+ else {
59
+ const openEditDialog = jsxElement.getOpeningElement().getText();
60
+ const closeEditDialog = jsxElement.getClosingElement().getText();
61
+ const childrensContent = children.map((child) => child.getText()).join("\n");
62
+ const newContent = `${openEditDialog}\n<DialogContent>\n${childrensContent}\n</DialogContent>\n${closeEditDialog}`;
63
+ elementsToReplace.push({ node: jsxElement, newText: newContent });
64
+ }
65
+ });
66
+ elementsToReplace.forEach(({ node, newText }) => {
67
+ node.replaceWithText(newText);
68
+ });
69
+ sourceFile.saveSync();
70
+ });
71
+ await project.save();
72
+ }
73
+ exports.default = addDialogContentToEditDialog;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.53.0",
3
+ "version": "1.54.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {