@griddo/cx 1.75.179 → 1.75.181

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.
Files changed (72) hide show
  1. package/README.md +22 -14
  2. package/build/index.js +65 -0
  3. package/gatsby-browser.tsx +140 -0
  4. package/gatsby-config.ts +40 -0
  5. package/gatsby-node.ts +134 -0
  6. package/gatsby-ssr.tsx +63 -0
  7. package/index.js +4 -0
  8. package/package.json +119 -100
  9. package/scripts/build-reset.ts +9 -0
  10. package/scripts/griddo-exporter.ts +305 -0
  11. package/src/components/Head.tsx +207 -0
  12. package/src/components/template.tsx +90 -0
  13. package/src/components/types.ts +35 -0
  14. package/src/components/utils.ts +138 -0
  15. package/src/html.tsx +31 -0
  16. package/src/services/auth.ts +64 -0
  17. package/src/services/distributors.ts +153 -0
  18. package/src/services/domains.ts +27 -0
  19. package/src/services/navigation.ts +169 -0
  20. package/src/services/robots.ts +64 -0
  21. package/src/services/settings.ts +52 -0
  22. package/src/services/sites.ts +196 -0
  23. package/src/services/store-with-for-loop.ts +513 -0
  24. package/src/services/store-with-promise-all.ts +515 -0
  25. package/src/services/store.ts +513 -0
  26. package/src/types/api.ts +184 -0
  27. package/src/types/global.ts +64 -0
  28. package/src/types/navigation.ts +25 -0
  29. package/src/types/pages.ts +145 -0
  30. package/src/types/sites.ts +64 -0
  31. package/src/types/templates.ts +11 -0
  32. package/src/utils/api.ts +325 -0
  33. package/src/utils/cache.ts +114 -0
  34. package/src/utils/domains.ts +32 -0
  35. package/src/utils/folders.ts +147 -0
  36. package/src/utils/instance.ts +71 -0
  37. package/src/utils/pages.ts +534 -0
  38. package/src/utils/searches.ts +103 -0
  39. package/src/utils/shared.ts +155 -0
  40. package/src/utils/sites.ts +279 -0
  41. package/.babelrc +0 -7
  42. package/LICENSE +0 -1
  43. package/gatsby-browser.js +0 -115
  44. package/gatsby-config.js +0 -38
  45. package/gatsby-node.js +0 -273
  46. package/gatsby-ssr.js +0 -43
  47. package/scripts/griddo-exporter.js +0 -133
  48. package/src/api/index.js +0 -185
  49. package/src/components/template.js +0 -261
  50. package/src/html.js +0 -30
  51. package/src/images/readme.md +0 -1
  52. package/src/scripts/build-reset.js +0 -12
  53. package/src/services/auth.js +0 -44
  54. package/src/services/distributors.js +0 -85
  55. package/src/services/domains.js +0 -16
  56. package/src/services/navigation.js +0 -104
  57. package/src/services/robots.js +0 -37
  58. package/src/services/settings.js +0 -25
  59. package/src/services/sites.js +0 -110
  60. package/src/utils/cache.js +0 -70
  61. package/src/utils/component-lib-helpers.js +0 -56
  62. package/src/utils/dataLayer.js +0 -47
  63. package/src/utils/delay.js +0 -5
  64. package/src/utils/domains.js +0 -24
  65. package/src/utils/folders.js +0 -123
  66. package/src/utils/helpers.js +0 -144
  67. package/src/utils/index.js +0 -44
  68. package/src/utils/package.js +0 -20
  69. package/src/utils/pages.js +0 -236
  70. package/src/utils/searches.js +0 -62
  71. package/src/utils/sites.js +0 -207
  72. package/static/griddo-full-logo.png +0 -0
@@ -0,0 +1,155 @@
1
+ // External libraries
2
+ import chalk from "chalk";
3
+ import dotenv from "dotenv";
4
+ import fs from "fs-extra";
5
+ import gradient from "gradient-string";
6
+ import { APIResponses } from "../types/api";
7
+ import { version } from "../../package.json";
8
+
9
+ dotenv.config();
10
+
11
+ // Envs
12
+ const GRIDDO_BUILD_LOGS =
13
+ !!process.env.GRIDDO_BUILD_LOGS &&
14
+ !!JSON.parse(process.env.GRIDDO_BUILD_LOGS);
15
+
16
+ /**
17
+ * Walk a directory and returns the file pathts.
18
+ *
19
+ * @param dir A directory path.
20
+ */
21
+ function walk(dir: string) {
22
+ const results: Array<string> = [];
23
+ const list = fs.readdirSync(dir);
24
+ list.forEach((file) => {
25
+ const newLocalFile = `${dir}/${file}`;
26
+ results.push(newLocalFile);
27
+ });
28
+
29
+ return results;
30
+ }
31
+
32
+ /**
33
+ * Custom log inside a line-box.
34
+ *
35
+ * @param str The string to be logged.
36
+ */
37
+ function logBox(str: string) {
38
+ const len = str.length;
39
+ const minWidth = str.length + 2;
40
+ const margin = " ".repeat(Math.floor((minWidth - len) / 2));
41
+ const borderTop = `╭${"─".repeat(minWidth)}╮\n`;
42
+ const borderBottom = `\n╰${"─".repeat(minWidth)}╯`;
43
+ const content = `│${margin}${str}${margin}│`;
44
+
45
+ console.log(`${borderTop}${content}${borderBottom}`);
46
+ }
47
+
48
+ /**
49
+ * Custom basic logging function controlled by a environment variable.
50
+ *
51
+ * @params str The string or strings separated by commans to be logged.
52
+ */
53
+ function logInfo(...str: Array<unknown>) {
54
+ if (GRIDDO_BUILD_LOGS) {
55
+ console.info(...str);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Custom delay using the "promise hack",
61
+ *
62
+ * @param ms Amount of miliseconds to be delayed
63
+ */
64
+ function delay(ms: number) {
65
+ return new Promise((res) => setTimeout(res, ms));
66
+ }
67
+
68
+ /**
69
+ * Return a scale size colors with a number and a measure string (KB by default).
70
+ *
71
+ * @param size The page size in KB.
72
+ * @param measure The measure string to be added in the log.
73
+ */
74
+ function logPageSize(size: number, measure = "KB") {
75
+ const sizeScale = {
76
+ low: 50,
77
+ mid: 80,
78
+ large: 130,
79
+ extraLarge: 210,
80
+ };
81
+
82
+ // Ternary pawa!
83
+ const color =
84
+ size > sizeScale.large
85
+ ? "red"
86
+ : size > sizeScale.mid
87
+ ? "magenta"
88
+ : size > sizeScale.low
89
+ ? "blue"
90
+ : "green";
91
+
92
+ return chalk[color].bold(`${size}${measure}`);
93
+ }
94
+
95
+ /**
96
+ * Converts milliseconds to seconds with a fixed number of decimals.
97
+ *
98
+ * @param ms The number in milliseconds.
99
+ * @param fixed The amount of fixed decimals.
100
+ * @returns The converted number in seconds with the fixed number of decimals.
101
+ */
102
+ export function msToSec(ms: number, decimals = 3) {
103
+ return (ms / 1000).toFixed(decimals);
104
+ }
105
+
106
+ /**
107
+ * Return a siteID from a response object if exist
108
+ * @param response A response object
109
+ */
110
+ export function getSafeSiteId(response: APIResponses) {
111
+ return "site" in response && response.site ? response?.site : undefined;
112
+ }
113
+
114
+ /**
115
+ * Print a f**king great Griddo builder logo.
116
+ */
117
+ function splash() {
118
+ const logo = `
119
+ ··
120
+ ·· ______ ______ _____ ______ ______ _____
121
+ ·· | ____ |_____/ | | \\ | \\ | |
122
+ ·· |_____| | \\_ __|__ |_____/ |_____/ |_____|
123
+ ·· ______ _ _ _____ ______ _______ ______
124
+ ·· |_____] | | | | | \\ |______ |_____/
125
+ ·· |_____] |_____| __|__ |_____ |_____/ |______ | \\_
126
+ ··
127
+ ·· ${version}
128
+ `;
129
+
130
+ console.log(gradient.cristal(logo));
131
+ }
132
+
133
+ function exporterLogo() {
134
+ const logo = `
135
+ ··
136
+ ·· /
137
+ ·· / //
138
+ ·· ______ ______ _____ ______ ______ _____ /· /
139
+ ·· | ____ |_____/ | | \\ | \\ | | / · / /
140
+ ·· |_____| | \\_ __|__ |_____/ |_____/ |_____| · · / / · /
141
+ ·· _______ _ _ _____ _____ ______ _______ _______ ______
142
+ ·· |______ \\___/ |_____] | | |_____/ | |______ |_____/
143
+ ·· |______ _/ \\_ | |_____| | \\_ | |______ | \\_
144
+ ··
145
+ ·· Griddo exporter orchestrator / / / · / /
146
+ ·· ${version} / / /· /
147
+ ·· /· /
148
+ ·· /
149
+ ··
150
+ `;
151
+
152
+ console.log(gradient.cristal(logo));
153
+ }
154
+
155
+ export { delay, exporterLogo, logBox, logInfo, logPageSize, splash, walk };
@@ -0,0 +1,279 @@
1
+ // Types
2
+ import type { BuildProcessData } from "../types/global";
3
+ import type { Site, SiteData } from "../types/sites";
4
+
5
+ // External libraries
6
+ import chalk from "chalk";
7
+ import fs from "fs-extra";
8
+ import { parse } from "js2xmlparser";
9
+ import path from "path";
10
+
11
+ // Services
12
+ import { AuthService } from "../services/auth";
13
+ import { SitesService } from "../services/sites";
14
+
15
+ // Utils
16
+ import { AllPagesResponse } from "../types/api";
17
+ import { deleteSites } from "./folders";
18
+ import { logInfo } from "./shared";
19
+
20
+ // Envs
21
+ const API_URL = process.env.API_URL;
22
+ const GRIDDO_RENDER_ALL_SITES = !!process.env.GRIDDO_RENDER_ALL_SITES;
23
+ const GRIDDO_RENDER_SITE =
24
+ process.env.GRIDDO_RENDER_SITE && parseInt(process.env.GRIDDO_RENDER_SITE);
25
+ const GRIDDO_RENDER_PAGES = (process.env.GRIDDO_RENDER_PAGES || "")
26
+ .split(",")
27
+ .map((item) => parseInt(item))
28
+ .filter(Boolean);
29
+
30
+ /**
31
+ * Check the instance sites and returns site prepared to be published and unpublished.
32
+ */
33
+ async function checkSites() {
34
+ console.log(`🔗 API URL ${chalk.underline(API_URL as string)}`);
35
+
36
+ // Login to API
37
+ await AuthService.login();
38
+
39
+ // Get all sites. An array of Site
40
+ const allSites = await SitesService.getAll();
41
+ // Filter the array of sites to get only the ones to build/render
42
+ const validSites = GRIDDO_RENDER_ALL_SITES
43
+ ? allSites.filter(
44
+ (site) => !GRIDDO_RENDER_SITE || site.id === GRIDDO_RENDER_SITE
45
+ )
46
+ : allSites.filter((site) =>
47
+ GRIDDO_RENDER_SITE
48
+ ? site.id === GRIDDO_RENDER_SITE
49
+ : !!site.shouldBeUpdated
50
+ );
51
+
52
+ // If there are valid sites...
53
+ if (validSites.length) {
54
+ const promisesOfValidSites = validSites.map(async (site) => {
55
+ const langResponse = await SitesService.getLanguages(site.id);
56
+
57
+ return (site.domains = langResponse.items
58
+ .filter((item) => {
59
+ return (
60
+ item.domain &&
61
+ (!process.env.DOMAIN ||
62
+ item.domain.slug.indexOf(process.env.DOMAIN) > 0)
63
+ );
64
+ })
65
+ .map((item) => ({ [item.id]: `${item.domain.slug}${item.path}` })));
66
+ });
67
+
68
+ await Promise.all(promisesOfValidSites);
69
+ }
70
+
71
+ // Save sites object to publish
72
+ const sitesToPublish = validSites.filter((site) =>
73
+ GRIDDO_RENDER_SITE
74
+ ? site.id === GRIDDO_RENDER_SITE
75
+ : !!site.isPublished && site.domains.length > 0
76
+ );
77
+
78
+ // Save sites object to unpublish
79
+ const sitesToUnpublish = validSites.filter(
80
+ (site) => !site.isPublished && site.shouldBeUpdated
81
+ );
82
+
83
+ return {
84
+ sitesToPublish,
85
+ sitesToUnpublish,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Unpublish an array of sites in two steps:
91
+ * - Sending the information to the API
92
+ * - Removing the files from the file system
93
+ *
94
+ * @param sites An array of sites
95
+ */
96
+ async function unpublishSites(sites: Array<Site>) {
97
+ for (const site of sites) {
98
+ const buildInfo = await SitesService.startSiteRender(site.id);
99
+ const { siteHash } = buildInfo;
100
+ const body = {
101
+ siteHash,
102
+ publishHashes: [],
103
+ unpublishHashes: [],
104
+ };
105
+
106
+ logInfo("Unpublish site starts", buildInfo);
107
+
108
+ await SitesService.endSiteRender(site.id, body);
109
+ }
110
+
111
+ await deleteSites(sites);
112
+ }
113
+
114
+ /**
115
+ * Return a single site generic data.
116
+ *
117
+ * @param siteID The site id.
118
+ * @param cached Boolean that indicates if we want to get cache version.
119
+ *
120
+ * @see SiteData
121
+ */
122
+ async function getSiteData(siteID: number, cached: boolean) {
123
+ const buildData = await SitesService.startSiteRender(siteID);
124
+ const siteInfo = await SitesService.getInfo(siteID, cached);
125
+ const siteLangs = await SitesService.getLanguages(siteID, cached);
126
+ const socials = await SitesService.getSocials(siteID, cached);
127
+ const siteLangsInfo = siteLangs.items;
128
+ 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"
131
+ // const sitePages = await SitesService.getPages(siteID, cached);
132
+ const sitePages: AllPagesResponse = [];
133
+
134
+ const { siteHash, unpublishHashes, publishIds } = buildData;
135
+ const { headers, footers } = siteInfo;
136
+ const validPagesIds = GRIDDO_RENDER_PAGES.length
137
+ ? GRIDDO_RENDER_PAGES.filter((item) => publishIds.includes(item))
138
+ : publishIds;
139
+
140
+ const siteData: SiteData = {
141
+ siteInfo,
142
+ validPagesIds,
143
+ siteHash,
144
+ unpublishHashes,
145
+ siteLangs: siteLangsInfo,
146
+ defaultLang,
147
+ headers,
148
+ footers,
149
+ socials,
150
+ sitePages,
151
+ };
152
+
153
+ return siteData;
154
+ }
155
+
156
+ /**
157
+ * Send end render signal to the API for all pages.
158
+ *
159
+ * @param buildProcessData The whole build process data.
160
+ * @param createdPages An array of pages ids.
161
+ */
162
+ async function setPagesRenderEnd(
163
+ buildProcessData: BuildProcessData,
164
+ createdPages: Array<number>
165
+ ) {
166
+ const promises = Object.keys(buildProcessData).map(async (siteID) => {
167
+ const body = buildProcessData[siteID];
168
+
169
+ logInfo(`Deploying ending call to site ${siteID}:`);
170
+
171
+ return SitesService.endSiteRender(parseInt(siteID), body);
172
+ });
173
+
174
+ await Promise.all(promises);
175
+
176
+ logInfo(`Set pages as deployed. Total ${createdPages.length}`);
177
+ }
178
+
179
+ /**
180
+ * Generate sitemaps and save them into file system.
181
+ *
182
+ * @param sites An array of sites
183
+ */
184
+ async function generateSitemaps(sites: Array<Site>) {
185
+ const promisesOfSites = sites.map(async (site) => {
186
+ const { id: siteID, languages } = site;
187
+
188
+ const promisesOfLanguages = languages.map(async (lang) => {
189
+ if (AuthService.headers) AuthService.headers["lang"] = lang.id.toString();
190
+
191
+ const response = await SitesService.getSitemap(siteID);
192
+
193
+ if (!response) return;
194
+
195
+ const {
196
+ items: sitemapPagesGroup,
197
+ url: { home },
198
+ } = response;
199
+
200
+ if (!home) return;
201
+
202
+ const langDomain = site.domains.find(
203
+ (domain) => Object.keys(domain)[0] == lang.id.toString()
204
+ );
205
+
206
+ if (!langDomain) return;
207
+
208
+ const slug = Object.values(langDomain)[0];
209
+ const sitemaps = [];
210
+ const sitemapPageGroupKeys = Object.keys(sitemapPagesGroup);
211
+
212
+ for (const templateId of sitemapPageGroupKeys) {
213
+ const sitemapPages = sitemapPagesGroup[templateId];
214
+
215
+ if (!sitemapPages.length) continue;
216
+
217
+ const siteMap = parse("urlset", {
218
+ "@": {
219
+ xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9",
220
+ "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
221
+ "xsi:schemaLocation":
222
+ "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd",
223
+ },
224
+ url: sitemapPages,
225
+ });
226
+ const sitemapName = `/sitemap-${templateId.toLowerCase()}.xml`;
227
+ const exactPath = path.resolve(
228
+ __dirname,
229
+ `../../public/${slug}${sitemapName}`
230
+ );
231
+
232
+ saveFile(exactPath, siteMap);
233
+
234
+ sitemaps.push(
235
+ `${home.endsWith("/") ? home.slice(0, -1) : home}${sitemapName}`
236
+ );
237
+ }
238
+
239
+ if (!sitemaps.length) return;
240
+
241
+ const siteMap = parse("sitemapindex", {
242
+ "@": { xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" },
243
+ sitemap: sitemaps.map((loc) => ({ loc })),
244
+ });
245
+ const exactPath = path.resolve(
246
+ __dirname,
247
+ `../../public/${slug}/sitemap.xml`
248
+ );
249
+
250
+ saveFile(exactPath, siteMap);
251
+ });
252
+
253
+ return Promise.all(promisesOfLanguages);
254
+ });
255
+
256
+ await Promise.all(promisesOfSites);
257
+ }
258
+
259
+ /**
260
+ * Saves the content to a file specified by its path. If the file exists, it will be overwritten.
261
+ *
262
+ * @param filePath The path of the file to save the content to.
263
+ * @param content The content to save to the file.
264
+ */
265
+ function saveFile(filePath: string, content: string) {
266
+ try {
267
+ fs.writeFileSync(filePath, content);
268
+ } catch (err) {
269
+ console.error(`Error saving file: ${err}`);
270
+ }
271
+ }
272
+
273
+ export {
274
+ checkSites,
275
+ unpublishSites,
276
+ setPagesRenderEnd,
277
+ getSiteData,
278
+ generateSitemaps,
279
+ };
package/.babelrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "presets": [["@babel/env", { "modules": false }], "@babel/react"],
3
- "plugins": [
4
- "babel-plugin-styled-components",
5
- "@babel/plugin-proposal-class-properties"
6
- ]
7
- }
package/LICENSE DELETED
@@ -1 +0,0 @@
1
- NO LICENSE YET
package/gatsby-browser.js DELETED
@@ -1,115 +0,0 @@
1
- /* eslint-disable node/no-extraneous-require */
2
- /* eslint-disable node/no-missing-require */
3
- const React = require('react');
4
- const { browser } = require('components');
5
- const { SessionProvider } = require('@griddo/core');
6
-
7
- exports.disableCorePrefetching = () => {
8
- if (browser.disableCorePrefetching) {
9
- browser.disableCorePrefetching();
10
- }
11
- };
12
-
13
- exports.onClientEntry = () => {
14
- if (browser.onClientEntry) {
15
- browser.onClientEntry();
16
- }
17
- };
18
-
19
- exports.onInitialClientRender = () => {
20
- if (browser.onInitialClientRender) {
21
- browser.onInitialClientRender();
22
- }
23
- };
24
-
25
- exports.onPostPrefetchPathname = props => {
26
- if (browser.onPostPrefetchPathname) {
27
- browser.onPostPrefetchPathname(props);
28
- }
29
- };
30
-
31
- exports.onPreRouteUpdate = props => {
32
- if (browser.onPreRouteUpdate) {
33
- browser.onPreRouteUpdate(props);
34
- }
35
- };
36
-
37
- exports.onPrefetchPathname = props => {
38
- if (browser.onPrefetchPathname) {
39
- browser.onPrefetchPathname(props);
40
- }
41
- };
42
-
43
- exports.onRouteUpdateDelayed = props => {
44
- if (browser.onServiceWorkerActive) {
45
- browser.onRouteUpdateDelayed(props);
46
- }
47
- };
48
-
49
- exports.onServiceWorkerActive = props => {
50
- if (browser.onServiceWorkerActive) {
51
- browser.onServiceWorkerActive(props);
52
- }
53
- };
54
-
55
- exports.onServiceWorkerInstalled = props => {
56
- if (browser.onServiceWorkerInstalled) {
57
- browser.onServiceWorkerInstalled(props);
58
- }
59
- };
60
-
61
- exports.onServiceWorkerRedundant = props => {
62
- if (browser.onServiceWorkerRedundant) {
63
- browser.onServiceWorkerRedundant(props);
64
- }
65
- };
66
-
67
- exports.onServiceWorkerUpdateFound = props => {
68
- if (browser.onServiceWorkerUpdateFound) {
69
- browser.onServiceWorkerUpdateFound(props);
70
- }
71
- };
72
-
73
- exports.onServiceWorkerUpdateReady = props => {
74
- if (browser.onServiceWorkerUpdateReady) {
75
- browser.onServiceWorkerUpdateReady(props);
76
- }
77
- };
78
-
79
- exports.registerServiceWorker = () => {
80
- if (browser.registerServiceWorker) {
81
- browser.registerServiceWorker();
82
- }
83
- };
84
-
85
- exports.replaceHydrateFunction = () => {
86
- if (browser.replaceHydrateFunction) {
87
- browser.replaceHydrateFunction();
88
- }
89
- };
90
-
91
- exports.shouldUpdateScroll = props => {
92
- if (browser.shouldUpdateScroll) {
93
- browser.shouldUpdateScroll(props);
94
- }
95
- };
96
-
97
- exports.wrapPageElement = props => {
98
- if (browser.wrapPageElement) {
99
- return browser.wrapPageElement(props);
100
- }
101
- };
102
-
103
- exports.wrapRootElement = props => {
104
- return (
105
- <SessionProvider>
106
- {browser.wrapRootElement ? browser.wrapRootElement(props) : props.element}
107
- </SessionProvider>
108
- );
109
- };
110
-
111
- exports.onRouteUpdate = props => {
112
- if (browser.onRouteUpdate) {
113
- browser.onRouteUpdate(props);
114
- }
115
- };
package/gatsby-config.js DELETED
@@ -1,38 +0,0 @@
1
- const computils = require('./src/utils/component-lib-helpers');
2
-
3
- require('dotenv').config();
4
-
5
- const assetPrefix = process.env.ASSET_PREFIX || undefined;
6
-
7
- // Gatsby configuration file from client
8
- const { plugins, ...gatsbyConfig } = require(computils.resolveComponentsPath(
9
- 'builder.config.js'
10
- ));
11
-
12
- const CONFIG = {
13
- // cliente config
14
- ...gatsbyConfig,
15
- plugins: [
16
- // client plugins
17
- ...plugins,
18
-
19
- // defaults plugins
20
- 'gatsby-plugin-provide-react',
21
- 'gatsby-plugin-react-svg',
22
- 'gatsby-plugin-react-helmet',
23
- 'gatsby-plugin-no-sourcemaps',
24
- {
25
- resolve: 'gatsby-plugin-remove-generator',
26
- options: {
27
- content: 'Griddo',
28
- },
29
- },
30
- ],
31
- };
32
-
33
- if (assetPrefix) {
34
- CONFIG.assetPrefix = assetPrefix;
35
- CONFIG.pathPrefix = null;
36
- }
37
-
38
- module.exports = CONFIG;