@comet/upgrade 1.114.0 → 1.115.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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = removeGraphQLClientFromSitePreviewHandlers;
4
- const fs_1 = require("fs");
4
+ const glob_1 = require("glob");
5
5
  const ts_morph_1 = require("ts-morph");
6
6
  /**
7
7
  * Removes the GraphQL client/fetch from the site preview handlers
@@ -11,39 +11,48 @@ const ts_morph_1 = require("ts-morph");
11
11
  */
12
12
  async function removeGraphQLClientFromSitePreviewHandlers() {
13
13
  const project = new ts_morph_1.Project({ tsConfigFilePath: "./site/tsconfig.json" });
14
- // App Router
15
- if ((0, fs_1.existsSync)("site/src/app/api/site-preview/route.ts")) {
16
- const sourceFile = project.getSourceFile("site/src/app/api/site-preview/route.ts");
14
+ const files = glob_1.glob.sync(["site/src/**/*.ts"]);
15
+ for (const filePath of files) {
16
+ const sourceFile = project.getSourceFile(filePath);
17
17
  if (!sourceFile) {
18
- throw new Error("Can't get source file for site/src/app/api/site-preview/route.ts");
18
+ throw new Error(`Can't get source file for ${filePath}`);
19
19
  }
20
- const getFunction = sourceFile.getFunction("GET");
21
- if (getFunction) {
22
- const callExpression = getFunction.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
23
- if (callExpression) {
24
- callExpression.removeArgument(1);
25
- }
20
+ const importsSitePreviewRoute = Boolean(sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/cms-site") &&
21
+ declaration
22
+ .getNamedImports()
23
+ .map((imp) => imp.getText())
24
+ .includes("sitePreviewRoute")));
25
+ if (importsSitePreviewRoute) {
26
+ sourceFile.forEachDescendant((node) => {
27
+ if (node.isKind(ts_morph_1.SyntaxKind.CallExpression)) {
28
+ const callExpr = node;
29
+ const expression = callExpr.getExpression();
30
+ if (expression.getText() === "sitePreviewRoute") {
31
+ if (callExpr.getArguments().length > 1) {
32
+ callExpr.removeArgument(1);
33
+ }
34
+ }
35
+ }
36
+ });
26
37
  }
27
- await sourceFile.save();
28
- }
29
- // Pages Router
30
- let pagesRouterApiRouteFile;
31
- if ((0, fs_1.existsSync)("site/src/pages/api/site-preview.page.ts")) {
32
- pagesRouterApiRouteFile = "site/src/pages/api/site-preview.page.ts";
33
- }
34
- else if ((0, fs_1.existsSync)("site/src/pages/api/site-preview.ts")) {
35
- // Projects without .page.ts extension
36
- pagesRouterApiRouteFile = "site/src/pages/api/site-preview.ts";
37
- }
38
- if (pagesRouterApiRouteFile) {
39
- const sourceFile = project.getSourceFile(pagesRouterApiRouteFile);
40
- if (!sourceFile) {
41
- throw new Error(`Can't get source file for ${pagesRouterApiRouteFile}`);
42
- }
43
- const callExpression = sourceFile.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
44
- if (callExpression) {
45
- callExpression.removeArgument(2);
38
+ const legacyPagesRouterSitePreviewApiHandler = Boolean(sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/cms-site") &&
39
+ declaration
40
+ .getNamedImports()
41
+ .map((imp) => imp.getText())
42
+ .includes("legacyPagesRouterSitePreviewApiHandler")));
43
+ if (legacyPagesRouterSitePreviewApiHandler) {
44
+ sourceFile.forEachDescendant((node) => {
45
+ if (node.isKind(ts_morph_1.SyntaxKind.CallExpression)) {
46
+ const callExpr = node;
47
+ const expression = callExpr.getExpression();
48
+ if (expression.getText() === "legacyPagesRouterSitePreviewApiHandler") {
49
+ if (callExpr.getArguments().length > 2) {
50
+ callExpr.removeArgument(2);
51
+ }
52
+ }
53
+ }
54
+ });
46
55
  }
47
- await sourceFile.save();
56
+ sourceFile.saveSync();
48
57
  }
49
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.114.0",
3
+ "version": "1.115.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = removeGraphQLFetchFromSitePreviewRoute;
4
- const glob_1 = require("glob");
5
- const ts_morph_1 = require("ts-morph");
6
- /**
7
- * Remove the second argument from sitePreviewRoute(request, createGraphQLFetch());
8
- * Remove the third argument from legacyPagesRouterSitePreviewApiHandler(req, res, createGraphQLClient());
9
- */
10
- async function removeGraphQLFetchFromSitePreviewRoute() {
11
- const project = new ts_morph_1.Project({ tsConfigFilePath: "./site/tsconfig.json" });
12
- const files = glob_1.glob.sync(["site/src/**/*.ts"]);
13
- for (const filePath of files) {
14
- const sourceFile = project.getSourceFile(filePath);
15
- if (!sourceFile) {
16
- throw new Error(`Can't get source file for ${filePath}`);
17
- }
18
- const importsSitePreviewRoute = Boolean(sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/cms-site") &&
19
- declaration
20
- .getNamedImports()
21
- .map((imp) => imp.getText())
22
- .includes("sitePreviewRoute")));
23
- if (importsSitePreviewRoute) {
24
- sourceFile.forEachDescendant((node) => {
25
- if (node.isKind(ts_morph_1.SyntaxKind.CallExpression)) {
26
- const callExpr = node;
27
- const expression = callExpr.getExpression();
28
- if (expression.getText() === "sitePreviewRoute") {
29
- if (callExpr.getArguments().length > 1) {
30
- callExpr.removeArgument(1);
31
- }
32
- }
33
- }
34
- });
35
- }
36
- const legacyPagesRouterSitePreviewApiHandler = Boolean(sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/cms-site") &&
37
- declaration
38
- .getNamedImports()
39
- .map((imp) => imp.getText())
40
- .includes("legacyPagesRouterSitePreviewApiHandler")));
41
- if (legacyPagesRouterSitePreviewApiHandler) {
42
- sourceFile.forEachDescendant((node) => {
43
- if (node.isKind(ts_morph_1.SyntaxKind.CallExpression)) {
44
- const callExpr = node;
45
- const expression = callExpr.getExpression();
46
- if (expression.getText() === "legacyPagesRouterSitePreviewApiHandler") {
47
- if (callExpr.getArguments().length > 2) {
48
- callExpr.removeArgument(2);
49
- }
50
- }
51
- }
52
- });
53
- }
54
- sourceFile.saveSync();
55
- }
56
- }