@comet/upgrade 1.51.0 → 1.53.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.
@@ -41,5 +41,8 @@ class PackageJson {
41
41
  this.json.scripts ??= {};
42
42
  this.json.scripts[name] = script;
43
43
  }
44
+ removeScript(name) {
45
+ delete this.json.scripts?.[name];
46
+ }
44
47
  }
45
48
  exports.PackageJson = PackageJson;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stage = void 0;
4
+ const fs_1 = require("fs");
5
+ const package_json_util_1 = require("../util/package-json.util");
6
+ const adminEslintConfig = `import eslintConfigReact from "@comet/eslint-config/react.js";
7
+
8
+ /** @type {import('eslint')} */
9
+ const config = [
10
+ {
11
+ ignores: ["schema.json", "src/fragmentTypes.json", "dist/**", "src/**/*.generated.ts"],
12
+ },
13
+ ...eslintConfigReact,
14
+ ];
15
+
16
+ export default config;`;
17
+ const apiEslintConfig = `import eslintConfigNestJs from "@comet/eslint-config/nestjs.js";
18
+
19
+ /** @type {import('eslint')} */
20
+ const config = [
21
+ {
22
+ ignores: ["src/db/migrations/**", "dist/**", "src/**/*.generated.ts"],
23
+ },
24
+ ...eslintConfigNestJs,
25
+ ];
26
+
27
+ export default config;`;
28
+ const siteEslintConfig = `import eslintConfigNextJs from "@comet/eslint-config/nextjs.js";
29
+
30
+ /** @type {import('eslint')} */
31
+ const config = [
32
+ {
33
+ ignores: ["**/**/*.generated.ts", "dist/**", "lang/**", "lang-compiled/**", "lang-extracted/**", ".next/**", "public/**"],
34
+ },
35
+ ...eslintConfigNextJs,
36
+ ];
37
+
38
+ export default config;`;
39
+ exports.stage = "before-install";
40
+ /**
41
+ * This Updates script is doing following:
42
+ *
43
+ * - updates eslint to version 9.
44
+ * - creates new eslint.config.mjs file with default configuration
45
+ * - copies content from .eslint.json to new eslint.config.mjs as a comment
46
+ * - deletes old .eslint.json file
47
+ */
48
+ async function updateEslint() {
49
+ if ((0, fs_1.existsSync)("admin/package.json")) {
50
+ updateDevDependenciesInPackageJsons({ packageJsonPath: "admin/package.json" });
51
+ createNewFlatConfigurationFile({
52
+ workingDirectory: "admin/",
53
+ fileContent: adminEslintConfig,
54
+ });
55
+ deleteOldEslintRc({ workingDirectory: "admin/" });
56
+ }
57
+ if ((0, fs_1.existsSync)("api/package.json")) {
58
+ updateDevDependenciesInPackageJsons({ packageJsonPath: "api/package.json" });
59
+ createNewFlatConfigurationFile({
60
+ workingDirectory: "api/",
61
+ fileContent: apiEslintConfig,
62
+ });
63
+ deleteOldEslintRc({ workingDirectory: "api/" });
64
+ }
65
+ if ((0, fs_1.existsSync)("site/package.json")) {
66
+ updateDevDependenciesInPackageJsons({ packageJsonPath: "site/package.json" });
67
+ createNewFlatConfigurationFile({
68
+ workingDirectory: "site/",
69
+ fileContent: siteEslintConfig,
70
+ });
71
+ deleteOldEslintRc({ workingDirectory: "site/" });
72
+ // remove .eslintrc.cli.js
73
+ if ((0, fs_1.existsSync)("site/.eslintrc.cli.js")) {
74
+ (0, fs_1.rmSync)("site/.eslintrc.cli.js");
75
+ const packageJson = new package_json_util_1.PackageJson("site/package.json");
76
+ packageJson.removeScript("lint:eslint");
77
+ packageJson.addScript("lint:eslint", "eslint --max-warnings 0 src/ **/*.json --no-warn-ignored");
78
+ packageJson.save();
79
+ }
80
+ }
81
+ }
82
+ exports.default = updateEslint;
83
+ const updateDevDependenciesInPackageJsons = ({ packageJsonPath }) => {
84
+ console.log(`🚀 Update eslint to v9.18.0 in ${packageJsonPath}`);
85
+ const packageJson = new package_json_util_1.PackageJson(packageJsonPath);
86
+ packageJson.updateDependency("eslint", "^9.18.0");
87
+ packageJson.save();
88
+ };
89
+ const createNewFlatConfigurationFile = ({ workingDirectory, fileContent }) => {
90
+ console.log(`🚀 Create new eslint.config.mjs flat configuration .file ${workingDirectory}`);
91
+ const eslintConfig = (0, fs_1.readFileSync)(`${workingDirectory}.eslintrc.json`, "utf-8");
92
+ const commentedEslintConfig = eslintConfig
93
+ .split("\n")
94
+ .map((line) => `// ${line}`)
95
+ .join("\n");
96
+ const oldEslintConfigTodo = `// TODO: integrate custom rules from project into new eslint.config.mjs file
97
+ //
98
+ // Content from .eslintrc.json:
99
+ //
100
+ ${commentedEslintConfig}
101
+ `;
102
+ (0, fs_1.writeFileSync)(`${workingDirectory}eslint.config.mjs`, oldEslintConfigTodo + fileContent);
103
+ };
104
+ const deleteOldEslintRc = ({ workingDirectory }) => {
105
+ console.log(`🚀 Delete old .eslintrc.json configuration file ${workingDirectory}`);
106
+ (0, fs_1.rmSync)(`${workingDirectory}.eslintrc.json`);
107
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const glob_1 = require("glob");
4
+ const ts_morph_1 = require("ts-morph");
5
+ const renameMap = {
6
+ Menu: "MainNavigation",
7
+ MenuProps: "MainNavigationProps",
8
+ MenuClassKey: "MainNavigationClassKey",
9
+ MenuItem: "MainNavigationItem",
10
+ MenuItemProps: "MainNavigationItemProps",
11
+ MenuItemClassKey: "MainNavigationItemClassKey",
12
+ MenuCollapsibleItem: "MainNavigationCollapsibleItem",
13
+ MenuCollapsibleItemProps: "MainNavigationCollapsibleItemProps",
14
+ MenuCollapsibleItemClassKey: "MainNavigationCollapsibleItemClassKey",
15
+ IWithMenu: "WithMainNavigation",
16
+ withMenu: "withMainNavigation",
17
+ MenuItemAnchorLink: "MainNavigationItemAnchorLink",
18
+ MenuItemAnchorLinkProps: "MainNavigationItemAnchorLinkProps",
19
+ MenuItemGroup: "MainNavigationItemGroup",
20
+ MenuItemGroupClassKey: "MainNavigationItemGroupClassKey",
21
+ MenuItemGroupProps: "MainNavigationItemGroupProps",
22
+ MenuItemRouterLink: "MainNavigationItemRouterLink",
23
+ MenuItemRouterLinkProps: "MainNavigationItemRouterLinkProps",
24
+ MenuContext: "useMainNavigation",
25
+ };
26
+ async function renameComponents() {
27
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
28
+ const files = glob_1.glob.sync(["admin/src/**/*.tsx"]);
29
+ for (const filePath of files) {
30
+ const sourceFile = project.getSourceFile(filePath);
31
+ if (!sourceFile) {
32
+ throw new Error(`Can't get source file for ${filePath}`);
33
+ }
34
+ const adminImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue() === "@comet/admin");
35
+ if (adminImport) {
36
+ const namedImports = adminImport.getNamedImports();
37
+ for (const [oldName, newName] of Object.entries(renameMap)) {
38
+ const namedImport = namedImports.find((imported) => imported.getName() === oldName);
39
+ if (namedImport) {
40
+ namedImport.setName(newName);
41
+ if (oldName === "MenuContext") {
42
+ const useContextCalls = sourceFile.getDescendantsOfKind(ts_morph_1.ts.SyntaxKind.CallExpression).filter((call) => {
43
+ const expression = call.getExpression();
44
+ return (expression.getText() === "useContext" &&
45
+ call.getArguments().length === 1 &&
46
+ call.getArguments()[0].getText() === "MenuContext");
47
+ });
48
+ for (const call of useContextCalls) {
49
+ call.replaceWithText("useMainNavigation()");
50
+ }
51
+ }
52
+ else {
53
+ const references = sourceFile
54
+ .getDescendantsOfKind(ts_morph_1.ts.SyntaxKind.Identifier)
55
+ .filter((identifier) => identifier.getText() === oldName);
56
+ for (const reference of references) {
57
+ reference.replaceWithText(newName);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ await sourceFile.save();
64
+ }
65
+ }
66
+ exports.default = renameComponents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.51.0",
3
+ "version": "1.53.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {