@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.
@@ -0,0 +1,41 @@
1
+ import type { GatsbyNode } from "gatsby";
2
+
3
+ import { IS_COMPONENT_LIBRARY, PROJECT_ALIASES } from "./instance";
4
+
5
+ // TODO: Use webpack types
6
+ const onCreateWebpackConfig: GatsbyNode["onCreateWebpackConfig"] = ({
7
+ actions,
8
+ plugins,
9
+ loaders,
10
+ getConfig,
11
+ }) => {
12
+ if (IS_COMPONENT_LIBRARY) {
13
+ const config = getConfig();
14
+ config.module.rules = [
15
+ // Omit the default rule where test === '\.jsx?$'
16
+ ...config.module.rules.filter(
17
+ (rule: { test: string }) => String(rule.test) !== String(/\.jsx?$/)
18
+ ),
19
+ // Recreate it with custom exclude filter
20
+ {
21
+ ...loaders.js(),
22
+ test: /\.jsx?$/,
23
+ // Exclude all node_modules from transpilation, except for '@griddo/cx'
24
+ exclude: (modulePath: string) =>
25
+ /node_modules/.test(modulePath) && !/@griddo\/cx/.test(modulePath),
26
+ },
27
+ ];
28
+ actions.replaceWebpackConfig(config);
29
+ }
30
+
31
+ // Add component-system aliases to Webpack's Resolve:
32
+ actions.setWebpackConfig({
33
+ resolve: {
34
+ fallback: { path: false },
35
+ alias: PROJECT_ALIASES,
36
+ },
37
+ plugins: [plugins.provide({ process: "process/browser", React: "react" })],
38
+ });
39
+ };
40
+
41
+ export { onCreateWebpackConfig };
@@ -1,11 +1,11 @@
1
- // External libraries
2
- import findUp from "find-up";
3
1
  import path from "path";
2
+
3
+ import findUp from "find-up";
4
4
  import pkgDir from "pkg-dir";
5
5
 
6
- // Envs
7
- const isComponentLibraryEnv = __dirname.includes("node_modules");
8
- const projectAliases = getComponentsLibAliases();
6
+ // Consts
7
+ const IS_COMPONENT_LIBRARY = __dirname.includes("node_modules");
8
+ const PROJECT_ALIASES = getComponentsLibAliases();
9
9
 
10
10
  /**
11
11
  * Returns the instance or monorepo paths.
@@ -13,7 +13,7 @@ const projectAliases = getComponentsLibAliases();
13
13
  * @param customPath The path for the instance components
14
14
  */
15
15
  function resolveComponentsPath(customPath = "") {
16
- return isComponentLibraryEnv
16
+ return IS_COMPONENT_LIBRARY
17
17
  ? path.resolve(pkgDir.sync(__dirname) as string, "../../../", customPath)
18
18
  : path.resolve(
19
19
  pkgDir.sync(__dirname) as string,
@@ -40,6 +40,7 @@ function getComponentsJSConfig() {
40
40
  * Get the instance webpack aliases
41
41
  */
42
42
  function getComponentsLibAliases() {
43
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
43
44
  const xsConfig = require(getComponentsJSConfig() as string);
44
45
 
45
46
  return Object.keys(xsConfig?.compilerOptions?.paths).reduce(
@@ -65,7 +66,7 @@ function getComponentsLibAliases() {
65
66
  export {
66
67
  getComponentsJSConfig,
67
68
  getComponentsLibAliases,
68
- isComponentLibraryEnv,
69
- projectAliases,
69
+ IS_COMPONENT_LIBRARY,
70
+ PROJECT_ALIASES,
70
71
  resolveComponentsPath,
71
72
  };
@@ -1,5 +1,3 @@
1
- // Types
2
- import type { Core, Fields } from "@griddo/core";
3
1
  import type {
4
2
  APIPageObject,
5
3
  GatsbyPageObject,
@@ -10,15 +8,15 @@ import type {
10
8
  PageAdditionalInfo,
11
9
  } from "../types/pages";
12
10
  import type { TemplateWithDistributor } from "../types/templates";
11
+ import type { Core, Fields } from "@griddo/core";
13
12
 
14
- // External libraries
15
- import dotenv from "dotenv";
16
13
  import fs from "fs";
17
14
  import path from "path";
18
15
 
19
- // Utils
20
- import { formatImage } from "../components/utils";
16
+ import dotenv from "dotenv";
17
+
21
18
  import { postSearchInfo } from "./searches";
19
+ import { formatImage } from "../components/utils";
22
20
 
23
21
  dotenv.config();
24
22
 
@@ -28,7 +26,7 @@ const GRIDDO_SEARCH_FEATURE = !!JSON.parse(
28
26
  );
29
27
  const HAS_ASSET_PREFIX = !!process.env.GRIDDO_ASSET_PREFIX;
30
28
 
31
- // Constants
29
+ // Consts
32
30
  const DEFAULT_ITEMS_PER_PAGE_FOR_LIST_TEMPLATES = 25;
33
31
  const COMPONENT = path.resolve(__dirname, "../../src/components/template.tsx");
34
32
 
@@ -328,7 +326,7 @@ function createGriddoMultiPages(
328
326
  ({ sectionSlug }: { sectionSlug: string }) => sectionSlug === "/"
329
327
  )
330
328
  ) {
331
- // @ts-expect-error
329
+ // @ts-expect-error ? ? ?
332
330
  multiPageElements.push({});
333
331
  }
334
332
 
@@ -384,7 +382,7 @@ function getMultiPageElements(page: TemplateWithDistributor) {
384
382
  const getMultiPageComponent = (
385
383
  // No puede ser Core.Page['template'] porque a medida que va bajando en
386
384
  // el árbol ya no es la estructura de un template.
387
- template: Record<string, any>,
385
+ template: Record<string, unknown>,
388
386
  level = 0
389
387
  ) => {
390
388
  // If it doesn't have a "template strcuture"
@@ -392,7 +390,11 @@ function getMultiPageElements(page: TemplateWithDistributor) {
392
390
 
393
391
  // For each prop in the "template"
394
392
  for (const key in template) {
395
- const currentComponent = template[key];
393
+ const currentComponent = template[key] as {
394
+ component: string;
395
+ hasGriddoMultiPage: boolean;
396
+ elements: Array<Record<string, unknown>>;
397
+ };
396
398
  const isValidComponent =
397
399
  currentComponent || typeof currentComponent === "object";
398
400
  const hasGriddoMultiPageProp = JSON.stringify(
@@ -415,7 +417,9 @@ function getMultiPageElements(page: TemplateWithDistributor) {
415
417
  if (!level) resolve(null);
416
418
  };
417
419
 
418
- getMultiPageComponent([page]); // ==> En array para que también revise la propia template como objeto.
420
+ // `page` en un array para que también revise la propia template como objeto.
421
+ // @ts-expect-error remove the array
422
+ getMultiPageComponent([page]);
419
423
  });
420
424
 
421
425
  return multiPageElements as Promise<MultiPageElements>;
@@ -492,7 +496,6 @@ function getPaginatedPages(listTemplate: TemplateWithDistributor) {
492
496
  * addPageNumberToUrl("web.com", 3) // "web.com/3"
493
497
  * addPageNumberToUrl("web.com", 3, { addEndingSlash: true }) // "web.com/3/"
494
498
  */
495
-
496
499
  function addPageNumberToUrl(
497
500
  url: string,
498
501
  pageNumber: number,
@@ -1,8 +1,6 @@
1
- // Types
2
1
  import type { PostSearchInfoResponse } from "../types/api";
3
2
  import type { PostSearchInfoProps } from "../types/global";
4
3
 
5
- // API
6
4
  import { post } from "./api";
7
5
 
8
6
  // Envs
@@ -1,10 +1,11 @@
1
- // External libraries
2
1
  import chalk from "chalk";
3
2
  import dotenv from "dotenv";
4
3
  import fs from "fs-extra";
5
4
  import gradient from "gradient-string";
6
- import { APIResponses } from "../types/api";
5
+
7
6
  import { version } from "../../package.json";
7
+ import { APIResponses } from "../types/api";
8
+ import { Site } from "../types/sites";
8
9
 
9
10
  dotenv.config();
10
11
 
@@ -48,7 +49,7 @@ function logBox(str: string) {
48
49
  /**
49
50
  * Custom basic logging function controlled by a environment variable.
50
51
  *
51
- * @params str The string or strings separated by commans to be logged.
52
+ * @param str The string or strings separated by commans to be logged.
52
53
  */
53
54
  function logInfo(...str: Array<unknown>) {
54
55
  if (GRIDDO_BUILD_LOGS) {
@@ -112,44 +113,88 @@ export function getSafeSiteId(response: APIResponses) {
112
113
  }
113
114
 
114
115
  /**
115
- * Print a f**king great Griddo builder logo.
116
+ * Execute functions and return time it takes for functions to execute
117
+ * @param funcs Array of functions
118
+ * @returns seconds it takes for functions to execute
119
+ */
120
+ function measureFunctions(...funcs: Array<() => void>) {
121
+ const start = performance.now();
122
+ funcs.forEach((func) => func());
123
+
124
+ return msToSec(performance.now() - start);
125
+ }
126
+
127
+ /**
128
+ * Remove props from an object
129
+ *
130
+ * @param obj The object
131
+ * @param props An array of props to be removed
132
+ */
133
+ function removeProperties(obj: Record<string, unknown>, props: Array<string>) {
134
+ for (const key in obj) {
135
+ if (props.includes(key)) {
136
+ delete obj[key];
137
+ } else if (typeof obj[key] === "object") {
138
+ removeProperties(obj[key] as Record<string, unknown>, props);
139
+ }
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Return a list of sites with their names and ids.
145
+ *
146
+ * @param sites An array of sites objects
147
+ */
148
+ function siteList(sites: Array<Site>) {
149
+ return sites.map(({ name, id }) => `${name} (${id})`).join(", ");
150
+ }
151
+
152
+ /**
153
+ * Print a f**king great Griddo build domain logo.
116
154
  */
117
155
  function splash() {
118
156
  const logo = `
119
- ··
120
- ·· ______ ______ _____ ______ ______ _____
121
- ·· | ____ |_____/ | | \\ | \\ | |
122
- ·· |_____| | \\_ __|__ |_____/ |_____/ |_____|
123
- ·· ______ _ _ _____ ______ _______ ______
124
- ·· |_____] | | | | | \\ |______ |_____/
125
- ·· |_____] |_____| __|__ |_____ |_____/ |______ | \\_
126
- ··
127
- ·· ${version}
157
+ ___ _ _ _ _ ___ ___ ____ _ _ ____ _ __ _
158
+ |==] |__| | |___ |__> |__> [__] |\\/| |--| | | \\|
128
159
  `;
129
160
 
130
161
  console.log(gradient.cristal(logo));
131
162
  }
132
163
 
164
+ /**
165
+ * Print a f**king great Griddo builder logo.
166
+ */
133
167
  function exporterLogo() {
134
168
  const logo = `
135
169
  ··
136
- ·· /
137
- ·· / //
138
- ·· ______ ______ _____ ______ ______ _____ /· /
139
- ·· | ____ |_____/ | | \\ | \\ | | / · / /
140
- ·· |_____| | \\_ __|__ |_____/ |_____/ |_____| · · / / · /
170
+ ··
171
+ ··
172
+ ·· ______ ______ _____ ______ ______ _____
173
+ ·· | ____ |_____/ | | \\ | \\ | |
174
+ ·· |_____| | \\_ __|__ |_____/ |_____/ |_____|
141
175
  ·· _______ _ _ _____ _____ ______ _______ _______ ______
142
176
  ·· |______ \\___/ |_____] | | |_____/ | |______ |_____/
143
177
  ·· |______ _/ \\_ | |_____| | \\_ | |______ | \\_
144
178
  ··
145
- ·· Griddo exporter orchestrator / / / · / /
146
- ·· ${version} / / /· /
147
- ·· /· /
148
- ·· /
179
+ ·· Griddo exporter orchestrator
180
+ ·· ${version}
181
+ ··
182
+ ··
149
183
  ··
150
184
  `;
151
185
 
152
186
  console.log(gradient.cristal(logo));
153
187
  }
154
188
 
155
- export { delay, exporterLogo, logBox, logInfo, logPageSize, splash, walk };
189
+ export {
190
+ delay,
191
+ exporterLogo,
192
+ logBox,
193
+ logInfo,
194
+ logPageSize,
195
+ measureFunctions,
196
+ removeProperties,
197
+ siteList,
198
+ splash,
199
+ walk,
200
+ };
@@ -1,21 +1,17 @@
1
- // Types
2
1
  import type { BuildProcessData } from "../types/global";
3
2
  import type { Site, SiteData } from "../types/sites";
4
3
 
5
- // External libraries
4
+ import path from "path";
5
+
6
6
  import chalk from "chalk";
7
7
  import fs from "fs-extra";
8
8
  import { parse } from "js2xmlparser";
9
- import path from "path";
10
9
 
11
- // Services
10
+ import { deleteSites } from "./folders";
11
+ import { logInfo } from "./shared";
12
12
  import { AuthService } from "../services/auth";
13
13
  import { SitesService } from "../services/sites";
14
-
15
- // Utils
16
14
  import { AllPagesResponse } from "../types/api";
17
- import { deleteSites } from "./folders";
18
- import { logInfo } from "./shared";
19
15
 
20
16
  // Envs
21
17
  const API_URL = process.env.API_URL;
@@ -55,13 +51,12 @@ async function checkSites() {
55
51
  const langResponse = await SitesService.getLanguages(site.id);
56
52
 
57
53
  return (site.domains = langResponse.items
58
- .filter((item) => {
59
- return (
54
+ .filter(
55
+ (item) =>
60
56
  item.domain &&
61
57
  (!process.env.DOMAIN ||
62
58
  item.domain.slug.indexOf(process.env.DOMAIN) > 0)
63
- );
64
- })
59
+ )
65
60
  .map((item) => ({ [item.id]: `${item.domain.slug}${item.path}` })));
66
61
  });
67
62
 
@@ -126,8 +121,8 @@ async function getSiteData(siteID: number, cached: boolean) {
126
121
  const socials = await SitesService.getSocials(siteID, cached);
127
122
  const siteLangsInfo = siteLangs.items;
128
123
  const defaultLang = siteLangsInfo.find((lang) => lang.isDefault);
129
- // eliminado para validar que efectivamente no rompe nada
130
- // si el cambio es correcto, hay que eliminar las 7 líneas que contienen "sitePages"
124
+ // TODO: Eliminado para validar que efectivamente no rompe nada si el cambio
125
+ // es correcto, hay que eliminar las 7 líneas que contienen "sitePages":
131
126
  // const sitePages = await SitesService.getPages(siteID, cached);
132
127
  const sitePages: AllPagesResponse = [];
133
128
 
@@ -154,18 +149,36 @@ async function getSiteData(siteID: number, cached: boolean) {
154
149
  }
155
150
 
156
151
  /**
157
- * Send end render signal to the API for all pages.
152
+ * Save a file with the end of build process
158
153
  *
154
+ * @param filePathName The pathname for the file report
159
155
  * @param buildProcessData The whole build process data.
160
- * @param createdPages An array of pages ids.
161
156
  */
162
- async function setPagesRenderEnd(
163
- buildProcessData: BuildProcessData,
164
- createdPages: Array<number>
157
+ async function generateBuildReport(
158
+ filePathName: string,
159
+ buildProcessData: BuildProcessData
165
160
  ) {
161
+ // Get the token
162
+ const authControl = await AuthService.login();
163
+
164
+ const buildSitesInfo = Object.keys(buildProcessData).map((siteID) => ({
165
+ ...buildProcessData[siteID],
166
+ siteId: parseInt(siteID),
167
+ }));
168
+
169
+ const report = {
170
+ authControl,
171
+ sites: buildSitesInfo,
172
+ };
173
+
174
+ fs.writeFileSync(filePathName, JSON.stringify(report));
175
+
176
+ logInfo(`Build report saved for ${buildSitesInfo.length} site(s)`);
177
+
178
+ // API version
179
+ // TODO: Revemo when the file version is implemented.
166
180
  const promises = Object.keys(buildProcessData).map(async (siteID) => {
167
181
  const body = buildProcessData[siteID];
168
-
169
182
  logInfo(`Deploying ending call to site ${siteID}:`);
170
183
 
171
184
  return SitesService.endSiteRender(parseInt(siteID), body);
@@ -173,7 +186,7 @@ async function setPagesRenderEnd(
173
186
 
174
187
  await Promise.all(promises);
175
188
 
176
- logInfo(`Set pages as deployed. Total ${createdPages.length}`);
189
+ logInfo(`Build end signal sent for ${buildSitesInfo.length} site(s)`);
177
190
  }
178
191
 
179
192
  /**
@@ -273,7 +286,7 @@ function saveFile(filePath: string, content: string) {
273
286
  export {
274
287
  checkSites,
275
288
  unpublishSites,
276
- setPagesRenderEnd,
289
+ generateBuildReport,
277
290
  getSiteData,
278
291
  generateSitemaps,
279
292
  };