@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,58 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import path from "node:path";
3
-
4
- import { GRIDDO_SSG_VERBOSE_LOGS } from "../../../constants/envs";
5
- import { verboseLog } from "../../../utils/loggin";
6
- import { getRenderPathsFromDB } from "../../../utils/render";
7
-
8
- /**
9
- * Spawn a new node process `gatsby build`
10
- * @note This proccess can not access to the custom Griddo `process.env` so it
11
- * needs variables passed to it via the `env` prop.
12
- */
13
- async function gatsbyBuild(assetPrefixWithDomain: string): Promise<void> {
14
- verboseLog(`read assetPrefixWithDomain, ${assetPrefixWithDomain}`);
15
- verboseLog(`using this NODE_OPTIONS in gatsby command: ${process.env.NODE_OPTIONS}`);
16
-
17
- const { __ssg } = await getRenderPathsFromDB();
18
-
19
- // Remove `--openssl-legacy-provider` from NODE_OPTIONS because this value
20
- // break Gatsby render.
21
- const nodeOptionsWithoutLegacyOpenSSL = process.env.NODE_OPTIONS
22
- ? process.env.NODE_OPTIONS.replace(/--openssl-legacy-provider\s*/g, "").trim()
23
- : "";
24
-
25
- // Ruta al ejecutable de Gatsby
26
- const gatsbyExecutable = path.join(__ssg, "node_modules", ".bin", "gatsby");
27
-
28
- const args = ["build", "--prefix-paths"];
29
- if (GRIDDO_SSG_VERBOSE_LOGS) {
30
- args.push("--verbose");
31
- }
32
-
33
- return new Promise((resolve, reject) => {
34
- const child = spawn(gatsbyExecutable, args, {
35
- cwd: __ssg,
36
- stdio: ["ignore", "inherit", "inherit"],
37
- env: {
38
- ...process.env,
39
- SPAWN_ASSET_PREFIX_WITH_DOMAIN: assetPrefixWithDomain,
40
- NODE_OPTIONS: nodeOptionsWithoutLegacyOpenSSL,
41
- },
42
- });
43
-
44
- child.on("close", (code) => {
45
- if (code === 0) {
46
- resolve();
47
- } else {
48
- reject(new Error(`Gatsby build failed with exit code ${code}`));
49
- }
50
- });
51
-
52
- child.on("error", (error) => {
53
- reject(new Error(`Failed to start Gatsby build process: ${error.message}`));
54
- });
55
- });
56
- }
57
-
58
- export { gatsbyBuild };
@@ -1,276 +0,0 @@
1
- import fsp from "node:fs/promises";
2
- import path from "node:path";
3
-
4
- import { findFilesBySuffix } from "../../../utils/folders";
5
- import { infoLog, verboseLog } from "../../../utils/loggin";
6
- import { getAssetsDiffBetweenRenders, patchHtmlFile } from "./diff-assets";
7
-
8
- interface SyncRenderConfig {
9
- src: string;
10
- dst: string;
11
- pagesToCreate: Array<number>;
12
- pagesToDelete: Array<number>;
13
- artifactsToCopyToExports: Array<string>;
14
- }
15
- interface CopyFilePath {
16
- from: string;
17
- to: string;
18
- }
19
- interface SyncState {
20
- htmlToAdd: Array<CopyFilePath>;
21
- jsonToAdd: Array<CopyFilePath>;
22
- htmlToDelete: Array<string>;
23
- jsonToDelete: Array<string>;
24
- }
25
- interface PageInfo {
26
- id: number;
27
- composePath: string; // p.ej. '/about-us' o '/'
28
- htmlPath: string; // p.ej. '/path/to/public/about-us/index.html'
29
- jsonPath: string; // p.ej. '/path/to/public/page-data/about-us/page-data.json'
30
- }
31
- interface GatsbyPageData {
32
- result: {
33
- pageContext: {
34
- id: number;
35
- fullPath: {
36
- site: string;
37
- domain: string;
38
- domainUrl: string;
39
- language: string;
40
- page: string;
41
- compose: string;
42
- };
43
- };
44
- };
45
- }
46
-
47
- class SyncRender {
48
- private bundleDir: string;
49
- private currentRenderDir: string;
50
- private pagesToCreate: Array<number>;
51
- private pagesToDelete: Array<number>;
52
- private assetArtifacts: Array<string>;
53
-
54
- private state: SyncState = {
55
- htmlToAdd: [],
56
- jsonToAdd: [],
57
- htmlToDelete: [],
58
- jsonToDelete: [],
59
- };
60
-
61
- constructor(config: SyncRenderConfig) {
62
- this.bundleDir = config.dst;
63
- this.currentRenderDir = config.src;
64
- this.pagesToCreate = config.pagesToCreate;
65
- this.pagesToDelete = config.pagesToDelete;
66
- this.assetArtifacts = config.artifactsToCopyToExports;
67
- }
68
-
69
- public async execute() {
70
- await this.setPagesToDelete();
71
- await this.setPagesToAdd();
72
- await this.sync();
73
- await this.assertAssetsAreValid();
74
- }
75
-
76
- private async assertAssetsAreValid() {
77
- const isDifferent = await getAssetsDiffBetweenRenders(this.currentRenderDir, this.bundleDir);
78
- if (isDifferent) {
79
- infoLog(
80
- "Warning: JavaScript and CSS bundles must have the same files and content. You can ignore this warning if the rendering process only has pages to unpublish.",
81
- );
82
- } else {
83
- infoLog("Previous and current JavaScript and CSS packages successfully matched");
84
- }
85
- }
86
-
87
- private async setPagesToDelete() {
88
- // ¿Por qué se incluyen this.pagesToCreate en las candidatas para borrarse?
89
- // El set de ids incluye tanto las páginas a borrar como las que se van
90
- // a crear para manejar correctamente por ejemplo los cambios de slug.
91
- // Si la página `id=3` tiene slug `slug=about` y despues viene con
92
- // `slug=about-us` borramos la página `id=3` en el render previo y la
93
- // volvemos a crear.
94
- // Resumido lo que pasará es que las páginas que se van a crear se
95
- // borran previamente por si ha cambiado el slug. Porque el slug hace
96
- // que se guarden en otro directorio.
97
- // ¿Qué pasaría si no la borrásemos? que tendríamos las dos páginas
98
- // `/about/index.html` y `/about-us/index.html`
99
- const candidateIdsToDelete = new Set<number>([...this.pagesToDelete, ...this.pagesToCreate]);
100
- const existingPreviousPages = await this.scanPages(this.bundleDir);
101
-
102
- for (const page of existingPreviousPages) {
103
- if (candidateIdsToDelete.has(page.id)) {
104
- this.state.htmlToDelete.push(page.htmlPath);
105
- this.state.jsonToDelete.push(page.jsonPath);
106
- }
107
- }
108
-
109
- verboseLog(`${this.state.htmlToDelete.length} pages HTML to delete`);
110
- verboseLog(`${this.state.jsonToDelete.length} pages JSON to delete`);
111
- }
112
-
113
- private async setPagesToAdd() {
114
- const candidateIdsToCreate = new Set<number>(this.pagesToCreate);
115
- const newPages = await this.scanPages(this.currentRenderDir);
116
-
117
- for (const page of newPages) {
118
- if (candidateIdsToCreate.has(page.id)) {
119
- const htmlTo = path.join(this.bundleDir, page.composePath, "index.html");
120
- const normalizedCompose = page.composePath === "/" ? "index" : page.composePath;
121
- const jsonTo = path.join(this.bundleDir, "page-data", normalizedCompose, "page-data.json");
122
-
123
- this.state.htmlToAdd.push({ from: page.htmlPath, to: htmlTo });
124
- this.state.jsonToAdd.push({ from: page.jsonPath, to: jsonTo });
125
- }
126
- }
127
-
128
- verboseLog(`${this.state.htmlToAdd.length} pages HTML to create`);
129
- verboseLog(`${this.state.jsonToAdd.length} pages JSON to create`);
130
- }
131
-
132
- private async sync() {
133
- // Delete...
134
- const allFilesToDelete = [...this.state.htmlToDelete, ...this.state.jsonToDelete];
135
- for (const file of allFilesToDelete) {
136
- try {
137
- // Usar `force: true` para no fallar si el archivo ya no existe.
138
- await fsp.rm(file, { force: true });
139
- verboseLog(`Sync (remove) : ${file}`);
140
- } catch (e) {
141
- // El error solo se registraría si es un problema de permisos, etc.
142
- console.error(`Failed to remove ${file}:`, e);
143
- }
144
- }
145
-
146
- await this.restoreWebpackCompilationHash();
147
-
148
- // Copy...
149
- const allFilesToAdd = [...this.state.htmlToAdd, ...this.state.jsonToAdd];
150
- for (const file of allFilesToAdd) {
151
- try {
152
- await fsp.mkdir(path.dirname(file.to), { recursive: true });
153
- await fsp.copyFile(file.from, file.to);
154
- verboseLog(`Sync (copy) : ${file.from} -> ${file.to}`);
155
- } catch (e) {
156
- console.error(`Failed to copy ${file.from} to ${file.to}:`, e);
157
- }
158
- }
159
-
160
- // AVOID TO RESTORE webpackCompilationHash
161
- // await this.copyAppDataJsonFile();
162
- await this.copyAssetArtifacts();
163
- await this.copySitemaps();
164
- }
165
-
166
- private async restoreWebpackCompilationHash() {
167
- const appDataJson = path.join(this.bundleDir, "page-data", "app-data.json");
168
- const webpackCompilationHash = JSON.parse(
169
- await fsp.readFile(appDataJson, "utf8"),
170
- ).webpackCompilationHash;
171
- console.log(
172
- "Leyendo el webpackCompilationHash desde",
173
- appDataJson,
174
- "=",
175
- webpackCompilationHash,
176
- );
177
-
178
- const changedHtmlFilePaths = this.state.htmlToAdd.map(({ from }) => from);
179
-
180
- for (const htmlFilePath of changedHtmlFilePaths) {
181
- await patchHtmlFile(htmlFilePath, webpackCompilationHash);
182
- }
183
- }
184
-
185
- // private async copyAppDataJsonFile() {
186
- // try {
187
- // const src = path.join(this.currentRenderDir, "page-data", "app-data.json");
188
- // const dst = path.join(this.bundleDir, "page-data", "app-data.json");
189
- // await fsp.copyFile(src, dst);
190
- // verboseLog("Copied app-data.json");
191
- // } catch (e) {
192
- // console.error("Failed to copy app-data.json:", e);
193
- // }
194
- // }
195
-
196
- private async copyAssetArtifacts() {
197
- for (const assetArtifact of this.assetArtifacts) {
198
- const src = path.join(this.currentRenderDir, assetArtifact);
199
- const dst = path.join(this.bundleDir, assetArtifact);
200
- try {
201
- await fsp.mkdir(path.dirname(dst), { recursive: true });
202
- await fsp.copyFile(src, dst);
203
- verboseLog(`Copied artifact: ${assetArtifact}`);
204
- } catch (e) {
205
- console.error(`Failed to copy artifact ${src} to ${dst}:`, e);
206
- }
207
- }
208
- }
209
-
210
- private async copySitemaps() {
211
- const renderSrc = path.resolve(this.currentRenderDir);
212
- const renderDst = path.resolve(this.bundleDir);
213
-
214
- // Primero, elimina los sitemaps existentes en el destino
215
- const xmlFilesInDst = findFilesBySuffix(renderDst, ".xml");
216
- for await (const xmlFile of xmlFilesInDst) {
217
- const basename = path.basename(xmlFile);
218
- if (basename.startsWith("sitemap-") || basename === "sitemap.xml") {
219
- await fsp.rm(xmlFile, { force: true });
220
- }
221
- }
222
-
223
- // Segundo, copia los nuevos sitemaps desde el origen
224
- const xmlFilesInSrc = findFilesBySuffix(renderSrc, ".xml");
225
- for await (const src of xmlFilesInSrc) {
226
- // Reconstruye la ruta de destino de forma más robusta
227
- const relativePath = path.relative(renderSrc, src);
228
- const dst = path.join(renderDst, relativePath);
229
-
230
- try {
231
- await fsp.mkdir(path.dirname(dst), { recursive: true });
232
- await fsp.copyFile(src, dst);
233
- } catch (e) {
234
- console.error(`Failed to copy sitemap ${src} to ${dst}:`, e);
235
- }
236
- }
237
-
238
- verboseLog(`Copied sitemap files.`);
239
- }
240
-
241
- /**
242
- * Escanea un directorio de build de Gatsby y extrae la información esencial de cada página.
243
- * Lee cada page-data.json una sola vez para optimizar el rendimiento.
244
- * @param dir Directorio a escanear (src o dst).
245
- * @returns Un array con la información de cada página encontrada.
246
- */
247
- private async scanPages(dir: string): Promise<Array<PageInfo>> {
248
- // Array de paths de page-data.json
249
- const gatsbyPageDataFiles = findFilesBySuffix(path.join(dir, "page-data"), "page-data.json");
250
- const pagesFound: Array<PageInfo> = [];
251
-
252
- for await (const jsonFile of gatsbyPageDataFiles) {
253
- try {
254
- const content = JSON.parse(await fsp.readFile(jsonFile, "utf-8")) as GatsbyPageData;
255
- const id = content.result.pageContext.id;
256
- const composePath = content.result.pageContext.fullPath.compose;
257
- // Esto es necesario porque Gatsby convierte la ruta "/" en un
258
- // directorio llamado "index" en lo que archivos page-data.json
259
- // se refiere.
260
- const normalizedCompose = composePath === "/" ? "index" : composePath;
261
-
262
- pagesFound.push({
263
- id,
264
- composePath,
265
- htmlPath: path.join(dir, composePath, "index.html"),
266
- jsonPath: path.join(dir, "page-data", normalizedCompose, "page-data.json"),
267
- });
268
- } catch (e) {
269
- console.error(`Error reading or parsing page data from ${jsonFile}:`, e);
270
- }
271
- }
272
- return pagesFound;
273
- }
274
- }
275
-
276
- 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,30 +0,0 @@
1
- import childProcess from "node:child_process";
2
- import path from "node:path";
3
-
4
- import { pathExists } from "../utils/folders";
5
- import { getRenderPathsFromDB } from "../utils/render";
6
-
7
- async function prepareAssetsDir() {
8
- const [domain] = process.argv.slice(2);
9
-
10
- const { __exports } = await getRenderPathsFromDB({ domain });
11
-
12
- const assetsDir = path.join(__exports, "assets");
13
- const domainAssetsDir = path.join(__exports, domain);
14
-
15
- if (await pathExists(assetsDir)) {
16
- childProcess.execSync(`rm -rf ${domainAssetsDir}`);
17
- childProcess.execSync(`mv ${assetsDir} ${domainAssetsDir}`);
18
- } else {
19
- console.log("Assets directory not found");
20
- }
21
- }
22
-
23
- async function main() {
24
- await prepareAssetsDir();
25
- }
26
-
27
- main().catch((err) => {
28
- console.error("Error", err?.stdout?.toString() || err);
29
- process.exit(1);
30
- });
@@ -1,54 +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/npm-deps/pkg-dir";
7
-
8
- // Interfaz para abstraer la DB
9
- export interface Database {
10
- read(): Promise<RenderDB>;
11
- write(renderDB: RenderDB): Promise<void>;
12
- }
13
-
14
- export class JsonDatabase implements Database {
15
- private readonly dbFilePath: string;
16
-
17
- constructor(customDBPath?: string) {
18
- this.dbFilePath =
19
- customDBPath ??
20
- path.join(
21
- pkgDirSync({ cwd: path.resolve(__dirname, "../../..") }) ?? "",
22
- ".cx-cache",
23
- "db.json",
24
- );
25
- }
26
-
27
- async read(customDBFilePath?: string): Promise<RenderDB> {
28
- try {
29
- const raw = await fsp.readFile(customDBFilePath || this.dbFilePath, "utf-8");
30
- return JSON.parse(raw) as RenderDB;
31
- } catch (error) {
32
- if (error instanceof Error) {
33
- console.error(`Error reading DB file at ${this.dbFilePath}:`, error.message);
34
- } else {
35
- console.error(`Unknown error reading DB file at ${this.dbFilePath}:`, error);
36
- }
37
- throw error;
38
- }
39
- }
40
-
41
- async write(renderDB: RenderDB): Promise<void> {
42
- try {
43
- await fsp.mkdir(path.dirname(this.dbFilePath), { recursive: true });
44
- await fsp.writeFile(this.dbFilePath, JSON.stringify(renderDB, null, 2));
45
- } catch (error) {
46
- if (error instanceof Error) {
47
- console.error(`Error writing to DB file at ${this.dbFilePath}:`, error.message);
48
- } else {
49
- console.error(`Unknown error writing to DB file at ${this.dbFilePath}:`, error);
50
- }
51
- throw error;
52
- }
53
- }
54
- }
@@ -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/npm-deps/pkg-dir";
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 };
@@ -1,59 +0,0 @@
1
- import type { RenderInfo } from "./global";
2
-
3
- const RENDER_MODE = {
4
- FROM_SCRATCH: "FROM_SCRATCH",
5
- INCREMENTAL: "INCREMENTAL",
6
- IDLE: "IDLE",
7
- } as const;
8
-
9
- type RenderMode = (typeof RENDER_MODE)[keyof typeof RENDER_MODE];
10
-
11
- export interface RenderModeTuple {
12
- renderMode: RenderMode;
13
- reason?: string;
14
- }
15
-
16
- type DomainLike = string;
17
-
18
- type RenderDB = {
19
- proDomainPrefix: string;
20
- griddoVersion: string;
21
- buildReportFileName: string;
22
- sortedDomains: Array<DomainLike>;
23
- paths: {
24
- root: string;
25
- cx: string;
26
- ssg: string;
27
- cxCache: string;
28
- components: string;
29
- exportsDir: string;
30
- };
31
- domains: {
32
- [key: DomainLike]: {
33
- renderMode?: RenderMode;
34
- shouldBeRendered?: boolean;
35
- isRendering?: boolean;
36
- renderInfo?: RenderInfo;
37
- renderModeReason?: string;
38
- };
39
- };
40
- };
41
-
42
- interface Report {
43
- authControl:
44
- | {
45
- Authorization: string;
46
- "Cache-Control": string;
47
- lang?: string | undefined;
48
- }
49
- | undefined;
50
- sites: Array<{
51
- siteId: number;
52
- publishHashes: Array<string>;
53
- siteHash: string | null;
54
- unpublishHashes: Array<string>;
55
- publishPagesIds: Array<number>;
56
- }>;
57
- }
58
-
59
- export { RENDER_MODE, type RenderDB, type RenderMode, type Report };
@@ -1,38 +0,0 @@
1
- import type { Artifacts } from "../types/global";
2
-
3
- import path from "node:path";
4
-
5
- import { getRenderPathsFromDB } from "./render";
6
-
7
- /**
8
- * Returns the artifacts of CX.
9
- */
10
- async function getCxArtifacts(domain: string): Promise<Artifacts> {
11
- const { __exports, __cache, __root, __ssg } = await getRenderPathsFromDB({ domain });
12
-
13
- return {
14
- initials: [
15
- __exports, // `<root>/exports/<domain>`
16
- __cache, // `<root>/.cx-cache/<domain>`
17
- path.join(__exports, "logs"),
18
- path.join(__root, "store"),
19
- path.join(__root, "apiCache"),
20
- ],
21
- disposables: [
22
- path.join(__root, "store"),
23
- path.join(__root, "apiCache"),
24
- path.join(__root, "dist"),
25
- path.join(__root, "dist-restored"),
26
- path.join(__root, "assets"),
27
- path.join(__root, "render-detail-log.txt"),
28
- path.join(__ssg, "domains.json"),
29
- path.join(__ssg, "domains.txt"),
30
- path.join(__ssg, "render-metadata.json"),
31
- ],
32
- cacheables: [],
33
- archivables: ["dist", "assets"],
34
- restaurable: ["dist"],
35
- };
36
- }
37
-
38
- export { getCxArtifacts };
@@ -1,34 +0,0 @@
1
- //
2
- // Brush adds color to a string|number, it does not print it!
3
- // Its simple, no log, no chains, just color in a string|number
4
- // usage:
5
- // console.log(brush.green("sucess!"))
6
- //
7
-
8
- const RESET = "\x1b[0m";
9
- const CODES = {
10
- black: "\x1b[30m",
11
- red: "\x1b[31m",
12
- green: "\x1b[32m",
13
- yellow: "\x1b[33m",
14
- blue: "\x1b[34m",
15
- magenta: "\x1b[35m",
16
- cyan: "\x1b[36m",
17
- white: "\x1b[37m",
18
- gray: "\x1b[90m",
19
- bold: "\x1b[1m",
20
- dim: "\x1b[2m",
21
- } as const;
22
-
23
- type ColorFunction = (text: string | number) => string;
24
- type ColorName = keyof typeof CODES;
25
- type Brush = Record<ColorName, ColorFunction>;
26
-
27
- const brush = {} as Brush;
28
-
29
- for (const color in CODES) {
30
- const key = color as ColorName;
31
- brush[key] = (text: string | number) => `${CODES[key]}${text}${RESET}`;
32
- }
33
-
34
- export { brush };