@comet/upgrade 1.83.0 → 1.84.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,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ts_morph_1 = require("ts-morph");
|
|
4
|
+
async function replaceMuiButtonWithCometAdminButton() {
|
|
5
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
|
|
6
|
+
const sourceFiles = project.getSourceFiles("admin/src/**/*.{ts,tsx}");
|
|
7
|
+
for (const sourceFile of sourceFiles) {
|
|
8
|
+
let changed = false;
|
|
9
|
+
const importDeclarations = sourceFile.getImportDeclarations();
|
|
10
|
+
for (const importDecl of importDeclarations) {
|
|
11
|
+
if (importDecl.getModuleSpecifierValue() === "@mui/material") {
|
|
12
|
+
const namedImports = importDecl.getNamedImports();
|
|
13
|
+
const buttonImport = namedImports.find((ni) => ni.getName() === "Button");
|
|
14
|
+
if (buttonImport) {
|
|
15
|
+
// Remove Button from @mui/material import
|
|
16
|
+
buttonImport.remove();
|
|
17
|
+
changed = true;
|
|
18
|
+
// If no named imports left, remove the whole import
|
|
19
|
+
if (importDecl.getNamedImports().length === 0) {
|
|
20
|
+
importDecl.remove();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Add Button import from @comet/admin if it was removed
|
|
26
|
+
if (changed) {
|
|
27
|
+
// Check if already imported from @comet/admin
|
|
28
|
+
const cometAdminImport = importDeclarations.find((id) => id.getModuleSpecifierValue() === "@comet/admin");
|
|
29
|
+
if (cometAdminImport) {
|
|
30
|
+
// Add Button if not already present
|
|
31
|
+
if (!cometAdminImport.getNamedImports().some((ni) => ni.getName() === "Button")) {
|
|
32
|
+
cometAdminImport.addNamedImport("Button");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
sourceFile.addImportDeclaration({
|
|
37
|
+
moduleSpecifier: "@comet/admin",
|
|
38
|
+
namedImports: ["Button"],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (changed) {
|
|
43
|
+
await sourceFile.save();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
await project.save();
|
|
47
|
+
}
|
|
48
|
+
exports.default = replaceMuiButtonWithCometAdminButton;
|