@comet/upgrade 1.14.0 → 1.16.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.
- package/README.md +6 -0
- package/lib/index.js +19 -9
- package/lib/v7/replace-gridcoldef-import.js +47 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,12 @@ For example:
|
|
|
14
14
|
npx @comet/upgrade v4
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
You can also run a single upgrade script by providing the path to the script:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npx @comet/upgrade v7/hide-graphql-field-suggestions.ts
|
|
21
|
+
```
|
|
22
|
+
|
|
17
23
|
## Create a new upgrade script
|
|
18
24
|
|
|
19
25
|
1. Start the development process:
|
package/lib/index.js
CHANGED
|
@@ -50,6 +50,11 @@ function main() {
|
|
|
50
50
|
console.error("Missing target version! Usage: npx @comet/upgrade <version>");
|
|
51
51
|
process.exit(-1);
|
|
52
52
|
}
|
|
53
|
+
const isUpgradeScript = fs_1.default.existsSync(path_1.default.join(__dirname, targetVersionArg.replace(/\.ts$/, ".js")));
|
|
54
|
+
if (isUpgradeScript) {
|
|
55
|
+
yield runUpgradeScript(targetVersionArg.replace(/\.ts$/, ".js"));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
53
58
|
const targetVersion = semver_1.default.coerce(targetVersionArg, { includePrerelease: true });
|
|
54
59
|
if (!targetVersion) {
|
|
55
60
|
console.error("Can't parse version number. Example usage: npx @comet/upgrade v4");
|
|
@@ -136,17 +141,22 @@ function updateDependencies(targetVersion) {
|
|
|
136
141
|
}
|
|
137
142
|
function runUpgradeScripts(targetVersionFolder) {
|
|
138
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
var _a;
|
|
140
144
|
const scriptsFolder = path_1.default.join(__dirname, targetVersionFolder);
|
|
141
145
|
for (const fileName of fs_1.default.readdirSync(scriptsFolder)) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
yield runUpgradeScript(path_1.default.join(targetVersionFolder, fileName));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function runUpgradeScript(script) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
var _a;
|
|
153
|
+
const upgradeScript = yield (_a = path_1.default.join(__dirname, script), Promise.resolve().then(() => __importStar(require(_a))));
|
|
154
|
+
try {
|
|
155
|
+
yield upgradeScript.default();
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
console.error(`Script '${script}' failed to execute. See original error below`);
|
|
159
|
+
console.error(error);
|
|
150
160
|
}
|
|
151
161
|
});
|
|
152
162
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const promises_1 = require("fs/promises");
|
|
13
|
+
const glob_1 = require("glob");
|
|
14
|
+
const ts_morph_1 = require("ts-morph");
|
|
15
|
+
/**
|
|
16
|
+
* Replaces the import of `GridColDef` from `@mui/x-data-grid*` with `GridColDef` from `@comet/admin`.
|
|
17
|
+
*/
|
|
18
|
+
function replaceGridColDefImport() {
|
|
19
|
+
var _a;
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const files = glob_1.glob.sync(["admin/src/**/*.ts", "admin/src/**/*.tsx"]);
|
|
22
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
|
|
23
|
+
for (const filePath of files) {
|
|
24
|
+
const fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
|
|
25
|
+
if (!fileContent.includes("GridColDef")) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
29
|
+
if (!sourceFile) {
|
|
30
|
+
throw new Error(`Can't get source file for ${filePath}`);
|
|
31
|
+
}
|
|
32
|
+
const dataGridImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@mui/x-data-grid"));
|
|
33
|
+
if (!dataGridImport) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
(_a = dataGridImport
|
|
37
|
+
.getNamedImports()
|
|
38
|
+
.find((namedImport) => namedImport.getText() === "GridColDef")) === null || _a === void 0 ? void 0 : _a.remove();
|
|
39
|
+
sourceFile.addImportDeclaration({
|
|
40
|
+
namedImports: ["GridColDef"],
|
|
41
|
+
moduleSpecifier: "@comet/admin",
|
|
42
|
+
});
|
|
43
|
+
sourceFile.saveSync();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.default = replaceGridColDefImport;
|