@griddo/cx 10.4.20 → 10.4.21

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.
@@ -1,8 +1,7 @@
1
- import { spawnSync } from "node:child_process";
2
1
  import fs from "node:fs";
3
2
  import path from "node:path";
4
3
 
5
- import { attempts, getGatsbyAssetPrefixSlug } from "./utils";
4
+ import { attempts, gatsbyBuild, getGatsbyAssetPrefixSlug } from "./utils";
6
5
  import { RobotsService } from "../../services/robots";
7
6
  import { createBuildData } from "../../utils/create-build-data";
8
7
  import { getInstanceDomains } from "../../utils/domains";
@@ -120,27 +119,7 @@ async function runGatsbyAdapter() {
120
119
  await doLifeCycle({
121
120
  name: "SSG",
122
121
  attempts: attempts.ssg,
123
- steps: [
124
- () => {
125
- // Run Gatsby
126
- const render = spawnSync("yarn", ["gatsby-build"], {
127
- cwd: __ssg,
128
- stdio: ["ignore", "inherit", "ignore"],
129
- encoding: "utf8",
130
- shell: true,
131
- env: Object.assign(process.env, {
132
- GRIDDO_EXPORTER: "true",
133
- GRIDDO_ASSET_PREFIX: assetPrefix,
134
- }),
135
- });
136
-
137
- // @todo gestionar esto desde doLifeCycle.
138
- if (render.status !== 0) {
139
- throw new Error("Error in 'yarn gatsby-build'");
140
- }
141
- },
142
- () => pause("SSG LifeCycle"),
143
- ],
122
+ steps: [() => gatsbyBuild(domain), () => pause("SSG LifeCycle")],
144
123
  });
145
124
 
146
125
  /*
@@ -148,6 +127,7 @@ async function runGatsbyAdapter() {
148
127
  */
149
128
  await doLifeCycle({
150
129
  name: "Relocation",
130
+ attempts: attempts.relocation,
151
131
  steps: [
152
132
  () => legacy__createDistFromGatsbyPublic(domain, needsAssetPrefix),
153
133
  () => pause("Relocation LifeCycle"),
@@ -201,11 +181,11 @@ async function runGatsbyAdapter() {
201
181
  */
202
182
  await doLifeCycle({
203
183
  name: "Clean",
184
+ attempts: attempts.clean,
204
185
  steps: [
205
186
  () => removeDirsSync(__ssg, ["static", "public", "dist"]),
206
187
  () => pause("Clean LifeCycle"),
207
188
  ],
208
- attempts: attempts.clean,
209
189
  });
210
190
  }
211
191
  }
@@ -1,3 +1,5 @@
1
+ import { spawnSync } from "node:child_process";
2
+
1
3
  import { Fields } from "@griddo/core";
2
4
  import dotenv from "dotenv";
3
5
 
@@ -5,6 +7,8 @@ import { getConfig } from "../../utils/temp-utils";
5
7
 
6
8
  dotenv.config();
7
9
 
10
+ const config = getConfig();
11
+
8
12
  const attempts = {
9
13
  prepare: JSON.parse(process.env.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS || "1"),
10
14
  restore: JSON.parse(process.env.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS || "1"),
@@ -82,4 +86,24 @@ function addCloudinaryParams(image: string, params: string) {
82
86
  return `https://${head}/${params}${fullId}`;
83
87
  }
84
88
 
85
- export { attempts, formatImage, getGatsbyAssetPrefixSlug };
89
+ function gatsbyBuild(domain: string) {
90
+ const assetPrefix = getGatsbyAssetPrefixSlug(domain);
91
+ const { __ssg } = config.paths();
92
+
93
+ const command = spawnSync("yarn", ["gatsby-build"], {
94
+ cwd: __ssg,
95
+ stdio: ["ignore", "inherit", "ignore"],
96
+ encoding: "utf8",
97
+ shell: true,
98
+ env: Object.assign(process.env, {
99
+ GRIDDO_EXPORTER: "true",
100
+ LOCAL_GRIDDO_ASSET_PREFIX: assetPrefix,
101
+ }),
102
+ });
103
+
104
+ if (command.status !== 0) {
105
+ throw new Error("Error in 'yarn gatsby-build'");
106
+ }
107
+ }
108
+
109
+ export { attempts, formatImage, gatsbyBuild, getGatsbyAssetPrefixSlug };
@@ -0,0 +1,2 @@
1
+ // noop
2
+ export const noop = true;
@@ -5,8 +5,7 @@ import { runGatsbyAdapter } from "./adapters";
5
5
  import { logBox, measureExecutionTime } from "./utils/shared";
6
6
 
7
7
  async function startRender() {
8
- const exeTime = await measureExecutionTime(runGatsbyAdapter).catch((e) => {
9
- console.log(e);
8
+ const exeTime = await measureExecutionTime(runGatsbyAdapter).catch(() => {
10
9
  console.log("<[ Render will be reset ]>");
11
10
  process.exit(1);
12
11
  });
@@ -346,7 +346,12 @@ async function doLifeCycle(args: {
346
346
  // if no errors, go out!! :)
347
347
  break;
348
348
  } catch (error) {
349
- console.log(`Error in ${name}. Attempt (${trysCount + 1})`);
349
+ const errorString = chalk.bgRed.black(` Error in ${name} LifeCycle `);
350
+ const attemptsString = chalk.yellow(`Attempt (${trysCount + 1})`);
351
+ console.log(`\n${errorString} ${attemptsString}\n`);
352
+ console.log(error);
353
+ console.log();
354
+
350
355
  trysCount++;
351
356
  }
352
357
  }
package/gatsby-config.ts CHANGED
@@ -8,7 +8,7 @@ dotenv.config();
8
8
 
9
9
  // Este process.env.GRIDDO_ASSET_PREFIX se lee porque se ha introducido en
10
10
  // `getEnvRunner()`.
11
- const GRIDDO_ASSET_PREFIX = process.env.GRIDDO_ASSET_PREFIX || undefined;
11
+ const GRIDDO_ASSET_PREFIX = process.env.LOCAL_GRIDDO_ASSET_PREFIX || undefined;
12
12
 
13
13
  // Gatsby configuration file from client
14
14
  // eslint-disable-next-line @typescript-eslint/no-var-requires
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.20",
4
+ "version": "10.4.21",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -45,7 +45,7 @@
45
45
  "@babel/preset-env": "^7.14.5",
46
46
  "@babel/preset-react": "^7.14.5",
47
47
  "@babel/preset-typescript": "^7.16.5",
48
- "@griddo/core": "^10.4.20",
48
+ "@griddo/core": "^10.4.21",
49
49
  "@svgr/webpack": "^5.5.0",
50
50
  "@types/cheerio": "^0.22.35",
51
51
  "babel-loader": "^8.0.6",
@@ -120,5 +120,5 @@
120
120
  "resolutions": {
121
121
  "memoizee": "0.4.15"
122
122
  },
123
- "gitHead": "8e355cb3ed943e2677b8b4065c148e30220e0958"
123
+ "gitHead": "e9ee5308a0c6829e0e3c0c82d28f5e580d0bb804"
124
124
  }
@@ -83,9 +83,20 @@ function getGatsbyAssetPrefixSlug(domain: string) {
83
83
  return `${assetPrefix}/${domain}`;
84
84
  }
85
85
 
86
+ // @todo: Arreglar esta movida de variables de entorno locales solo para Gatsby
87
+ function getLocalGatsbyAssetPrefixSlug(domain: string) {
88
+ const { proDomain } = getConfig();
89
+
90
+ const assetPrefix = process.env.LOCAL_GRIDDO_ASSET_PREFIX;
91
+ if (!assetPrefix || !domain) return "";
92
+ if (!domain.startsWith(proDomain)) return "";
93
+
94
+ return `${assetPrefix}/${domain}`;
95
+ }
96
+
86
97
  function getMatchPath(domain: string, compose: string) {
87
98
  const domainWithNoSlashes = domain.replace("/", "");
88
- const assetPrefix = getGatsbyAssetPrefixSlug(domainWithNoSlashes);
99
+ const assetPrefix = getLocalGatsbyAssetPrefixSlug(domainWithNoSlashes);
89
100
  const needsAssetDomainPrefix = assetPrefix && assetPrefix !== "";
90
101
  const matchPath = needsAssetDomainPrefix ? compose : "";
91
102