@comet/upgrade 1.12.0 → 1.13.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,41 @@
|
|
|
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 execute_command_util_1 = require("../util/execute-command.util");
|
|
15
|
+
const format_code_util_1 = require("../util/format-code.util");
|
|
16
|
+
function useGraphqlScalars() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// replace graphql-type-json with graphql-scalars in api/package.json
|
|
19
|
+
const packageJson = yield (0, promises_1.readFile)(`api/package.json`);
|
|
20
|
+
if (!packageJson.includes("graphql-type-json")) {
|
|
21
|
+
// if not found, it was not used in the project, so we can skip this migration
|
|
22
|
+
console.log("graphql-type-json not found in api/package.json. Skipping migration.");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
yield (0, execute_command_util_1.executeCommand)("npm", ["uninstall", "--prefix", "api", "--no-audit", "--loglevel", "error", "graphql-type-json"]);
|
|
26
|
+
yield (0, execute_command_util_1.executeCommand)("npm", ["install", "--prefix", "api", "--no-audit", "--loglevel", "error", "graphql-scalars"]);
|
|
27
|
+
// replace graphql-type-json with graphql-scalars in all api files
|
|
28
|
+
// before: import { GraphQLJSONObject } from "graphql-type-json";
|
|
29
|
+
// after: import { GraphQLJSONObject } from "graphql-scalars";
|
|
30
|
+
const files = glob_1.glob.sync(["api/src/**/*.ts"]);
|
|
31
|
+
for (const filePath of files) {
|
|
32
|
+
let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
|
|
33
|
+
if (!fileContent.includes("graphql-type-json")) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
fileContent = fileContent.replace(/graphql-type-json/g, "graphql-scalars");
|
|
37
|
+
yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.default = useGraphqlScalars;
|