@comet/upgrade 1.24.0 → 1.26.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,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("fs/promises");
4
+ const glob_1 = require("glob");
5
+ const ts_morph_1 = require("ts-morph");
6
+ const renamedExports = {
7
+ getMostSignificantPreviewImageUrlTemplate: "getMostSignificantPreviewImageUrlTemplateFromBlock",
8
+ getPreviewImageUrlTemplates: "getPreviewImageUrlTemplatesFromBlock",
9
+ getSearchText: "getSearchTextFromBlock",
10
+ inputToData: "blockInputToData",
11
+ TransformResponse: "TransformBlockResponse",
12
+ TransformResponseArray: "TransformBlockResponseArray",
13
+ transformToSave: "transformToBlockSave",
14
+ transformToSaveIndex: "transformToBlockSaveIndex",
15
+ TraversableTransformResponse: "TraversableTransformBlockResponse",
16
+ TraversableTransformResponseArray: "TraversableTransformBlockResponseArray",
17
+ typesafeMigrationPipe: "typeSafeBlockMigrationPipe",
18
+ };
19
+ async function mergeBlocksApiIntoCmsApi() {
20
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
21
+ const files = glob_1.glob.sync(["api/src/**/*.ts"]);
22
+ for (const filePath of files) {
23
+ const sourceFile = project.getSourceFile(filePath);
24
+ if (!sourceFile) {
25
+ throw new Error(`Can't get source file for ${filePath}`);
26
+ }
27
+ const blocksApiImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/blocks-api"));
28
+ if (!blocksApiImport) {
29
+ continue;
30
+ }
31
+ const blocksApiImports = blocksApiImport.getNamedImports().map((namedImport) => namedImport.getText());
32
+ const importsToRename = Object.entries(renamedExports).filter(([oldExport]) => blocksApiImports.includes(oldExport));
33
+ blocksApiImport.remove();
34
+ const cmsApiImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/cms-api"));
35
+ if (cmsApiImport) {
36
+ cmsApiImport.addNamedImports(blocksApiImports);
37
+ }
38
+ else {
39
+ sourceFile.addImportDeclaration({
40
+ namedImports: blocksApiImports,
41
+ moduleSpecifier: "@comet/cms-api",
42
+ });
43
+ }
44
+ await sourceFile.save();
45
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
46
+ for (const [oldExport, newExport] of importsToRename) {
47
+ fileContent = fileContent.replaceAll(oldExport, newExport);
48
+ }
49
+ await (0, promises_1.writeFile)(filePath, fileContent);
50
+ }
51
+ }
52
+ exports.default = mergeBlocksApiIntoCmsApi;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts_morph_1 = require("ts-morph");
4
+ /**
5
+ * from
6
+ *
7
+ * createAuthResolver({
8
+ * currentUser: CurrentUser,
9
+ * }),
10
+ *
11
+ *
12
+ * to
13
+ *
14
+ * createAuthResolver({}),
15
+ */
16
+ async function removeCurrentUserFromAuthModule() {
17
+ console.log("Remove Current User From Auth Module");
18
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
19
+ const sourceFiles = project.getSourceFiles("api/src/**/*.ts");
20
+ sourceFiles.forEach((sourceFile) => {
21
+ const createAuthResolverCall = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((callExpression) => {
22
+ const expression = callExpression.getExpression();
23
+ return expression.getText() === "createAuthResolver";
24
+ });
25
+ if (createAuthResolverCall) {
26
+ const argument = createAuthResolverCall.getArguments()[0];
27
+ if (argument && argument.getKind() === ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
28
+ const objectLiteral = argument.asKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
29
+ const currentUserProp = objectLiteral.getProperty("currentUser");
30
+ if (currentUserProp) {
31
+ console.log("Found createAuthResolver and removed currentUser in ", sourceFile.getFilePath());
32
+ currentUserProp.remove();
33
+ }
34
+ }
35
+ sourceFile.save();
36
+ }
37
+ });
38
+ }
39
+ exports.default = removeCurrentUserFromAuthModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.24.0",
3
+ "version": "1.26.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {