@griddo/cx 1.75.236 → 1.75.238

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.
@@ -5,6 +5,8 @@ import crypto from "crypto";
5
5
  import fs from "fs";
6
6
  import path from "path";
7
7
 
8
+ import fsx from "fs-extra";
9
+
8
10
  // Consts
9
11
  const API_CACHE_DIR_PATH = path.resolve(__dirname, "./../../apiCache");
10
12
  const SITE_HASH_FILENAME = `${API_CACHE_DIR_PATH}/siteHash.json`;
@@ -73,10 +75,10 @@ function saveCache<T>(petition: Petition, content: T) {
73
75
  function searchCacheData<T>(petition: Petition) {
74
76
  try {
75
77
  const file = generateFilenameWithHash(petition);
76
- const content = fs.readFileSync(file, {
78
+ const jsonData = fsx.readJSONSync(file, {
77
79
  encoding: "utf-8",
78
80
  });
79
- return JSON.parse(content) as T;
81
+ return jsonData as T;
80
82
  } catch {
81
83
  return null;
82
84
  }
@@ -87,9 +89,10 @@ function searchCacheData<T>(petition: Petition) {
87
89
  */
88
90
  function getHashSites(): HashSites {
89
91
  try {
90
- const content = fs.readFileSync(SITE_HASH_FILENAME, { encoding: "utf-8" });
91
-
92
- return JSON.parse(content) || {};
92
+ const jsonData = fsx.readJSONSync(SITE_HASH_FILENAME, {
93
+ encoding: "utf-8",
94
+ });
95
+ return jsonData || {};
93
96
  } catch {
94
97
  return {};
95
98
  }
@@ -0,0 +1,60 @@
1
+ import { logBox } from "./shared";
2
+
3
+ const GRIDDO_SKIP_BUILD_CHECKS = process.env.GRIDDO_SKIP_BUILD_CHECKS;
4
+ const GRIDDO_ENVS_VARS: ReadonlyArray<string> = [];
5
+
6
+ /**
7
+ * Check if the environment is secure to launch a render.
8
+ * If something fails throws an error and exit
9
+ */
10
+ function buildHealthCheck() {
11
+ // Bypass the check using this env var, handy for local renders.
12
+ if (GRIDDO_SKIP_BUILD_CHECKS) {
13
+ console.info(`🫥 Build health check skipped`);
14
+
15
+ return true;
16
+ }
17
+
18
+ // Checklist
19
+ const envsVars = checkEnvsVars(GRIDDO_ENVS_VARS);
20
+
21
+ // Render is safe if...
22
+ const renderingIsSave = envsVars;
23
+
24
+ // The environment is suitable for a build-render
25
+ if (renderingIsSave) {
26
+ console.info("✅ Build health check passed");
27
+
28
+ return true;
29
+ }
30
+
31
+ // Error
32
+ logBox(`Error. The environment is not suitable for a build.`);
33
+ process.exit(1);
34
+ }
35
+
36
+ /**
37
+ * Check if a list of environments variables exist with any value.
38
+ *
39
+ * @todo Also check the value.
40
+ * @param envs An array of environments variables
41
+ * @returns exists with (1) if there are missing envs vars
42
+ */
43
+ function checkEnvsVars(envs: ReadonlyArray<string>) {
44
+ const missingEnvs = envs.filter((envName) => {
45
+ return !process.env[envName];
46
+ });
47
+
48
+ if (missingEnvs.length) {
49
+ const missingEnvsMsg = missingEnvs.join("\n");
50
+ console.log(
51
+ `ENV CHECK FAILED. These envs vars are missing: \n\n${missingEnvsMsg}`
52
+ );
53
+
54
+ return false;
55
+ }
56
+
57
+ return true;
58
+ }
59
+
60
+ export { buildHealthCheck };
@@ -142,14 +142,11 @@ async function createGatsbyPageObject(
142
142
  } = additionalInfo;
143
143
 
144
144
  // Update page object
145
- page = {
146
- ...page,
147
- breadcrumb,
148
- siteSlug,
149
- apiUrl: baseUrl,
150
- publicApiUrl: additionalInfo.publicBaseUrl,
151
- instance: additionalInfo.instance,
152
- };
145
+ page.breadcrumb = breadcrumb;
146
+ page.siteSlug = siteSlug;
147
+ page.apiUrl = baseUrl;
148
+ page.publicApiUrl = additionalInfo.publicBaseUrl;
149
+ page.instance = additionalInfo.instance;
153
150
 
154
151
  const foundLanguage = siteLangs.find(({ id }) => id === page?.language);
155
152
  const locale = foundLanguage?.locale.replace(/_/g, "-");
@@ -240,7 +237,7 @@ async function createGatsbyPageObject(
240
237
  * @param page A Griddo single page object.
241
238
  * @param additionalInfo Additional page info.
242
239
  */
243
- async function createGriddoSinglePage(
240
+ async function createGriddoSinglePageForGatsby(
244
241
  page: GriddoSinglePage,
245
242
  additionalInfo: PageAdditionalInfo
246
243
  ) {
@@ -250,7 +247,7 @@ async function createGriddoSinglePage(
250
247
  /**
251
248
  * Create multiples pages from one page as list paginated pages
252
249
  */
253
- async function createGriddoListPages(
250
+ async function createGriddoListPagesForGatsby(
254
251
  {
255
252
  page,
256
253
  pages,
@@ -309,7 +306,7 @@ async function createGriddoListPages(
309
306
  * @param page A Griddo Multipage object.
310
307
  * @param additionalInfo Additional page info.
311
308
  */
312
- function createGriddoMultiPages(
309
+ function createGriddoMultiPagesForGatsby(
313
310
  page: GriddoMultiPage,
314
311
  additionalInfo: PageAdditionalInfo
315
312
  ) {
@@ -375,7 +372,9 @@ function createGriddoMultiPages(
375
372
  *
376
373
  * @param page The page to get the multipage parts.
377
374
  */
378
- function getMultiPageElements(page: TemplateWithDistributor) {
375
+ function getMultiPageElements(
376
+ page: TemplateWithDistributor
377
+ ): Promise<MultiPageElements> | null {
379
378
  const multiPageElements = new Promise((resolve) => {
380
379
  // Recursive
381
380
  const getMultiPageComponent = (
@@ -542,9 +541,9 @@ function addPageNumberToTitle(title: string, pageNumber: number) {
542
541
  }
543
542
 
544
543
  export {
545
- createGriddoListPages,
546
- createGriddoMultiPages,
547
- createGriddoSinglePage,
544
+ createGriddoListPagesForGatsby,
545
+ createGriddoMultiPagesForGatsby,
546
+ createGriddoSinglePageForGatsby,
548
547
  getMultiPageElements,
549
548
  getPaginatedPages,
550
549
  };
@@ -1,12 +1,13 @@
1
+ import type { APIResponses } from "../types/api";
2
+ import type { APIPageObject } from "../types/pages";
3
+ import type { Site } from "../types/sites";
4
+
1
5
  import chalk from "chalk";
2
6
  import dotenv from "dotenv";
3
7
  import fs from "fs-extra";
4
8
  import gradient from "gradient-string";
5
9
 
6
10
  import { version } from "../../package.json";
7
- import { APIResponses } from "../types/api";
8
- import { APIPageObject } from "../types/pages";
9
- import { Site } from "../types/sites";
10
11
 
11
12
  dotenv.config();
12
13
 
@@ -11,7 +11,6 @@ import { deleteSites } from "./folders";
11
11
  import { logInfo } from "./shared";
12
12
  import { AuthService } from "../services/auth";
13
13
  import { SitesService } from "../services/sites";
14
- import { AllPagesResponse } from "../types/api";
15
14
 
16
15
  // Envs
17
16
  const API_URL = process.env.API_URL;
@@ -132,10 +131,6 @@ async function getSiteData(siteID: number) {
132
131
  const socials = await SitesService.getSocials(siteID);
133
132
  const siteLangsInfo = siteLangs.items;
134
133
  const defaultLang = siteLangsInfo.find((lang) => lang.isDefault);
135
- // TODO: Eliminado para validar que efectivamente no rompe nada si el cambio
136
- // es correcto, hay que eliminar las 7 líneas que contienen "sitePages":
137
- // const sitePages = await SitesService.getPages(siteID, cacheKey);
138
- const sitePages: AllPagesResponse = [];
139
134
 
140
135
  const { siteHash, unpublishHashes, publishIds } = buildData;
141
136
  const { headers, footers } = siteInfo;
@@ -153,7 +148,6 @@ async function getSiteData(siteID: number) {
153
148
  headers,
154
149
  footers,
155
150
  socials,
156
- sitePages,
157
151
  };
158
152
 
159
153
  return siteData;
@@ -217,7 +211,7 @@ async function generateSitemaps(sites: Array<Site>) {
217
211
  if (!langDomain) return;
218
212
 
219
213
  const slug = Object.values(langDomain)[0];
220
- const sitemaps: string[] = [];
214
+ const sitemaps: Array<string> = [];
221
215
  const sitemapPageGroupKeys = Object.keys(sitemapPagesGroup);
222
216
 
223
217
  const sitemapBasePath = path.resolve(