@griddo/cx 11.7.6-rc.1 → 11.7.6

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 (300) hide show
  1. package/README.md +228 -25
  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/move-assets.d.ts +1 -0
  6. package/build/commands/prepare-domains-render.d.ts +1 -0
  7. package/build/{exporter/constants → constants}/envs.d.ts +7 -1
  8. package/build/constants/index.d.ts +57 -0
  9. package/build/end-render.js +74 -0
  10. package/build/end-render.js.map +7 -0
  11. package/build/{exporter/constants/errors.d.ts → errors/errors-data.d.ts} +3 -5
  12. package/build/{exporter/utils/errors.d.ts → errors/index.d.ts} +3 -3
  13. package/build/index.d.ts +29 -0
  14. package/build/index.js +73 -0
  15. package/build/index.js.map +7 -0
  16. package/build/prepare-domains-render.js +73 -0
  17. package/build/prepare-domains-render.js.map +7 -0
  18. package/build/react/Favicon/index.d.ts +5 -0
  19. package/build/react/Favicon/utils.d.ts +9 -0
  20. package/build/react/GriddoIntegrations/index.d.ts +20 -0
  21. package/build/react/GriddoIntegrations/utils.d.ts +26 -0
  22. package/{react/index.tsx → build/react/index.d.ts} +0 -1
  23. package/build/react/index.js +3 -0
  24. package/build/registers/api.d.ts +9 -0
  25. package/build/registers/gatsby.d.ts +9 -0
  26. package/build/registers/index.d.ts +3 -0
  27. package/build/reset-render.js +74 -0
  28. package/build/reset-render.js.map +7 -0
  29. package/build/{exporter/services → services}/auth.d.ts +1 -1
  30. package/build/services/domains.d.ts +6 -0
  31. package/build/services/register.d.ts +36 -0
  32. package/build/{exporter/services → services}/robots.d.ts +6 -0
  33. package/build/services/settings.d.ts +4 -0
  34. package/build/{exporter/services → services}/sites.d.ts +2 -5
  35. package/build/services/store.d.ts +6 -0
  36. package/build/start-render.js +100 -0
  37. package/build/start-render.js.map +7 -0
  38. package/build/{exporter/types → types}/api.d.ts +4 -3
  39. package/build/{exporter/types → types}/global.d.ts +6 -6
  40. package/build/{exporter/types → types}/navigation.d.ts +1 -1
  41. package/build/{exporter/types → types}/sites.d.ts +2 -1
  42. package/build/upload-search-content.js +74 -0
  43. package/build/upload-search-content.js.map +7 -0
  44. package/build/utils/alerts.d.ts +3 -0
  45. package/build/{exporter/utils → utils}/cache.d.ts +12 -7
  46. package/build/utils/core-utils.d.ts +107 -0
  47. package/build/utils/create-build-data.d.ts +8 -0
  48. package/build/{exporter/utils → utils}/domains.d.ts +1 -1
  49. package/build/utils/folders.d.ts +53 -0
  50. package/build/{exporter/utils/check-health.d.ts → utils/health-checks.d.ts} +2 -2
  51. package/build/{exporter/utils → utils}/loggin.d.ts +16 -2
  52. package/build/{exporter/utils → utils}/pages.d.ts +2 -2
  53. package/build/utils/render.d.ts +13 -0
  54. package/build/utils/searches.d.ts +15 -0
  55. package/build/{exporter/utils → utils}/sites.d.ts +3 -3
  56. package/build/{exporter/utils → utils}/store.d.ts +38 -10
  57. package/cx.config.d.ts +5 -0
  58. package/cx.config.js +36 -0
  59. package/exporter/adapters/gatsby/index.ts +146 -60
  60. package/exporter/adapters/gatsby/utils.ts +161 -0
  61. package/exporter/artifacts/README.md +34 -0
  62. package/exporter/{utils/artifacts.ts → artifacts/index.ts} +8 -9
  63. package/exporter/build.sh +38 -5
  64. package/exporter/commands/end-render.ts +81 -56
  65. package/exporter/commands/move-assets.ts +11 -0
  66. package/exporter/commands/prepare-domains-render.ts +31 -149
  67. package/exporter/commands/reset-render.ts +3 -12
  68. package/exporter/commands/start-render.ts +47 -18
  69. package/exporter/commands/upload-search-content.ts +21 -206
  70. package/exporter/constants/envs.ts +51 -59
  71. package/exporter/constants/index.ts +129 -0
  72. package/exporter/{constants/errors.ts → errors/errors-data.ts} +15 -24
  73. package/exporter/{utils/errors.ts → errors/index.ts} +9 -10
  74. package/exporter/index.ts +82 -0
  75. package/{react → exporter/react}/Favicon/index.tsx +7 -1
  76. package/{react → exporter/react}/GriddoIntegrations/index.tsx +14 -6
  77. package/{react → exporter/react}/GriddoIntegrations/utils.ts +9 -4
  78. package/exporter/react/index.tsx +11 -0
  79. package/exporter/registers/api.ts +14 -0
  80. package/exporter/registers/gatsby.ts +14 -0
  81. package/exporter/registers/index.ts +4 -0
  82. package/exporter/services/auth.ts +6 -7
  83. package/exporter/services/domains.ts +16 -0
  84. package/exporter/services/navigation.ts +10 -4
  85. package/exporter/services/reference-fields.ts +23 -8
  86. package/exporter/services/register.ts +113 -0
  87. package/exporter/services/robots.ts +15 -8
  88. package/exporter/services/settings.ts +17 -0
  89. package/exporter/services/sites.ts +24 -35
  90. package/exporter/services/store.ts +76 -118
  91. package/exporter/types/api.ts +27 -24
  92. package/exporter/types/global.ts +10 -8
  93. package/exporter/types/navigation.ts +1 -1
  94. package/exporter/types/pages.ts +3 -2
  95. package/exporter/types/sites.ts +2 -1
  96. package/exporter/utils/alerts.ts +29 -0
  97. package/exporter/utils/api.ts +82 -46
  98. package/exporter/utils/cache.ts +59 -34
  99. package/exporter/utils/core-utils.ts +247 -86
  100. package/exporter/utils/create-build-data.ts +17 -0
  101. package/exporter/utils/domains.ts +7 -10
  102. package/exporter/utils/folders.ts +92 -161
  103. package/exporter/utils/health-checks.ts +64 -0
  104. package/exporter/utils/images.ts +6 -1
  105. package/exporter/utils/instance.ts +12 -9
  106. package/exporter/utils/loggin.ts +89 -24
  107. package/exporter/utils/pages.ts +88 -23
  108. package/exporter/utils/render.ts +48 -147
  109. package/exporter/utils/searches.ts +156 -0
  110. package/exporter/utils/sites.ts +77 -67
  111. package/exporter/utils/store.ts +178 -85
  112. package/gatsby-browser.tsx +58 -41
  113. package/gatsby-config.ts +12 -6
  114. package/gatsby-node.ts +77 -15
  115. package/gatsby-ssr.tsx +1 -2
  116. package/package.json +74 -33
  117. package/src/README.md +7 -0
  118. package/src/components/Head.tsx +46 -13
  119. package/src/components/template.tsx +30 -8
  120. package/src/gatsby-node-utils.ts +2 -91
  121. package/src/html.tsx +11 -2
  122. package/src/types.ts +5 -5
  123. package/start-render.js +3 -1
  124. package/tsconfig.json +2 -3
  125. package/build/adapters/gatsby/actions/clean.js +0 -10
  126. package/build/adapters/gatsby/actions/clean.js.map +0 -1
  127. package/build/adapters/gatsby/actions/close.js +0 -12
  128. package/build/adapters/gatsby/actions/close.js.map +0 -1
  129. package/build/adapters/gatsby/actions/data.js +0 -18
  130. package/build/adapters/gatsby/actions/data.js.map +0 -1
  131. package/build/adapters/gatsby/actions/healthCheck.js +0 -10
  132. package/build/adapters/gatsby/actions/healthCheck.js.map +0 -1
  133. package/build/adapters/gatsby/actions/init.js +0 -9
  134. package/build/adapters/gatsby/actions/init.js.map +0 -1
  135. package/build/adapters/gatsby/actions/meta.js +0 -14
  136. package/build/adapters/gatsby/actions/meta.js.map +0 -1
  137. package/build/adapters/gatsby/actions/prepare.js +0 -9
  138. package/build/adapters/gatsby/actions/prepare.js.map +0 -1
  139. package/build/adapters/gatsby/actions/relocation.js +0 -15
  140. package/build/adapters/gatsby/actions/relocation.js.map +0 -1
  141. package/build/adapters/gatsby/actions/restore.js +0 -26
  142. package/build/adapters/gatsby/actions/restore.js.map +0 -1
  143. package/build/adapters/gatsby/actions/ssg.js +0 -9
  144. package/build/adapters/gatsby/actions/ssg.js.map +0 -1
  145. package/build/adapters/gatsby/actions/sync.js +0 -50
  146. package/build/adapters/gatsby/actions/sync.js.map +0 -1
  147. package/build/adapters/gatsby/index.js +0 -74
  148. package/build/adapters/gatsby/index.js.map +0 -1
  149. package/build/adapters/gatsby/shared/context.js +0 -25
  150. package/build/adapters/gatsby/shared/context.js.map +0 -1
  151. package/build/adapters/gatsby/shared/extract-assets.js +0 -58
  152. package/build/adapters/gatsby/shared/extract-assets.js.map +0 -1
  153. package/build/adapters/gatsby/shared/gatsby-build.js +0 -49
  154. package/build/adapters/gatsby/shared/gatsby-build.js.map +0 -1
  155. package/build/adapters/gatsby/shared/sync-render.js +0 -208
  156. package/build/adapters/gatsby/shared/sync-render.js.map +0 -1
  157. package/build/adapters/gatsby/shared/types.js +0 -3
  158. package/build/adapters/gatsby/shared/types.js.map +0 -1
  159. package/build/commands/end-render.js +0 -63
  160. package/build/commands/end-render.js.map +0 -1
  161. package/build/commands/prepare-assets-directory.js +0 -32
  162. package/build/commands/prepare-assets-directory.js.map +0 -1
  163. package/build/commands/prepare-domains-render.js +0 -138
  164. package/build/commands/prepare-domains-render.js.map +0 -1
  165. package/build/commands/reset-render.js +0 -22
  166. package/build/commands/reset-render.js.map +0 -1
  167. package/build/commands/start-render.js +0 -35
  168. package/build/commands/start-render.js.map +0 -1
  169. package/build/commands/upload-search-content.js +0 -189
  170. package/build/commands/upload-search-content.js.map +0 -1
  171. package/build/constants/endpoints.js +0 -42
  172. package/build/constants/endpoints.js.map +0 -1
  173. package/build/constants/envs.js +0 -73
  174. package/build/constants/envs.js.map +0 -1
  175. package/build/constants/errors.js +0 -89
  176. package/build/constants/errors.js.map +0 -1
  177. package/build/exporter/adapters/gatsby/actions/clean.d.ts +0 -3
  178. package/build/exporter/adapters/gatsby/actions/close.d.ts +0 -3
  179. package/build/exporter/adapters/gatsby/actions/data.d.ts +0 -2
  180. package/build/exporter/adapters/gatsby/actions/healthCheck.d.ts +0 -2
  181. package/build/exporter/adapters/gatsby/actions/init.d.ts +0 -2
  182. package/build/exporter/adapters/gatsby/actions/meta.d.ts +0 -2
  183. package/build/exporter/adapters/gatsby/actions/prepare.d.ts +0 -2
  184. package/build/exporter/adapters/gatsby/actions/relocation.d.ts +0 -2
  185. package/build/exporter/adapters/gatsby/actions/restore.d.ts +0 -3
  186. package/build/exporter/adapters/gatsby/actions/ssg.d.ts +0 -3
  187. package/build/exporter/adapters/gatsby/actions/sync.d.ts +0 -3
  188. package/build/exporter/adapters/gatsby/index.d.ts +0 -9
  189. package/build/exporter/adapters/gatsby/shared/context.d.ts +0 -38
  190. package/build/exporter/adapters/gatsby/shared/extract-assets.d.ts +0 -7
  191. package/build/exporter/adapters/gatsby/shared/gatsby-build.d.ts +0 -7
  192. package/build/exporter/adapters/gatsby/shared/sync-render.d.ts +0 -36
  193. package/build/exporter/adapters/gatsby/shared/types.d.ts +0 -34
  194. package/build/exporter/commands/prepare-assets-directory.d.ts +0 -2
  195. package/build/exporter/commands/prepare-domains-render.d.ts +0 -2
  196. package/build/exporter/services/db.d.ts +0 -4
  197. package/build/exporter/services/store.d.ts +0 -15
  198. package/build/exporter/types/render.d.ts +0 -50
  199. package/build/exporter/utils/artifacts.d.ts +0 -6
  200. package/build/exporter/utils/brush.d.ts +0 -18
  201. package/build/exporter/utils/core-utils.d.ts +0 -77
  202. package/build/exporter/utils/folders.d.ts +0 -66
  203. package/build/exporter/utils/render.d.ts +0 -49
  204. package/build/services/auth.js +0 -39
  205. package/build/services/auth.js.map +0 -1
  206. package/build/services/db.js +0 -34
  207. package/build/services/db.js.map +0 -1
  208. package/build/services/navigation.js +0 -93
  209. package/build/services/navigation.js.map +0 -1
  210. package/build/services/reference-fields.js +0 -131
  211. package/build/services/reference-fields.js.map +0 -1
  212. package/build/services/robots.js +0 -58
  213. package/build/services/robots.js.map +0 -1
  214. package/build/services/sites.js +0 -109
  215. package/build/services/sites.js.map +0 -1
  216. package/build/services/store.js +0 -282
  217. package/build/services/store.js.map +0 -1
  218. package/build/types/api.js +0 -3
  219. package/build/types/api.js.map +0 -1
  220. package/build/types/global.js +0 -3
  221. package/build/types/global.js.map +0 -1
  222. package/build/types/navigation.js +0 -3
  223. package/build/types/navigation.js.map +0 -1
  224. package/build/types/pages.js +0 -3
  225. package/build/types/pages.js.map +0 -1
  226. package/build/types/render.js +0 -10
  227. package/build/types/render.js.map +0 -1
  228. package/build/types/sites.js +0 -3
  229. package/build/types/sites.js.map +0 -1
  230. package/build/types/templates.js +0 -3
  231. package/build/types/templates.js.map +0 -1
  232. package/build/utils/api.js +0 -161
  233. package/build/utils/api.js.map +0 -1
  234. package/build/utils/artifacts.js +0 -34
  235. package/build/utils/artifacts.js.map +0 -1
  236. package/build/utils/brush.js +0 -30
  237. package/build/utils/brush.js.map +0 -1
  238. package/build/utils/cache.js +0 -106
  239. package/build/utils/cache.js.map +0 -1
  240. package/build/utils/check-health.js +0 -68
  241. package/build/utils/check-health.js.map +0 -1
  242. package/build/utils/core-utils.js +0 -251
  243. package/build/utils/core-utils.js.map +0 -1
  244. package/build/utils/domains.js +0 -37
  245. package/build/utils/domains.js.map +0 -1
  246. package/build/utils/errors.js +0 -30
  247. package/build/utils/errors.js.map +0 -1
  248. package/build/utils/folders.js +0 -339
  249. package/build/utils/folders.js.map +0 -1
  250. package/build/utils/images.js +0 -45
  251. package/build/utils/images.js.map +0 -1
  252. package/build/utils/instance.js +0 -66
  253. package/build/utils/instance.js.map +0 -1
  254. package/build/utils/loggin.js +0 -102
  255. package/build/utils/loggin.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 -144
  259. package/build/utils/render.js.map +0 -1
  260. package/build/utils/sites.js +0 -239
  261. package/build/utils/sites.js.map +0 -1
  262. package/build/utils/store.js +0 -193
  263. package/build/utils/store.js.map +0 -1
  264. package/exporter/adapters/gatsby/actions/clean.ts +0 -14
  265. package/exporter/adapters/gatsby/actions/close.ts +0 -17
  266. package/exporter/adapters/gatsby/actions/data.ts +0 -25
  267. package/exporter/adapters/gatsby/actions/healthCheck.ts +0 -10
  268. package/exporter/adapters/gatsby/actions/init.ts +0 -12
  269. package/exporter/adapters/gatsby/actions/meta.ts +0 -18
  270. package/exporter/adapters/gatsby/actions/prepare.ts +0 -9
  271. package/exporter/adapters/gatsby/actions/relocation.ts +0 -15
  272. package/exporter/adapters/gatsby/actions/restore.ts +0 -36
  273. package/exporter/adapters/gatsby/actions/ssg.ts +0 -12
  274. package/exporter/adapters/gatsby/actions/sync.ts +0 -70
  275. package/exporter/adapters/gatsby/shared/context.ts +0 -50
  276. package/exporter/adapters/gatsby/shared/extract-assets.ts +0 -61
  277. package/exporter/adapters/gatsby/shared/gatsby-build.ts +0 -54
  278. package/exporter/adapters/gatsby/shared/sync-render.ts +0 -294
  279. package/exporter/adapters/gatsby/shared/types.ts +0 -35
  280. package/exporter/build-esbuild.noop +0 -42
  281. package/exporter/commands/prepare-assets-directory.ts +0 -33
  282. package/exporter/services/db.ts +0 -32
  283. package/exporter/types/render.ts +0 -59
  284. package/exporter/utils/brush.ts +0 -34
  285. package/exporter/utils/check-health.ts +0 -79
  286. package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
  287. package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
  288. package/build/{exporter/commands → commands}/end-render.d.ts +0 -0
  289. package/build/{exporter/commands → commands}/reset-render.d.ts +0 -0
  290. package/build/{exporter/commands → commands}/start-render.d.ts +0 -0
  291. package/build/{exporter/commands → commands}/upload-search-content.d.ts +0 -0
  292. package/build/{exporter/constants → constants}/endpoints.d.ts +0 -0
  293. package/build/{exporter/services → services}/navigation.d.ts +0 -0
  294. package/build/{exporter/services → services}/reference-fields.d.ts +0 -0
  295. package/build/{exporter/types → types}/pages.d.ts +1 -1
  296. /package/build/{exporter/types → types}/templates.d.ts +0 -0
  297. /package/build/{exporter/utils → utils}/api.d.ts +0 -0
  298. /package/build/{exporter/utils → utils}/images.d.ts +0 -0
  299. /package/build/{exporter/utils → utils}/instance.d.ts +0 -0
  300. /package/{react → exporter/react}/Favicon/utils.ts +0 -0
@@ -1,70 +0,0 @@
1
- import type { RenderContext } from "../shared/context";
2
- import type { SSG } from "../shared/types";
3
-
4
- import fsp from "node:fs/promises";
5
- import path from "node:path";
6
-
7
- import { RENDER_MODE } from "../../../types/render";
8
- import {
9
- deleteDisposableSiteDirs,
10
- deleteEmptyDirectories,
11
- moveDirs,
12
- removeVirtualPages,
13
- } from "../../../utils/folders";
14
- import { extractAssetsFromDist } from "../shared/extract-assets";
15
- import { SyncRender } from "../shared/sync-render";
16
-
17
- export async function syncAction(context: RenderContext<SSG>) {
18
- const {
19
- renderMode,
20
- cxArtifacts,
21
- domain,
22
- pagesToCreate,
23
- pagesToDelete,
24
- paths: { __cx, __ssg, __cache, __exports },
25
- ssg: { ssgArtifacts, assetPrefix },
26
- } = context;
27
-
28
- const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
29
- const distDir = path.join(__cx, "dist");
30
- const distRestoredDir = path.join(__cx, "dist-restored");
31
- const storeDir = path.join(context.paths.__cx, "store");
32
-
33
- await removeVirtualPages(storeDir);
34
- // caching...
35
- await moveDirs(__cx, __cache, cxArtifacts.cacheables);
36
- await moveDirs(__ssg, __cache, ssgArtifacts.cacheables);
37
-
38
- if (renderMode === RENDER_MODE.FROM_SCRATCH) {
39
- await deleteDisposableSiteDirs(distDir);
40
- }
41
-
42
- if (renderMode === RENDER_MODE.INCREMENTAL) {
43
- await deleteDisposableSiteDirs(distRestoredDir);
44
-
45
- const syncRender = new SyncRender({
46
- src: distDir,
47
- dst: distRestoredDir,
48
- pagesToCreate,
49
- pagesToDelete,
50
- artifactsToCopyToExports: ["build-report.json"],
51
- });
52
-
53
- syncRender.setPagesToDelete();
54
- syncRender.setPagesToAdd();
55
- syncRender.sync();
56
-
57
- await fsp.rm(distDir, { force: true, recursive: true });
58
- await fsp.rename(distRestoredDir, distDir);
59
- await deleteEmptyDirectories(distDir);
60
- }
61
-
62
- if (needsAssetPrefix) {
63
- await extractAssetsFromDist(domain);
64
- }
65
-
66
- // archiving...
67
- await moveDirs(__cx, __exports, cxArtifacts.archivables, {
68
- withBackup: true,
69
- });
70
- }
@@ -1,50 +0,0 @@
1
- import type { Artifacts, PlaceholderPath } from "../../../types/global";
2
- import type { RenderMode } from "../../../types/render";
3
-
4
- interface RenderContextProps<T> {
5
- domain: string;
6
- renderMode: RenderMode;
7
- paths: Record<string, string>;
8
- ssg: T;
9
- renderMetadata: {
10
- proDomain: string;
11
- griddoVersion: string;
12
- buildReportFileName: string;
13
- };
14
- cxArtifacts: Artifacts;
15
- }
16
-
17
- /**
18
- * Encapsulates the state, configuration, and artifacts for a single SSG
19
- * render process.
20
- *
21
- * This class is instantiated at the beginning of a render and passed through
22
- * each lifecycle step, providing a centralized and consistent context for all
23
- * operations. It is agnostic to the specific SSG being used.
24
- */
25
- export class RenderContext<T = unknown> {
26
- readonly domain: string;
27
- readonly renderMode: RenderMode;
28
- readonly paths: Record<PlaceholderPath, string>;
29
- pagesToCreate: number[] = [];
30
- pagesToDelete: number[] = [];
31
- ssg: T;
32
- renderMetadata: { proDomain: string; griddoVersion: string; buildReportFileName: string };
33
- cxArtifacts: Artifacts;
34
-
35
- constructor({
36
- domain,
37
- renderMode,
38
- ssg,
39
- paths,
40
- renderMetadata,
41
- cxArtifacts,
42
- }: RenderContextProps<T>) {
43
- this.domain = domain;
44
- this.renderMode = renderMode;
45
- this.paths = paths;
46
- this.renderMetadata = renderMetadata;
47
- this.cxArtifacts = cxArtifacts;
48
- this.ssg = ssg;
49
- }
50
- }
@@ -1,61 +0,0 @@
1
- import fsp from "node:fs/promises";
2
- import path from "node:path";
3
-
4
- import { pathExists } from "../../../utils/folders";
5
- import { getRenderPathsFromDB } from "../../../utils/render";
6
-
7
- /**
8
- * Update the Griddo's `/dist` dir with the contents from `public` dir only
9
- * with files of type: js, json and css.
10
- * TODO: Explicar que el static se copia a assets porque el js va en el subdominio de assets.
11
- */
12
- async function extractAssetsFromDist(domain: string) {
13
- const { __cx } = await getRenderPathsFromDB({ domain });
14
-
15
- // Archivos (no carpetas) válidos de public
16
- const filesFromDist = (await fsp.readdir(path.join(__cx, "dist"))).filter(
17
- (file) =>
18
- path.extname(file) === ".js" ||
19
- path.extname(file) === ".json" ||
20
- path.extname(file) === ".css",
21
- );
22
-
23
- // Creamos assets si es necesario (needsAssetPrefix)
24
- await fsp.mkdir(path.join(__cx, "assets"), { recursive: true });
25
- // page-data folder
26
- await fsp.cp(path.join(__cx, "dist", "page-data"), path.join(__cx, "assets", "page-data"), {
27
- preserveTimestamps: true,
28
- recursive: true,
29
- });
30
- // static folder si existe
31
- if (await pathExists(path.join(__cx, "static"))) {
32
- await fsp.cp(path.join(__cx, "static"), path.join(__cx, "assets"), {
33
- force: false,
34
- preserveTimestamps: true,
35
- recursive: true,
36
- });
37
- }
38
- // dist/static -> assets/static
39
- await fsp.cp(path.join(__cx, "dist", "static"), path.join(__cx, "assets", "static"), {
40
- force: false,
41
- preserveTimestamps: true,
42
- recursive: true,
43
- });
44
- // otro static...
45
- if (await pathExists(path.join(__cx, "static"))) {
46
- await fsp.cp(path.join(__cx, "static"), path.join(__cx, "dist", domain), {
47
- preserveTimestamps: true,
48
- recursive: true,
49
- force: false,
50
- });
51
- }
52
-
53
- // Copia el resto de archivos...
54
- for (const file of filesFromDist) {
55
- const fileSrc = path.join(__cx, "dist", file);
56
- const fileDest = path.join(__cx, "assets", file);
57
- await fsp.cp(fileSrc, fileDest, { preserveTimestamps: true, recursive: true });
58
- }
59
- }
60
-
61
- export { extractAssetsFromDist };
@@ -1,54 +0,0 @@
1
- import { spawn } from "node:child_process";
2
-
3
- import { GRIDDO_SSG_VERBOSE_LOGS } from "../../../constants/envs";
4
- import { verboseLog } from "../../../utils/loggin";
5
- import { getRenderPathsFromDB } from "../../../utils/render";
6
-
7
- /**
8
- * Spawn a new node process `yarn gatsby-build`
9
- * @note This proccess (`yarn gatsby-build`) can not access to the custom Griddo
10
- * `process.env` so it needs variables passed to it via the `env` prop.
11
- */
12
- async function gatsbyBuild(assetPrefixWithDomain: string): Promise<void> {
13
- verboseLog(`read assetPrefixWithDomain, ${assetPrefixWithDomain}`);
14
- verboseLog(`using this NODE_OPTIONS in gatsby command: ${process.env.NODE_OPTIONS}`);
15
-
16
- const { __ssg } = await getRenderPathsFromDB();
17
-
18
- // Remove `--openssl-legacy-provider` from NODE_OPTIONS because this value
19
- // break Gatsby render.
20
- const nodeOptionsWithoutLegacyOpenSSL = process.env.NODE_OPTIONS
21
- ? process.env.NODE_OPTIONS.replace(/--openssl-legacy-provider\s*/g, "").trim()
22
- : "";
23
-
24
- const args = ["gatsby-build"];
25
- if (GRIDDO_SSG_VERBOSE_LOGS) {
26
- args.push("--verbose");
27
- }
28
-
29
- return new Promise((resolve, reject) => {
30
- const child = spawn("yarn", args, {
31
- cwd: __ssg,
32
- stdio: ["ignore", "inherit", "inherit"], // stdout y stderr van a consola directamente
33
- env: Object.assign(process.env, {
34
- GRIDDO_EXPORTER: "true",
35
- SPAWN_ASSET_PREFIX_WITH_DOMAIN: assetPrefixWithDomain,
36
- NODE_OPTIONS: nodeOptionsWithoutLegacyOpenSSL,
37
- }),
38
- });
39
-
40
- child.on("close", (code) => {
41
- if (code === 0) {
42
- resolve();
43
- } else {
44
- reject(new Error(`Gatsby build failed with exit code ${code}`));
45
- }
46
- });
47
-
48
- child.on("error", (error) => {
49
- reject(new Error(`Failed to start Gatsby build process: ${error.message}`));
50
- });
51
- });
52
- }
53
-
54
- export { gatsbyBuild };
@@ -1,294 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
-
4
- import { verboseLog } from "../../../utils/loggin";
5
-
6
- type SyncRenderConfig = {
7
- src: string;
8
- dst: string;
9
- pagesToCreate: Array<number>;
10
- pagesToDelete: Array<number>;
11
- artifactsToCopyToExports: Array<string>;
12
- };
13
-
14
- type CopyFilePath = {
15
- from: string;
16
- to: string;
17
- };
18
-
19
- type SyncState = {
20
- htmlToAdd: Array<CopyFilePath>;
21
- jsonToAdd: Array<CopyFilePath>;
22
- htmlToDelete: Array<string>;
23
- jsonToDelete: Array<string>;
24
- };
25
-
26
- class SyncRender {
27
- private bundleDir: string;
28
- private currentRenderDir: string;
29
- private pagesToCreate: Array<number>;
30
- private pagesToDelete: Array<number>;
31
- private assetArtifacts: Array<string>;
32
-
33
- private state: SyncState = {
34
- htmlToAdd: [],
35
- jsonToAdd: [],
36
- htmlToDelete: [],
37
- jsonToDelete: [],
38
- };
39
-
40
- constructor(config: SyncRenderConfig) {
41
- this.bundleDir = config.dst;
42
- this.currentRenderDir = config.src;
43
- this.pagesToCreate = config.pagesToCreate;
44
- this.pagesToDelete = config.pagesToDelete;
45
- this.assetArtifacts = config.artifactsToCopyToExports;
46
- }
47
-
48
- // Se basa en los paths encontrados en page-data.json y no en recorrer físicamente el file-system
49
- setPagesToDelete() {
50
- // El set de ids están tanto las páginas que se van a crear como borrar.
51
- // El por qué poner las que se van a crear es porque necesitamos quitar esas páginas con esos ids por si las que se van a crear tienen otro slug.
52
- // Por ejemplo si se va crear la página id3 con slug /page-with-new-slug
53
- // pero existía antes con el slug /page se borrará /page del sistema de
54
- // ficheros y después se creará /page-with-new-slug ya que solo puede
55
- // existir una página con el mismo id salvo que sea Multi-Page o
56
- // Listado-Estático.
57
- const idSet = new Set<number>([...this.pagesToDelete, ...this.pagesToCreate]);
58
- const composePaths = this.getPageComposePaths(this.bundleDir);
59
-
60
- for (const compose of composePaths) {
61
- const normalizedCompose = compose === "/" ? "index" : compose;
62
- const json = JSON.parse(
63
- fs.readFileSync(
64
- path.join(this.bundleDir, "page-data", normalizedCompose, "page-data.json"),
65
- "utf8",
66
- ),
67
- );
68
- const id = json.result.pageContext.id;
69
- const pagePath = json.result.pageContext.fullPath.compose as string;
70
- // si el id de la página está en los ids para borrar (idSet) se añade
71
- if (idSet.has(id)) {
72
- try {
73
- this.state.htmlToDelete.push(path.join(this.bundleDir, pagePath, "index.html"));
74
- this.state.jsonToDelete.push(
75
- path.join(
76
- this.bundleDir,
77
- "page-data",
78
- pagePath === "/" ? "index" : pagePath,
79
- "page-data.json",
80
- ),
81
- );
82
- } catch (e) {
83
- console.log(e);
84
- }
85
- }
86
- }
87
-
88
- verboseLog(`${this.state.htmlToDelete.length} pages HTML to delete`);
89
- verboseLog(`${this.state.jsonToDelete.length} pages JSON to delete`);
90
- }
91
-
92
- // Se basa en los paths encontrados en page-data.json y no en recorrer físicamente el file-system
93
- // Cuando añadimos una página con id 3 (p.e.), hay que buscar todas las
94
- // páginas con ese id en el bundle y borrar sus html/json. Esto va a pasar
95
- // por ejemplo si cambiamos el slug de la página 3. Eso hará que se guarde
96
- // en distintas carpetas pero no es una página que venga en "pagesToDelete"
97
- setPagesToAdd() {
98
- const idSet = new Set<number>(this.pagesToCreate);
99
- const composePaths = this.getPageComposePaths(this.currentRenderDir);
100
-
101
- for (const compose of composePaths) {
102
- // 1 - leemos el page-data.json de la página para añadir
103
- // Gatsby crea un directorio `index` para la página raíz `/`
104
- const normalizedCompose = compose === "/" ? "index" : compose;
105
- const json = JSON.parse(
106
- fs.readFileSync(
107
- path.join(this.currentRenderDir, "page-data", normalizedCompose, "page-data.json"),
108
- "utf8",
109
- ),
110
- );
111
- // 2 - sacamos el id
112
- const id = json.result.pageContext.id;
113
-
114
- // 3 - obtenemos el src y dst del HTML
115
- const htmlFrom = path.join(this.currentRenderDir, compose, "index.html");
116
- const htmlTo = path.join(this.bundleDir, compose, "index.html");
117
- // 4 - obtenemos el src/dst del JSON
118
- const jsonFrom = path.join(
119
- this.currentRenderDir,
120
- "page-data",
121
- normalizedCompose,
122
- "page-data.json",
123
- );
124
- const jsonTo = path.join(this.bundleDir, "page-data", normalizedCompose, "page-data.json");
125
-
126
- // Solo actuamos en la página si su id está en pagesToCreate
127
- if (idSet.has(id)) {
128
- try {
129
- this.state.htmlToAdd.push({ from: htmlFrom, to: htmlTo });
130
- this.state.jsonToAdd.push({ from: jsonFrom, to: jsonTo });
131
- } catch (e) {
132
- console.log(e);
133
- }
134
- }
135
-
136
- verboseLog(`${this.state.htmlToAdd.length} pages HTML to create`);
137
- verboseLog(`${this.state.jsonToAdd.length} pages JSON to create`);
138
- }
139
- }
140
-
141
- /**
142
- * Realiza la sincronización de los archivos HTML y JSON entre el directorio
143
- * actual de renderizado y el directorio de exportación.
144
- */
145
- sync() {
146
- // remove html's
147
- for (const html of this.state.htmlToDelete) {
148
- try {
149
- fs.rmSync(html);
150
- verboseLog(`Sync (remove) : ${html}`);
151
- } catch (e) {
152
- console.log(`Does not exist ${html}`, e);
153
- }
154
- }
155
-
156
- // remove json's
157
- for (const json of this.state.jsonToDelete) {
158
- try {
159
- fs.rmSync(json);
160
- verboseLog(`Sync (remove) : ${json}`);
161
- } catch (e) {
162
- console.log(`Does not exist ${json}`, e);
163
- }
164
- }
165
-
166
- // copy html's
167
- for (const html of this.state.htmlToAdd) {
168
- fs.mkdirSync(path.dirname(html.to), { recursive: true });
169
- fs.copyFileSync(html.from, html.to);
170
- verboseLog(`Sync (copy) : ${html.from} -> ${html.to}`);
171
- }
172
-
173
- // copy json's
174
- for (const json of this.state.jsonToAdd) {
175
- fs.mkdirSync(path.dirname(json.to), { recursive: true });
176
- fs.copyFileSync(json.from, json.to);
177
- verboseLog(`Sync (copy) : ${json.from} -> ${json.to}`);
178
- }
179
-
180
- // update app-data.json (update the webpackCompilationHash)
181
- this.copyAppDataJsonFile();
182
-
183
- // copy artifacts
184
- this.copyDirs();
185
-
186
- // copy sitemaps
187
- this.copySitemaps();
188
- }
189
-
190
- /**
191
- * Busca archivos por extensión de forma recursiva en un directorio.
192
- * @param dir Directorio base.
193
- * @param extension Extensión a buscar (ej: ".ts", ".js").
194
- * @returns Lista de rutas absolutas de archivos encontrados.
195
- */
196
- private findFilesByExtension(dir: string, extension: string): Array<string> {
197
- let results: Array<string> = [];
198
-
199
- if (!fs.existsSync(dir)) {
200
- return [];
201
- }
202
-
203
- const list = fs.readdirSync(dir, { withFileTypes: true });
204
-
205
- for (const item of list) {
206
- const fullPath = path.join(dir, item.name);
207
-
208
- if (item.isDirectory()) {
209
- results = results.concat(this.findFilesByExtension(fullPath, extension));
210
- } else if (item.isFile() && fullPath.endsWith(extension)) {
211
- results.push(fullPath);
212
- }
213
- }
214
-
215
- return results;
216
- }
217
-
218
- private findAllPageDataJsons(dir: string) {
219
- return this.findFilesByExtension(dir, ".json").filter((n) => n.endsWith("page-data.json"));
220
- }
221
-
222
- private getPageComposePaths(src: string) {
223
- // [page-data/foo/bar/page-data.json, ...]
224
- const allPageDataJson = this.findAllPageDataJsons(src);
225
-
226
- // Array de fullPaths
227
- // Entre ellos un fullPath puede ser: "/" (El root de la instancia)
228
-
229
- // No sé si hacer esto en este momento...
230
- // fullPath: "/foo/bar" => "foo/bar"
231
- // fullPath: "/" => "index"
232
- return allPageDataJson.map(
233
- (p) => JSON.parse(fs.readFileSync(p, "utf-8")).result.pageContext.fullPath.compose,
234
- );
235
- }
236
-
237
- private copyAppDataJsonFile() {
238
- fs.copyFileSync(
239
- path.join(this.currentRenderDir, "page-data", "app-data.json"),
240
- path.join(this.bundleDir, "page-data", "app-data.json"),
241
- );
242
- verboseLog("Copied app-data.json");
243
- }
244
-
245
- private copyDirs() {
246
- for (const assetArtifact of this.assetArtifacts) {
247
- fs.copyFileSync(
248
- path.join(this.currentRenderDir, assetArtifact),
249
- path.join(this.bundleDir, assetArtifact),
250
- );
251
- verboseLog(
252
- `Copied ${path.join(this.currentRenderDir, assetArtifact)} -> to -> ${path.join(
253
- this.bundleDir,
254
- assetArtifact,
255
- )}`,
256
- );
257
- }
258
- }
259
-
260
- private copySitemaps() {
261
- /*
262
- 1. buscar directorios que tengan como hijo un `sitemap.xml`
263
- 2. copiar todos los sitemap.xml y sitemap-* a /exports/sites/<domain>/<site>/ borrando previamente los .xmls que existan
264
- */
265
- const renderSrc = path.resolve(this.currentRenderDir);
266
- const renderDst = path.resolve(this.bundleDir);
267
- const xmlFilesInSrc = this.findFilesByExtension(renderSrc, ".xml");
268
- const xmlFilesInDst = this.findFilesByExtension(renderDst, ".xml");
269
-
270
- // Eliminar los sitemaps de griddo que existan en el destino, se van a
271
- // crear todos nuevos en la fase Meta.
272
- for (const xmlFile of xmlFilesInDst) {
273
- if (
274
- path.basename(xmlFile).startsWith("sitemap-") ||
275
- path.basename(xmlFile) === "sitemap.xml"
276
- ) {
277
- fs.rmSync(xmlFile, { force: true });
278
- }
279
- }
280
-
281
- for (const xmlFile of xmlFilesInSrc) {
282
- const src = xmlFile;
283
- // cambia la ruta, de src -> dst
284
- const dst = xmlFile.replace(renderSrc, renderDst);
285
-
286
- if (!fs.existsSync(path.dirname(dst))) {
287
- fs.mkdirSync(path.dirname(dst), { recursive: true });
288
- }
289
- fs.copyFileSync(src, dst);
290
- }
291
- }
292
- }
293
-
294
- export { SyncRender };
@@ -1,35 +0,0 @@
1
- interface SSG {
2
- assetPrefix: string;
3
- ssgArtifacts: {
4
- disposables: string[];
5
- cacheables: string[];
6
- };
7
- }
8
-
9
- // Minimal representation of the page structure
10
- interface GatsbyPageData {
11
- path: string;
12
- result: {
13
- pageContext: {
14
- id: number;
15
- title: string;
16
- path: string;
17
- openGraph: any;
18
- pageMetadata: any;
19
- page: {
20
- site: number;
21
- id: number;
22
- fullPath: { compose: string };
23
- language: number;
24
- title: string;
25
- fullUrl: string;
26
- templateId: string;
27
- template: {
28
- templateType: string;
29
- };
30
- };
31
- };
32
- };
33
- }
34
-
35
- export type { GatsbyPageData, SSG };
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # Build CX script file
4
- #
5
- # This file generates the necessary builds for CX.
6
- # - Setup, to generate necessary elements (tsconfig, etc..)
7
- # - Library, CX library that will be used by the SSG framework.
8
- # - Scripts, CX scripts that will be used by infra during the render process.
9
- #
10
- # @todo:
11
- # In the future, we will try to eliminate the bundling processes and use
12
- # TypeScript or ESModules directly.
13
-
14
- # start
15
- echo "📦 Building ..."
16
-
17
- # CLI options
18
- log="--log-level=error"
19
- production_node_opts="--bundle --platform=node --minify --sourcemap"
20
- debugging_node_opts="--bundle --platform=node --sourcemap"
21
- # react_opts="--platform=node --external:@griddo-instance --external:react --external:react-dom --bundle --minify"
22
-
23
- # Manage --minify for debugging
24
- bundle_node_opts=$production_node_opts
25
- if [ "$1" = "--debug" ]; then
26
- bundle_node_opts=$debugging_node_opts
27
- fi
28
-
29
- # library
30
- # esbuild ${log} ./exporter/index.ts ${bundle_node_opts} --outfile=./build/index.js
31
- # esbuild ${log} ./exporter/react/index.tsx ${react_opts} --outfile=./build/react/index.js
32
-
33
- # scripts
34
- esbuild ${log} ./exporter/commands/end-render.ts ${bundle_node_opts} --outfile=./build/end-render.js
35
- esbuild ${log} ./exporter/commands/upload-search-content.ts ${bundle_node_opts} --outfile=./build/upload-search-content.js
36
- esbuild ${log} ./exporter/commands/reset-render.ts ${bundle_node_opts} --outfile=./build/reset-render.js
37
- esbuild ${log} ./exporter/commands/start-render.ts ${bundle_node_opts} --outfile=./build/start-render.js
38
- esbuild ${log} ./exporter/commands/prepare-domains-render.ts ${bundle_node_opts} --outfile=./build/prepare-domains-render.js
39
- esbuild ${log} ./exporter/commands/prepare-assets-directory.ts ${bundle_node_opts} --outfile=./build/prepare-assets-directory.js
40
-
41
- # types
42
- tsc --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import childProcess from "node:child_process";
4
- import path from "node:path";
5
-
6
- import { doLifeCycle } from "../utils/core-utils";
7
- import { pathExists } from "../utils/folders";
8
- import { getRenderPathsFromDB } from "../utils/render";
9
-
10
- async function prepareAssetsAction() {
11
- const [domain] = process.argv.slice(2);
12
-
13
- const { __exports } = await getRenderPathsFromDB({ domain });
14
-
15
- const assetsDir = path.join(__exports, "assets");
16
- const domainAssetsDir = path.join(__exports, domain);
17
-
18
- if (await pathExists(assetsDir)) {
19
- childProcess.execSync(`rm -rf ${domainAssetsDir}`);
20
- childProcess.execSync(`mv ${assetsDir} ${domainAssetsDir}`);
21
- } else {
22
- console.log("Assets directory not found");
23
- }
24
- }
25
-
26
- async function main() {
27
- await doLifeCycle("PrepareAssets(Internal)", prepareAssetsAction);
28
- }
29
-
30
- main().catch((err) => {
31
- console.error("Error", err?.stdout?.toString() || err);
32
- process.exit(1);
33
- });
@@ -1,32 +0,0 @@
1
- import type { RenderDB } from "../types/render";
2
-
3
- import fsp from "node:fs/promises";
4
- import path from "node:path";
5
-
6
- import { pkgDirSync } from "../utils/folders";
7
-
8
- const root = pkgDirSync({ cwd: path.resolve(__dirname, "../../..") }) || "";
9
- const cache = path.join(root, ".cx-cache");
10
- const dbFilePath = path.join(cache, "db.json");
11
-
12
- async function readDB(customDBPath = "") {
13
- const file = customDBPath || dbFilePath;
14
- try {
15
- return JSON.parse(await fsp.readFile(file, "utf-8")) as RenderDB;
16
- } catch (error) {
17
- console.error(`Failed to read DB file at ${file}:`, error);
18
- throw error;
19
- }
20
- }
21
-
22
- async function writeDB(renderDB: RenderDB, customDBPath = "") {
23
- const file = customDBPath || dbFilePath;
24
- try {
25
- await fsp.writeFile(file, JSON.stringify(renderDB));
26
- } catch (error) {
27
- console.error(`Failed to write DB file at ${file}:`, error);
28
- throw error;
29
- }
30
- }
31
-
32
- export { readDB, writeDB };