@comet/upgrade 1.12.0 → 1.14.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/lib/index.js +13 -15
- package/lib/v7/use-graphql-scalars.js +41 -0
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -39,29 +39,26 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
39
39
|
const path_1 = __importDefault(require("path"));
|
|
40
40
|
const semver_1 = __importDefault(require("semver"));
|
|
41
41
|
const execute_command_util_1 = require("./util/execute-command.util");
|
|
42
|
-
const VERSION_NUMBER = /^v?\d+$/;
|
|
43
42
|
const microservices = ["api", "admin", "site"];
|
|
44
43
|
function microserviceExists(microservice) {
|
|
45
44
|
return fs_1.default.existsSync(`${microservice}/package.json`);
|
|
46
45
|
}
|
|
47
46
|
function main() {
|
|
48
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
|
|
48
|
+
const targetVersionArg = process.argv[2];
|
|
50
49
|
if (targetVersionArg === undefined) {
|
|
51
50
|
console.error("Missing target version! Usage: npx @comet/upgrade <version>");
|
|
52
51
|
process.exit(-1);
|
|
53
52
|
}
|
|
54
|
-
|
|
53
|
+
const targetVersion = semver_1.default.coerce(targetVersionArg, { includePrerelease: true });
|
|
54
|
+
if (!targetVersion) {
|
|
55
55
|
console.error("Can't parse version number. Example usage: npx @comet/upgrade v4");
|
|
56
56
|
process.exit(-1);
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
const targetVersion = Number(targetVersionArg);
|
|
62
|
-
const scriptsFolder = path_1.default.join(__dirname, `v${targetVersion}`);
|
|
58
|
+
const targetVersionFolder = `v${targetVersion.major}`;
|
|
59
|
+
const scriptsFolder = path_1.default.join(__dirname, targetVersionFolder);
|
|
63
60
|
if (!fs_1.default.existsSync(scriptsFolder)) {
|
|
64
|
-
console.error(`Can't find target version '
|
|
61
|
+
console.error(`Can't find upgrade scripts for target version '${targetVersionFolder}'`);
|
|
65
62
|
listTargetVersions();
|
|
66
63
|
process.exit(-1);
|
|
67
64
|
}
|
|
@@ -69,7 +66,7 @@ function main() {
|
|
|
69
66
|
console.info(`Upgrading from v${currentVersion} to v${targetVersion}`);
|
|
70
67
|
console.info("Updating dependencies");
|
|
71
68
|
yield updateDependencies(targetVersion);
|
|
72
|
-
yield runUpgradeScripts(
|
|
69
|
+
yield runUpgradeScripts(targetVersionFolder);
|
|
73
70
|
yield runEslintFix();
|
|
74
71
|
});
|
|
75
72
|
}
|
|
@@ -130,23 +127,24 @@ function updateDependencies(targetVersion) {
|
|
|
130
127
|
"--no-audit",
|
|
131
128
|
"--loglevel",
|
|
132
129
|
"error",
|
|
133
|
-
|
|
134
|
-
...
|
|
130
|
+
targetVersion.prerelease.length > 0 ? "--save-exact" : "",
|
|
131
|
+
...dependencies.map((dependency) => `${dependency}@${targetVersion.version}`),
|
|
132
|
+
...devDependencies.map((dependency) => `${dependency}@${targetVersion.version}`),
|
|
135
133
|
]);
|
|
136
134
|
}
|
|
137
135
|
});
|
|
138
136
|
}
|
|
139
|
-
function runUpgradeScripts(
|
|
137
|
+
function runUpgradeScripts(targetVersionFolder) {
|
|
140
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
139
|
var _a;
|
|
142
|
-
const scriptsFolder = path_1.default.join(__dirname,
|
|
140
|
+
const scriptsFolder = path_1.default.join(__dirname, targetVersionFolder);
|
|
143
141
|
for (const fileName of fs_1.default.readdirSync(scriptsFolder)) {
|
|
144
142
|
const upgradeScript = yield (_a = path_1.default.join(scriptsFolder, fileName), Promise.resolve().then(() => __importStar(require(_a))));
|
|
145
143
|
try {
|
|
146
144
|
yield upgradeScript.default();
|
|
147
145
|
}
|
|
148
146
|
catch (error) {
|
|
149
|
-
console.error(`Script '
|
|
147
|
+
console.error(`Script '${targetVersionFolder}/${fileName}' failed to execute. See original error below`);
|
|
150
148
|
console.error(error);
|
|
151
149
|
}
|
|
152
150
|
}
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/upgrade",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Upgrade scripts for Comet DXP",
|
|
5
5
|
"homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"eslint": "^8.56.0",
|
|
32
32
|
"glob": "^10.3.10",
|
|
33
33
|
"prettier": "^2.8.1",
|
|
34
|
-
"semver": "^7.
|
|
34
|
+
"semver": "^7.6.2",
|
|
35
35
|
"ts-morph": "^22.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@comet/eslint-config": "^3.2.1",
|
|
39
39
|
"@types/node": "^20.0.0",
|
|
40
40
|
"@types/prettier": "^2.7.1",
|
|
41
|
-
"@types/semver": "^7.
|
|
41
|
+
"@types/semver": "^7.5.8",
|
|
42
42
|
"husky": "^8.0.2",
|
|
43
43
|
"lint-staged": "^13.1.0",
|
|
44
44
|
"npm-run-all": "^4.1.5",
|