@comet/upgrade 1.23.0 → 1.25.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.
@@ -29,12 +29,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const fs_1 = __importDefault(require("fs"));
30
30
  const crypto = __importStar(require("node:crypto"));
31
31
  const ts_morph_1 = require("ts-morph");
32
+ const execute_command_util_1 = require("../util/execute-command.util");
32
33
  async function addSitePreviewSecret() {
33
34
  updateApiFiles1();
34
35
  updateApiFiles2();
35
36
  updateApiFiles3();
36
37
  updateDotEnvFile();
37
38
  updateValuesTplFile();
39
+ updateChart();
40
+ await executeHelmDependencyUpdate();
38
41
  }
39
42
  exports.default = addSitePreviewSecret;
40
43
  function updateApiFiles1() {
@@ -146,3 +149,37 @@ function updateValuesTplFile() {
146
149
  fs_1.default.writeFileSync(valuesFileName, content);
147
150
  console.log(" finished.");
148
151
  }
152
+ function updateChart() {
153
+ const filename = "deployment/helm/Chart.yaml";
154
+ console.log(`Update ${filename}`);
155
+ if (!fs_1.default.existsSync(filename)) {
156
+ console.error(" could not find file, please make sure to remove authproxy-preview and execute helm dependency update.");
157
+ return;
158
+ }
159
+ const file = fs_1.default.readFileSync(filename, "utf8");
160
+ const lines = file.split(/\n/);
161
+ let startingLine = 0;
162
+ let isAuthproxyPreview = false;
163
+ lines.forEach((line, index) => {
164
+ const match1 = line.match(/-.*oauth2-proxy/);
165
+ if (match1) {
166
+ startingLine = index;
167
+ }
168
+ const match2 = line.match(/alias.*authproxy-preview/);
169
+ if (match2) {
170
+ isAuthproxyPreview = true;
171
+ }
172
+ const match3 = line.match(/- .*/);
173
+ if (match3 && isAuthproxyPreview) {
174
+ lines.splice(startingLine, index - startingLine);
175
+ isAuthproxyPreview = false;
176
+ }
177
+ });
178
+ const content = lines.join("\n").replace(/oauth2-proxy-preview/g, "site");
179
+ fs_1.default.writeFileSync(filename, content);
180
+ console.log(" finished.");
181
+ }
182
+ async function executeHelmDependencyUpdate() {
183
+ console.log('Execute "helm dependency update deployment/helm" ...');
184
+ await (0, execute_command_util_1.executeCommand)("helm", ["dependency", "update", "deployment/helm"]);
185
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("fs/promises");
4
+ const glob_1 = require("glob");
5
+ const ts_morph_1 = require("ts-morph");
6
+ const renamedExports = {
7
+ getMostSignificantPreviewImageUrlTemplate: "getMostSignificantPreviewImageUrlTemplateFromBlock",
8
+ getPreviewImageUrlTemplates: "getPreviewImageUrlTemplatesFromBlock",
9
+ getSearchText: "getSearchTextFromBlock",
10
+ inputToData: "blockInputToData",
11
+ TransformResponse: "TransformBlockResponse",
12
+ TransformResponseArray: "TransformBlockResponseArray",
13
+ transformToSave: "transformToBlockSave",
14
+ transformToSaveIndex: "transformToBlockSaveIndex",
15
+ TraversableTransformResponse: "TraversableTransformBlockResponse",
16
+ TraversableTransformResponseArray: "TraversableTransformBlockResponseArray",
17
+ typesafeMigrationPipe: "typeSafeBlockMigrationPipe",
18
+ };
19
+ async function mergeBlocksApiIntoCmsApi() {
20
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
21
+ const files = glob_1.glob.sync(["api/src/**/*.ts"]);
22
+ for (const filePath of files) {
23
+ const sourceFile = project.getSourceFile(filePath);
24
+ if (!sourceFile) {
25
+ throw new Error(`Can't get source file for ${filePath}`);
26
+ }
27
+ const blocksApiImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/blocks-api"));
28
+ if (!blocksApiImport) {
29
+ continue;
30
+ }
31
+ const blocksApiImports = blocksApiImport.getNamedImports().map((namedImport) => namedImport.getText());
32
+ const importsToRename = Object.entries(renamedExports).filter(([oldExport]) => blocksApiImports.includes(oldExport));
33
+ blocksApiImport.remove();
34
+ const cmsApiImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/cms-api"));
35
+ if (cmsApiImport) {
36
+ cmsApiImport.addNamedImports(blocksApiImports);
37
+ }
38
+ else {
39
+ sourceFile.addImportDeclaration({
40
+ namedImports: blocksApiImports,
41
+ moduleSpecifier: "@comet/cms-api",
42
+ });
43
+ }
44
+ await sourceFile.save();
45
+ let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
46
+ for (const [oldExport, newExport] of importsToRename) {
47
+ fileContent = fileContent.replaceAll(oldExport, newExport);
48
+ }
49
+ await (0, promises_1.writeFile)(filePath, fileContent);
50
+ }
51
+ }
52
+ exports.default = mergeBlocksApiIntoCmsApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.23.0",
3
+ "version": "1.25.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {