@griddo/cx 1.75.224 → 1.75.226

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/cx",
3
3
  "description": "Griddo SSG based on Gatsby",
4
- "version": "1.75.224",
4
+ "version": "1.75.226",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -20,14 +20,18 @@
20
20
  "griddo-cx": "./index.js"
21
21
  },
22
22
  "scripts": {
23
- "build": "yarn run build:exporter && yarn run build:reset-render",
24
- "build:reset-render": "esbuild ./scripts/reset-render.ts --bundle --platform=node --minify --outfile=./build/reset-render.js",
23
+ "build": "yarn run build:exporter && yarn run build:reset-render && yarn run build:build-complete",
25
24
  "build:exporter": "esbuild ./scripts/griddo-exporter.ts --bundle --platform=node --minify --outfile=./build/index.js",
25
+ "build:build-complete": "esbuild ./scripts/build-complete.ts --bundle --platform=node --minify --outfile=./build/build-complete.js",
26
+ "build:reset-render": "esbuild ./scripts/reset-render.ts --bundle --platform=node --minify --outfile=./build/reset-render.js",
26
27
  "export": "gatsby telemetry --disable && gatsby build --prefix-paths",
27
28
  "clean": "gatsby clean; rm -rf .cache public assets dist build store",
28
29
  "prepare": "yarn run build",
29
30
  "watch:tscheck": "tsc --noEmit --watch",
30
- "reset-render": "node ./build/reset-render.js"
31
+ "complete-render": "node ./build/build-complete.js",
32
+ "reset-render": "node ./build/reset-render.js",
33
+ "build:complete": "node ./build/build-complete.js",
34
+ "build:reset": "node ./build/reset-render.js"
31
35
  },
32
36
  "dependencies": {
33
37
  "@babel/core": "^7.21.0",
@@ -64,7 +68,7 @@
64
68
  "react-helmet": "^6.0.0"
65
69
  },
66
70
  "devDependencies": {
67
- "@griddo/eslint-config-back": "^1.75.224",
71
+ "@griddo/eslint-config-back": "^1.75.226",
68
72
  "@types/babel__core": "^7.20.0",
69
73
  "@types/babel__preset-env": "^7.9.2",
70
74
  "@types/csvtojson": "^2.0.0",
@@ -112,5 +116,5 @@
112
116
  "publishConfig": {
113
117
  "access": "public"
114
118
  },
115
- "gitHead": "1c4e2c06dd6fbee54a37eba2c8f2ebd27b38781f"
119
+ "gitHead": "26895cf4c323b6031eee9c65bfefa8ecaa4eae38"
116
120
  }
@@ -0,0 +1,87 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import pkgDir from "pkg-dir";
5
+
6
+ import { AuthService } from "../src/services/auth";
7
+ import { SitesService } from "../src/services/sites";
8
+ import { logInfo } from "../src/utils/shared";
9
+
10
+ // Where we are going to find export folders
11
+ const execBasePath = pkgDir.sync()!;
12
+
13
+ // Where we are going to find archived exports
14
+ const exportArchiveBasePath = path.resolve(execBasePath, "exports/sites");
15
+
16
+ type Report = {
17
+ authControl:
18
+ | {
19
+ Authorization: string;
20
+ "Cache-Control": string;
21
+ lang?: string | undefined;
22
+ }
23
+ | undefined;
24
+ sites: {
25
+ siteId: number;
26
+ publishHashes: string[];
27
+ siteHash: string | null;
28
+ unpublishHashes: string[];
29
+ }[];
30
+ };
31
+
32
+ export async function buildComplete(report: Report) {
33
+ await AuthService.login();
34
+
35
+ const promises = report.sites.map((site) => {
36
+ const { siteId, ...body } = site;
37
+
38
+ logInfo(`Deploying ending call to site ${siteId}:`);
39
+
40
+ return SitesService.endSiteRender(siteId, body);
41
+ });
42
+
43
+ await Promise.all(promises);
44
+
45
+ logInfo(`Build end signal sent for ${report.sites.length} site(s)`);
46
+ }
47
+
48
+ function getExportedDomains() {
49
+ const domains = fs.readdirSync(exportArchiveBasePath);
50
+
51
+ return domains;
52
+ }
53
+
54
+ function getBuildReports(domains: string[]) {
55
+ const reports = [];
56
+
57
+ for (const domain of domains) {
58
+ const buildReportFile = path.resolve(
59
+ exportArchiveBasePath,
60
+ domain,
61
+ "dist",
62
+ "__build-report__.json"
63
+ );
64
+
65
+ if (!fs.existsSync(buildReportFile)) {
66
+ console.log(`Build report "${buildReportFile}" not found.`);
67
+ continue;
68
+ }
69
+
70
+ const buildReport = JSON.parse(fs.readFileSync(buildReportFile, "utf-8"));
71
+
72
+ reports.push(buildReport);
73
+ }
74
+
75
+ return reports;
76
+ }
77
+
78
+ async function main() {
79
+ const domains = getExportedDomains();
80
+ const reports = getBuildReports(domains);
81
+
82
+ for (const report of reports) {
83
+ await buildComplete(report);
84
+ }
85
+ }
86
+
87
+ main();
@@ -203,7 +203,7 @@ const getDomainRunner = (domain: string) => {
203
203
  } catch (error) {
204
204
  logError(
205
205
  `🚚 Error moving files to ${currentExportArchivePath}`,
206
- error.message
206
+ (error as Error).message
207
207
  );
208
208
  restoreArtifactBackup(artifact);
209
209
  continue;
@@ -56,7 +56,12 @@ function createSha256(data: string) {
56
56
  function saveCache<T>(petition: Petition, content: T) {
57
57
  const stringContent =
58
58
  typeof content === "string" ? content : JSON.stringify(content);
59
- fs.writeFileSync(generateFilenameWithHash(petition), stringContent, "utf8");
59
+ const filename = generateFilenameWithHash(petition);
60
+ const filepath = path.dirname(filename);
61
+ if (!fs.existsSync(filepath)) {
62
+ fs.mkdirSync(filepath, { recursive: true });
63
+ }
64
+ fs.writeFileSync(filename, stringContent, "utf8");
60
65
  }
61
66
 
62
67
  /**
@@ -185,19 +185,6 @@ async function generateBuildReport(
185
185
  fs.writeFileSync(filePathName, JSON.stringify(report));
186
186
 
187
187
  logInfo(`Build report saved for ${buildSitesInfo.length} site(s)`);
188
-
189
- // Tell API the build has finished
190
- // TODO: Remove when the file version is implemented.
191
- const promises = Object.keys(buildProcessData).map(async (siteID) => {
192
- const body = buildProcessData[siteID];
193
- logInfo(`Deploying ending call to site ${siteID}:`);
194
-
195
- return SitesService.endSiteRender(parseInt(siteID), body);
196
- });
197
-
198
- await Promise.all(promises);
199
-
200
- logInfo(`Build end signal sent for ${buildSitesInfo.length} site(s)`);
201
188
  }
202
189
 
203
190
  /**