@comet/upgrade 1.20.0 → 1.21.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
@@ -1,36 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
4
  };
@@ -43,53 +11,50 @@ const microservices = ["api", "admin", "site"];
43
11
  function microserviceExists(microservice) {
44
12
  return fs_1.default.existsSync(`${microservice}/package.json`);
45
13
  }
46
- function main() {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const targetVersionArg = process.argv[2];
49
- if (targetVersionArg === undefined) {
50
- console.error("Missing target version! Usage: npx @comet/upgrade <version>");
51
- process.exit(-1);
52
- }
53
- const isUpgradeScript = targetVersionArg.endsWith(".ts");
54
- if (isUpgradeScript) {
55
- if (fs_1.default.existsSync(path_1.default.join(__dirname, targetVersionArg.replace(/\.ts$/, ".js")))) {
56
- yield runUpgradeScript(targetVersionArg.replace(/\.ts$/, ".js"));
57
- yield runEslintFix();
58
- }
59
- else {
60
- console.error(`Can't find upgrade script '${targetVersionArg}'`);
61
- process.exit(-1);
62
- }
63
- return;
64
- }
65
- const targetVersion = semver_1.default.coerce(targetVersionArg, { includePrerelease: true });
66
- if (!targetVersion) {
67
- console.error("Can't parse version number. Example usage: npx @comet/upgrade v4");
68
- process.exit(-1);
14
+ async function main() {
15
+ const targetVersionArg = process.argv[2];
16
+ if (targetVersionArg === undefined) {
17
+ console.error("Missing target version! Usage: npx @comet/upgrade <version>");
18
+ process.exit(-1);
19
+ }
20
+ const isUpgradeScript = targetVersionArg.endsWith(".ts");
21
+ if (isUpgradeScript) {
22
+ if (fs_1.default.existsSync(path_1.default.join(__dirname, targetVersionArg.replace(/\.ts$/, ".js")))) {
23
+ await runUpgradeScript(targetVersionArg.replace(/\.ts$/, ".js"));
24
+ await runEslintFix();
69
25
  }
70
- const targetVersionFolder = `v${targetVersion.major}`;
71
- const scriptsFolder = path_1.default.join(__dirname, targetVersionFolder);
72
- if (!fs_1.default.existsSync(scriptsFolder)) {
73
- console.error(`Can't find upgrade scripts for target version '${targetVersionFolder}'`);
74
- listTargetVersions();
26
+ else {
27
+ console.error(`Can't find upgrade script '${targetVersionArg}'`);
75
28
  process.exit(-1);
76
29
  }
77
- const currentVersion = getCurrentVersion();
78
- console.info(`Upgrading from v${currentVersion} to v${targetVersion}`);
79
- console.info("Updating dependencies");
80
- yield updateDependencies(targetVersion);
81
- yield runUpgradeScripts(targetVersionFolder);
82
- yield runEslintFix();
83
- });
30
+ return;
31
+ }
32
+ const targetVersion = semver_1.default.coerce(targetVersionArg, { includePrerelease: true });
33
+ if (!targetVersion) {
34
+ console.error("Can't parse version number. Example usage: npx @comet/upgrade v4");
35
+ process.exit(-1);
36
+ }
37
+ const targetVersionFolder = `v${targetVersion.major}`;
38
+ const scriptsFolder = path_1.default.join(__dirname, targetVersionFolder);
39
+ if (!fs_1.default.existsSync(scriptsFolder)) {
40
+ console.error(`Can't find upgrade scripts for target version '${targetVersionFolder}'`);
41
+ listTargetVersions();
42
+ process.exit(-1);
43
+ }
44
+ const currentVersion = getCurrentVersion();
45
+ console.info(`Upgrading from v${currentVersion} to v${targetVersion}`);
46
+ console.info("Updating dependencies");
47
+ await updateDependencies(targetVersion);
48
+ await runUpgradeScripts(targetVersionFolder);
49
+ await runEslintFix();
84
50
  }
85
51
  function getCurrentVersion() {
86
- var _a;
87
52
  if (!microserviceExists("admin")) {
88
53
  console.error(`File 'admin/package.json' doesn't exist. Make sure to call the script in the root of your project`);
89
54
  process.exit(-1);
90
55
  }
91
56
  const packageJson = JSON.parse(fs_1.default.readFileSync("admin/package.json").toString());
92
- const versionRange = (_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["@comet/admin"];
57
+ const versionRange = packageJson.dependencies?.["@comet/admin"];
93
58
  if (versionRange === undefined) {
94
59
  console.error(`Package '@comet/admin' isn't listed as a dependency. Is this a Comet DXP project?`);
95
60
  process.exit(-1);
@@ -103,86 +68,79 @@ function getCurrentVersion() {
103
68
  const version = versionMatches[0];
104
69
  return semver_1.default.major(version);
105
70
  }
106
- function updateDependencies(targetVersion) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const packages = {
109
- api: ["@comet/blocks-api", "@comet/cms-api"],
110
- admin: [
111
- "@comet/admin",
112
- "@comet/admin-color-picker",
113
- "@comet/admin-date-time",
114
- "@comet/admin-icons",
115
- "@comet/admin-react-select",
116
- "@comet/admin-rte",
117
- "@comet/admin-theme",
118
- "@comet/blocks-admin",
119
- "@comet/cms-admin",
120
- ],
121
- site: ["@comet/cms-site"],
122
- };
123
- for (const microservice of microservices) {
124
- if (!microserviceExists(microservice)) {
125
- console.warn(`File '${microservice}/package.json' doesn't exist. Skipping microservice`);
126
- continue;
127
- }
128
- const packageJson = JSON.parse(fs_1.default.readFileSync(`${microservice}/package.json`).toString());
129
- const dependencies = packages[microservice].filter((packageName) => { var _a; return ((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a[packageName]) !== undefined; });
130
- const devDependencies = ["@comet/cli", "@comet/eslint-config", "@comet/eslint-plugin"].filter((packageName) => { var _a; return ((_a = packageJson.devDependencies) === null || _a === void 0 ? void 0 : _a[packageName]) !== undefined; });
131
- if (dependencies.length === 0 && devDependencies.length === 0) {
132
- console.warn(`Microservice '${microservice}' has no Comet DXP dependencies. Skipping install`);
133
- continue;
134
- }
135
- yield (0, execute_command_util_1.executeCommand)("npm", [
136
- "install",
137
- "--prefix",
138
- microservice,
139
- "--no-audit",
140
- "--loglevel",
141
- "error",
142
- targetVersion.prerelease.length > 0 ? "--save-exact" : "",
143
- ...dependencies.map((dependency) => `${dependency}@${targetVersion.version}`),
144
- ...devDependencies.map((dependency) => `${dependency}@${targetVersion.version}`),
145
- ]);
71
+ async function updateDependencies(targetVersion) {
72
+ const packages = {
73
+ api: ["@comet/blocks-api", "@comet/cms-api"],
74
+ admin: [
75
+ "@comet/admin",
76
+ "@comet/admin-color-picker",
77
+ "@comet/admin-date-time",
78
+ "@comet/admin-icons",
79
+ "@comet/admin-react-select",
80
+ "@comet/admin-rte",
81
+ "@comet/admin-theme",
82
+ "@comet/blocks-admin",
83
+ "@comet/cms-admin",
84
+ ],
85
+ site: ["@comet/cms-site"],
86
+ };
87
+ for (const microservice of microservices) {
88
+ if (!microserviceExists(microservice)) {
89
+ console.warn(`File '${microservice}/package.json' doesn't exist. Skipping microservice`);
90
+ continue;
146
91
  }
147
- });
148
- }
149
- function runUpgradeScripts(targetVersionFolder) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- const scriptsFolder = path_1.default.join(__dirname, targetVersionFolder);
152
- for (const fileName of fs_1.default.readdirSync(scriptsFolder)) {
153
- yield runUpgradeScript(path_1.default.join(targetVersionFolder, fileName));
92
+ const packageJson = JSON.parse(fs_1.default.readFileSync(`${microservice}/package.json`).toString());
93
+ const dependencies = packages[microservice].filter((packageName) => packageJson.dependencies?.[packageName] !== undefined);
94
+ const devDependencies = ["@comet/cli", "@comet/eslint-config", "@comet/eslint-plugin"].filter((packageName) => packageJson.devDependencies?.[packageName] !== undefined);
95
+ if (dependencies.length === 0 && devDependencies.length === 0) {
96
+ console.warn(`Microservice '${microservice}' has no Comet DXP dependencies. Skipping install`);
97
+ continue;
154
98
  }
155
- });
99
+ await (0, execute_command_util_1.executeCommand)("npm", [
100
+ "install",
101
+ "--prefix",
102
+ microservice,
103
+ "--no-audit",
104
+ "--loglevel",
105
+ "error",
106
+ targetVersion.prerelease.length > 0 ? "--save-exact" : "",
107
+ ...dependencies.map((dependency) => `${dependency}@${targetVersion.version}`),
108
+ ...devDependencies.map((dependency) => `${dependency}@${targetVersion.version}`),
109
+ ]);
110
+ }
156
111
  }
157
- function runUpgradeScript(script) {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- var _a;
160
- const upgradeScript = yield (_a = path_1.default.join(__dirname, script), Promise.resolve().then(() => __importStar(require(_a))));
161
- try {
162
- yield upgradeScript.default();
112
+ async function runUpgradeScripts(targetVersionFolder) {
113
+ const scriptsFolder = path_1.default.join(__dirname, targetVersionFolder);
114
+ for (const fileName of fs_1.default.readdirSync(scriptsFolder)) {
115
+ await runUpgradeScript(path_1.default.join(targetVersionFolder, fileName));
116
+ }
117
+ }
118
+ async function runUpgradeScript(script) {
119
+ const upgradeScript = await import(path_1.default.join(__dirname, script));
120
+ try {
121
+ // Need default.default because of ESM interoperability with CommonJS.
122
+ // See https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext.
123
+ await upgradeScript.default.default();
124
+ }
125
+ catch (error) {
126
+ console.error(`Script '${script}' failed to execute. See original error below`);
127
+ console.error(error);
128
+ }
129
+ }
130
+ async function runEslintFix() {
131
+ console.info("Fixing ESLint errors");
132
+ for (const microservice of microservices) {
133
+ if (!microserviceExists(microservice)) {
134
+ continue;
163
135
  }
164
- catch (error) {
165
- console.error(`Script '${script}' failed to execute. See original error below`);
166
- console.error(error);
136
+ try {
137
+ await (0, execute_command_util_1.executeCommand)("npm", ["run", "--prefix", microservice, "--no-audit", "--loglevel", "error", "lint:eslint", "--", "--fix"]);
167
138
  }
168
- });
169
- }
170
- function runEslintFix() {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- console.info("Fixing ESLint errors");
173
- for (const microservice of microservices) {
174
- if (!microserviceExists(microservice)) {
175
- continue;
176
- }
177
- try {
178
- yield (0, execute_command_util_1.executeCommand)("npm", ["run", "--prefix", microservice, "--no-audit", "--loglevel", "error", "lint:eslint", "--", "--fix"]);
179
- }
180
- catch (err) {
181
- console.error(`Failed to fix ESLint errors in ${microservice}. See original error below`);
182
- console.error(err);
183
- }
139
+ catch (err) {
140
+ console.error(`Failed to fix ESLint errors in ${microservice}. See original error below`);
141
+ console.error(err);
184
142
  }
185
- });
143
+ }
186
144
  }
187
145
  function listTargetVersions() {
188
146
  console.info("Available target versions");
@@ -1,22 +1,10 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.formatCode = void 0;
13
4
  const eslint_1 = require("eslint");
14
- function formatCode(code, filePath) {
15
- var _a, _b, _c, _d;
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const eslint = new eslint_1.ESLint({ cwd: process.cwd(), fix: true });
18
- const lintResult = yield eslint.lintText(code, { filePath });
19
- return (_d = (_b = (_a = lintResult[0]) === null || _a === void 0 ? void 0 : _a.output) !== null && _b !== void 0 ? _b : (_c = lintResult[0]) === null || _c === void 0 ? void 0 : _c.source) !== null && _d !== void 0 ? _d : code;
20
- });
5
+ async function formatCode(code, filePath) {
6
+ const eslint = new eslint_1.ESLint({ cwd: process.cwd(), fix: true });
7
+ const lintResult = await eslint.lintText(code, { filePath });
8
+ return lintResult[0]?.output ?? lintResult[0]?.source ?? code;
21
9
  }
22
10
  exports.formatCode = formatCode;
@@ -1,26 +1,15 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.updateDependencyVersion = void 0;
13
4
  const promises_1 = require("fs/promises");
14
5
  const format_code_util_1 = require("./format-code.util");
15
- function updateDependencyVersion(packageJsonPath, packageName, newVersion) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const fileContent = (yield (0, promises_1.readFile)(packageJsonPath)).toString();
18
- const packageJson = JSON.parse(fileContent);
19
- if (packageJson.dependencies && packageJson.dependencies[packageName]) {
20
- packageJson.dependencies[packageName] = newVersion;
21
- }
22
- const updatedContent = JSON.stringify(packageJson, null, 4);
23
- yield (0, promises_1.writeFile)(packageJsonPath, yield (0, format_code_util_1.formatCode)(updatedContent, packageJsonPath));
24
- });
6
+ async function updateDependencyVersion(packageJsonPath, packageName, newVersion) {
7
+ const fileContent = (await (0, promises_1.readFile)(packageJsonPath)).toString();
8
+ const packageJson = JSON.parse(fileContent);
9
+ if (packageJson.dependencies && packageJson.dependencies[packageName]) {
10
+ packageJson.dependencies[packageName] = newVersion;
11
+ }
12
+ const updatedContent = JSON.stringify(packageJson, null, 4);
13
+ await (0, promises_1.writeFile)(packageJsonPath, await (0, format_code_util_1.formatCode)(updatedContent, packageJsonPath));
25
14
  }
26
15
  exports.updateDependencyVersion = updateDependencyVersion;
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -17,23 +8,21 @@ const prettier_1 = __importDefault(require("prettier"));
17
8
  /**
18
9
  * Removes unnecessary clear:types script before GraphQL code generation that interferes with block code generation.
19
10
  */
20
- function removeClearTypesScript() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- if (!fs_1.default.existsSync("site/package.json")) {
23
- return;
24
- }
25
- const sitePackageJson = JSON.parse(fs_1.default.readFileSync("site/package.json").toString());
26
- if (sitePackageJson.scripts["clear:types"]) {
27
- delete sitePackageJson.scripts["clear:types"];
28
- }
29
- if (sitePackageJson.scripts["gql:types"]) {
30
- sitePackageJson.scripts["gql:types"] = sitePackageJson.scripts["gql:types"].replace("npm run clear:types && ", "");
31
- }
32
- if (sitePackageJson.scripts["gql:watch"]) {
33
- sitePackageJson.scripts["gql:watch"] = sitePackageJson.scripts["gql:watch"].replace("npm run clear:types && ", "");
34
- }
35
- const prettierConfig = yield prettier_1.default.resolveConfig(process.cwd());
36
- fs_1.default.writeFileSync("site/package.json", prettier_1.default.format(JSON.stringify(sitePackageJson), Object.assign(Object.assign({}, prettierConfig), { parser: "json" })));
37
- });
11
+ async function removeClearTypesScript() {
12
+ if (!fs_1.default.existsSync("site/package.json")) {
13
+ return;
14
+ }
15
+ const sitePackageJson = JSON.parse(fs_1.default.readFileSync("site/package.json").toString());
16
+ if (sitePackageJson.scripts["clear:types"]) {
17
+ delete sitePackageJson.scripts["clear:types"];
18
+ }
19
+ if (sitePackageJson.scripts["gql:types"]) {
20
+ sitePackageJson.scripts["gql:types"] = sitePackageJson.scripts["gql:types"].replace("npm run clear:types && ", "");
21
+ }
22
+ if (sitePackageJson.scripts["gql:watch"]) {
23
+ sitePackageJson.scripts["gql:watch"] = sitePackageJson.scripts["gql:watch"].replace("npm run clear:types && ", "");
24
+ }
25
+ const prettierConfig = await prettier_1.default.resolveConfig(process.cwd());
26
+ fs_1.default.writeFileSync("site/package.json", prettier_1.default.format(JSON.stringify(sitePackageJson), { ...prettierConfig, parser: "json" }));
38
27
  }
39
28
  exports.default = removeClearTypesScript;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const promises_1 = require("fs/promises");
13
4
  const glob_1 = require("glob");
@@ -15,17 +6,15 @@ const format_code_util_1 = require("../util/format-code.util");
15
6
  /**
16
7
  * Renames BuildRuntime component to JobRuntime.
17
8
  */
18
- function renameBuildRuntime() {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const files = glob_1.glob.sync(["admin/src/**/*.tsx"]);
21
- for (const filePath of files) {
22
- let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
23
- if (!fileContent.includes("BuildRuntime")) {
24
- continue;
25
- }
26
- fileContent = fileContent.replace(/BuildRuntime/g, "JobRuntime");
27
- yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
9
+ async function renameBuildRuntime() {
10
+ const files = glob_1.glob.sync(["admin/src/**/*.tsx"]);
11
+ for (const filePath of files) {
12
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
13
+ if (!fileContent.includes("BuildRuntime")) {
14
+ continue;
28
15
  }
29
- });
16
+ fileContent = fileContent.replace(/BuildRuntime/g, "JobRuntime");
17
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
18
+ }
30
19
  }
31
20
  exports.default = renameBuildRuntime;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const promises_1 = require("fs/promises");
13
4
  const glob_1 = require("glob");
@@ -15,18 +6,16 @@ const format_code_util_1 = require("../util/format-code.util");
15
6
  /**
16
7
  * Renames JobStatus enum to KubernetesJobStatus.
17
8
  */
18
- function renameJobStatusEnum() {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const files = glob_1.glob.sync(["api/src/**/*.ts"]);
21
- for (const filePath of files) {
22
- let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
23
- // Some of our projects have a custom JobStatus enum, so we need to check for that.
24
- if (!/import { .*JobStatus.*} from "@comet\/cms-api";/.test(fileContent)) {
25
- continue;
26
- }
27
- fileContent = fileContent.replace(/JobStatus/g, "KubernetesJobStatus");
28
- yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
9
+ async function renameJobStatusEnum() {
10
+ const files = glob_1.glob.sync(["api/src/**/*.ts"]);
11
+ for (const filePath of files) {
12
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
13
+ // Some of our projects have a custom JobStatus enum, so we need to check for that.
14
+ if (!/import { .*JobStatus.*} from "@comet\/cms-api";/.test(fileContent)) {
15
+ continue;
29
16
  }
30
- });
17
+ fileContent = fileContent.replace(/JobStatus/g, "KubernetesJobStatus");
18
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
19
+ }
31
20
  }
32
21
  exports.default = renameJobStatusEnum;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const promises_1 = require("fs/promises");
13
4
  const glob_1 = require("glob");
@@ -15,17 +6,15 @@ const format_code_util_1 = require("../util/format-code.util");
15
6
  /**
16
7
  * Renames @SubjectEntity() decorator to @AffectedEntity().
17
8
  */
18
- function renameSubjectEntityDecorator() {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const files = glob_1.glob.sync(["api/src/**/*.ts"]);
21
- for (const filePath of files) {
22
- let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
23
- if (!fileContent.includes("SubjectEntity")) {
24
- continue;
25
- }
26
- fileContent = fileContent.replace(/SubjectEntity/g, "AffectedEntity");
27
- yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
9
+ async function renameSubjectEntityDecorator() {
10
+ const files = glob_1.glob.sync(["api/src/**/*.ts"]);
11
+ for (const filePath of files) {
12
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
13
+ if (!fileContent.includes("SubjectEntity")) {
14
+ continue;
28
15
  }
29
- });
16
+ fileContent = fileContent.replace(/SubjectEntity/g, "AffectedEntity");
17
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
18
+ }
30
19
  }
31
20
  exports.default = renameSubjectEntityDecorator;
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
27
  };
@@ -38,14 +29,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
29
  const fs_1 = __importDefault(require("fs"));
39
30
  const crypto = __importStar(require("node:crypto"));
40
31
  const ts_morph_1 = require("ts-morph");
41
- function addSitePreviewSecret() {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- updateApiFiles1();
44
- updateApiFiles2();
45
- updateApiFiles3();
46
- updateDotEnvFile();
47
- updateValuesTplFile();
48
- });
32
+ async function addSitePreviewSecret() {
33
+ updateApiFiles1();
34
+ updateApiFiles2();
35
+ updateApiFiles3();
36
+ updateDotEnvFile();
37
+ updateValuesTplFile();
49
38
  }
50
39
  exports.default = addSitePreviewSecret;
51
40
  function updateApiFiles1() {
@@ -65,39 +54,41 @@ function updateApiFiles1() {
65
54
  sourceFile.saveSync();
66
55
  console.log(" finished");
67
56
  }
68
- function updateApiFiles2() {
69
- var _a, _b;
70
- return __awaiter(this, void 0, void 0, function* () {
71
- console.log("Add sitePreviewSecret to api/src/config/config.ts ...");
72
- const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
73
- const sourceFile = project.getSourceFile("api/src/config/config.ts");
74
- if (!sourceFile) {
75
- console.error(" Could not file file, make sure to add sitePreviewSecret: envVars.SITE_PREVIEW_SECRET");
76
- return;
77
- }
78
- (_b = (_a = sourceFile
79
- .getFunction("createConfig")) === null || _a === void 0 ? void 0 : _a.getBody()) === null || _b === void 0 ? void 0 : _b.getDescendantsOfKind(ts_morph_1.SyntaxKind.ReturnStatement)[0].getChildrenOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)[0].addProperty("sitePreviewSecret: envVars.SITE_PREVIEW_SECRET,");
80
- sourceFile.saveSync();
81
- console.log(" finished");
82
- });
57
+ async function updateApiFiles2() {
58
+ console.log("Add sitePreviewSecret to api/src/config/config.ts ...");
59
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
60
+ const sourceFile = project.getSourceFile("api/src/config/config.ts");
61
+ if (!sourceFile) {
62
+ console.error(" Could not file file, make sure to add sitePreviewSecret: envVars.SITE_PREVIEW_SECRET");
63
+ return;
64
+ }
65
+ sourceFile
66
+ .getFunction("createConfig")
67
+ ?.getBody()
68
+ ?.getDescendantsOfKind(ts_morph_1.SyntaxKind.ReturnStatement)[0]
69
+ .getChildrenOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)[0]
70
+ .addProperty("sitePreviewSecret: envVars.SITE_PREVIEW_SECRET,");
71
+ sourceFile.saveSync();
72
+ console.log(" finished");
83
73
  }
84
- function updateApiFiles3() {
85
- var _a, _b;
86
- return __awaiter(this, void 0, void 0, function* () {
87
- console.log("Add sitePreviewSecret to api/src/app.module.ts ...");
88
- const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
89
- const sourceFile = project.getSourceFile("api/src/app.module.ts");
90
- if (!sourceFile) {
91
- console.error(" Could not file file, make sure to add sitePreviewSecret to PageTreeModule");
92
- return;
93
- }
94
- (_b = (_a = sourceFile
95
- .getClassOrThrow("AppModule")
96
- .getMethodOrThrow("forRoot")
97
- .getBody()) === null || _a === void 0 ? void 0 : _a.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => call.getText().includes("PageTreeModule.forRoot"))) === null || _b === void 0 ? void 0 : _b.getChildrenOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)[0].addProperty("sitePreviewSecret: config.sitePreviewSecret,");
98
- sourceFile.saveSync();
99
- console.log(" finished");
100
- });
74
+ async function updateApiFiles3() {
75
+ console.log("Add sitePreviewSecret to api/src/app.module.ts ...");
76
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
77
+ const sourceFile = project.getSourceFile("api/src/app.module.ts");
78
+ if (!sourceFile) {
79
+ console.error(" Could not file file, make sure to add sitePreviewSecret to PageTreeModule");
80
+ return;
81
+ }
82
+ sourceFile
83
+ .getClassOrThrow("AppModule")
84
+ .getMethodOrThrow("forRoot")
85
+ .getBody()
86
+ ?.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
87
+ .find((call) => call.getText().includes("PageTreeModule.forRoot"))
88
+ ?.getChildrenOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)[0]
89
+ .addProperty("sitePreviewSecret: config.sitePreviewSecret,");
90
+ sourceFile.saveSync();
91
+ console.log(" finished");
101
92
  }
102
93
  function updateDotEnvFile() {
103
94
  console.log("Update .env");
@@ -1,50 +1,41 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const ts_morph_1 = require("ts-morph");
13
4
  /**
14
5
  * Adds the `formatError` property to `GraphQLModule` options to hide `GraphQL` field suggestions for non dev environments.
15
6
  */
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 = `
7
+ async function hideGraphqlFieldSuggestions() {
8
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
9
+ const sourceFile = project.getSourceFile("api/src/app.module.ts");
10
+ if (!sourceFile)
11
+ throw new Error("app.module.ts not found");
12
+ // Add the required import statements
13
+ sourceFile.addImportDeclaration({
14
+ namedImports: ["ValidationError"],
15
+ moduleSpecifier: "apollo-server-express",
16
+ });
17
+ sourceFile.addImportDeclaration({
18
+ namedImports: ["ApolloDriverConfig"],
19
+ moduleSpecifier: "@nestjs/apollo",
20
+ });
21
+ // Get the forRoot method within AppModule
22
+ const forRootMethod = sourceFile.getClassOrThrow("AppModule").getMethodOrThrow("forRoot");
23
+ // Get the GraphQLModule.forRootAsync call within the forRoot method
24
+ const graphqlForRootCall = forRootMethod
25
+ .getBody()
26
+ ?.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
27
+ .find((call) => call.getText().includes("GraphQLModule.forRootAsync"));
28
+ if (!graphqlForRootCall)
29
+ throw new Error("GraphQLModule.forRootAsync call not found within forRoot method.");
30
+ // Add the generic type ApolloDriverConfig to the GraphQLModule.forRootAsync call
31
+ if (!forRootMethod.getFullText().includes("GraphQLModule.forRootAsync<ApolloDriverConfig>")) {
32
+ const expression = graphqlForRootCall.getExpression();
33
+ if (!expression)
34
+ throw new Error("Expression not found within GraphQLModule.forRootAsync call.");
35
+ const expressionText = expression.getText();
36
+ expression.replaceWithText(expressionText.replace(`${expressionText}`, `${expressionText}<ApolloDriverConfig>`));
37
+ }
38
+ const formatErrorImplText = `
48
39
  (error) => {
49
40
  if (process.env.NODE_ENV !== "development") {
50
41
  if (error instanceof ValidationError) {
@@ -53,22 +44,21 @@ function hideGraphqlFieldSuggestions() {
53
44
  }
54
45
  return error;
55
46
  }`;
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: formatErrorImplText,
70
- });
71
- sourceFile.saveSync();
47
+ // return if property formatError already exists
48
+ if (graphqlForRootCall.getArguments().find((arg) => arg.getText().includes("formatError"))) {
49
+ 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}`);
50
+ }
51
+ // Find the useFactory function within the GraphQLModule.forRootAsync call
52
+ const useFactoryFunction = graphqlForRootCall.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ArrowFunction, "useFactory function not found within GraphQLModule.forRootAsync call.");
53
+ if (!useFactoryFunction.getParent().getText().includes("useFactory"))
54
+ throw new Error("useFactory function not found within GraphQLModule.forRootAsync call.");
55
+ // Find the object literal being returned by the useFactory function
56
+ const returnObjectLiteral = useFactoryFunction.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression, "Object literal not found within useFactory function.");
57
+ // Add your formatError to GraphQLModule.forRootAsync options
58
+ returnObjectLiteral.addPropertyAssignment({
59
+ name: "formatError",
60
+ initializer: formatErrorImplText,
72
61
  });
62
+ sourceFile.saveSync();
73
63
  }
74
64
  exports.default = hideGraphqlFieldSuggestions;
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -18,21 +9,19 @@ const format_code_util_1 = require("../util/format-code.util");
18
9
  /**
19
10
  * Imports types from `@comet/admin-theme` in vendors.d.ts to allow using custom theme variants and colors
20
11
  */
21
- function importAdminThemeTypes() {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const filePath = "admin/src/vendors.d.ts";
24
- const typeReference = '/// <reference types="@comet/admin-theme" />';
25
- let fileContent = "";
26
- if (fs_1.default.existsSync(filePath)) {
27
- fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
28
- }
29
- if (fileContent.includes(typeReference)) {
30
- return;
31
- }
32
- fileContent = `${typeReference}
12
+ async function importAdminThemeTypes() {
13
+ const filePath = "admin/src/vendors.d.ts";
14
+ const typeReference = '/// <reference types="@comet/admin-theme" />';
15
+ let fileContent = "";
16
+ if (fs_1.default.existsSync(filePath)) {
17
+ fileContent = (await (0, promises_1.readFile)(filePath)).toString();
18
+ }
19
+ if (fileContent.includes(typeReference)) {
20
+ return;
21
+ }
22
+ fileContent = `${typeReference}
33
23
 
34
24
  ${fileContent}`;
35
- yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
36
- });
25
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
37
26
  }
38
27
  exports.default = importAdminThemeTypes;
@@ -1,29 +1,18 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const promises_1 = require("fs/promises");
13
4
  const glob_1 = require("glob");
14
5
  const format_code_util_1 = require("../util/format-code.util");
15
6
  // Renames DateFilter to DateTimeFilter
16
- function renameDateFilterToDateTimeFilter() {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const files = glob_1.glob.sync(["api/src/**/*.ts"]);
19
- for (const filePath of files) {
20
- let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
21
- if (!fileContent.includes("DateFilter")) {
22
- continue;
23
- }
24
- fileContent = fileContent.replace(/DateFilter/g, "DateTimeFilter");
25
- yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
7
+ async function renameDateFilterToDateTimeFilter() {
8
+ const files = glob_1.glob.sync(["api/src/**/*.ts"]);
9
+ for (const filePath of files) {
10
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
11
+ if (!fileContent.includes("DateFilter")) {
12
+ continue;
26
13
  }
27
- });
14
+ fileContent = fileContent.replace(/DateFilter/g, "DateTimeFilter");
15
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
16
+ }
28
17
  }
29
18
  exports.default = renameDateFilterToDateTimeFilter;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const promises_1 = require("fs/promises");
13
4
  const glob_1 = require("glob");
@@ -15,33 +6,31 @@ const ts_morph_1 = require("ts-morph");
15
6
  /**
16
7
  * Replaces the import of `GridColDef` from `@mui/x-data-grid*` with `GridColDef` from `@comet/admin`.
17
8
  */
18
- function replaceGridColDefImport() {
19
- var _a;
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const files = glob_1.glob.sync(["admin/src/**/*.ts", "admin/src/**/*.tsx"]);
22
- const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
23
- for (const filePath of files) {
24
- const fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
25
- if (!fileContent.includes("GridColDef")) {
26
- continue;
27
- }
28
- const sourceFile = project.getSourceFile(filePath);
29
- if (!sourceFile) {
30
- throw new Error(`Can't get source file for ${filePath}`);
31
- }
32
- const dataGridImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@mui/x-data-grid"));
33
- if (!dataGridImport) {
34
- continue;
35
- }
36
- (_a = dataGridImport
37
- .getNamedImports()
38
- .find((namedImport) => namedImport.getText() === "GridColDef")) === null || _a === void 0 ? void 0 : _a.remove();
39
- sourceFile.addImportDeclaration({
40
- namedImports: ["GridColDef"],
41
- moduleSpecifier: "@comet/admin",
42
- });
43
- sourceFile.saveSync();
9
+ async function replaceGridColDefImport() {
10
+ const files = glob_1.glob.sync(["admin/src/**/*.ts", "admin/src/**/*.tsx"]);
11
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
12
+ for (const filePath of files) {
13
+ const fileContent = (await (0, promises_1.readFile)(filePath)).toString();
14
+ if (!fileContent.includes("GridColDef")) {
15
+ continue;
44
16
  }
45
- });
17
+ const sourceFile = project.getSourceFile(filePath);
18
+ if (!sourceFile) {
19
+ throw new Error(`Can't get source file for ${filePath}`);
20
+ }
21
+ const dataGridImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@mui/x-data-grid"));
22
+ if (!dataGridImport) {
23
+ continue;
24
+ }
25
+ dataGridImport
26
+ .getNamedImports()
27
+ .find((namedImport) => namedImport.getText() === "GridColDef")
28
+ ?.remove();
29
+ sourceFile.addImportDeclaration({
30
+ namedImports: ["GridColDef"],
31
+ moduleSpecifier: "@comet/admin",
32
+ });
33
+ sourceFile.saveSync();
34
+ }
46
35
  }
47
36
  exports.default = replaceGridColDefImport;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const promises_1 = require("fs/promises");
13
4
  const execute_command_util_1 = require("../util/execute-command.util");
@@ -15,35 +6,33 @@ const format_code_util_1 = require("../util/format-code.util");
15
6
  /**
16
7
  * Replaces the old font package "Roboto" with the new "Roboto Flex"
17
8
  */
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
- });
9
+ async function replaceRobotoWithRobotoFlex() {
10
+ await replacePackageInPackageJson();
11
+ await removeOldPackageImports();
12
+ await addNewPackageImport();
13
+ await (0, execute_command_util_1.executeCommand)("npm", ["install", "--prefix", "admin", "--no-audit", "--loglevel", "error"]);
25
14
  }
26
15
  exports.default = replaceRobotoWithRobotoFlex;
27
- const replacePackageInPackageJson = () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const replacePackageInPackageJson = async () => {
28
17
  const filePath = "admin/package.json";
29
- let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
18
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
30
19
  const searchString = "@fontsource/roboto";
31
20
  const re = new RegExp(`^.*${searchString}.*$`, "gm");
32
21
  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* () {
22
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
23
+ };
24
+ const removeOldPackageImports = async () => {
36
25
  const filePath = "admin/src/App.tsx";
37
- let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
26
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
38
27
  const searchString = 'import "@fontsource/roboto';
39
28
  const re = new RegExp(`^.*${searchString}.*$`, "gm");
40
29
  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* () {
30
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
31
+ };
32
+ const addNewPackageImport = async () => {
44
33
  const filePath = "admin/src/App.tsx";
45
- let fileContent = (yield (0, promises_1.readFile)(filePath)).toString();
34
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
46
35
  fileContent = `import "@fontsource-variable/roboto-flex/full.css";
47
36
  ${fileContent}`;
48
- yield (0, promises_1.writeFile)(filePath, yield (0, format_code_util_1.formatCode)(fileContent, filePath));
49
- });
37
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
38
+ };
@@ -1,41 +1,30 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const promises_1 = require("fs/promises");
13
4
  const glob_1 = require("glob");
14
5
  const execute_command_util_1 = require("../util/execute-command.util");
15
6
  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;
7
+ async function useGraphqlScalars() {
8
+ // replace graphql-type-json with graphql-scalars in api/package.json
9
+ const packageJson = await (0, promises_1.readFile)(`api/package.json`);
10
+ if (!packageJson.includes("graphql-type-json")) {
11
+ // if not found, it was not used in the project, so we can skip this migration
12
+ console.log("graphql-type-json not found in api/package.json. Skipping migration.");
13
+ return;
14
+ }
15
+ await (0, execute_command_util_1.executeCommand)("npm", ["uninstall", "--prefix", "api", "--no-audit", "--loglevel", "error", "graphql-type-json"]);
16
+ await (0, execute_command_util_1.executeCommand)("npm", ["install", "--prefix", "api", "--no-audit", "--loglevel", "error", "graphql-scalars"]);
17
+ // replace graphql-type-json with graphql-scalars in all api files
18
+ // before: import { GraphQLJSONObject } from "graphql-type-json";
19
+ // after: import { GraphQLJSONObject } from "graphql-scalars";
20
+ const files = glob_1.glob.sync(["api/src/**/*.ts"]);
21
+ for (const filePath of files) {
22
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
23
+ if (!fileContent.includes("graphql-type-json")) {
24
+ continue;
24
25
  }
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
- });
26
+ fileContent = fileContent.replace(/graphql-type-json/g, "graphql-scalars");
27
+ await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
28
+ }
40
29
  }
41
30
  exports.default = useGraphqlScalars;
@@ -1,33 +1,22 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const fs_1 = require("fs");
13
4
  const execute_command_util_1 = require("../util/execute-command.util");
14
5
  const update_dependency_version_util_1 = require("../util/update-dependency-version.util");
15
6
  const adminPackageJsonPath = "admin/package.json";
16
- function updateMuiVersion() {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- if (!(0, fs_1.existsSync)(adminPackageJsonPath)) {
19
- return;
20
- }
21
- yield (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/material", "^6.0.0");
22
- yield (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/system", "^6.0.0");
23
- yield (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/utils", "^6.0.0");
24
- yield (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/icons-material", "^6.0.0");
25
- yield (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/lab", "^6.0.0-beta.10");
26
- yield (0, execute_command_util_1.executeCommand)("npm", ["install", "--prefix", "admin", "--no-audit", "--loglevel", "error"]);
27
- yield (0, execute_command_util_1.executeCommand)("npx", ["@mui/codemod@latest", "v6.0.0/list-item-button-prop", "admin/src"]);
28
- yield (0, execute_command_util_1.executeCommand)("npx", ["@mui/codemod@latest", "v6.0.0/styled", "admin/src"]);
29
- yield (0, execute_command_util_1.executeCommand)("npx", ["@mui/codemod@latest", "v6.0.0/sx-prop", "admin/src"]);
30
- yield (0, execute_command_util_1.executeCommand)("npx", ["@mui/codemod@latest", "v6.0.0/theme-v6", "admin/src/theme.ts"]);
31
- });
7
+ async function updateMuiVersion() {
8
+ if (!(0, fs_1.existsSync)(adminPackageJsonPath)) {
9
+ return;
10
+ }
11
+ await (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/material", "^6.0.0");
12
+ await (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/system", "^6.0.0");
13
+ await (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/utils", "^6.0.0");
14
+ await (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/icons-material", "^6.0.0");
15
+ await (0, update_dependency_version_util_1.updateDependencyVersion)(adminPackageJsonPath, "@mui/lab", "^6.0.0-beta.10");
16
+ await (0, execute_command_util_1.executeCommand)("npm", ["install", "--prefix", "admin", "--no-audit", "--loglevel", "error"]);
17
+ await (0, execute_command_util_1.executeCommand)("npx", ["@mui/codemod@latest", "v6.0.0/list-item-button-prop", "admin/src"]);
18
+ await (0, execute_command_util_1.executeCommand)("npx", ["@mui/codemod@latest", "v6.0.0/styled", "admin/src"]);
19
+ await (0, execute_command_util_1.executeCommand)("npx", ["@mui/codemod@latest", "v6.0.0/sx-prop", "admin/src"]);
20
+ await (0, execute_command_util_1.executeCommand)("npx", ["@mui/codemod@latest", "v6.0.0/theme-v6", "admin/src/theme.ts"]);
32
21
  }
33
22
  exports.default = updateMuiVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@comet/eslint-config": "^3.2.1",
39
+ "@tsconfig/node20": "^20.1.4",
39
40
  "@types/node": "^20.0.0",
40
41
  "@types/prettier": "^2.7.1",
41
42
  "@types/semver": "^7.5.8",
@@ -43,7 +44,7 @@
43
44
  "lint-staged": "^13.1.0",
44
45
  "npm-run-all": "^4.1.5",
45
46
  "rimraf": "^3.0.2",
46
- "typescript": "^4.9.4"
47
+ "typescript": "~5.1.0"
47
48
  },
48
49
  "engines": {
49
50
  "node": "20"