@comet/upgrade 1.76.0 → 1.78.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,56 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Remove the second argument from sitePreviewRoute(request, createGraphQLFetch());
|
|
7
|
+
* Remove the third argument from legacyPagesRouterSitePreviewApiHandler(req, res, createGraphQLClient());
|
|
8
|
+
*/
|
|
9
|
+
async function removeGraphQLFetchFromSitePreviewRoute() {
|
|
10
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./site/tsconfig.json" });
|
|
11
|
+
const files = glob_1.glob.sync(["site/src/**/*.ts"]);
|
|
12
|
+
for (const filePath of files) {
|
|
13
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
14
|
+
if (!sourceFile) {
|
|
15
|
+
throw new Error(`Can't get source file for ${filePath}`);
|
|
16
|
+
}
|
|
17
|
+
const importsSitePreviewRoute = Boolean(sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/cms-site") &&
|
|
18
|
+
declaration
|
|
19
|
+
.getNamedImports()
|
|
20
|
+
.map((imp) => imp.getText())
|
|
21
|
+
.includes("sitePreviewRoute")));
|
|
22
|
+
if (importsSitePreviewRoute) {
|
|
23
|
+
sourceFile.forEachDescendant((node) => {
|
|
24
|
+
if (node.isKind(ts_morph_1.SyntaxKind.CallExpression)) {
|
|
25
|
+
const callExpr = node;
|
|
26
|
+
const expression = callExpr.getExpression();
|
|
27
|
+
if (expression.getText() === "sitePreviewRoute") {
|
|
28
|
+
if (callExpr.getArguments().length > 1) {
|
|
29
|
+
callExpr.removeArgument(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const legacyPagesRouterSitePreviewApiHandler = Boolean(sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/cms-site") &&
|
|
36
|
+
declaration
|
|
37
|
+
.getNamedImports()
|
|
38
|
+
.map((imp) => imp.getText())
|
|
39
|
+
.includes("legacyPagesRouterSitePreviewApiHandler")));
|
|
40
|
+
if (legacyPagesRouterSitePreviewApiHandler) {
|
|
41
|
+
sourceFile.forEachDescendant((node) => {
|
|
42
|
+
if (node.isKind(ts_morph_1.SyntaxKind.CallExpression)) {
|
|
43
|
+
const callExpr = node;
|
|
44
|
+
const expression = callExpr.getExpression();
|
|
45
|
+
if (expression.getText() === "legacyPagesRouterSitePreviewApiHandler") {
|
|
46
|
+
if (callExpr.getArguments().length > 2) {
|
|
47
|
+
callExpr.removeArgument(2);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
sourceFile.saveSync();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.default = removeGraphQLFetchFromSitePreviewRoute;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ts_morph_1 = require("ts-morph");
|
|
4
|
+
/**
|
|
5
|
+
* Update the configuration of the DamModule and BlobStorageModule and add ImgproxyModule to app.module.ts
|
|
6
|
+
*
|
|
7
|
+
* - Adds `cacheDirectory` to `BlobStorageModule.register`
|
|
8
|
+
* - Adds `ImgproxyModule` import
|
|
9
|
+
* - Add `maxSrcResolution` to `DamModule.register`
|
|
10
|
+
* - Removes `cacheDirectory` and `imgproxyConfig` from `DamModule.register`
|
|
11
|
+
*/
|
|
12
|
+
async function updateDamConfiguration() {
|
|
13
|
+
const project = new ts_morph_1.Project();
|
|
14
|
+
const filePath = "api/src/app.module.ts"; // Update this path to your actual file path
|
|
15
|
+
const sourceFile = project.addSourceFileAtPath(filePath);
|
|
16
|
+
// Update BlobStorageModule configuration
|
|
17
|
+
const blobStorageModuleCall = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => {
|
|
18
|
+
const expression = call.getExpression();
|
|
19
|
+
return expression.getText() === "BlobStorageModule.register";
|
|
20
|
+
});
|
|
21
|
+
if (blobStorageModuleCall) {
|
|
22
|
+
const args = blobStorageModuleCall.getArguments();
|
|
23
|
+
if (args.length > 0 && args[0].getKind() === ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
|
|
24
|
+
const objectLiteral = args[0];
|
|
25
|
+
const cacheDirectoryProperty = objectLiteral.getProperty("cacheDirectory");
|
|
26
|
+
if (!cacheDirectoryProperty) {
|
|
27
|
+
objectLiteral.addPropertyAssignment({
|
|
28
|
+
name: "cacheDirectory",
|
|
29
|
+
initializer: "`${config.blob.storageDirectoryPrefix}-cache`",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Add ImgproxyModule import
|
|
35
|
+
sourceFile.addImportDeclaration({
|
|
36
|
+
namedImports: ["ImgproxyModule"],
|
|
37
|
+
moduleSpecifier: "@comet/cms-api",
|
|
38
|
+
});
|
|
39
|
+
// Add ImgproxyModule configuration
|
|
40
|
+
const importsArray = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression).find((array) => {
|
|
41
|
+
const parent = array.getParent();
|
|
42
|
+
return parent && parent.getKind() === ts_morph_1.SyntaxKind.PropertyAssignment && parent.getName() === "imports";
|
|
43
|
+
});
|
|
44
|
+
if (importsArray) {
|
|
45
|
+
const imgproxyModuleCall = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => {
|
|
46
|
+
const expression = call.getExpression();
|
|
47
|
+
return expression.getText() === "ImgproxyModule.register";
|
|
48
|
+
});
|
|
49
|
+
if (!imgproxyModuleCall) {
|
|
50
|
+
importsArray.addElement("ImgproxyModule.register(config.imgproxy)");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Update DamModule configuration
|
|
54
|
+
const damModuleCall = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => {
|
|
55
|
+
const expression = call.getExpression();
|
|
56
|
+
return expression.getText() === "DamModule.register";
|
|
57
|
+
});
|
|
58
|
+
if (damModuleCall) {
|
|
59
|
+
const args = damModuleCall.getArguments();
|
|
60
|
+
if (args.length > 0 && args[0].getKind() === ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
|
|
61
|
+
const objectLiteral = args[0];
|
|
62
|
+
const damConfigProperty = objectLiteral.getProperty("damConfig");
|
|
63
|
+
if (damConfigProperty && damConfigProperty.getKind() === ts_morph_1.SyntaxKind.PropertyAssignment) {
|
|
64
|
+
const damConfigObject = damConfigProperty.getInitializerIfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
65
|
+
if (damConfigObject) {
|
|
66
|
+
const maxSrcResolutionProperty = damConfigObject.getProperty("maxSrcResolution");
|
|
67
|
+
if (!maxSrcResolutionProperty) {
|
|
68
|
+
damConfigObject.addPropertyAssignment({
|
|
69
|
+
name: "maxSrcResolution",
|
|
70
|
+
initializer: "config.dam.maxSrcResolution",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const cacheDirectoryProperty = damConfigObject.getProperty("cacheDirectory");
|
|
74
|
+
if (cacheDirectoryProperty) {
|
|
75
|
+
cacheDirectoryProperty.remove();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const imgproxyConfigProperty = objectLiteral.getProperty("imgproxyConfig");
|
|
80
|
+
if (imgproxyConfigProperty) {
|
|
81
|
+
imgproxyConfigProperty.remove();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
await project.save();
|
|
86
|
+
}
|
|
87
|
+
exports.default = updateDamConfiguration;
|