@comet/upgrade 1.52.0 → 1.53.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,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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.52.0",
3
+ "version": "1.53.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {