@comet/upgrade 1.52.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;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const glob_1 = require("glob");
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const renameMap = {
|
|
6
|
+
Menu: "MainNavigation",
|
|
7
|
+
MenuProps: "MainNavigationProps",
|
|
8
|
+
MenuClassKey: "MainNavigationClassKey",
|
|
9
|
+
MenuItem: "MainNavigationItem",
|
|
10
|
+
MenuItemProps: "MainNavigationItemProps",
|
|
11
|
+
MenuItemClassKey: "MainNavigationItemClassKey",
|
|
12
|
+
MenuCollapsibleItem: "MainNavigationCollapsibleItem",
|
|
13
|
+
MenuCollapsibleItemProps: "MainNavigationCollapsibleItemProps",
|
|
14
|
+
MenuCollapsibleItemClassKey: "MainNavigationCollapsibleItemClassKey",
|
|
15
|
+
IWithMenu: "WithMainNavigation",
|
|
16
|
+
withMenu: "withMainNavigation",
|
|
17
|
+
MenuItemAnchorLink: "MainNavigationItemAnchorLink",
|
|
18
|
+
MenuItemAnchorLinkProps: "MainNavigationItemAnchorLinkProps",
|
|
19
|
+
MenuItemGroup: "MainNavigationItemGroup",
|
|
20
|
+
MenuItemGroupClassKey: "MainNavigationItemGroupClassKey",
|
|
21
|
+
MenuItemGroupProps: "MainNavigationItemGroupProps",
|
|
22
|
+
MenuItemRouterLink: "MainNavigationItemRouterLink",
|
|
23
|
+
MenuItemRouterLinkProps: "MainNavigationItemRouterLinkProps",
|
|
24
|
+
MenuContext: "useMainNavigation",
|
|
25
|
+
};
|
|
26
|
+
async function renameComponents() {
|
|
27
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
|
|
28
|
+
const files = glob_1.glob.sync(["admin/src/**/*.tsx"]);
|
|
29
|
+
for (const filePath of files) {
|
|
30
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
31
|
+
if (!sourceFile) {
|
|
32
|
+
throw new Error(`Can't get source file for ${filePath}`);
|
|
33
|
+
}
|
|
34
|
+
const adminImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue() === "@comet/admin");
|
|
35
|
+
if (adminImport) {
|
|
36
|
+
const namedImports = adminImport.getNamedImports();
|
|
37
|
+
for (const [oldName, newName] of Object.entries(renameMap)) {
|
|
38
|
+
const namedImport = namedImports.find((imported) => imported.getName() === oldName);
|
|
39
|
+
if (namedImport) {
|
|
40
|
+
namedImport.setName(newName);
|
|
41
|
+
if (oldName === "MenuContext") {
|
|
42
|
+
const useContextCalls = sourceFile.getDescendantsOfKind(ts_morph_1.ts.SyntaxKind.CallExpression).filter((call) => {
|
|
43
|
+
const expression = call.getExpression();
|
|
44
|
+
return (expression.getText() === "useContext" &&
|
|
45
|
+
call.getArguments().length === 1 &&
|
|
46
|
+
call.getArguments()[0].getText() === "MenuContext");
|
|
47
|
+
});
|
|
48
|
+
for (const call of useContextCalls) {
|
|
49
|
+
call.replaceWithText("useMainNavigation()");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const references = sourceFile
|
|
54
|
+
.getDescendantsOfKind(ts_morph_1.ts.SyntaxKind.Identifier)
|
|
55
|
+
.filter((identifier) => identifier.getText() === oldName);
|
|
56
|
+
for (const reference of references) {
|
|
57
|
+
reference.replaceWithText(newName);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
await sourceFile.save();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.default = renameComponents;
|