@griddo/cx 10.4.30 → 10.4.32

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.
@@ -6,6 +6,8 @@ import {
6
6
  legacy__createDistFromGatsbyPublic,
7
7
  runGatsbyBuildCommand,
8
8
  } from "./utils";
9
+ import { throwError } from "../../errors";
10
+ import { NoDomainsFoundError, RenderUUIDError } from "../../errors/errors-data";
9
11
  import { RobotsService } from "../../services/robots";
10
12
  import {
11
13
  attempts,
@@ -37,7 +39,11 @@ async function runGatsbyAdapter() {
37
39
 
38
40
  fs.writeFileSync(renderSentinelFile, new Date().toISOString());
39
41
 
40
- const domains = await getInstanceDomains();
42
+ const domains: Array<string> = await getInstanceDomains();
43
+
44
+ if (!domains.length) {
45
+ throwError(NoDomainsFoundError);
46
+ }
41
47
 
42
48
  for (const domain of domains) {
43
49
  const { __ssg, __exports, __caches, __cx, __components } = config.paths(
@@ -252,14 +258,7 @@ async function runGatsbyAdapter() {
252
258
  steps: [
253
259
  () => {
254
260
  if (!fs.existsSync(renderSentinelFile)) {
255
- logBox(
256
- `Something has happened and the rendering uuid cannot be read safely.
257
- There was probably a instance deployment during the render and files were deleted.
258
-
259
- The files generated in this render will not be published.`,
260
- "Render UUID error"
261
- );
262
- throw new Error("Render sentinel file does not exist.");
261
+ throwError(RenderUUIDError);
263
262
  }
264
263
  },
265
264
  ],
@@ -156,21 +156,24 @@ async function legacy__createDistFromGatsbyPublic(
156
156
 
157
157
  try {
158
158
  fsx.mkdirSync(cxAssetsDir, { recursive: true });
159
- fsx.copySync(publicDir, cxDistDir);
159
+ fsx.copySync(publicDir, cxDistDir, { preserveTimestamps: true });
160
160
 
161
161
  if (needsAssetPrefix) {
162
- fsx.copySync(pageDataSrc, pageDataDest);
162
+ fsx.copySync(pageDataSrc, pageDataDest, { preserveTimestamps: true });
163
163
  if (fsx.existsSync(projectStaticSrc)) {
164
164
  fsx.copySync(projectStaticSrc, projectStaticDest, {
165
165
  overwrite: false,
166
+ preserveTimestamps: true,
166
167
  });
167
168
  }
168
169
  fsx.copySync(gatsbyStaticSrc, gatsbyStaticDest, {
169
170
  overwrite: false,
171
+ preserveTimestamps: true,
170
172
  });
171
173
  if (fsx.existsSync(projectStaticSrc)) {
172
174
  fsx.copySync(projectStaticSrc, cxDistDirWithDomain, {
173
175
  overwrite: false,
176
+ preserveTimestamps: true,
174
177
  });
175
178
  }
176
179
 
@@ -178,7 +181,7 @@ async function legacy__createDistFromGatsbyPublic(
178
181
  validFilesFromPublic.map(async (file) => {
179
182
  const fileSrc = `${publicDir}/${file}`;
180
183
  const fileDest = `${cxAssetsDir}/${file}`;
181
- fsx.copySync(fileSrc, fileDest);
184
+ fsx.copySync(fileSrc, fileDest, { preserveTimestamps: true });
182
185
  });
183
186
  }
184
187
  } catch (err) {
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Do you want to add a new error to the list?
3
+ *
4
+ * 1 - Add the new error type name to the `ErrorsType` union type.
5
+ * 2 - Export a new ErrorData object in this file by completing
6
+ * the `error` and `message` properties obligatorily.
7
+ *
8
+ */
9
+
10
+ import { ErrorData } from ".";
11
+
12
+ export type ErrorsType =
13
+ | "NoDomainsFoundError"
14
+ | "RenderUUIDError"
15
+ | "DistributorSourcesNotFoundError";
16
+
17
+ export const NoDomainsFoundError: ErrorData = {
18
+ id: 100,
19
+ error: "NoDomainsFoundError",
20
+ message: "No domains found in this instance. The process cannot continue.",
21
+ expected:
22
+ "This can happen if the API is not functioning or the site is not properly configured, or the domains are not registered.",
23
+ hint: "You can contact the instance administrator.",
24
+ };
25
+
26
+ export const RenderUUIDError: ErrorData = {
27
+ id: 101,
28
+ error: "RenderUUIDError",
29
+ message: `Render sentinel file does not exist.
30
+ The rendering uuid cannot be read safely.
31
+ There was probably a instance deployment during the render and files were deleted.
32
+
33
+ The files generated in this render will not be published.`,
34
+ };
35
+
36
+ export const DistributorSourcesNotFoundError: ErrorData = {
37
+ id: 102,
38
+ error: "DistributorSourcesNotFoundError",
39
+ message: "El distribuidor no tiene souces definidos.",
40
+ expected:
41
+ "Se espera que al menos tenga un fuente de datos en la propiedad `sources`, aunque esté vacía.",
42
+ };
@@ -1,2 +1,31 @@
1
- // noop
2
- export const noop = true;
1
+ import type { ErrorsType } from "./errors-data";
2
+
3
+ import { logBox } from "../utils/core-utils";
4
+
5
+ export type ErrorData = {
6
+ id: number;
7
+ error: ErrorsType;
8
+ message: string;
9
+ expected?: string;
10
+ hint?: string;
11
+ };
12
+
13
+ class RenderError extends Error {
14
+ constructor() {
15
+ super();
16
+ this.name = "InternalCXError";
17
+ this.stack = "";
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Throws an error with the provided error message, expected value, and hint.
23
+ */
24
+ function throwError({ error, message, expected = "", hint = "" }: ErrorData) {
25
+ const errorMessage = [message, expected, hint].filter(Boolean).join("\n");
26
+
27
+ logBox(errorMessage, error, 1, 0);
28
+ throw new RenderError();
29
+ }
30
+
31
+ export { throwError };
@@ -11,12 +11,21 @@ import {
11
11
  filterHeadIntegrations,
12
12
  } from "../../utils/integrations";
13
13
 
14
+
14
15
  export interface GriddoIntegrationsProps {
15
16
  integrations?: Array<Core.PageIntegration>;
16
17
  location: "head" | "start-body" | "end-body";
17
18
  id?: string;
18
19
  analyticScript?: string;
19
20
  dimensions?: Dimensions;
21
+ pageInfo: {
22
+ pageContext: {
23
+ siteScript: string;
24
+ page: {
25
+ dimensions: Dimensions;
26
+ };
27
+ };
28
+ };
20
29
  }
21
30
 
22
31
  function GriddoIntegrations(props: GriddoIntegrationsProps) {
@@ -26,6 +35,7 @@ function GriddoIntegrations(props: GriddoIntegrationsProps) {
26
35
  id,
27
36
  analyticScript: siteScript,
28
37
  dimensions,
38
+ pageInfo
29
39
  } = props;
30
40
 
31
41
  const integrations = maybeIntegrations || [];
@@ -37,7 +47,7 @@ function GriddoIntegrations(props: GriddoIntegrationsProps) {
37
47
  "end-body": filterBodyIntegrationFromPosition(integrations, "end"),
38
48
  };
39
49
 
40
- const ints = integrationsGroupedBy[location];
50
+ const integrationsOrdered = integrationsGroupedBy[location];
41
51
 
42
52
  // Analytics GTM + Dimensions
43
53
  const emptyCodeScript = { props: { dangerouslySetInnerHTML: {} } };
@@ -45,6 +55,7 @@ function GriddoIntegrations(props: GriddoIntegrationsProps) {
45
55
  const { analyticsScript, analyticsDimensions } = composeAnalytics(
46
56
  siteScript,
47
57
  dimensions,
58
+ pageInfo,
48
59
  generateAutomaticDimensions,
49
60
  );
50
61
 
@@ -87,7 +98,7 @@ function GriddoIntegrations(props: GriddoIntegrationsProps) {
87
98
 
88
99
  return (
89
100
  <>
90
- {ints?.map((integration, key) => {
101
+ {integrationsOrdered?.map((integration, key) => {
91
102
  /* Data Layer */
92
103
  if (integration.type === "datalayer") {
93
104
  return (
@@ -119,7 +130,11 @@ function GriddoIntegrations(props: GriddoIntegrationsProps) {
119
130
 
120
131
  /* Integration integration.type === "addon" */
121
132
  if (integration.type === "addon") {
122
- return parse(integration.content, { trim: true });
133
+ return (
134
+ <React.Fragment key={key}>
135
+ {parse(integration.content, { trim: true })}
136
+ </React.Fragment>
137
+ );
123
138
  }
124
139
 
125
140
  return null;
@@ -46,11 +46,7 @@ class DistributorService {
46
46
  }
47
47
 
48
48
  if (mode === "manual") {
49
- return {
50
- mode,
51
- fixed,
52
- fullRelations,
53
- };
49
+ return { mode, fixed, fullRelations };
54
50
  }
55
51
 
56
52
  if (mode === "navigation") {
@@ -107,7 +103,17 @@ class DistributorService {
107
103
  }
108
104
 
109
105
  const { site, lang } = data;
106
+
107
+ // Infor that the distributor has not dat.sources
108
+ if (!data.sources) {
109
+ logBox(
110
+ `Warning: Page with id: ${page.id} in the site ${site} has a ReferenceField with \`undefined\` \`data.sources\``,
111
+ "Undefined data.sources in ReferenceField"
112
+ );
113
+ }
114
+
110
115
  const body = this.getBody(data, page);
116
+
111
117
  const response = await SitesService.getDistributorData(
112
118
  page,
113
119
  body,
@@ -291,8 +291,8 @@ async function createStore(domain: string) {
291
291
 
292
292
  verbose(`Store site: ${site.name}`);
293
293
  verbose(`${validPagesIds.length} valid pages from API`);
294
- verbose(`changed ${pagesToDeleteFromStore.length} pages from API`);
295
- verbose(`deleted ${changedPages.length} pages in store`);
294
+ verbose(`changed ${changedPages.length} pages from API`);
295
+ verbose(`deleted ${pagesToDeleteFromStore.length} pages from store`);
296
296
  verbose(`missing ${pagesMissingInStore.length} pages in store`);
297
297
  verbose(`write ${pagesToWriteToStore.length} pages to store`);
298
298
 
@@ -11,7 +11,6 @@ async function startRender() {
11
11
  process.exit(0);
12
12
  } catch (error) {
13
13
  console.log(error);
14
- console.log("<[ Render will be reset ]>");
15
14
  process.exit(1);
16
15
  }
17
16
  }
@@ -117,6 +117,7 @@ function copyDirsSync(
117
117
  // Then copy src to dst
118
118
  fs.cpSync(srcCompose, dstCompose, {
119
119
  recursive: true,
120
+ preserveTimestamps: true,
120
121
  });
121
122
  if (withBackup) {
122
123
  deleteBackup(dstCompose);
@@ -27,10 +27,16 @@ function filterBodyIntegrationFromPosition(
27
27
  }
28
28
 
29
29
  function filterHeadIntegrations(integrations: Array<Core.PageIntegration>) {
30
+ // A la hora de filtrar las integraciones, los addons si que tienen contenido en head
31
+ // pero en el caso de analytics y datalayer el contenido llega a null, pero deben ir en el <head>
30
32
  return integrations
31
33
  ?.filter(
32
34
  (integration) =>
33
- integration.contentHead !== null && integration.contentHead !== ""
35
+ (integration.type==='addon' && integration.contentHead !== null && integration.contentHead !== "")
36
+ ||
37
+ (integration.type === 'analytics')
38
+ ||
39
+ (integration.type === 'datalayer')
34
40
  )
35
41
  .map((integration) => {
36
42
  return {
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": "10.4.30",
4
+ "version": "10.4.32",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -48,7 +48,7 @@
48
48
  "@babel/preset-env": "^7.14.5",
49
49
  "@babel/preset-react": "^7.14.5",
50
50
  "@babel/preset-typescript": "^7.16.5",
51
- "@griddo/core": "10.4.30",
51
+ "@griddo/core": "10.4.32",
52
52
  "@svgr/webpack": "^5.5.0",
53
53
  "babel-loader": "^8.0.6",
54
54
  "babel-plugin-transform-runtime": "^6.23.0",
@@ -119,5 +119,5 @@
119
119
  "publishConfig": {
120
120
  "access": "public"
121
121
  },
122
- "gitHead": "b9de29bad583d1e4f40f614cab7f3944d3f057f6"
122
+ "gitHead": "151e9f780f11806f31b75c6a7fe425548377feee"
123
123
  }
@@ -5,7 +5,6 @@ import * as React from "react";
5
5
  import { GriddoIntegrations } from "../../build/react";
6
6
  import { cleanCommaSeparated, formatImage } from "../utils";
7
7
 
8
-
9
8
  /**
10
9
  * Gatsby Head API
11
10
  * https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-head/
@@ -13,8 +12,6 @@ import { cleanCommaSeparated, formatImage } from "../utils";
13
12
  const Head = (props: CustomHeadProps) => {
14
13
  const {
15
14
  pageContext: {
16
- griddoVersion,
17
- renderDate,
18
15
  locale,
19
16
  openGraph,
20
17
  page: {
@@ -137,12 +134,12 @@ const Head = (props: CustomHeadProps) => {
137
134
  )}
138
135
 
139
136
  {/* Debug */}
140
- {!siteOptions?.avoidDebugMetas && (
137
+ {/* {!siteOptions?.avoidDebugMetas && (
141
138
  <meta
142
139
  property="debug"
143
140
  content={`Griddo v${griddoVersion} @ ${renderDate}}`}
144
141
  />
145
- )}
142
+ )} */}
146
143
 
147
144
  {/* Keywords */}
148
145
  {siteOptions?.useMetaKeywords && !!pageMetadata?.metaKeywords && (
@@ -155,6 +152,7 @@ const Head = (props: CustomHeadProps) => {
155
152
  integrations={integrations}
156
153
  dimensions={dimensions}
157
154
  analyticScript={siteScript}
155
+ pageInfo={props}
158
156
  />
159
157
  </>
160
158
  );
@@ -1,2 +0,0 @@
1
- export declare const printWarningMessage: (message: string, location: string, expected: string) => void;
2
- export declare const printErrorMessage: (message: string, location: string, expected: string) => void;
@@ -1,53 +0,0 @@
1
- import chalk from "chalk";
2
-
3
- export const printWarningMessage = (
4
- message: string,
5
- location: string,
6
- expected: string
7
- ) => {
8
- const heading = " > PRINT WARNING MESSAGE";
9
- const longestLineLength = Math.max(
10
- message.length,
11
- location.length,
12
- heading.length,
13
- expected.length
14
- );
15
- const line = "+".padEnd(longestLineLength + 15, "-") + "+";
16
-
17
- console.log(line);
18
- console.log(
19
- chalk.keyword("orange").bold("|" + heading.padEnd(longestLineLength + 5))
20
- );
21
- console.log("|");
22
- console.log("|" + ` Location: "${location}"`.padEnd(longestLineLength + 5));
23
- console.log("|" + ` Message: ${message}`.padEnd(longestLineLength + 5));
24
- console.log("|" + ` Expected: ${expected}`.padEnd(longestLineLength + 5));
25
- console.log("|");
26
- console.log(line + "\n");
27
- };
28
-
29
- export const printErrorMessage = (
30
- message: string,
31
- location: string,
32
- expected: string
33
- ) => {
34
- const heading = " > PRINT ERROR MESSAGE";
35
- const longestLineLength = Math.max(
36
- message.length,
37
- location.length,
38
- heading.length,
39
- expected.length
40
- );
41
- const line = "+".padEnd(longestLineLength + 15, "-") + "+";
42
-
43
- console.log(line);
44
- console.log(
45
- chalk.keyword("red").bold("|" + heading.padEnd(longestLineLength + 5))
46
- );
47
- console.log("|");
48
- console.log("|" + ` Location: "${location}"`.padEnd(longestLineLength + 5));
49
- console.log("|" + ` Message: ${message}`.padEnd(longestLineLength + 5));
50
- console.log("|" + ` Expected: ${expected}`.padEnd(longestLineLength + 5));
51
- console.log("|");
52
- console.log(line + "\n");
53
- };