@griddo/cx 11.7.12-rc.4 → 11.7.12

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 (303) hide show
  1. package/README.md +226 -27
  2. package/build/adapters/gatsby/index.d.ts +4 -0
  3. package/build/adapters/gatsby/utils.d.ts +22 -0
  4. package/build/artifacts/index.d.ts +6 -0
  5. package/build/commands/end-render.d.ts +2 -0
  6. package/build/commands/move-assets.d.ts +1 -0
  7. package/build/commands/prepare-domains-render.d.ts +1 -0
  8. package/build/commands/reset-render.d.ts +2 -0
  9. package/build/commands/start-render.d.ts +2 -0
  10. package/build/commands/upload-search-content.d.ts +2 -0
  11. package/build/constants/endpoints.d.ts +19 -0
  12. package/build/constants/envs.d.ts +37 -0
  13. package/build/constants/index.d.ts +57 -0
  14. package/build/end-render.js +74 -0
  15. package/build/end-render.js.map +7 -0
  16. package/build/errors/errors-data.d.ts +22 -0
  17. package/build/errors/index.d.ts +15 -0
  18. package/build/index.d.ts +29 -0
  19. package/build/index.js +73 -0
  20. package/build/index.js.map +7 -0
  21. package/build/prepare-domains-render.js +73 -0
  22. package/build/prepare-domains-render.js.map +7 -0
  23. package/build/react/Favicon/index.d.ts +5 -0
  24. package/build/react/Favicon/utils.d.ts +9 -0
  25. package/build/react/GriddoIntegrations/index.d.ts +20 -0
  26. package/build/react/GriddoIntegrations/utils.d.ts +26 -0
  27. package/{react/index.tsx → build/react/index.d.ts} +0 -1
  28. package/build/react/index.js +3 -0
  29. package/build/registers/api.d.ts +9 -0
  30. package/build/registers/gatsby.d.ts +9 -0
  31. package/build/registers/index.d.ts +3 -0
  32. package/build/reset-render.js +74 -0
  33. package/build/reset-render.js.map +7 -0
  34. package/build/services/auth.d.ts +10 -0
  35. package/build/services/domains.d.ts +6 -0
  36. package/build/services/navigation.d.ts +50 -0
  37. package/build/services/reference-fields.d.ts +20 -0
  38. package/build/services/register.d.ts +36 -0
  39. package/build/services/robots.d.ts +19 -0
  40. package/build/services/settings.d.ts +4 -0
  41. package/build/services/sites.d.ts +29 -0
  42. package/build/services/store.d.ts +6 -0
  43. package/build/start-render.js +100 -0
  44. package/build/start-render.js.map +7 -0
  45. package/build/types/api.d.ts +142 -0
  46. package/build/types/global.d.ts +84 -0
  47. package/build/types/navigation.d.ts +28 -0
  48. package/build/types/pages.d.ts +144 -0
  49. package/build/types/sites.d.ts +57 -0
  50. package/build/types/templates.d.ts +8 -0
  51. package/build/upload-search-content.js +74 -0
  52. package/build/upload-search-content.js.map +7 -0
  53. package/build/utils/alerts.d.ts +3 -0
  54. package/build/utils/api.d.ts +23 -0
  55. package/build/utils/cache.d.ts +35 -0
  56. package/build/utils/core-utils.d.ts +107 -0
  57. package/build/utils/create-build-data.d.ts +8 -0
  58. package/build/utils/domains.d.ts +13 -0
  59. package/build/utils/folders.d.ts +53 -0
  60. package/build/utils/health-checks.d.ts +7 -0
  61. package/build/utils/images.d.ts +16 -0
  62. package/build/utils/instance.d.ts +21 -0
  63. package/build/utils/loggin.d.ts +51 -0
  64. package/build/utils/pages.d.ts +34 -0
  65. package/build/utils/render.d.ts +13 -0
  66. package/build/utils/searches.d.ts +15 -0
  67. package/build/utils/sites.d.ts +31 -0
  68. package/build/utils/store.d.ts +81 -0
  69. package/cx.config.d.ts +5 -0
  70. package/cx.config.js +36 -0
  71. package/exporter/adapters/gatsby/index.ts +153 -73
  72. package/exporter/adapters/gatsby/utils.ts +161 -0
  73. package/exporter/artifacts/README.md +34 -0
  74. package/exporter/artifacts/index.ts +33 -0
  75. package/exporter/build.sh +38 -4
  76. package/exporter/commands/end-render.ts +70 -72
  77. package/exporter/commands/move-assets.ts +11 -0
  78. package/exporter/commands/prepare-domains-render.ts +31 -143
  79. package/exporter/commands/reset-render.ts +3 -10
  80. package/exporter/commands/start-render.ts +45 -22
  81. package/exporter/commands/upload-search-content.ts +21 -194
  82. package/exporter/constants/endpoints.ts +1 -2
  83. package/exporter/constants/envs.ts +55 -57
  84. package/exporter/constants/index.ts +129 -0
  85. package/exporter/{constants/errors.ts → errors/errors-data.ts} +14 -24
  86. package/exporter/{utils/errors.ts → errors/index.ts} +9 -10
  87. package/exporter/index.ts +82 -0
  88. package/{react → exporter/react}/Favicon/index.tsx +7 -1
  89. package/{react → exporter/react}/GriddoIntegrations/index.tsx +22 -16
  90. package/{react → exporter/react}/GriddoIntegrations/utils.ts +9 -21
  91. package/exporter/react/index.tsx +11 -0
  92. package/exporter/registers/api.ts +14 -0
  93. package/exporter/registers/gatsby.ts +14 -0
  94. package/exporter/registers/index.ts +4 -0
  95. package/exporter/services/auth.ts +6 -7
  96. package/exporter/services/domains.ts +16 -0
  97. package/exporter/services/navigation.ts +10 -4
  98. package/exporter/services/reference-fields.ts +24 -9
  99. package/exporter/services/register.ts +113 -0
  100. package/exporter/services/robots.ts +16 -9
  101. package/exporter/services/settings.ts +17 -0
  102. package/exporter/services/sites.ts +24 -36
  103. package/exporter/services/store.ts +96 -107
  104. package/exporter/types/api.ts +28 -27
  105. package/exporter/types/global.ts +11 -8
  106. package/exporter/types/navigation.ts +1 -1
  107. package/exporter/types/pages.ts +3 -2
  108. package/exporter/types/sites.ts +2 -1
  109. package/exporter/utils/alerts.ts +29 -0
  110. package/exporter/utils/api.ts +75 -55
  111. package/exporter/utils/cache.ts +62 -37
  112. package/exporter/utils/core-utils.ts +272 -133
  113. package/exporter/utils/create-build-data.ts +17 -0
  114. package/exporter/utils/domains.ts +7 -10
  115. package/exporter/utils/folders.ts +98 -163
  116. package/exporter/utils/health-checks.ts +64 -0
  117. package/exporter/utils/images.ts +6 -1
  118. package/exporter/utils/instance.ts +13 -9
  119. package/exporter/utils/loggin.ts +91 -44
  120. package/exporter/utils/pages.ts +88 -23
  121. package/exporter/utils/render.ts +48 -180
  122. package/exporter/utils/searches.ts +156 -0
  123. package/exporter/utils/sites.ts +197 -19
  124. package/exporter/utils/store.ts +180 -87
  125. package/gatsby-browser.tsx +58 -41
  126. package/gatsby-config.ts +17 -10
  127. package/gatsby-node.ts +78 -17
  128. package/gatsby-ssr.tsx +1 -2
  129. package/package.json +86 -36
  130. package/src/README.md +7 -0
  131. package/src/components/Head.tsx +46 -13
  132. package/src/components/template.tsx +30 -8
  133. package/src/gatsby-node-utils.ts +2 -73
  134. package/src/html.tsx +11 -2
  135. package/src/types.ts +5 -5
  136. package/start-render.js +7 -0
  137. package/tsconfig.json +3 -5
  138. package/build/adapters/gatsby/actions/clean.js +0 -10
  139. package/build/adapters/gatsby/actions/clean.js.map +0 -1
  140. package/build/adapters/gatsby/actions/close.js +0 -12
  141. package/build/adapters/gatsby/actions/close.js.map +0 -1
  142. package/build/adapters/gatsby/actions/data.js +0 -18
  143. package/build/adapters/gatsby/actions/data.js.map +0 -1
  144. package/build/adapters/gatsby/actions/healthCheck.js +0 -10
  145. package/build/adapters/gatsby/actions/healthCheck.js.map +0 -1
  146. package/build/adapters/gatsby/actions/init.js +0 -22
  147. package/build/adapters/gatsby/actions/init.js.map +0 -1
  148. package/build/adapters/gatsby/actions/logs.js +0 -12
  149. package/build/adapters/gatsby/actions/logs.js.map +0 -1
  150. package/build/adapters/gatsby/actions/meta.js +0 -13
  151. package/build/adapters/gatsby/actions/meta.js.map +0 -1
  152. package/build/adapters/gatsby/actions/prepare.js +0 -9
  153. package/build/adapters/gatsby/actions/prepare.js.map +0 -1
  154. package/build/adapters/gatsby/actions/relocation.js +0 -15
  155. package/build/adapters/gatsby/actions/relocation.js.map +0 -1
  156. package/build/adapters/gatsby/actions/restore.js +0 -26
  157. package/build/adapters/gatsby/actions/restore.js.map +0 -1
  158. package/build/adapters/gatsby/actions/ssg.js +0 -9
  159. package/build/adapters/gatsby/actions/ssg.js.map +0 -1
  160. package/build/adapters/gatsby/actions/sync.js +0 -51
  161. package/build/adapters/gatsby/actions/sync.js.map +0 -1
  162. package/build/adapters/gatsby/index.js +0 -78
  163. package/build/adapters/gatsby/index.js.map +0 -1
  164. package/build/adapters/gatsby/shared/artifacts.js +0 -20
  165. package/build/adapters/gatsby/shared/artifacts.js.map +0 -1
  166. package/build/adapters/gatsby/shared/context.js +0 -31
  167. package/build/adapters/gatsby/shared/context.js.map +0 -1
  168. package/build/adapters/gatsby/shared/diff-assets.js +0 -101
  169. package/build/adapters/gatsby/shared/diff-assets.js.map +0 -1
  170. package/build/adapters/gatsby/shared/extract-assets.js +0 -58
  171. package/build/adapters/gatsby/shared/extract-assets.js.map +0 -1
  172. package/build/adapters/gatsby/shared/gatsby-build.js +0 -55
  173. package/build/adapters/gatsby/shared/gatsby-build.js.map +0 -1
  174. package/build/adapters/gatsby/shared/sync-render.js +0 -210
  175. package/build/adapters/gatsby/shared/sync-render.js.map +0 -1
  176. package/build/adapters/gatsby/shared/types.js +0 -3
  177. package/build/adapters/gatsby/shared/types.js.map +0 -1
  178. package/build/commands/end-render.js +0 -87
  179. package/build/commands/end-render.js.map +0 -1
  180. package/build/commands/prepare-assets-directory.js +0 -30
  181. package/build/commands/prepare-assets-directory.js.map +0 -1
  182. package/build/commands/prepare-domains-render.js +0 -133
  183. package/build/commands/prepare-domains-render.js.map +0 -1
  184. package/build/commands/reset-render.js +0 -21
  185. package/build/commands/reset-render.js.map +0 -1
  186. package/build/commands/start-render.js +0 -44
  187. package/build/commands/start-render.js.map +0 -1
  188. package/build/commands/upload-search-content.js +0 -180
  189. package/build/commands/upload-search-content.js.map +0 -1
  190. package/build/constants/endpoints.js +0 -43
  191. package/build/constants/endpoints.js.map +0 -1
  192. package/build/constants/envs.js +0 -68
  193. package/build/constants/envs.js.map +0 -1
  194. package/build/constants/errors.js +0 -81
  195. package/build/constants/errors.js.map +0 -1
  196. package/build/services/auth.js +0 -40
  197. package/build/services/auth.js.map +0 -1
  198. package/build/services/db-class.js +0 -49
  199. package/build/services/db-class.js.map +0 -1
  200. package/build/services/db.js +0 -34
  201. package/build/services/db.js.map +0 -1
  202. package/build/services/navigation.js +0 -96
  203. package/build/services/navigation.js.map +0 -1
  204. package/build/services/reference-fields.js +0 -131
  205. package/build/services/reference-fields.js.map +0 -1
  206. package/build/services/robots.js +0 -60
  207. package/build/services/robots.js.map +0 -1
  208. package/build/services/sites.js +0 -110
  209. package/build/services/sites.js.map +0 -1
  210. package/build/services/store.js +0 -257
  211. package/build/services/store.js.map +0 -1
  212. package/build/types/api.js +0 -3
  213. package/build/types/api.js.map +0 -1
  214. package/build/types/global.js +0 -3
  215. package/build/types/global.js.map +0 -1
  216. package/build/types/navigation.js +0 -3
  217. package/build/types/navigation.js.map +0 -1
  218. package/build/types/pages.js +0 -3
  219. package/build/types/pages.js.map +0 -1
  220. package/build/types/render.js +0 -10
  221. package/build/types/render.js.map +0 -1
  222. package/build/types/sites.js +0 -3
  223. package/build/types/sites.js.map +0 -1
  224. package/build/types/templates.js +0 -3
  225. package/build/types/templates.js.map +0 -1
  226. package/build/utils/api.js +0 -165
  227. package/build/utils/api.js.map +0 -1
  228. package/build/utils/artifacts.js +0 -38
  229. package/build/utils/artifacts.js.map +0 -1
  230. package/build/utils/brush.js +0 -30
  231. package/build/utils/brush.js.map +0 -1
  232. package/build/utils/cache.js +0 -106
  233. package/build/utils/cache.js.map +0 -1
  234. package/build/utils/check-environment-health.js +0 -73
  235. package/build/utils/check-environment-health.js.map +0 -1
  236. package/build/utils/core-utils.js +0 -270
  237. package/build/utils/core-utils.js.map +0 -1
  238. package/build/utils/domains.js +0 -37
  239. package/build/utils/domains.js.map +0 -1
  240. package/build/utils/errors.js +0 -30
  241. package/build/utils/errors.js.map +0 -1
  242. package/build/utils/folders.js +0 -341
  243. package/build/utils/folders.js.map +0 -1
  244. package/build/utils/images.js +0 -45
  245. package/build/utils/images.js.map +0 -1
  246. package/build/utils/instance.js +0 -66
  247. package/build/utils/instance.js.map +0 -1
  248. package/build/utils/loggin.js +0 -119
  249. package/build/utils/loggin.js.map +0 -1
  250. package/build/utils/npm-deps/find-up-simple.js +0 -75
  251. package/build/utils/npm-deps/find-up-simple.js.map +0 -1
  252. package/build/utils/npm-deps/pkg-dir.js +0 -20
  253. package/build/utils/npm-deps/pkg-dir.js.map +0 -1
  254. package/build/utils/npm-deps/xml-parser.js +0 -49
  255. package/build/utils/npm-deps/xml-parser.js.map +0 -1
  256. package/build/utils/pages.js +0 -359
  257. package/build/utils/pages.js.map +0 -1
  258. package/build/utils/render.js +0 -168
  259. package/build/utils/render.js.map +0 -1
  260. package/build/utils/sitemaps.js +0 -110
  261. package/build/utils/sitemaps.js.map +0 -1
  262. package/build/utils/sites.js +0 -105
  263. package/build/utils/sites.js.map +0 -1
  264. package/build/utils/store.js +0 -193
  265. package/build/utils/store.js.map +0 -1
  266. package/cli.mjs +0 -136
  267. package/exporter/adapters/gatsby/actions/clean.ts +0 -14
  268. package/exporter/adapters/gatsby/actions/close.ts +0 -17
  269. package/exporter/adapters/gatsby/actions/data.ts +0 -25
  270. package/exporter/adapters/gatsby/actions/healthCheck.ts +0 -10
  271. package/exporter/adapters/gatsby/actions/init.ts +0 -26
  272. package/exporter/adapters/gatsby/actions/logs.ts +0 -13
  273. package/exporter/adapters/gatsby/actions/meta.ts +0 -16
  274. package/exporter/adapters/gatsby/actions/prepare.ts +0 -9
  275. package/exporter/adapters/gatsby/actions/relocation.ts +0 -15
  276. package/exporter/adapters/gatsby/actions/restore.ts +0 -36
  277. package/exporter/adapters/gatsby/actions/ssg.ts +0 -12
  278. package/exporter/adapters/gatsby/actions/sync.ts +0 -71
  279. package/exporter/adapters/gatsby/shared/artifacts.ts +0 -16
  280. package/exporter/adapters/gatsby/shared/context.ts +0 -50
  281. package/exporter/adapters/gatsby/shared/diff-assets.ts +0 -113
  282. package/exporter/adapters/gatsby/shared/extract-assets.ts +0 -61
  283. package/exporter/adapters/gatsby/shared/gatsby-build.ts +0 -58
  284. package/exporter/adapters/gatsby/shared/sync-render.ts +0 -276
  285. package/exporter/adapters/gatsby/shared/types.ts +0 -35
  286. package/exporter/build-esbuild.noop +0 -42
  287. package/exporter/commands/prepare-assets-directory.ts +0 -30
  288. package/exporter/services/db-class.ts +0 -54
  289. package/exporter/services/db.ts +0 -32
  290. package/exporter/types/render.ts +0 -59
  291. package/exporter/utils/artifacts.ts +0 -38
  292. package/exporter/utils/brush.ts +0 -34
  293. package/exporter/utils/check-environment-health.ts +0 -84
  294. package/exporter/utils/npm-deps/find-up-simple.ts +0 -100
  295. package/exporter/utils/npm-deps/pkg-dir.ts +0 -17
  296. package/exporter/utils/npm-deps/xml-parser.ts +0 -57
  297. package/exporter/utils/sitemaps.ts +0 -129
  298. package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
  299. package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
  300. package/react/DynamicScript/index.tsx +0 -33
  301. package/tsconfig.commands.json +0 -36
  302. package/tsconfig.exporter.json +0 -19
  303. /package/{react → exporter/react}/Favicon/utils.ts +0 -0
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { CheckHealthError } from "../constants/errors";
4
- import { isTruthy } from "./core-utils";
5
- import { throwError } from "./errors";
6
- import { infoLog } from "./loggin";
7
-
8
- const GRIDDO_ENVS_VARS: ReadonlyArray<string> = [];
9
- const GRIDDO_SKIP_BUILD_CHECKS = isTruthy(process.env.GRIDDO_SKIP_BUILD_CHECKS);
10
-
11
- /**
12
- * Check if a list of environments variables exist with any value.
13
- *
14
- * @todo Also check the value.
15
- * @param envs An array of environments variables
16
- * @returns exists with (1) if there are missing envs vars
17
- */
18
- function checkEnvsVars(envs: ReadonlyArray<string>) {
19
- const missingEnvs = envs.filter((envName) => {
20
- return !process.env[envName];
21
- });
22
-
23
- if (missingEnvs.length) {
24
- const missingEnvsMsg = missingEnvs.join("\n");
25
- console.error(`Env check failed. These envs vars are missing: \n\n${missingEnvsMsg}`);
26
-
27
- return false;
28
- }
29
-
30
- return true;
31
- }
32
-
33
- function checkEnvsVarsAndValues(envs: Array<Record<string, string>>): boolean {
34
- for (const env of envs) {
35
- const [key, expected] = Object.entries(env)[0];
36
- const actual = process.env[key];
37
-
38
- if (actual !== expected) {
39
- return false;
40
- }
41
- }
42
- return true;
43
- }
44
-
45
- /**
46
- * Check if the environment is secure to launch a render.
47
- * If something fails then log an error message and exit from the process.
48
- * Otherwise just return true.
49
- */
50
- export function checkEnvironmentHealth() {
51
- // Bypass the check using this env var, handy for local renders.
52
- if (GRIDDO_SKIP_BUILD_CHECKS) {
53
- infoLog("Build health check skipped");
54
-
55
- return true;
56
- }
57
-
58
- // Checklist
59
- // check if it's setted
60
- const areRequiredEnvsSet = checkEnvsVars(GRIDDO_ENVS_VARS);
61
- // check if it's setted and the value
62
- const areEnvsMatchingExpected = checkEnvsVarsAndValues([
63
- {
64
- GRIDDO_RENDER_BY_DOMAINS: "true",
65
- },
66
- ]);
67
-
68
- // Render is safe if...
69
- const isSafeToRender = areRequiredEnvsSet && areEnvsMatchingExpected;
70
-
71
- // The environment is suitable for a build-render
72
- if (isSafeToRender) {
73
- console.info("\nBuild health check passed\n");
74
-
75
- return true;
76
- }
77
-
78
- // Error
79
- console.log("Activate this environment vars");
80
- console.log(`
81
- GRIDDO_RENDER_BY_DOMAINS: "true"
82
- `);
83
- throwError(CheckHealthError);
84
- }
@@ -1,100 +0,0 @@
1
- import fs from "node:fs";
2
- import fsPromises from "node:fs/promises";
3
- import path from "node:path";
4
- import process from "node:process";
5
- import { fileURLToPath } from "node:url";
6
-
7
- /**
8
- * Opciones para controlar el comportamiento de la búsqueda.
9
- */
10
- export type Options = {
11
- /**
12
- El directorio desde donde empezar a buscar.
13
- @default process.cwd()
14
- */
15
- readonly cwd?: URL | string;
16
-
17
- /**
18
- El tipo de ruta a buscar.
19
- @default 'file'
20
- */
21
- readonly type?: "file" | "directory";
22
-
23
- /**
24
- Un directorio en el que la búsqueda se detiene si no se encuentran coincidencias.
25
- @default El directorio raíz del sistema
26
- */
27
- readonly stopAt?: URL | string;
28
- };
29
-
30
- // Función auxiliar para convertir una URL en una ruta de archivo de tipo string.
31
- const toPath = (urlOrPath: URL | string | undefined): string | undefined =>
32
- urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
33
-
34
- /**
35
- * Encuentra un archivo o directorio de forma asíncrona subiendo por los directorios padre.
36
- * @param name - El nombre del archivo o directorio a buscar.
37
- * @param options - Opciones de búsqueda.
38
- * @returns La ruta encontrada o `undefined` si no se pudo encontrar.
39
- */
40
- export async function findUp(name: string, options: Options = {}): Promise<string | undefined> {
41
- const { cwd = process.cwd(), type = "file", stopAt: stopAtOption } = options;
42
-
43
- let directory = path.resolve(toPath(cwd) ?? "");
44
- const { root } = path.parse(directory);
45
- const stopAt = stopAtOption ? path.resolve(directory, toPath(stopAtOption)!) : root;
46
- const isAbsoluteName = path.isAbsolute(name);
47
-
48
- while (true) {
49
- const filePath = isAbsoluteName ? name : path.join(directory, name);
50
- try {
51
- // eslint-disable-next-line no-await-in-loop
52
- const stats = await fsPromises.stat(filePath);
53
- if ((type === "file" && stats.isFile()) || (type === "directory" && stats.isDirectory())) {
54
- return filePath;
55
- }
56
- } catch {
57
- // Ignora errores (ej. el archivo no existe) y continúa la búsqueda.
58
- }
59
-
60
- if (directory === stopAt || directory === root) {
61
- break;
62
- }
63
-
64
- directory = path.dirname(directory);
65
- }
66
- }
67
-
68
- /**
69
- * Encuentra un archivo o directorio de forma síncrona subiendo por los directorios padre.
70
- * @param name - El nombre del archivo o directorio a buscar.
71
- * @param options - Opciones de búsqueda.
72
- * @returns La ruta encontrada o `undefined` si no se pudo encontrar.
73
- */
74
- export function findUpSync(name: string, options: Options = {}): string | undefined {
75
- const { cwd = process.cwd(), type = "file", stopAt: stopAtOption } = options;
76
-
77
- let directory = path.resolve(toPath(cwd) ?? "");
78
- const { root } = path.parse(directory);
79
- const stopAt = stopAtOption ? path.resolve(directory, toPath(stopAtOption)!) : root;
80
- const isAbsoluteName = path.isAbsolute(name);
81
-
82
- while (true) {
83
- const filePath = isAbsoluteName ? name : path.join(directory, name);
84
- try {
85
- const stats = fs.statSync(filePath, { throwIfNoEntry: false });
86
- if ((type === "file" && stats?.isFile()) || (type === "directory" && stats?.isDirectory())) {
87
- return filePath;
88
- }
89
- } catch {
90
- // En teoría, statSync con `throwIfNoEntry: false` no debería lanzar un error,
91
- // pero se mantiene por seguridad.
92
- }
93
-
94
- if (directory === stopAt || directory === root) {
95
- break;
96
- }
97
-
98
- directory = path.dirname(directory);
99
- }
100
- }
@@ -1,17 +0,0 @@
1
- import path from "node:path";
2
-
3
- import { findUp, findUpSync } from "./find-up-simple";
4
-
5
- async function pkgDir(options?: { readonly cwd?: string }) {
6
- const { cwd } = options || {};
7
- const filePath = await findUp("package.json", { cwd });
8
- return filePath && path.dirname(filePath);
9
- }
10
-
11
- function pkgDirSync(options?: { readonly cwd?: string }) {
12
- const { cwd } = options || {};
13
- const filePath = findUpSync("package.json", { cwd });
14
- return filePath && path.dirname(filePath);
15
- }
16
-
17
- export { pkgDir, pkgDirSync };
@@ -1,57 +0,0 @@
1
- import type { SitemapItem } from "../../types/api";
2
-
3
- function escapeXml(unsafe: string) {
4
- return unsafe.replace(/[<>&'"”]/g, (c) => {
5
- switch (c) {
6
- case "<":
7
- return "&lt;";
8
- case ">":
9
- return "&gt;";
10
- case "&":
11
- return "&amp;";
12
- case "'":
13
- return "&apos;";
14
- case '"':
15
- return "&quot;";
16
- case "”":
17
- return "&quot;";
18
- default:
19
- return c;
20
- }
21
- });
22
- }
23
-
24
- function generateUrlsetXml(pages: Array<SitemapItem>) {
25
- const urls = pages
26
- .map(
27
- (page) =>
28
- ` <url>
29
- <loc>${escapeXml(page.loc)}</loc>
30
- <lastmod>${page.lastmod}</lastmod>
31
- <priority>${page.priority}</priority>
32
- </url>`,
33
- )
34
- .join("\n");
35
-
36
- return `<?xml version="1.0" encoding="UTF-8"?>
37
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
38
- ${urls}
39
- </urlset>`;
40
- }
41
-
42
- function generateSitemapIndexXml(sitemaps: Array<string>) {
43
- const sitemapEntries = sitemaps
44
- .map(
45
- (loc) => ` <sitemap>
46
- <loc>${escapeXml(loc)}</loc>
47
- </sitemap>`,
48
- )
49
- .join("\n");
50
-
51
- return `<?xml version="1.0" encoding="UTF-8"?>
52
- <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
53
- ${sitemapEntries}
54
- </sitemapindex>`;
55
- }
56
-
57
- export { generateSitemapIndexXml, generateUrlsetXml };
@@ -1,129 +0,0 @@
1
- import fsp from "node:fs/promises";
2
- import path from "node:path";
3
-
4
- import { AuthService } from "../services/auth";
5
- import { getSitemap } from "../services/sites";
6
- import { pathExists } from "./folders";
7
- import { verboseLog } from "./loggin";
8
- import { generateSitemapIndexXml, generateUrlsetXml } from "./npm-deps/xml-parser";
9
- import { getRenderPathsFromDB } from "./render";
10
- import { getBuildMetadata } from "./store";
11
-
12
- /**
13
- * Generate sitemaps and save them into file system.
14
- */
15
- async function generateSitemaps(domain: string) {
16
- const { __root } = await getRenderPathsFromDB();
17
- const { sitesToPublish } = await getBuildMetadata(domain);
18
- const distDir = path.join(__root, "dist");
19
- const templateSitemapPrefix = "sitemap-";
20
-
21
- const isGriddoSitemapFile = (file: string) =>
22
- file === "sitemap.xml" || (file.startsWith(templateSitemapPrefix) && file.endsWith(".xml"));
23
-
24
- for (const site of sitesToPublish) {
25
- const { id, languages } = site;
26
-
27
- for (const lang of languages) {
28
- // Local copy of headers to avoid mutating the shared object
29
- const localHeaders: Record<string, string> = AuthService.headers
30
- ? { ...AuthService.headers }
31
- : {};
32
- localHeaders.lang = lang.id.toString();
33
-
34
- const response = await getSitemap({ siteId: id, headers: localHeaders });
35
-
36
- if (!response) {
37
- continue;
38
- }
39
-
40
- const { items: sitemapPagesGroup, url } = response;
41
- const { home, domain } = url;
42
-
43
- if (!home) {
44
- continue;
45
- }
46
-
47
- const domainLanguage = site.domains.find(
48
- (domain) => Object.keys(domain)[0] === lang.id.toString(),
49
- );
50
-
51
- if (!domainLanguage) {
52
- continue;
53
- }
54
-
55
- const slug = Object.values(domainLanguage)[0];
56
- const sitemaps: Array<string> = [];
57
- const sitemapPageGroupKeys = Object.keys(sitemapPagesGroup);
58
- const sitemapBasePath = path.join(distDir, slug.replace(domain, ""));
59
-
60
- /** delete every griddo sitemap file before create the new ones */
61
- if (await pathExists(sitemapBasePath)) {
62
- try {
63
- const files = await fsp.readdir(sitemapBasePath);
64
- for (const file of files) {
65
- if (isGriddoSitemapFile(file)) {
66
- const filePath = path.join(sitemapBasePath, file);
67
- try {
68
- await fsp.rm(filePath);
69
- } catch (err) {
70
- console.error(`Error deleting file ${filePath}:`, err);
71
- }
72
- }
73
- }
74
- } catch (err) {
75
- console.error(`Error reading ${sitemapBasePath}:`, err);
76
- }
77
- }
78
-
79
- for (const templateId of sitemapPageGroupKeys) {
80
- const sitemapPages = sitemapPagesGroup[templateId];
81
-
82
- if (!sitemapPages.length) {
83
- continue;
84
- }
85
-
86
- const siteMap = generateUrlsetXml(sitemapPages);
87
-
88
- const sitemapName = `/${templateSitemapPrefix}${templateId.toLowerCase()}.xml`;
89
- const exactPath = path.join(sitemapBasePath, sitemapName);
90
-
91
- await saveFile(exactPath, siteMap);
92
-
93
- sitemaps.push(`${home.endsWith("/") ? home.slice(0, -1) : home}${sitemapName}`);
94
- }
95
-
96
- if (!sitemaps.length) {
97
- continue;
98
- }
99
-
100
- const siteMap = generateSitemapIndexXml(sitemaps);
101
-
102
- const exactPath = path.join(sitemapBasePath, "sitemap.xml");
103
-
104
- await saveFile(exactPath, siteMap);
105
- verboseLog(`sitemap generated in ${exactPath}`);
106
- }
107
- }
108
- }
109
-
110
- /**
111
- * Saves the content to a file specified by its path. If the file exists, it will be overwritten.
112
- *
113
- * @param filePath The path of the file to save the content to.
114
- * @param content The content to save to the file.
115
- */
116
- async function saveFile(filePath: string, content: string) {
117
- try {
118
- const pathName = path.dirname(filePath);
119
- if (!(await pathExists(pathName))) {
120
- await fsp.mkdir(pathName, { recursive: true });
121
- }
122
- await fsp.writeFile(filePath, content);
123
- } catch (error) {
124
- console.log(error);
125
- throw new Error(`Error saving a file`);
126
- }
127
- }
128
-
129
- export { generateSitemaps };
@@ -1,55 +0,0 @@
1
- exports.onCreateWebpackConfig = (
2
- { stage, actions, getConfig, rules },
3
- { rule: ruleProps = {} },
4
- ) => {
5
- const { include, exclude, options, ...otherProps } = ruleProps;
6
-
7
- if (["develop", "develop-html", "build-html", "build-javascript"].includes(stage)) {
8
- // Add the react-svg-loader rule
9
- actions.setWebpackConfig({
10
- module: {
11
- rules: [
12
- {
13
- test: /\.svg$/,
14
- include,
15
- exclude,
16
- ...otherProps,
17
- use: [
18
- {
19
- loader: "@svgr/webpack",
20
- options,
21
- },
22
- ],
23
- },
24
- ],
25
- },
26
- });
27
- const cfg = getConfig();
28
- const imgsRule = rules.images();
29
-
30
- const newUrlLoaderRule =
31
- include || exclude
32
- ? {
33
- ...imgsRule,
34
- include: exclude,
35
- exclude: include,
36
- }
37
- : {
38
- ...imgsRule,
39
- test: new RegExp(imgsRule.test.toString().replace("svg|", "").slice(1, -1)),
40
- };
41
-
42
- cfg.module.rules = [
43
- // Remove the base url-loader images rule entirely
44
- ...cfg.module.rules.filter((rule) => {
45
- if (rule.test) {
46
- return rule.test.toString() !== imgsRule.test.toString();
47
- }
48
- return true;
49
- }),
50
- // Put it back without SVG loading
51
- newUrlLoaderRule,
52
- ];
53
- actions.replaceWebpackConfig(cfg);
54
- }
55
- };
@@ -1,8 +0,0 @@
1
- {
2
- "name": "gatsby-plugin-svgr-loader",
3
- "version": "0.1.0",
4
- "main": "gatsby-node.js",
5
- "dependencies": {
6
- "@svgr/webpack": "^4.3.2"
7
- }
8
- }
@@ -1,33 +0,0 @@
1
- import { useEffect } from "react";
2
-
3
- const DynamicScript = (props: { scriptContent: string }) => {
4
- const { scriptContent } = props;
5
-
6
- useEffect(() => {
7
- if (!scriptContent) {
8
- return;
9
- }
10
-
11
- const scriptText = scriptContent.replace(/<script>|<\/script>/g, "");
12
- if (!scriptText.trim()) {
13
- return;
14
- }
15
-
16
- const script = document.createElement("script");
17
- script.innerHTML = scriptText;
18
- script.async = true;
19
-
20
- document.body.appendChild(script);
21
-
22
- return () => {
23
- // Hacemos un chequeo por si el script ya fue removido por otro proceso.
24
- if (document.body.contains(script)) {
25
- document.body.removeChild(script);
26
- }
27
- };
28
- }, [scriptContent]);
29
-
30
- return null;
31
- };
32
-
33
- export { DynamicScript };
@@ -1,36 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Opciones del Proyecto */
4
- "target": "es2022", // Genera JavaScript compatible con versiones modernas de Node.js
5
- "module": "commonjs", // El formato de módulo que usará Node.js para ejecutar los scripts
6
- "outDir": "./build", // Directorio de salida para los archivos .js compilados
7
- "rootDir": "./exporter", // Directorio raíz de los fuentes, para mantener la estructura en 'outDir'
8
-
9
- /* Módulos */
10
- "moduleResolution": "node", // Cómo se resuelven los módulos (estándar para Node)
11
- "esModuleInterop": true, // Permite una mejor interoperabilidad entre CommonJS y ES Modules
12
-
13
- // AÑADIDO: Permitir la importación de archivos .json como módulos.
14
- // Esto soluciona el error con `import ... from "../../package.json"`.
15
- "resolveJsonModule": true,
16
-
17
- /* Opciones de Emisión */
18
- "sourceMap": true, // Genera sourcemaps para facilitar el debugging
19
-
20
- /* Chequeo de Tipos Estricto */
21
- "strict": true, // Habilita todas las opciones de chequeo de tipos estrictas
22
- "skipLibCheck": true, // Evita el chequeo de tipos en los archivos de declaración (.d.ts) de las dependencias
23
-
24
- /* Opciones Adicionales */
25
- "forceConsistentCasingInFileNames": true, // Asegura que las mayúsculas y minúsculas en los nombres de archivo sean consistentes
26
- "types": ["node"]
27
- },
28
- "include": [
29
- "exporter/**/*.ts", // Incluye todos los archivos .ts dentro de la carpeta exporter
30
- "exporter/**/*.tsx"
31
- ],
32
- "exclude": [
33
- "node_modules", // Excluye las dependencias
34
- "**/*.test.ts" // Excluye los archivos de test
35
- ]
36
- }
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2022",
4
- "lib": ["dom", "esnext"],
5
- "jsx": "react-jsx",
6
- "module": "esnext",
7
- "moduleResolution": "node",
8
- "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "strict": true,
11
- "skipLibCheck": true,
12
- "resolveJsonModule": true,
13
- "outDir": "./build",
14
- "sourceMap": true,
15
- "inlineSourceMap": false,
16
- "types": ["node"]
17
- },
18
- "include": ["./exporter/**/*.ts", "./exporter/**/*.tsx", "global.d.ts"]
19
- }
File without changes