@comet/upgrade 1.6.0 → 1.8.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
CHANGED
|
@@ -35,10 +35,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const child_process_1 = require("child_process");
|
|
39
38
|
const fs_1 = __importDefault(require("fs"));
|
|
40
39
|
const path_1 = __importDefault(require("path"));
|
|
41
40
|
const semver_1 = __importDefault(require("semver"));
|
|
41
|
+
const execute_command_util_1 = require("./util/execute-command.util");
|
|
42
42
|
const VERSION_NUMBER = /^v?\d+$/;
|
|
43
43
|
const microservices = ["api", "admin", "site"];
|
|
44
44
|
function microserviceExists(microservice) {
|
|
@@ -123,7 +123,7 @@ function updateDependencies(targetVersion) {
|
|
|
123
123
|
console.warn(`Microservice '${microservice}' has no Comet DXP dependencies. Skipping install`);
|
|
124
124
|
continue;
|
|
125
125
|
}
|
|
126
|
-
yield executeCommand("npm", [
|
|
126
|
+
yield (0, execute_command_util_1.executeCommand)("npm", [
|
|
127
127
|
"install",
|
|
128
128
|
"--prefix",
|
|
129
129
|
microservice,
|
|
@@ -136,21 +136,6 @@ function updateDependencies(targetVersion) {
|
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
// Inspired by https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/createReactApp.js#L383
|
|
140
|
-
function executeCommand(command, args = []) {
|
|
141
|
-
return new Promise((resolve, reject) => {
|
|
142
|
-
const child = (0, child_process_1.spawn)(command, args, { stdio: "inherit" });
|
|
143
|
-
child.on("close", (code) => {
|
|
144
|
-
if (code !== 0) {
|
|
145
|
-
reject({
|
|
146
|
-
command: `${command} ${args.join(" ")}`,
|
|
147
|
-
});
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
resolve();
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
139
|
function runUpgradeScripts(targetVersion) {
|
|
155
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
141
|
var _a;
|
|
@@ -175,7 +160,7 @@ function runEslintFix() {
|
|
|
175
160
|
continue;
|
|
176
161
|
}
|
|
177
162
|
try {
|
|
178
|
-
yield executeCommand("npm", ["run", "--prefix", microservice, "--no-audit", "--loglevel", "error", "lint:eslint", "--", "--fix"]);
|
|
163
|
+
yield (0, execute_command_util_1.executeCommand)("npm", ["run", "--prefix", microservice, "--no-audit", "--loglevel", "error", "lint:eslint", "--", "--fix"]);
|
|
179
164
|
}
|
|
180
165
|
catch (err) {
|
|
181
166
|
console.error(`Failed to fix ESLint errors in ${microservice}. See original error below`);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeCommand = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
// Inspired by https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/createReactApp.js#L383
|
|
6
|
+
function executeCommand(command, args = []) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const child = (0, child_process_1.spawn)(command, args, { stdio: "inherit" });
|
|
9
|
+
child.on("close", (code) => {
|
|
10
|
+
if (code !== 0) {
|
|
11
|
+
reject({
|
|
12
|
+
command: `${command} ${args.join(" ")}`,
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
resolve();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.executeCommand = executeCommand;
|
|
@@ -0,0 +1,74 @@
|
|
|
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 ts_morph_1 = require("ts-morph");
|
|
13
|
+
/**
|
|
14
|
+
* Adds the `formatError` property to `GraphQLModule` options to hide `GraphQL` field suggestions for non dev environments.
|
|
15
|
+
*/
|
|
16
|
+
function hideGraphqlFieldSuggestions() {
|
|
17
|
+
var _a;
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
|
|
20
|
+
const sourceFile = project.getSourceFile("api/src/app.module.ts");
|
|
21
|
+
if (!sourceFile)
|
|
22
|
+
throw new Error("app.module.ts not found");
|
|
23
|
+
// Add the required import statements
|
|
24
|
+
sourceFile.addImportDeclaration({
|
|
25
|
+
namedImports: ["ValidationError"],
|
|
26
|
+
moduleSpecifier: "apollo-server-express",
|
|
27
|
+
});
|
|
28
|
+
sourceFile.addImportDeclaration({
|
|
29
|
+
namedImports: ["ApolloDriverConfig"],
|
|
30
|
+
moduleSpecifier: "@nestjs/apollo",
|
|
31
|
+
});
|
|
32
|
+
// Get the forRoot method within AppModule
|
|
33
|
+
const forRootMethod = sourceFile.getClassOrThrow("AppModule").getMethodOrThrow("forRoot");
|
|
34
|
+
// Get the GraphQLModule.forRootAsync call within the forRoot method
|
|
35
|
+
const graphqlForRootCall = (_a = forRootMethod
|
|
36
|
+
.getBody()) === null || _a === void 0 ? void 0 : _a.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => call.getText().includes("GraphQLModule.forRootAsync"));
|
|
37
|
+
if (!graphqlForRootCall)
|
|
38
|
+
throw new Error("GraphQLModule.forRootAsync call not found within forRoot method.");
|
|
39
|
+
// Add the generic type ApolloDriverConfig to the GraphQLModule.forRootAsync call
|
|
40
|
+
if (!forRootMethod.getFullText().includes("GraphQLModule.forRootAsync<ApolloDriverConfig>")) {
|
|
41
|
+
const expression = graphqlForRootCall.getExpression();
|
|
42
|
+
if (!expression)
|
|
43
|
+
throw new Error("Expression not found within GraphQLModule.forRootAsync call.");
|
|
44
|
+
const expressionText = expression.getText();
|
|
45
|
+
expression.replaceWithText(expressionText.replace(`${expressionText}`, `${expressionText}<ApolloDriverConfig>`));
|
|
46
|
+
}
|
|
47
|
+
const formatErrorImplText = `
|
|
48
|
+
(error) => {
|
|
49
|
+
if (process.env.NODE_ENV !== "development") {
|
|
50
|
+
if (error instanceof ValidationError) {
|
|
51
|
+
return new ValidationError("Invalid request.");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return error;
|
|
55
|
+
}`;
|
|
56
|
+
// return if property formatError already exists
|
|
57
|
+
if (graphqlForRootCall.getArguments().find((arg) => arg.getText().includes("formatError"))) {
|
|
58
|
+
throw new Error(`formatError property already exists in GraphQLModule.forRootAsync options. To be sure GraphQl field suggestions are disabled for non dev environments, please check if the implementation already contains: ${formatErrorImplText}`);
|
|
59
|
+
}
|
|
60
|
+
// Find the useFactory function within the GraphQLModule.forRootAsync call
|
|
61
|
+
const useFactoryFunction = graphqlForRootCall.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ArrowFunction, "useFactory function not found within GraphQLModule.forRootAsync call.");
|
|
62
|
+
if (!useFactoryFunction.getParent().getText().includes("useFactory"))
|
|
63
|
+
throw new Error("useFactory function not found within GraphQLModule.forRootAsync call.");
|
|
64
|
+
// Find the object literal being returned by the useFactory function
|
|
65
|
+
const returnObjectLiteral = useFactoryFunction.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression, "Object literal not found within useFactory function.");
|
|
66
|
+
// Add your formatError to GraphQLModule.forRootAsync options
|
|
67
|
+
returnObjectLiteral.addPropertyAssignment({
|
|
68
|
+
name: "formatError",
|
|
69
|
+
initializer: ({ write }) => write(formatErrorImplText),
|
|
70
|
+
});
|
|
71
|
+
sourceFile.saveSync();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.default = hideGraphqlFieldSuggestions;
|
|
@@ -0,0 +1,49 @@
|
|
|
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 execute_command_util_1 = require("../util/execute-command.util");
|
|
14
|
+
const format_code_util_1 = require("../util/format-code.util");
|
|
15
|
+
/**
|
|
16
|
+
* Replaces the old font package "Roboto" with the new "Roboto Flex"
|
|
17
|
+
*/
|
|
18
|
+
function replaceRobotoWithRobotoFlex() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
yield replacePackageInPackageJson();
|
|
21
|
+
yield removeOldPackageImports();
|
|
22
|
+
yield addNewPackageImport();
|
|
23
|
+
yield (0, execute_command_util_1.executeCommand)("npm", ["install", "--prefix", "admin", "--no-audit", "--loglevel", "error"]);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.default = replaceRobotoWithRobotoFlex;
|
|
27
|
+
const replacePackageInPackageJson = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const filePath = "admin/package.json";
|
|
29
|
+
let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
|
|
30
|
+
const searchString = "@fontsource/roboto";
|
|
31
|
+
const re = new RegExp(`^.*${searchString}.*$`, "gm");
|
|
32
|
+
fileContent = fileContent.replace(re, ' "@fontsource-variable/roboto-flex": "^5.0.0",');
|
|
33
|
+
yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
|
|
34
|
+
});
|
|
35
|
+
const removeOldPackageImports = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const filePath = "admin/src/App.tsx";
|
|
37
|
+
let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
|
|
38
|
+
const searchString = 'import "@fontsource/roboto';
|
|
39
|
+
const re = new RegExp(`^.*${searchString}.*$`, "gm");
|
|
40
|
+
fileContent = fileContent.replace(re, "");
|
|
41
|
+
yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
|
|
42
|
+
});
|
|
43
|
+
const addNewPackageImport = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const filePath = "admin/src/App.tsx";
|
|
45
|
+
let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
|
|
46
|
+
fileContent = `import "@fontsource-variable/roboto-flex/full.css";
|
|
47
|
+
${fileContent}`;
|
|
48
|
+
yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
|
|
49
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/upgrade",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Upgrade scripts for Comet DXP",
|
|
5
5
|
"homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"eslint": "^8.56.0",
|
|
32
32
|
"glob": "^10.3.10",
|
|
33
33
|
"prettier": "^2.8.1",
|
|
34
|
-
"semver": "^7.3.8"
|
|
34
|
+
"semver": "^7.3.8",
|
|
35
|
+
"ts-morph": "^22.0.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@comet/eslint-config": "^3.2.1",
|