@griddo/cx 1.75.192 → 1.75.195

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.
@@ -3,19 +3,19 @@
3
3
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
4
4
  /* eslint-disable node/shebang */
5
5
 
6
- require("dotenv").config();
7
-
8
- // External libraries
9
- import chalk from "chalk";
10
6
  import { execSync } from "child_process";
11
7
  import fs from "fs";
12
8
  import path from "path";
9
+
10
+ import chalk from "chalk";
11
+ import dotenv from "dotenv";
13
12
  import pkgDir from "pkg-dir";
14
13
 
15
- // Utils
16
14
  import { initCache } from "../src/utils/cache";
17
15
  import { findDomains } from "../src/utils/domains";
18
- import { exporterLogo as splash } from "../src/utils/shared";
16
+ import { exporterLogo as splash, measureFunctions } from "../src/utils/shared";
17
+
18
+ dotenv.config();
19
19
 
20
20
  // Envs
21
21
  const artifactsArchivable = ["dist", "assets", "apiCache", ".cache"];
@@ -72,10 +72,16 @@ const logWarning = (...message: Array<any>) => console.log(...message);
72
72
  // -----------------------------------------------------------------------------
73
73
  const domainExport = async (domain: string) => {
74
74
  const runner = getDomainRunner(domain);
75
- runner.init();
76
- runner.restoreArtifacts();
75
+ // onPreExporter
76
+ const endRestore = measureFunctions(runner.init, runner.restoreArtifacts);
77
+ logInfo(`\n⌛️ Domain ${domain} restaured: ${endRestore}s`);
78
+
79
+ // Gatsby
77
80
  runner.runExporter();
78
- runner.archiveArtifacts();
81
+
82
+ // onPostExporter
83
+ const endArchive = measureFunctions(runner.archiveArtifacts);
84
+ logInfo(`\n⌛️ Domain ${domain} archived: ${endArchive}s`);
79
85
  };
80
86
 
81
87
  const launchExports = async () => {
@@ -108,8 +114,14 @@ const getDomainRunner = (domain: string) => {
108
114
  };
109
115
 
110
116
  const getArtifactPaths = (artifact = "") => {
111
- const domainExportArchiveBasePath = path.resolve(exportArchiveBasePath, domain);
112
- const currentExportArchivePath = path.resolve(domainExportArchiveBasePath, artifact);
117
+ const domainExportArchiveBasePath = path.resolve(
118
+ exportArchiveBasePath,
119
+ domain
120
+ );
121
+ const currentExportArchivePath = path.resolve(
122
+ domainExportArchiveBasePath,
123
+ artifact
124
+ );
113
125
  const currentExportBackupPath = `${currentExportArchivePath}-BACKUP`;
114
126
  const currentExportWorkingPath = path.resolve(workingPath, artifact);
115
127
 
@@ -142,18 +154,27 @@ const getDomainRunner = (domain: string) => {
142
154
  };
143
155
 
144
156
  const archiveExportArtifact = (artifact: string) => {
145
- const { currentExportArchivePath, currentExportWorkingPath } = getArtifactPaths(artifact);
146
-
147
- logInfo(`🚚 Moving files from ${chalk.gray(currentExportWorkingPath)} to ${chalk.gray(currentExportArchivePath)}`);
157
+ const { currentExportArchivePath, currentExportWorkingPath } =
158
+ getArtifactPaths(artifact);
159
+
160
+ logInfo(
161
+ `🚚 Moving files from ${chalk.gray(
162
+ currentExportWorkingPath
163
+ )} to ${chalk.gray(currentExportArchivePath)}`
164
+ );
148
165
  run(`mv ${currentExportWorkingPath} ${currentExportArchivePath}`);
149
166
  };
150
167
 
151
168
  const archiveArtifacts = () => {
152
169
  for (const artifact of artifactsArchivable) {
153
- const { currentExportWorkingPath, currentExportArchivePath } = getArtifactPaths(artifact);
170
+ const { currentExportWorkingPath, currentExportArchivePath } =
171
+ getArtifactPaths(artifact);
154
172
 
155
173
  if (!fs.existsSync(currentExportWorkingPath)) {
156
- logError("📁 Source directory has not been created:", currentExportWorkingPath);
174
+ logError(
175
+ "📁 Source directory has not been created:",
176
+ currentExportWorkingPath
177
+ );
157
178
  continue;
158
179
  }
159
180
 
@@ -162,7 +183,10 @@ const getDomainRunner = (domain: string) => {
162
183
  archiveExportArtifact(artifact);
163
184
  deleteArtifactBackup(artifact);
164
185
  } catch (error) {
165
- logError(`🚚 Error moving files to ${currentExportArchivePath}`, error.message);
186
+ logError(
187
+ `🚚 Error moving files to ${currentExportArchivePath}`,
188
+ error.message
189
+ );
166
190
  restoreArtifactBackup(artifact);
167
191
  continue;
168
192
  }
@@ -171,7 +195,8 @@ const getDomainRunner = (domain: string) => {
171
195
 
172
196
  const restoreArtifacts = () => {
173
197
  for (const artifact of artifactsArchivable) {
174
- const { currentExportArchivePath, currentExportWorkingPath } = getArtifactPaths(artifact);
198
+ const { currentExportArchivePath, currentExportWorkingPath } =
199
+ getArtifactPaths(artifact);
175
200
 
176
201
  if (fs.existsSync(currentExportArchivePath)) {
177
202
  logWarning(`️♻️ Restoring ${chalk.gray(currentExportArchivePath)}`);
@@ -183,7 +208,8 @@ const getDomainRunner = (domain: string) => {
183
208
  };
184
209
 
185
210
  const createArtifactBackup = (artifact: string) => {
186
- const { currentExportArchivePath, currentExportBackupPath } = getArtifactPaths(artifact);
211
+ const { currentExportArchivePath, currentExportBackupPath } =
212
+ getArtifactPaths(artifact);
187
213
 
188
214
  if (fs.existsSync(currentExportArchivePath)) {
189
215
  logInfo(`💿 Creating backup of ${chalk.gray(currentExportArchivePath)}`);
@@ -192,18 +218,22 @@ const getDomainRunner = (domain: string) => {
192
218
  };
193
219
 
194
220
  const restoreArtifactBackup = (artifact: string) => {
195
- const { currentExportArchivePath, currentExportBackupPath } = getArtifactPaths(artifact);
221
+ const { currentExportArchivePath, currentExportBackupPath } =
222
+ getArtifactPaths(artifact);
196
223
 
197
224
  if (fs.existsSync(currentExportBackupPath)) {
198
- logWarning(`️♻️ Restoring backup ${chalk.gray(currentExportArchivePath)}`);
225
+ logWarning(
226
+ `️♻️ Restoring backup ${chalk.gray(currentExportArchivePath)}`
227
+ );
199
228
  run(`mv ${currentExportBackupPath} ${currentExportArchivePath}`);
200
229
  }
201
230
  };
202
231
 
203
232
  const deleteArtifactBackup = (artifact: string) => {
204
- const { currentExportArchivePath, currentExportBackupPath } = getArtifactPaths(artifact);
233
+ const { currentExportArchivePath, currentExportBackupPath } =
234
+ getArtifactPaths(artifact);
205
235
 
206
- logWarning(`️❌ Removing backup ${chalk.gray(currentExportArchivePath)}`);
236
+ logWarning(`️🗑️ Removing backup ${chalk.gray(currentExportArchivePath)}`);
207
237
  run(`rm -rf ${currentExportBackupPath}`);
208
238
  };
209
239
 
@@ -211,6 +241,7 @@ const getDomainRunner = (domain: string) => {
211
241
  console.log(`\n${chalk.black(chalk.bgGreen(" Gatsby (start) "))}\n`);
212
242
 
213
243
  run("yarn export");
244
+ // run("cp build-report.json build-report-${domain}.json")
214
245
  logSuccess("Your sites have been exported correctly");
215
246
 
216
247
  console.log(`\n${chalk.black(chalk.bgGreen(" Gatsby (end) "))}\n`);
@@ -224,13 +255,14 @@ const getDomainRunner = (domain: string) => {
224
255
  const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
225
256
 
226
257
  if (fs.existsSync(distPath)) {
227
- logWarning(`🚚 Moving ${chalk.gray(distPath)} to ${chalk.gray(publicPath)}`);
258
+ logWarning(
259
+ `🚚 Moving ${chalk.gray(distPath)} to ${chalk.gray(publicPath)}`
260
+ );
228
261
  run(`mv ${distPath} ${publicPath}`);
229
262
  }
230
263
  };
231
264
 
232
265
  // TODO: Esto no debería hacerse desde infra
233
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
234
266
  const movePublicToDist = () => {
235
267
  const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
236
268
  const { currentExportWorkingPath: distPath } = getArtifactPaths("dist");
@@ -243,10 +275,11 @@ const getDomainRunner = (domain: string) => {
243
275
 
244
276
  const removeDisposableArtifacts = () => {
245
277
  for (const artifact of artifactsDisposable) {
246
- const { currentExportWorkingPath: artifactPath } = getArtifactPaths(artifact);
278
+ const { currentExportWorkingPath: artifactPath } =
279
+ getArtifactPaths(artifact);
247
280
 
248
281
  if (fs.existsSync(artifactPath)) {
249
- logWarning(`❌ Removing ${chalk.gray(artifactPath)}`);
282
+ logWarning(`🗑️ Removing ${chalk.gray(artifactPath)}`);
250
283
  run(`rm -rf ${artifactPath}`);
251
284
  }
252
285
  }
@@ -273,6 +306,6 @@ const getDomainRunner = (domain: string) => {
273
306
  console.clear();
274
307
 
275
308
  launchExports().catch((err) => {
276
- console.error(" ERROR", err?.stdout?.toString() || err);
309
+ console.error("⛔️ ERROR", err?.stdout?.toString() || err);
277
310
  process.exit(1);
278
311
  });
@@ -1,17 +1,10 @@
1
- // Types
2
1
  import type { CustomHeadProps } from "./types";
3
2
 
4
- // Instance elements
5
- import {
6
- generateAutomaticDimensions,
7
- // @ts-ignore
8
- } from "components";
9
-
10
- // External libraries
3
+ // @ts-expect-error components is unknown
4
+ import { generateAutomaticDimensions } from "components";
11
5
  import parse from "html-react-parser";
12
6
  import * as React from "react";
13
7
 
14
- // Utils
15
8
  import { cleanCommaSeparated, composeAnalytics, formatImage } from "./utils";
16
9
 
17
10
  /**
@@ -1,20 +1,10 @@
1
- // Types
2
- import type { Core } from "@griddo/core";
3
1
  import type { TemplateProps } from "./types";
2
+ import type { Core } from "@griddo/core";
4
3
 
5
- // Components and functions
6
4
  import { Page as RenderGriddoPage } from "@griddo/core";
5
+ // @ts-expect-error components is unknown
6
+ import { components, SiteProvider, templates } from "components";
7
7
  import { Link, navigate } from "gatsby";
8
-
9
- // Instance elements
10
- import {
11
- components,
12
- SiteProvider,
13
- templates,
14
- // @ts-ignore
15
- } from "components";
16
-
17
- // External libraries
18
8
  import * as React from "react";
19
9
  import { Helmet } from "react-helmet";
20
10
 
@@ -1,7 +1,7 @@
1
- import type { Core } from "@griddo/core";
2
- import type { HeadProps } from "gatsby";
3
1
  import type { AllPagesResponse } from "../types/api";
4
2
  import type { GatsbyPageObject } from "../types/pages";
3
+ import type { Core } from "@griddo/core";
4
+ import type { HeadProps } from "gatsby";
5
5
 
6
6
  export interface CustomHeadProps extends HeadProps {
7
7
  pageContext: GatsbyPageObject["context"] & {
@@ -6,7 +6,6 @@
6
6
  //
7
7
  // Browserify doesn't work with the mixture of typescript + webpack 5 + SSR
8
8
 
9
- // Types
10
9
  import type { Fields } from "@griddo/core";
11
10
 
12
11
  /**
@@ -22,6 +21,7 @@ function cleanCommaSeparated(str: string) {
22
21
 
23
22
  /**
24
23
  * Format Cloudinary or DAM URL
24
+ *
25
25
  * @param image The image url
26
26
  * @param width With of the image
27
27
  * @param height Height of the image
@@ -59,7 +59,7 @@ function addGriddoDamParams(image: string, params: string) {
59
59
  }
60
60
 
61
61
  /**
62
- * Take a cloudinary url and add query params.
62
+ * Take a cloudinary url and add query params.
63
63
  */
64
64
  function addCloudinaryParams(image: string, params: string) {
65
65
  const plainUrl = image.replace("https://", "");
@@ -78,16 +78,13 @@ function composeAnalytics(
78
78
  siteScript: string;
79
79
  page: {
80
80
  dimensions: {
81
- // TODO: Type dimensions / remove any
82
- values: any;
81
+ values: Record<string, unknown>;
83
82
  };
84
83
  };
85
84
  };
86
85
  },
87
86
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
88
- generateAutomaticDimensions = (page: Record<string, unknown>) => {
89
- return null;
90
- }
87
+ generateAutomaticDimensions = (page: Record<string, unknown>) => null
91
88
  ) {
92
89
  const {
93
90
  pageContext: {
@@ -107,7 +104,8 @@ function composeAnalytics(
107
104
  const allDimensionsValues = {
108
105
  ...dimensionValues,
109
106
  ...automaticDimensionValues,
110
- };
107
+ // TODO: remove any
108
+ } as Record<string, any>;
111
109
 
112
110
  const allDimensions = [];
113
111
 
package/src/html.tsx CHANGED
@@ -1,6 +1,8 @@
1
- import * as React from "react";
2
1
  import type { HtmlProps } from "./components/types";
3
2
 
3
+ import * as React from "react";
4
+
5
+ // TODO: JSDoc
4
6
  export default function HTML(props: HtmlProps) {
5
7
  return (
6
8
  <html {...props.htmlAttributes}>
@@ -1,4 +1,3 @@
1
- // External libraries
2
1
  import axios from "axios";
3
2
  import chalk from "chalk";
4
3
 
@@ -43,6 +42,8 @@ class AuthService {
43
42
  };
44
43
  }
45
44
 
45
+ return this.headers;
46
+
46
47
  console.log("👋 Login\n");
47
48
  } catch (e) {
48
49
  console.error(
@@ -1,13 +1,13 @@
1
- // Types
2
- import type { Core, Fields } from "@griddo/core";
3
1
  import type { FetchDataProps } from "../types/global";
4
2
  import type { APIPageObject } from "../types/pages";
3
+ import type { Core, Fields } from "@griddo/core";
4
+ import type {
5
+ QueriedData,
6
+ Reference,
7
+ } from "@griddo/core/dist/types/api-response-fields";
5
8
 
6
- // Utils
7
- import { logBox } from "../utils/shared";
8
-
9
- // Services
10
9
  import { SitesService } from "./sites";
10
+ import { logBox } from "../utils/shared";
11
11
 
12
12
  /**
13
13
  * Service to work with distributors.
@@ -15,6 +15,7 @@ import { SitesService } from "./sites";
15
15
  class DistributorService {
16
16
  /**
17
17
  * Get the body data from a ReferenceField in auto or manual mode.
18
+ *
18
19
  * @param data The ReferenceField props.
19
20
  * @returns The props for one of the ReferenceField mode.
20
21
  */
@@ -118,9 +119,10 @@ class DistributorService {
118
119
  try {
119
120
  const { template } = page;
120
121
  const checkDistributors = async (
121
- // No puede ser Core.Page['template'] porque a medida que va bajando en
122
- // el árbol ya no es la estructura de un template.
123
- templateChunk: Record<string, any>, // Core.Page['template'],
122
+ templateChunk: {
123
+ hasDistributorData?: boolean;
124
+ queriedItems: QueriedData<unknown>;
125
+ },
124
126
  level = 1
125
127
  ) => {
126
128
  // If it doesn't a "template strcuture"
@@ -138,7 +140,12 @@ class DistributorService {
138
140
  // Si la key es `queriedItems` saltamos al siguiente `key`
139
141
  if (key === "queriedItems") continue;
140
142
 
141
- const component = templateChunk[key];
143
+ const _key = key as "hasDistributorData" | "queriedItems";
144
+ const component = templateChunk[_key] as unknown as {
145
+ data: Reference<unknown>;
146
+ queriedItems: QueriedData<unknown>;
147
+ hasDistributorData: boolean;
148
+ };
142
149
 
143
150
  // Si el elemento no existe o no es un objeto saltamos al siguiente `key`
144
151
  if (!component || typeof component !== "object") continue;
@@ -147,8 +154,8 @@ class DistributorService {
147
154
  if (component.hasDistributorData) {
148
155
  component.queriedItems = await this.fetchContentTypeData({
149
156
  page,
150
- component,
151
157
  cached,
158
+ component,
152
159
  });
153
160
  }
154
161
 
@@ -157,7 +164,9 @@ class DistributorService {
157
164
  };
158
165
 
159
166
  const getDistributors = async (template: Core.Page["template"]) => {
160
- await checkDistributors([template]); // ==> En array para que también revise la propia template como objeto.
167
+ // `template` es un array para que también revise la propia template como objeto.
168
+ // @ts-expect-error remove the array
169
+ await checkDistributors([template]);
161
170
 
162
171
  return template;
163
172
  };
@@ -1,13 +1,11 @@
1
- // Types
2
1
  import type { Domains } from "../types/global";
3
2
 
4
- // Utils
5
3
  import { get } from "../utils/api";
6
4
 
7
5
  // Envs
8
6
  const API_URL = process.env.API_URL;
9
7
 
10
- // Constants
8
+ // Consts
11
9
  const ENDPOINTS = {
12
10
  GET_ALL: `${API_URL}/domains`,
13
11
  };
@@ -1,4 +1,3 @@
1
- // Types
2
1
  import type { Footer, Header } from "../types/navigation";
3
2
  import type { APIPageObject } from "../types/pages";
4
3
 
@@ -1,11 +1,8 @@
1
- // Types
2
1
  import type { Robots } from "../types/global";
3
2
 
4
- // External libraries
5
3
  import fs from "fs";
6
4
  import path from "path";
7
5
 
8
- // Utils
9
6
  import { get } from "../utils/api";
10
7
 
11
8
  /**
@@ -47,7 +44,7 @@ class RobotsService {
47
44
  /**
48
45
  * TODO: JSDoc
49
46
  */
50
- async writeFiles(basePath = "") {
47
+ async writeFiles(basePath: string) {
51
48
  for (const robot of this.robots) {
52
49
  const basePathLocation = path.join(basePath, robot.path);
53
50
  const fileLocation = path.join(basePathLocation, "robots.txt");
@@ -1,7 +1,5 @@
1
- // Types
2
1
  import type { Settings } from "../types/global";
3
2
 
4
- // Utils
5
3
  import { get, post } from "../utils/api";
6
4
 
7
5
  /**
@@ -1,5 +1,3 @@
1
- // Types
2
- import type { Core } from "@griddo/core";
3
1
  import type {
4
2
  AllPagesResponse,
5
3
  AllSitesReponse,
@@ -14,11 +12,10 @@ import type {
14
12
  StartPageRenderResponse,
15
13
  } from "../types/api";
16
14
  import type { Site } from "../types/sites";
15
+ import type { Core } from "@griddo/core";
17
16
 
18
- // External libraries
19
17
  import dotenv from "dotenv";
20
18
 
21
- // Utils
22
19
  import { get, post } from "../utils/api";
23
20
 
24
21
  dotenv.config();
@@ -26,7 +23,7 @@ dotenv.config();
26
23
  // Envs
27
24
  const API_URL = process.env.API_URL;
28
25
 
29
- // Constants
26
+ // Consts
30
27
  const WITH_URI = `${API_URL}/site/`;
31
28
  const ENDPOINTS = {
32
29
  GET_ALL: `${API_URL}/sites/all`,