@griddo/cx 11.9.17 → 11.10.1
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.
- package/README.md +13 -240
- package/build/commands/end-render.d.ts +0 -1
- package/build/commands/end-render.js +31 -0
- package/build/commands/end-render.js.map +7 -0
- package/build/commands/prepare-assets-directory.js +9 -0
- package/build/commands/prepare-assets-directory.js.map +7 -0
- package/build/commands/prepare-domains-render.js +40 -0
- package/build/commands/prepare-domains-render.js.map +7 -0
- package/build/commands/reset-render.d.ts +0 -1
- package/build/commands/reset-render.js +31 -0
- package/build/commands/reset-render.js.map +7 -0
- package/build/commands/single-domain-upload-search-content.d.ts +1 -0
- package/build/commands/start-render.d.ts +0 -1
- package/build/commands/start-render.js +66 -0
- package/build/commands/start-render.js.map +7 -0
- package/build/commands/upload-search-content.d.ts +0 -1
- package/build/commands/upload-search-content.js +32 -0
- package/build/commands/upload-search-content.js.map +7 -0
- package/build/core/GriddoLog.d.ts +16 -0
- package/build/{utils/health-checks.d.ts → core/check-env-health.d.ts} +4 -2
- package/build/core/db-class.d.ts +11 -0
- package/build/core/db.d.ts +4 -0
- package/build/core/dist-rollback.d.ts +11 -0
- package/build/core/errors.d.ts +26 -0
- package/build/core/fs.d.ts +69 -0
- package/build/core/life-cycle.d.ts +26 -0
- package/build/core/logger.d.ts +18 -0
- package/build/core/objects.d.ts +11 -0
- package/build/core/print-logos.d.ts +5 -0
- package/build/index.d.ts +10 -29
- package/build/index.js +404 -73
- package/build/react/DynamicScript/index.d.ts +4 -0
- package/build/react/GriddoFavicon/index.d.ts +4 -0
- package/build/react/GriddoIntegrations/index.d.ts +3 -4
- package/build/react/GriddoIntegrations/utils.d.ts +7 -6
- package/build/react/GriddoOpenGraph/index.d.ts +10 -0
- package/build/react/index.d.ts +3 -2
- package/build/react/index.js +1 -3
- package/build/{utils → services}/api.d.ts +1 -1
- package/build/services/auth.d.ts +2 -5
- package/build/services/domains.d.ts +3 -4
- package/build/services/manage-sites.d.ts +22 -0
- package/build/services/manage-store.d.ts +32 -0
- package/build/services/navigation.d.ts +16 -16
- package/build/{utils → services}/pages.d.ts +3 -3
- package/build/services/reference-fields.d.ts +3 -3
- package/build/services/render-artifacts.d.ts +6 -0
- package/build/services/render.d.ts +70 -0
- package/build/services/robots.d.ts +2 -19
- package/build/services/sitemaps.d.ts +5 -0
- package/build/services/sites.d.ts +8 -5
- package/build/services/store.d.ts +10 -1
- package/build/shared/context.d.ts +36 -0
- package/build/shared/envs.d.ts +17 -0
- package/build/{errors/errors-data.d.ts → shared/errors.d.ts} +5 -3
- package/build/shared/npm-modules/brush.d.ts +18 -0
- package/build/shared/npm-modules/find-up-simple.d.ts +34 -0
- package/build/shared/npm-modules/pkg-dir.d.ts +7 -0
- package/build/shared/npm-modules/xml-parser.d.ts +4 -0
- package/build/{types → shared/types}/api.d.ts +18 -18
- package/build/{types → shared/types}/global.d.ts +15 -16
- package/build/{types → shared/types}/navigation.d.ts +5 -5
- package/build/{types → shared/types}/pages.d.ts +9 -9
- package/build/shared/types/render.d.ts +56 -0
- package/build/{types → shared/types}/sites.d.ts +18 -19
- package/build/shared/types.d.ts +15 -0
- package/build/ssg-adapters/gatsby/actions/clean.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/close.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/data.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/init.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/logs.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/meta.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/prepare.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/relocation.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/restore.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/ssg.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/sync.d.ts +3 -0
- package/build/ssg-adapters/gatsby/index.d.ts +9 -0
- package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +4 -0
- package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +15 -0
- package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +7 -0
- package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +7 -0
- package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +18 -0
- package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +26 -0
- package/build/ssg-adapters/gatsby/shared/types.d.ts +34 -0
- package/cli.mjs +231 -0
- package/exporter/build-esbuild.noop +42 -0
- package/exporter/build.sh +16 -24
- package/exporter/commands/README.md +142 -0
- package/exporter/commands/end-render.ts +53 -87
- package/exporter/commands/prepare-assets-directory.ts +35 -0
- package/exporter/commands/prepare-domains-render.ts +150 -33
- package/exporter/commands/reset-render.ts +13 -8
- package/exporter/commands/single-domain-upload-search-content.ts +206 -0
- package/exporter/commands/start-render.ts +14 -65
- package/exporter/commands/upload-search-content.ts +204 -26
- package/exporter/core/GriddoLog.ts +45 -0
- package/exporter/core/check-env-health.ts +203 -0
- package/exporter/core/db-class.ts +54 -0
- package/exporter/core/db.ts +33 -0
- package/exporter/core/dist-rollback.ts +49 -0
- package/exporter/core/errors.ts +93 -0
- package/exporter/core/fs.ts +385 -0
- package/exporter/{utils → core}/images.ts +1 -6
- package/exporter/{utils → core}/instance.ts +9 -13
- package/exporter/core/life-cycle.ts +73 -0
- package/exporter/core/logger.ts +137 -0
- package/exporter/core/objects.ts +37 -0
- package/exporter/core/print-logos.ts +21 -0
- package/exporter/index.ts +14 -56
- package/exporter/react/DynamicScript/index.tsx +33 -0
- package/exporter/react/{Favicon → GriddoFavicon}/index.tsx +3 -9
- package/exporter/react/GriddoIntegrations/index.tsx +17 -23
- package/exporter/react/GriddoIntegrations/utils.ts +24 -12
- package/exporter/react/GriddoOpenGraph/index.tsx +39 -0
- package/exporter/react/index.tsx +3 -9
- package/exporter/services/api.ts +306 -0
- package/exporter/services/auth.ts +8 -10
- package/exporter/services/domains.ts +23 -8
- package/exporter/services/manage-sites.ts +116 -0
- package/exporter/services/manage-store.ts +173 -0
- package/exporter/services/navigation.ts +12 -18
- package/exporter/{utils → services}/pages.ts +27 -92
- package/exporter/services/reference-fields.ts +14 -32
- package/exporter/services/render-artifacts.ts +44 -0
- package/exporter/services/render.ts +229 -0
- package/exporter/services/robots.ts +33 -61
- package/exporter/services/sitemaps.ts +129 -0
- package/exporter/services/sites.ts +40 -28
- package/exporter/services/store.ts +354 -321
- package/exporter/shared/context.ts +49 -0
- package/exporter/{constants → shared}/endpoints.ts +12 -11
- package/exporter/shared/envs.ts +58 -0
- package/exporter/{errors/errors-data.ts → shared/errors.ts} +24 -14
- package/exporter/shared/npm-modules/README.md +36 -0
- package/exporter/shared/npm-modules/brush.ts +34 -0
- package/exporter/shared/npm-modules/find-up-simple.ts +100 -0
- package/exporter/shared/npm-modules/pkg-dir.ts +17 -0
- package/exporter/shared/npm-modules/xml-parser.ts +57 -0
- package/exporter/{types → shared/types}/api.ts +40 -41
- package/exporter/{types → shared/types}/global.ts +17 -21
- package/exporter/{types → shared/types}/navigation.ts +3 -3
- package/exporter/{types → shared/types}/pages.ts +10 -11
- package/exporter/shared/types/render.ts +65 -0
- package/exporter/{types → shared/types}/sites.ts +18 -19
- package/exporter/shared/types.ts +15 -0
- package/exporter/ssg-adapters/gatsby/actions/clean.ts +26 -0
- package/exporter/ssg-adapters/gatsby/actions/close.ts +17 -0
- package/exporter/ssg-adapters/gatsby/actions/data.ts +22 -0
- package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +10 -0
- package/exporter/ssg-adapters/gatsby/actions/init.ts +12 -0
- package/exporter/ssg-adapters/gatsby/actions/logs.ts +10 -0
- package/exporter/ssg-adapters/gatsby/actions/meta.ts +13 -0
- package/exporter/ssg-adapters/gatsby/actions/prepare.ts +9 -0
- package/exporter/ssg-adapters/gatsby/actions/relocation.ts +15 -0
- package/exporter/ssg-adapters/gatsby/actions/restore.ts +21 -0
- package/exporter/ssg-adapters/gatsby/actions/ssg.ts +12 -0
- package/exporter/ssg-adapters/gatsby/actions/sync.ts +65 -0
- package/exporter/ssg-adapters/gatsby/index.ts +117 -0
- package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +17 -0
- package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +128 -0
- package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +75 -0
- package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +58 -0
- package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +33 -0
- package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +298 -0
- package/exporter/ssg-adapters/gatsby/shared/types.ts +35 -0
- package/gatsby-browser.tsx +41 -58
- package/gatsby-config.ts +10 -17
- package/gatsby-node.ts +20 -79
- package/gatsby-ssr.tsx +2 -1
- package/package.json +41 -78
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
- package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
- package/src/components/Head.tsx +28 -73
- package/src/components/template.tsx +6 -29
- package/src/gatsby-node-utils.ts +81 -2
- package/src/html.tsx +2 -11
- package/src/types.ts +3 -3
- package/tsconfig.commands.json +36 -0
- package/tsconfig.exporter.json +21 -0
- package/tsconfig.json +5 -3
- package/build/adapters/gatsby/index.d.ts +0 -4
- package/build/adapters/gatsby/utils.d.ts +0 -26
- package/build/artifacts/index.d.ts +0 -6
- package/build/constants/envs.d.ts +0 -37
- package/build/constants/index.d.ts +0 -57
- package/build/end-render.js +0 -74
- package/build/end-render.js.map +0 -7
- package/build/errors/index.d.ts +0 -15
- package/build/index.js.map +0 -7
- package/build/prepare-domains-render.js +0 -73
- package/build/prepare-domains-render.js.map +0 -7
- package/build/react/Favicon/index.d.ts +0 -5
- package/build/registers/api.d.ts +0 -9
- package/build/registers/gatsby.d.ts +0 -9
- package/build/registers/index.d.ts +0 -3
- package/build/reset-render.js +0 -74
- package/build/reset-render.js.map +0 -7
- package/build/services/register.d.ts +0 -36
- package/build/services/settings.d.ts +0 -4
- package/build/start-render.js +0 -100
- package/build/start-render.js.map +0 -7
- package/build/upload-search-content.js +0 -74
- package/build/upload-search-content.js.map +0 -7
- package/build/utils/alerts.d.ts +0 -3
- package/build/utils/cache.d.ts +0 -35
- package/build/utils/core-utils.d.ts +0 -107
- package/build/utils/create-build-data.d.ts +0 -8
- package/build/utils/domains.d.ts +0 -13
- package/build/utils/folders.d.ts +0 -53
- package/build/utils/loggin.d.ts +0 -51
- package/build/utils/render.d.ts +0 -13
- package/build/utils/searches.d.ts +0 -15
- package/build/utils/sites.d.ts +0 -31
- package/build/utils/store.d.ts +0 -81
- package/cx.config.d.ts +0 -5
- package/cx.config.js +0 -36
- package/exporter/adapters/gatsby/index.ts +0 -182
- package/exporter/adapters/gatsby/utils.ts +0 -186
- package/exporter/artifacts/README.md +0 -34
- package/exporter/artifacts/index.ts +0 -33
- package/exporter/commands/move-assets.ts +0 -11
- package/exporter/constants/envs.ts +0 -94
- package/exporter/constants/index.ts +0 -129
- package/exporter/errors/index.ts +0 -40
- package/exporter/registers/api.ts +0 -14
- package/exporter/registers/gatsby.ts +0 -14
- package/exporter/registers/index.ts +0 -4
- package/exporter/services/register.ts +0 -113
- package/exporter/services/settings.ts +0 -17
- package/exporter/utils/alerts.ts +0 -29
- package/exporter/utils/api.ts +0 -243
- package/exporter/utils/cache.ts +0 -142
- package/exporter/utils/core-utils.ts +0 -458
- package/exporter/utils/create-build-data.ts +0 -17
- package/exporter/utils/domains.ts +0 -39
- package/exporter/utils/folders.ts +0 -320
- package/exporter/utils/health-checks.ts +0 -64
- package/exporter/utils/loggin.ts +0 -184
- package/exporter/utils/render.ts +0 -71
- package/exporter/utils/searches.ts +0 -156
- package/exporter/utils/sites.ts +0 -312
- package/exporter/utils/store.ts +0 -314
- package/src/README.md +0 -7
- package/start-render.js +0 -7
- /package/build/commands/{move-assets.d.ts → prepare-assets-directory.d.ts} +0 -0
- /package/build/{utils → core}/images.d.ts +0 -0
- /package/build/{utils → core}/instance.d.ts +0 -0
- /package/build/react/{Favicon → GriddoFavicon}/utils.d.ts +0 -0
- /package/build/{constants → shared}/endpoints.d.ts +0 -0
- /package/build/{types → shared/types}/templates.d.ts +0 -0
- /package/exporter/react/{Favicon → GriddoFavicon}/utils.ts +0 -0
- /package/exporter/{types → shared/types}/templates.ts +0 -0
package/README.md
CHANGED
|
@@ -1,246 +1,19 @@
|
|
|
1
|
-
# Griddo
|
|
1
|
+
# Griddo Generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Este documento describe el flujo del render en Griddo Generator y otros aspectos técnicos relevantes.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- [Render flow](./docs/RENDER-FLOW.md)
|
|
8
|
+
- [Incremental render flow](./docs/INCREMENTAL-RENDER.md)
|
|
9
|
+
- [Directorios](./docs/DIRECTORIES.md)
|
|
10
|
+
- [CLI](./docs//CLI.md)
|
|
8
11
|
|
|
9
|
-
\*Para los casos del Adapter y los “scripts para infra”, estos utilizarán directamente el código Typescript de la biblioteca de CX. Para el caso del SSG, este utilizará el código bundlelizado disponible en `@griddo/cx` y `griddo/cx/react`
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
## TODO:
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## Exports
|
|
19
|
-
|
|
20
|
-
CX tiene dos exports separados: **main y react**.
|
|
21
|
-
|
|
22
|
-
- **main** se exporta en `@griddo/cx` . Es código que se ejecuta en un entorno nodejs.
|
|
23
|
-
- **react** se exporta en `@griddo-cx/react` . Es código React :)
|
|
24
|
-
|
|
25
|
-
**Ejemplo de import**
|
|
26
|
-
|
|
27
|
-
```tsx
|
|
28
|
-
// React import
|
|
29
|
-
import { GriddoIntegrations } from "@griddo/cx/react";
|
|
30
|
-
// Core import
|
|
31
|
-
import {
|
|
32
|
-
IS_COMPONENT_LIBRARY,
|
|
33
|
-
PROJECT_ALIASES,
|
|
34
|
-
resolveComponentsPath,
|
|
35
|
-
} from "@griddo/cx";
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Bundle
|
|
39
|
-
|
|
40
|
-
El bundle del código TypeScript se genera con [esbuild](https://esbuild.github.io/). Compilando el código a CommonJS junto con las definiciones de tipos.
|
|
41
|
-
|
|
42
|
-
Se puede ejecutar el bundle de todo CX con `yarn run build` desde `packages/griddo-cx` . Esto creará los distintos exports: _node_, _react_ y también los scripts para _infra_: reset-render, build-complete y upload-search-content junto con los archivos de definición de tipos.
|
|
43
|
-
|
|
44
|
-
Este comando, `yarn run build` se ejecuta en el despliegue del monorepo, npm prepare, etc. No es necesario que manualmente hagamos un build para los despliegues.
|
|
45
|
-
|
|
46
|
-
# Features
|
|
47
|
-
|
|
48
|
-
## Archivo de configuración
|
|
49
|
-
|
|
50
|
-
CX tiene un archivo de configuración en el raíz del package `griddo-cx/cx.config.js` donde se establecen ciertos valores globales para todo el package.
|
|
51
|
-
|
|
52
|
-
Los siguientes puntos están incluidos en el archivo de configuración y deben ser leídos de este, evitando hardcodear o volver a calcularlos en el resto del código.
|
|
53
|
-
|
|
54
|
-
```jsx
|
|
55
|
-
const config = {
|
|
56
|
-
proDomain: "pro-", // Prefijo para los dominios "pro"
|
|
57
|
-
griddoVersion, // Versión de griddo obtenida del package.json
|
|
58
|
-
buildReportFileName: "build-report.json", // Archivo de reporte de render
|
|
59
|
-
// función que resuelve la ruta absoluta a los placeholders
|
|
60
|
-
paths: (domain) => ({
|
|
61
|
-
__cache: path.join(CX_CACHE_DIR, domain || ""),
|
|
62
|
-
__components: COMPONENTS_DIR,
|
|
63
|
-
__cx: CX_ROOT_DIR,
|
|
64
|
-
__exports: path.join(EXPORTS_DIR, domain || ""),
|
|
65
|
-
__root: REPO_ROOT_DIR,
|
|
66
|
-
__ssg: SSG_DIR,
|
|
67
|
-
}),
|
|
68
|
-
};
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
El contenido del archivo de configuración se leerá con la función `getConfig()` donde sea que necesitemos acceder a la misma.
|
|
72
|
-
|
|
73
|
-
**Ejemplo**
|
|
74
|
-
|
|
75
|
-
```tsx
|
|
76
|
-
const config = getConfig()
|
|
77
|
-
const { proDomain, ... } = config
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Dominio \*pro-\*\*
|
|
81
|
-
|
|
82
|
-
En los renders de Griddo se diferencia cuando el render es de un dominio de producción, esto es que el dominio interno empieza por `pro-` , por ejemplo `pro-griddo`
|
|
83
|
-
|
|
84
|
-
Este `pro-` se especifica directamente y una sola vez en el archivo de configuración.
|
|
85
|
-
|
|
86
|
-
### Versión de Griddo
|
|
87
|
-
|
|
88
|
-
Si es necesario obtener la versión de CX la podemos tomar directamente del archivo de configuración
|
|
89
|
-
|
|
90
|
-
### Sistema de paths interno
|
|
91
|
-
|
|
92
|
-
Mediante el archivo de configuración se establecen unas rutas absolutas globales a todo CX e instancia (ya sea instancia interna del monorepo o la de un cliente) que nos ayudará a orquestar los artefactos durante los LifeCycles de un render. Un uso parecido a los `__dirname` o `__filename` de javascript CommonJS.
|
|
93
|
-
|
|
94
|
-
**Rutas con el dominio actual concatenado**
|
|
95
|
-
|
|
96
|
-
Ya que la mayoría de las veces el uso de estas rutas son durante el render de un dominio, la ruta incluirá el dominio para así hacer operaciones más fácilmente sin tener que estar adjuntándolo (concat) constantemente. Esto es así para los placeholders `__exports` y `__cache` . Para ello a `paths()` hay que pasarle el dominio como único argumento cuando obtengamos las rutas con `config.paths()`
|
|
97
|
-
|
|
98
|
-
**Ejemplo**
|
|
99
|
-
|
|
100
|
-
```tsx
|
|
101
|
-
const { __exports, __cache } = getConfig().paths("mi-dominio");
|
|
102
|
-
console.log(__exports); // ...export/sites/**mi-dominio**
|
|
103
|
-
console.log(__cache); // ...griddo-cx/.cx-cache/**mi-dominio**
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
Esta son las rutas existentes.
|
|
107
|
-
|
|
108
|
-
- `__cx` La ruta absoluta del package de CX
|
|
109
|
-
- `__ssg` La ruta absoluta del SGG configurado
|
|
110
|
-
- `__exports` La ruta donde se aloja el render final
|
|
111
|
-
- `__cache` La ruta del caché de CX, donde se guardan artefactos entre renders
|
|
112
|
-
- `__components` La ruta de la instancia. En el monorepo la de `griddo-components`
|
|
113
|
-
- `__root` El directorio raíz siempre, en el monorepo y en la instancia. (uso residual)
|
|
114
|
-
|
|
115
|
-
**Ejemplo de uso real**
|
|
116
|
-
|
|
117
|
-
```tsx
|
|
118
|
-
import { getConfig } from "./utils/config";
|
|
119
|
-
|
|
120
|
-
// Sin dominio
|
|
121
|
-
const config = await getConfig();
|
|
122
|
-
const { __cx, __ssg } = config.paths();
|
|
123
|
-
const storeDir = path.join(__cx, "store");
|
|
124
|
-
const templateFile = path.join(__ssg, "src/components/template.tsx");
|
|
125
|
-
|
|
126
|
-
// Con dominio
|
|
127
|
-
const { __cache } = config.paths("pre-griddo");
|
|
128
|
-
console.log(__exports); // /griddo/packages/griddo-cx/.cx-cache/**pre-griddo**
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
## LifeCycles
|
|
132
|
-
|
|
133
|
-
Los LifeCycles se utilizan dentro del contexto de un _Adapter_. Se usa a través de la función `doLifeCycle` que ejecuta un batch de funciones (`actions`) de forma secuencial. Informando por consola del inicio, fin y tiempo invertido en ejecutar todas las funciones del `actions`, manejando cualquier error en las mismas. En caso de error, es posible indicar un número de _attempts_ que hará que se ejecute de nuevo el clico de vida las veces indicadas.
|
|
134
|
-
|
|
135
|
-
En CX existen estos LifeCycles: `Prepare`, `Restore`, `Data`, `SSG`, `Relocation`, `Meta`, `Archive`, `Clean`, `HealthCheck` y uno de `__DEBUG__` internamente son iguales (usan `doLifeCycle`) y se utilizan estos distintos nombres para identificarlos dentro de un render, poner distintos _attempts_, etc..
|
|
136
|
-
|
|
137
|
-
**Ejemplo:**
|
|
138
|
-
|
|
139
|
-
```tsx
|
|
140
|
-
await doLifeCycle({
|
|
141
|
-
name: "SSG",
|
|
142
|
-
attempts: 2, // intentará hacer **todos** las actions dos veces si hay un error en alguno de ellos
|
|
143
|
-
actions: [func1, func2, func3],
|
|
144
|
-
});
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
# Scripts para infra.
|
|
148
|
-
|
|
149
|
-
Como hemos visto uno de los consumidores de CX son scripts “individuales” que están alojados en `griddo-cx/src/scripts` Estos scripts son siempre llamados por infra, o por el desarrollador cuando se hacen render en local.
|
|
150
|
-
|
|
151
|
-
## `start-render`
|
|
152
|
-
|
|
153
|
-
CX es una biblioteca por lo tanto no tiene nada ejecutable como tal, no hay un entry point desde el punto de vista del _package_. En el package.json existe un binario `griddo-cx` que usa infra/API para ejecutar un render, este binario apunta a `griddo-cx/start-rener.js` con el que se desencadena el proceso de publicación.
|
|
154
|
-
|
|
155
|
-
## `reset-render`
|
|
156
|
-
|
|
157
|
-
Lo ejecuta infra mediante `yarn run reset-render` . Este resetea la API en caso de que un render salga mal. De esa manera la API al ser preguntada volverá a comunicar que hay un render pendiente y comenzará con ello de nuevo.
|
|
158
|
-
|
|
159
|
-
Si no se llamase correctamente al script, la API se quedaría esperando a que finalice el render “eternamente”. Hay un time-out de X horas.
|
|
160
|
-
|
|
161
|
-
## `build-complete`
|
|
162
|
-
|
|
163
|
-
Lo ejecuta infra mediante `yarn run build-complete` cuando un render acaba de manera exitosa y el contenido ha sido subido al servidor, es decir, cuando se ha completado **una publicación**. Este script envía a la API información del render y le comunica que este ha terminado y que está disponible para un rrnuevo render.
|
|
164
|
-
|
|
165
|
-
## `upload-search-content`
|
|
166
|
-
|
|
167
|
-
Lo ejecuta infra mediante `yarn run upload-search-content` cuando un render ha acabado o con cierta frecuencia. Sube contenido de los estáticos del render a un endpoint para el uso en buscadores.
|
|
168
|
-
|
|
169
|
-
# Adapter
|
|
170
|
-
|
|
171
|
-
Un Adapter es una función que se ejecuta en el script `start-render.js` que es el que se triggea cuando API avisa de un nuevo render. Los Adapters están en el directorio `griddo-cx/exporter/adapters`
|
|
172
|
-
|
|
173
|
-
El Adapter es el responsable de manejar el proceso de render mediante las utilidades de la biblioteca. En el proceso puede hacer lo que estime oportuno salvando ciertas obligaciones para que un render sea Griddo-compliant.
|
|
174
|
-
|
|
175
|
-
<aside>
|
|
176
|
-
💡 Los Adapters utilizarán el código TypeScript de CX, no el bundlelizado. Ya que el propio adapter también se bundleliza.
|
|
177
|
-
|
|
178
|
-
</aside>
|
|
179
|
-
|
|
180
|
-
### **Obligaciones de un Adapter**
|
|
181
|
-
|
|
182
|
-
**Exports**
|
|
183
|
-
|
|
184
|
-
**Dist**
|
|
185
|
-
|
|
186
|
-
Dejar una carpeta con los archivos estáticos finales en el path `__exports` , que es una carpeta `exports/sites/<dominio>/dist` donde `dominio` es cada dominio de la instancia de Griddo. Una vez terminado el render, _infra_ tomará esa carpeta y la subirá. Infra la sube mediante sincronización por lo que siempre tiene que estar actualizada y con la totalidad de los datos. Si en la carpeta destino hay un archivo que no existe en la carpeta fuente `exports/sites/<dominio>/dist` se borrará.
|
|
187
|
-
|
|
188
|
-
**Assets**
|
|
189
|
-
|
|
190
|
-
Igualmente dejar una carpeta con los “assets” de javascript. Esto es verdad en el mundo Gatsby no sabremos qué pasará con otros frameworks.
|
|
191
|
-
|
|
192
|
-
**Caches**
|
|
193
|
-
|
|
194
|
-
El adapter deberá manejar manualmente la caché de Griddo utilizando las funciones `moveDirsSync`, `copyDirsSync` y `removeDirsSync`.
|
|
195
|
-
|
|
196
|
-
La caché de Griddo son dos directorios que se crean en `griddo-cx` por cada render y dominio: `store` y `apiCache` . Para facilitar el trabajo CX cuenta con placeholders para las rutas, en este caso `__cache` que haría referencia `griddo-cx/.cx-cache/<domain>`
|
|
197
|
-
|
|
198
|
-
```tsx
|
|
199
|
-
griddo-cx
|
|
200
|
-
|-.cx-cache
|
|
201
|
-
|- store
|
|
202
|
-
|- apiCache
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
¿Cómo se maneja la caché? ¿Qué hago con ella?
|
|
206
|
-
|
|
207
|
-
Los datos de la caché se generan de forma automática en `griddo-cx`El manejo se basa en _restaurar (Restore)_, _archivar_ (Arhive) o _invalidar (Clean)_ los directorios de la caché, tanto `store` como `apiCache`
|
|
208
|
-
|
|
209
|
-
**Restaurando la caché**
|
|
210
|
-
|
|
211
|
-
Cuando se inicia un render debemos mover tanto `store` como `apiCache` que estarán dentro de `griddo-cx/.rendrr-cache/<dominio>` al raíz de CX `griddo-cx` para que el proceso de render haga uso de las mismas.
|
|
212
|
-
|
|
213
|
-
**Archivando la caché**
|
|
214
|
-
|
|
215
|
-
Cuando el render de un dominio termina correctamente, se deben mover las carpetas `store` y `apiCache` a la carpeta de caches `griddo-cx/.cx-cache/<domain>` para poder restaurarlas en un próximo render.
|
|
216
|
-
|
|
217
|
-
**Invalidando la caché**
|
|
218
|
-
|
|
219
|
-
Si un render ha dado error pueden quedarse en el raíz de CX las carpetas `store` y `apiCache`. **Estas deben ser borradas** antes de la nueva fase de restauración. De hecho probablemente no exista nada que restaurar porque el render dio error. En ese caso lo que ocurre es que efectivamente no hay nada que restaurar y habrá que descargarse de nuevo todos los datos.
|
|
220
|
-
|
|
221
|
-
A su vez, en cada despliegue que exista en la instancia también se borrarán ya que de alguna manera se alojan en lo que sería el `node_modules` de la instancia. Y se borrará CX enteramente.
|
|
222
|
-
|
|
223
|
-
<aside>
|
|
224
|
-
💡 Coming soon: Gestión automática de la caché de Griddo (no de los frameworks SSGS)
|
|
225
|
-
|
|
226
|
-
</aside>
|
|
227
|
-
|
|
228
|
-
# Logs
|
|
229
|
-
|
|
230
|
-
…
|
|
231
|
-
|
|
232
|
-
# Errores
|
|
233
|
-
|
|
234
|
-
…
|
|
235
|
-
|
|
236
|
-
# Testing
|
|
237
|
-
|
|
238
|
-
…
|
|
239
|
-
|
|
240
|
-
# FAQ’s
|
|
241
|
-
|
|
242
|
-
### ¿Griddo procesa imágenes en tiempo de render?
|
|
243
|
-
|
|
244
|
-
No, los proyectos actuales de Griddo se apoyan en imágenes alojadas en remoto, en concreto en un servicio externo “DAM” propiedad de Secuoyas. Este servicio ofrece las transformaciones necesarias. Existen un componente de React en Griddo `<GriddoImage>` que las instancias pueden utilizar y que se integra con el “DAM”.
|
|
245
|
-
|
|
246
|
-
Algunas de las primeras instancias utilizan la misma estrategia con cloudinary, usando un componente de React proporcionado también por Griddo: `<CloudinaryImage>`
|
|
15
|
+
- Implementar `--root` en el CLI, solo en el `prepare-domains-render` y este ya lo deja escrito en `db.json`
|
|
16
|
+
- Usar el CLI en infra.
|
|
17
|
+
- Optimizar el caso en que un dominio solo tenga páginas para despublicar y/o eliminar. En esta situación, no sería necesario ejecutar Gatsby; bastaría con una sincronización para eliminar los archivos html y page-data correspondientes y regenerar los sitemaps.
|
|
18
|
+
- Rollback. Ver qué hacemos con el dist-backup... copy y después rsync.
|
|
19
|
+
- Usar db.json en lugar de archivo domains si es posible... (actualmente se lee domains.json)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";var Ae=Object.create;var J=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,Pe=Object.prototype.hasOwnProperty;var Fe=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Te(e))!Pe.call(r,n)&&n!==t&&J(r,n,{get:()=>e[n],enumerable:!(o=Oe(e,n))||o.enumerable});return r};var c=(r,e,t)=>(t=r!=null?Ae(xe(r)):{},Fe(e||!r||!r.__esModule?J(t,"default",{value:r,enumerable:!0}):t,r));var Ie=c(require("node:fs/promises")),_e=c(require("node:path"));var ae=c(require("node:path"));var Be="\x1B[0m",W={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",gray:"\x1B[90m",bold:"\x1B[1m",dim:"\x1B[2m"},d={};for(let r in W){let e=r;d[e]=t=>`${W[e]}${t}${Be}`}var O={FROM_SCRATCH:"FROM_SCRATCH",INCREMENTAL:"INCREMENTAL",IDLE:"IDLE",ERROR:"ERROR",COMPLETED:"COMPLETED"};var v=c(require("node:fs/promises")),L=c(require("node:path"));var X=c(require("node:path"));var V=c(require("node:fs"));var w=c(require("node:path")),Y=c(require("node:process")),q=require("node:url"),K=r=>r instanceof URL?(0,q.fileURLToPath)(r):r;function Z(r,e={}){let{cwd:t=Y.default.cwd(),type:o="file",stopAt:n}=e,a=w.default.resolve(K(t)??""),{root:f}=w.default.parse(a),p=n?w.default.resolve(a,K(n)):f,u=w.default.isAbsolute(r);for(;;){let _=u?r:w.default.join(a,r);try{let b=V.default.statSync(_,{throwIfNoEntry:!1});if(o==="file"&&b?.isFile()||o==="directory"&&b?.isDirectory())return _}catch{}if(a===p||a===f)break;a=w.default.dirname(a)}}function z(r){let{cwd:e}=r||{},t=Z("package.json",{cwd:e});return t&&X.default.dirname(t)}var{env:s}=process;function y(r){if(!r)return!1;switch(r.trim().toLowerCase()){case"1":case"true":case"yes":case"y":case"on":return!0;default:return!1}}var ir=s.GRIDDO_API_URL||s.API_URL,sr=s.GRIDDO_PUBLIC_API_URL||s.PUBLIC_API_URL,Q=s.botEmail||s.GRIDDO_BOT_USER,ee=s.botPassword||s.GRIDDO_BOT_PASSWORD,ar=Number.parseInt(s.GRIDDO_API_CONCURRENCY_COUNT||"10"),cr=y(s.GRIDDO_SKIP_BUILD_CHECKS),C=y(s.GRIDDO_BUILD_LOGS),re=Number.parseInt(s.GRIDDO_BUILD_LOGS_BUFFER_SIZE||"500"),dr=y(s.GRIDDO_SSG_VERBOSE_LOGS),fr=y(s.GRIDDO_SEARCH_FEATURE),pr=s.GRIDDO_ASSET_PREFIX||s.ASSET_PREFIX,lr=s.GRIDDO_REACT_APP_INSTANCE||s.REACT_APP_INSTANCE,ur=y(s.GRIDDO_AI_EMBEDDINGS),te=y(s.GRIDDO_VERBOSE_LOGS),mr=y(s.GRIDDO_USE_DIST_BACKUP),gr=y(s.GRIDDO_SSG_BUNDLE_ANALYZER);var i=class r{constructor(){}static verbose(...e){te&&console.log(d.yellow("verbose"),d.dim(e.join(" ")))}static build(...e){C&&r.log(...e)}static info(...e){console.log(`${d.blue("info")} ${e.join(" ")}`)}static success(...e){console.log(`${d.green("success")} ${e.join(" ")}`)}static error(...e){console.error(`${d.red("error")} ${e.join(" ")}`)}static warn(...e){console.warn(`${d.yellow("warn")} ${e.join(" ")}`)}static log(...e){console.log(...e)}};var Ce=z({cwd:L.default.resolve(__dirname,"../../..")})||"",Le=L.default.join(Ce,".griddo/cache"),oe=L.default.join(Le,"db.json");async function m(r=""){let e=r||oe;try{return JSON.parse(await v.default.readFile(e,"utf-8"))}catch(t){throw i.error(`Failed to read DB file at ${e}:`,t),t}}async function G(r,e=""){let t=e||oe;try{await v.default.writeFile(t,JSON.stringify(r,null," "))}catch(o){throw i.error(`Failed to write DB file at ${t}:`,o),o}}var U=c(require("node:fs/promises")),R=c(require("node:path"));var ie=c(require("node:fs/promises"));var k={error:"ArtifactError",message:"There was a problem with an artifact",expected:"An external process may have has modified or deleted one of the artifacts (files and directories).",hint:"Have there been any recent deployments? These can delete directories from the current render."};var ne={error:"LoginError",message:"There was a problem logging in to the API",expected:"This happens if the API is currently not working or the credentials are incorrect."};async function D(r){try{return await ie.default.access(r),!0}catch{return!1}}async function se(r){let e=await m(),{exportsDir:t,exportsDirBackup:o}=e.paths;i.info(`Cleaning exports dir for the domain ${r}`),i.verbose(`Deleting ${R.default.join(t,r)}...`),await U.default.rm(R.default.join(t,r),{recursive:!0,force:!0}),await D(R.default.join(o,r))?(await U.default.cp(R.default.join(o,r),R.default.join(t,r),{recursive:!0}),i.info(`export-backup dir for the domain ${r} found. Restoring before exit...`),i.verbose(`Copying ${R.default.join(o,r)} -> ${R.default.join(t,r)}...`)):i.info("No export-backup found, skipping rollback. Next render will create a new exports dir from scratch...")}var S=class extends Error{constructor(e){super(e instanceof Error?e.message:String(e)),this.name="InternalCXError",this.stack=e instanceof Error?e.stack:""}};function E(r,e){let{error:t,message:o,expected:n,hint:a}=r,f=i.log(d.red(`[ ${t} ]`)),p=[n,a].filter(Boolean).join(`
|
|
2
|
+
`);throw i.log(`
|
|
3
|
+
${f}
|
|
4
|
+
${o}
|
|
5
|
+
${p}
|
|
6
|
+
|
|
7
|
+
${d.red("stack")}
|
|
8
|
+
${JSON.stringify(e,null,2)}`),new S(e)}async function ce(r){try{await r()}catch(e){e instanceof S?i.error("Internal Griddo RenderError"):e instanceof Error?i.error(e.message):i.error(`An unexpected error occurred ${e}`);try{let o=await m(),{root:n}=o.paths;o.needsRollbackOnError?(i.info("Cleaning exports dir..."),i.verbose(`Deleting ${ae.default.join(n,"exports")}...`),await se(o.currentRenderingDomain)):i.info("No rollback needed, skipping...")}catch{i.info("Early render stage, no db.json created yet...")}let t=await m();throw t.domains[t.currentRenderingDomain].isRendering=!1,t.domains[t.currentRenderingDomain].renderMode=O.ERROR,await G(t),e}}var g=process.env.GRIDDO_API_URL,Ge=process.env.GRIDDO_PUBLIC_API_URL,vr=`${g}/ai/embeddings`,kr=`${Ge}/alert`,Ur=`${g}/domains`,Ne=`${g}/sites/all`,ve=`${g}/page`,de=`${g}/login_check`,jr=`${g}/debug/reset-render`,Mr=`${g}/domains/robots`,Hr=`${g}/search`,Jr=`${g}/settings`,ke=`${g}/site/`,fe=[ke,"/build/end"];var j=class{headers;async login(){try{let e=await fetch(de,{method:"POST",headers:{"Content-Type":"application/json",Connection:"close"},body:JSON.stringify({username:Q,password:ee})});if(!e.ok)throw new Error("Error while login in the API");let{token:t}=await e.json();return this.headers={Authorization:`bearer ${t}`,"Cache-Control":"no-store"},this.headers}catch(e){E(ne,e)}}},T=new j;var P=c(require("node:path"));async function pe(r){let e=await m();if(!e.domains[r])throw new Error(d.red(`[!] Error: Domain ${r} not found in DB`));if(!e.domains[r].renderMode)throw new Error(d.red(`[!] Error: Render mode not found for domain ${r}`));return{renderMode:e.domains[r].renderMode,reason:e.domains[r].renderModeReason}}async function x(r){let{domain:e,dbFilePath:t}=r||{},n=(await m(t)).paths;return{__root:n.root,__cache:P.default.join(n.cxCache,e||""),__components:n.components,__cx:n.cx,__sites:n.exportsDir,__exports:P.default.join(n.exportsDir,e||""),__exports_backup:P.default.join(n.exportsDirBackup,e||""),__ssg:n.ssg,__exports_dist:P.default.join(n.exportsDir,e||"","dist")}}async function le(){let r=await m();return{griddoVersion:r.griddoVersion,buildReportFileName:r.buildReportFileName}}var De=c(require("node:crypto")),N=c(require("node:fs/promises")),H=c(require("node:path"));var me=c(require("node:fs/promises"));var I=[],ue=null,F=null,Ue=re;var je=!C;function M(r){je||(I.push(r.toString()),I.length>=Ue&&Me().catch(e=>{i.error("Background log flush failed:",e)}))}async function Me(){if(F&&await F,I.length===0||!ue)return;F=(async()=>{let e=[...I];I.length=0;try{await me.default.appendFile(ue,`${e.join(`
|
|
9
|
+
`)}
|
|
10
|
+
`)}catch(t){I.unshift(...e),i.error("Error flushing logs:",t)}})();try{await F}finally{F=null}}var{env:He}=process,{RETRY_WAIT_SECONDS:Je="4",RETRY_ATTEMPTS:ge="4"}=He;async function Re(r,e,t=""){let{endpoint:o,body:n,cacheKey:a="",attempt:f=1,headers:p,useApiCacheDir:u=!0,logToFile:_=!0}=r,b={endpoint:o,body:n,headers:p,cacheKey:a};if(a&&u){let $=new Date,l=await Ye(b);if(l){if(_){let h=he(l),A=h?`site: ${h}`:"",B=ye(Date.now()-$.getTime());M(`${e} (cache) ${A} ${o} - ${B}s ${t}`)}return l}}try{let $=new Date,l={method:e.toUpperCase(),headers:Object.assign({},p,T.headers)};e.toLowerCase()!=="get"&&n&&(l.body=JSON.stringify(n),l.headers||(l.headers={}),l.headers["Content-Type"]="application/json");let h=await fetch(o,l);if(!h.ok){if(h.status===404)return null;throw new Error(`HTTP ${h.status}: ${h.statusText}`)}let A=await h.json();if(_){let B=he(A),be=B?`site: ${B}`:"",$e=ye(Date.now()-$.getTime());M(`${e} (fetch) ${be} ${o} - ${$e}s ${t}`)}return u&&await Ve(b,A),A}catch($){let l=$;if(f>parseInt(ge))throw i.log(`
|
|
11
|
+
Max attempts ${ge} reached
|
|
12
|
+
--------------------------------------
|
|
13
|
+
- ${e.toUpperCase()} ${o}
|
|
14
|
+
- BODY: ${JSON.stringify(n)}
|
|
15
|
+
- HEADERS: ${JSON.stringify(p)}
|
|
16
|
+
- ERROR: ${l.message}
|
|
17
|
+
--------------------------------------
|
|
18
|
+
`),new S(l);return We(l,{callInfo:{endpoint:o,body:n}}),i.warn(`Waiting for retry: ${e}`,o),await Ke(parseInt(Je)*1e3),Re({endpoint:o,body:n,headers:p,cacheKey:a,attempt:f+1},e,t)}}async function we(r){let{endpoint:e,body:t,headers:o}=r,n=e.endsWith("/distributor")&&`# ReferenceField body: ${JSON.stringify(t)} lang: ${JSON.stringify(o?.lang)}`;return Re(r,"post",n||"")}function We(r,e){let{message:t,stack:o}=r,{callInfo:n}=e,a=[];for(let u of Object.keys(n))a.push(`${u}: ${typeof n[u]=="object"?JSON.stringify(n[u]):n[u]}`);let f=a.join(`
|
|
19
|
+
`),p=`${t}
|
|
20
|
+
${o}`;i.warn(d.red(`
|
|
21
|
+
=============
|
|
22
|
+
|
|
23
|
+
{ Call info }
|
|
24
|
+
${f}
|
|
25
|
+
|
|
26
|
+
{ Error details }
|
|
27
|
+
${p}
|
|
28
|
+
|
|
29
|
+
=============
|
|
30
|
+
`))}function he(r){if(!(typeof r!="object"||r===null||Array.isArray(r)))return"site"in r&&r.site?r.site:void 0}function Ke(r){return new Promise(e=>setTimeout(e,r))}function ye(r,e=3){return Number.parseFloat((r/1e3).toFixed(e))}async function Ee(r){let{__root:e}=await x(),t=H.default.join(e,"apiCache"),o=De.default.createHash("sha256");return o.update(JSON.stringify(r)),`${t}/${o.digest("hex")}`}async function Ve(r,e){let t=typeof e=="string"?e:JSON.stringify(e),o=await Ee(r),n=H.default.dirname(o);await D(n)||await N.default.mkdir(n,{recursive:!0}),await N.default.writeFile(o,t,"utf8")}async function Ye(r){try{let e=await Ee(r),t=await N.default.readFile(e,"utf8");return JSON.parse(t)}catch{return null}}async function Se(r,e){let[t,o]=fe;await we({endpoint:`${t}${r}${o}`,body:e,useApiCacheDir:!1,logToFile:!1})}async function qe(r){let{buildReportFileName:e,domain:t,exportsSiteDir:o}=r,n=_e.default.resolve(o,t,"dist",e);return await D(n)||(i.info(`Build report file "${n}" not found.`),E(k)),JSON.parse(await Ie.default.readFile(n,"utf-8"))}async function Ze(){let{buildReportFileName:r}=await le(),{__sites:e}=await x();await T.login();let[t]=process.argv.slice(2),{renderMode:o,reason:n}=await pe(t);if(o===O.IDLE){i.info(`(From Current Render) [${t}]: Skipping end-render as it is marked as IDLE with the reason ${n}.`);return}let a=await qe({domain:t,exportsSiteDir:e,buildReportFileName:r});i.info(`Sending ending call to ${t} sites`);for(let f of a.sites){f.publishHashes=[...new Set(f.publishHashes)],f.unpublishHashes=[...new Set(f.unpublishHashes)];let{siteId:p,...u}=f;i.info(`Site (${p})`),await Se(p,u)}}async function Xe(){await Ze()}ce(Xe);
|
|
31
|
+
//# sourceMappingURL=end-render.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../exporter/commands/end-render.ts", "../../exporter/core/errors.ts", "../../exporter/shared/npm-modules/brush.ts", "../../exporter/shared/types/render.ts", "../../exporter/core/db.ts", "../../exporter/shared/npm-modules/pkg-dir.ts", "../../exporter/shared/npm-modules/find-up-simple.ts", "../../exporter/shared/envs.ts", "../../exporter/core/GriddoLog.ts", "../../exporter/core/dist-rollback.ts", "../../exporter/core/fs.ts", "../../exporter/shared/errors.ts", "../../exporter/shared/endpoints.ts", "../../exporter/services/auth.ts", "../../exporter/services/render.ts", "../../exporter/services/api.ts", "../../exporter/core/logger.ts", "../../exporter/services/sites.ts"],
|
|
4
|
+
"sourcesContent": ["import fsp from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { throwError, withErrorHandler } from \"../core/errors\";\nimport { pathExists } from \"../core/fs\";\nimport { GriddoLog } from \"../core/GriddoLog\";\nimport { AuthService } from \"../services/auth\";\nimport {\n\tgetRenderMetadataFromDB,\n\tgetRenderModeFromDB,\n\tgetRenderPathsHydratedWithDomainFromDB,\n} from \"../services/render\";\nimport { endSiteRender } from \"../services/sites\";\nimport { ArtifactError } from \"../shared/errors\";\nimport { RENDER_MODE, type Report } from \"../shared/types/render\";\n\nasync function getRenderReport(options: {\n\tdomain: string;\n\texportsSiteDir: string;\n\tbuildReportFileName: string;\n}) {\n\tconst { buildReportFileName, domain, exportsSiteDir } = options;\n\tconst buildReportFile = path.resolve(exportsSiteDir, domain, \"dist\", buildReportFileName);\n\n\tif (!(await pathExists(buildReportFile))) {\n\t\tGriddoLog.info(`Build report file \"${buildReportFile}\" not found.`);\n\t\tthrowError(ArtifactError);\n\t}\n\n\treturn JSON.parse(await fsp.readFile(buildReportFile, \"utf-8\")) as Report;\n}\n\nasync function endRender() {\n\tconst { buildReportFileName } = await getRenderMetadataFromDB();\n\tconst { __sites } = await getRenderPathsHydratedWithDomainFromDB();\n\n\tawait AuthService.login();\n\n\tconst [domain] = process.argv.slice(2);\n\n\tconst { renderMode, reason } = await getRenderModeFromDB(domain);\n\tif (renderMode === RENDER_MODE.IDLE) {\n\t\tGriddoLog.info(\n\t\t\t`(From Current Render) [${domain}]: Skipping end-render as it is marked as IDLE with the reason ${reason}.`,\n\t\t);\n\t\treturn;\n\t}\n\n\tconst report = await getRenderReport({\n\t\tdomain,\n\t\texportsSiteDir: __sites,\n\t\tbuildReportFileName,\n\t});\n\n\tGriddoLog.info(`Sending ending call to ${domain} sites`);\n\n\tfor (const site of report.sites) {\n\t\tsite.publishHashes = [...new Set(site.publishHashes)];\n\t\tsite.unpublishHashes = [...new Set(site.unpublishHashes)];\n\n\t\tconst { siteId, ...body } = site;\n\t\tGriddoLog.info(`Site (${siteId})`);\n\t\tawait endSiteRender(siteId, body);\n\t}\n}\n\nasync function main() {\n\tawait endRender();\n}\n\nwithErrorHandler(main);\n", "import type { ErrorsType } from \"../shared/errors\";\n\nimport path from \"node:path\";\n\nimport { brush } from \"../shared/npm-modules/brush\";\nimport { RENDER_MODE } from \"../shared/types/render\";\nimport { readDB, writeDB } from \"./db\";\nimport { distRollback } from \"./dist-rollback\";\nimport { GriddoLog } from \"./GriddoLog\";\n\nexport type ErrorData = {\n\terror: ErrorsType;\n\tmessage: string;\n\texpected?: string;\n\thint?: string;\n};\n\nexport class RenderError extends Error {\n\tconstructor(originalError?: unknown) {\n\t\tsuper(originalError instanceof Error ? originalError.message : String(originalError));\n\n\t\tthis.name = \"InternalCXError\";\n\t\tthis.stack = originalError instanceof Error ? originalError.stack : \"\";\n\t}\n}\n\n/**\n * Throws an error with the provided error message, expected value, and hint.\n */\nfunction throwError(options: ErrorData, stack?: unknown): never {\n\tconst { error, message, expected, hint } = options;\n\n\tconst errorColor = GriddoLog.log(brush.red(`[ ${error} ]`));\n\tconst extraText = [expected, hint].filter(Boolean).join(\"\\n\");\n\n\tGriddoLog.log(`\n${errorColor}\n${message}\n${extraText}\n\n${brush.red(\"stack\")}\n${JSON.stringify(stack, null, 2)}`);\n\n\tthrow new RenderError(stack);\n}\n\n/**\n * Executes the provided asynchronous function and handles errors that occur during execution.\n *\n * - If an error is thrown, attempts to log the error and, if necessary, rolls back the exports directory.\n * - Updates the render database to set the domain's rendering state to \"ERROR\" if an error occurs.\n *\n * @param fn - The asynchronous function to execute within the error handler.\n * @returns A promise that resolves when the function is executed successfully.\n * @throws RenderError | unknown - Rethrows the original error after handling and database state update.\n */\nasync function withErrorHandler(fn: () => Promise<void>) {\n\ttry {\n\t\tawait fn();\n\t} catch (error) {\n\t\tif (error instanceof RenderError) {\n\t\t\tGriddoLog.error(\"Internal Griddo RenderError\");\n\t\t} else if (error instanceof Error) {\n\t\t\tGriddoLog.error(error.message);\n\t\t} else {\n\t\t\tGriddoLog.error(`An unexpected error occurred ${error}`);\n\t\t}\n\n\t\t// Try to rollback the exports directory if needed\n\t\ttry {\n\t\t\tconst data = await readDB();\n\t\t\tconst { root } = data.paths;\n\t\t\tif (data.needsRollbackOnError) {\n\t\t\t\tGriddoLog.info(\"Cleaning exports dir...\");\n\t\t\t\tGriddoLog.verbose(`Deleting ${path.join(root, \"exports\")}...`);\n\n\t\t\t\tawait distRollback(data.currentRenderingDomain!);\n\t\t\t} else {\n\t\t\t\tGriddoLog.info(\"No rollback needed, skipping...\");\n\t\t\t}\n\t\t} catch (_e) {\n\t\t\tGriddoLog.info(\"Early render stage, no db.json created yet...\");\n\t\t}\n\n\t\tconst data = await readDB();\n\t\tdata.domains[data.currentRenderingDomain!].isRendering = false;\n\t\tdata.domains[data.currentRenderingDomain!].renderMode = RENDER_MODE.ERROR;\n\t\tawait writeDB(data);\n\t\tthrow error;\n\t}\n}\n\nexport { throwError, withErrorHandler };\n", "//\n// Brush adds color to a string|number, it does not print it!\n// Its simple, no log, no chains, just color in a string|number\n// usage:\n// console.log(brush.green(\"sucess!\"))\n//\n\nconst RESET = \"\\x1b[0m\";\nconst CODES = {\n\tblack: \"\\x1b[30m\",\n\tred: \"\\x1b[31m\",\n\tgreen: \"\\x1b[32m\",\n\tyellow: \"\\x1b[33m\",\n\tblue: \"\\x1b[34m\",\n\tmagenta: \"\\x1b[35m\",\n\tcyan: \"\\x1b[36m\",\n\twhite: \"\\x1b[37m\",\n\tgray: \"\\x1b[90m\",\n\tbold: \"\\x1b[1m\",\n\tdim: \"\\x1b[2m\",\n} as const;\n\ntype ColorFunction = (text: string | number) => string;\ntype ColorName = keyof typeof CODES;\ntype Brush = Record<ColorName, ColorFunction>;\n\nconst brush = {} as Brush;\n\nfor (const color in CODES) {\n\tconst key = color as ColorName;\n\tbrush[key] = (text: string | number) => `${CODES[key]}${text}${RESET}`;\n}\n\nexport { brush };\n", "import type { RenderInfo } from \"./global\";\n\nconst RENDER_MODE = {\n\tFROM_SCRATCH: \"FROM_SCRATCH\",\n\tINCREMENTAL: \"INCREMENTAL\",\n\tIDLE: \"IDLE\",\n\tERROR: \"ERROR\",\n\tCOMPLETED: \"COMPLETED\",\n} as const;\n\ntype RenderMode = (typeof RENDER_MODE)[keyof typeof RENDER_MODE];\n\nexport interface RenderModeTuple {\n\trenderMode: RenderMode;\n\treason?: string;\n}\n\ntype DomainLike = string;\n\ntype RenderDB = {\n\tgriddoVersion: string;\n\tbuildReportFileName: string;\n\tsortedDomains: DomainLike[];\n\tneedsRollbackOnError: boolean;\n\tcurrentRenderingDomain: string | null;\n\tcommitHash: string;\n\tcommitMessage: string;\n\tpaths: {\n\t\troot: string;\n\t\tcx: string;\n\t\tssg: string;\n\t\tcxCache: string;\n\t\tcomponents: string;\n\t\texportsDir: string;\n\t\texportsDirBackup: string;\n\t};\n\tdomains: {\n\t\t[key: DomainLike]: {\n\t\t\trenderMode?: RenderMode;\n\t\t\tshouldBeRendered?: boolean;\n\t\t\tisRendering?: boolean;\n\t\t\trenderInfo?: RenderInfo;\n\t\t\trenderModeReason?: string;\n\t\t};\n\t};\n};\n\ninterface Report {\n\tauthControl:\n\t\t| {\n\t\t\t\tAuthorization: string;\n\t\t\t\t\"Cache-Control\": string;\n\t\t\t\tlang?: string | undefined;\n\t\t }\n\t\t| undefined;\n\tsites: {\n\t\tsiteId: number;\n\t\tpublishHashes: string[];\n\t\tsiteHash: string | null;\n\t\tunpublishHashes: string[];\n\t\tpublishPagesIds: number[];\n\t}[];\n}\n\nexport { RENDER_MODE, type RenderDB, type RenderMode, type Report };\n", "import type { RenderDB } from \"../shared/types/render\";\n\nimport fsp from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { pkgDirSync } from \"../shared/npm-modules/pkg-dir\";\nimport { GriddoLog } from \"./GriddoLog\";\n\nconst root = pkgDirSync({ cwd: path.resolve(__dirname, \"../../..\") }) || \"\";\nconst cache = path.join(root, \".griddo/cache\");\nconst dbFilePath = path.join(cache, \"db.json\");\n\nasync function readDB(customDBPath = \"\") {\n\tconst file = customDBPath || dbFilePath;\n\ttry {\n\t\treturn JSON.parse(await fsp.readFile(file, \"utf-8\")) as RenderDB;\n\t} catch (error) {\n\t\tGriddoLog.error(`Failed to read DB file at ${file}:`, error);\n\t\tthrow error;\n\t}\n}\n\nasync function writeDB(renderDB: RenderDB, customDBPath = \"\") {\n\tconst file = customDBPath || dbFilePath;\n\ttry {\n\t\tawait fsp.writeFile(file, JSON.stringify(renderDB, null, \"\\t\"));\n\t} catch (error) {\n\t\tGriddoLog.error(`Failed to write DB file at ${file}:`, error);\n\t\tthrow error;\n\t}\n}\n\nexport { readDB, writeDB };\n", "import path from \"node:path\";\n\nimport { findUp, findUpSync } from \"./find-up-simple\";\n\nasync function pkgDir(options?: { readonly cwd?: string }) {\n\tconst { cwd } = options || {};\n\tconst filePath = await findUp(\"package.json\", { cwd });\n\treturn filePath && path.dirname(filePath);\n}\n\nfunction pkgDirSync(options?: { readonly cwd?: string }) {\n\tconst { cwd } = options || {};\n\tconst filePath = findUpSync(\"package.json\", { cwd });\n\treturn filePath && path.dirname(filePath);\n}\n\nexport { pkgDir, pkgDirSync };\n", "import fs from \"node:fs\";\nimport fsPromises from \"node:fs/promises\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Opciones para controlar el comportamiento de la b\u00FAsqueda.\n */\nexport type Options = {\n\t/**\n\tEl directorio desde donde empezar a buscar.\n\t@default process.cwd()\n\t*/\n\treadonly cwd?: URL | string;\n\n\t/**\n\tEl tipo de ruta a buscar.\n\t@default 'file'\n\t*/\n\treadonly type?: \"file\" | \"directory\";\n\n\t/**\n\tUn directorio en el que la b\u00FAsqueda se detiene si no se encuentran coincidencias.\n\t@default El directorio ra\u00EDz del sistema\n\t*/\n\treadonly stopAt?: URL | string;\n};\n\n// Funci\u00F3n auxiliar para convertir una URL en una ruta de archivo de tipo string.\nconst toPath = (urlOrPath: URL | string | undefined): string | undefined =>\n\turlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\n/**\n * Encuentra un archivo o directorio de forma as\u00EDncrona subiendo por los directorios padre.\n * @param name - El nombre del archivo o directorio a buscar.\n * @param options - Opciones de b\u00FAsqueda.\n * @returns La ruta encontrada o `undefined` si no se pudo encontrar.\n */\nexport async function findUp(name: string, options: Options = {}): Promise<string | undefined> {\n\tconst { cwd = process.cwd(), type = \"file\", stopAt: stopAtOption } = options;\n\n\tlet directory = path.resolve(toPath(cwd) ?? \"\");\n\tconst { root } = path.parse(directory);\n\tconst stopAt = stopAtOption ? path.resolve(directory, toPath(stopAtOption)!) : root;\n\tconst isAbsoluteName = path.isAbsolute(name);\n\n\twhile (true) {\n\t\tconst filePath = isAbsoluteName ? name : path.join(directory, name);\n\t\ttry {\n\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\tconst stats = await fsPromises.stat(filePath);\n\t\t\tif ((type === \"file\" && stats.isFile()) || (type === \"directory\" && stats.isDirectory())) {\n\t\t\t\treturn filePath;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignora errores (ej. el archivo no existe) y contin\u00FAa la b\u00FAsqueda.\n\t\t}\n\n\t\tif (directory === stopAt || directory === root) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n}\n\n/**\n * Encuentra un archivo o directorio de forma s\u00EDncrona subiendo por los directorios padre.\n * @param name - El nombre del archivo o directorio a buscar.\n * @param options - Opciones de b\u00FAsqueda.\n * @returns La ruta encontrada o `undefined` si no se pudo encontrar.\n */\nexport function findUpSync(name: string, options: Options = {}): string | undefined {\n\tconst { cwd = process.cwd(), type = \"file\", stopAt: stopAtOption } = options;\n\n\tlet directory = path.resolve(toPath(cwd) ?? \"\");\n\tconst { root } = path.parse(directory);\n\tconst stopAt = stopAtOption ? path.resolve(directory, toPath(stopAtOption)!) : root;\n\tconst isAbsoluteName = path.isAbsolute(name);\n\n\twhile (true) {\n\t\tconst filePath = isAbsoluteName ? name : path.join(directory, name);\n\t\ttry {\n\t\t\tconst stats = fs.statSync(filePath, { throwIfNoEntry: false });\n\t\t\tif ((type === \"file\" && stats?.isFile()) || (type === \"directory\" && stats?.isDirectory())) {\n\t\t\t\treturn filePath;\n\t\t\t}\n\t\t} catch {\n\t\t\t// En teor\u00EDa, statSync con `throwIfNoEntry: false` no deber\u00EDa lanzar un error,\n\t\t\t// pero se mantiene por seguridad.\n\t\t}\n\n\t\tif (directory === stopAt || directory === root) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n}\n", "const { env } = process;\n\n/**\n * Returns true/false from string\n */\nfunction envIsTruthy(value?: string): boolean {\n\tif (!value) return false;\n\n\tswitch (value.trim().toLowerCase()) {\n\t\tcase \"1\":\n\t\tcase \"true\":\n\t\tcase \"yes\":\n\t\tcase \"y\":\n\t\tcase \"on\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n// Credentials\nconst GRIDDO_API_URL = env.GRIDDO_API_URL || env.API_URL;\nconst GRIDDO_PUBLIC_API_URL = env.GRIDDO_PUBLIC_API_URL || env.PUBLIC_API_URL;\nconst GRIDDO_BOT_USER = env.botEmail || env.GRIDDO_BOT_USER;\nconst GRIDDO_BOT_PASSWORD = env.botPassword || env.GRIDDO_BOT_PASSWORD;\n\n// Rendering\nconst GRIDDO_API_CONCURRENCY_COUNT = Number.parseInt(env.GRIDDO_API_CONCURRENCY_COUNT || \"10\");\nconst GRIDDO_SKIP_BUILD_CHECKS = envIsTruthy(env.GRIDDO_SKIP_BUILD_CHECKS);\nconst GRIDDO_BUILD_LOGS = envIsTruthy(env.GRIDDO_BUILD_LOGS);\nconst GRIDDO_BUILD_LOGS_BUFFER_SIZE = Number.parseInt(env.GRIDDO_BUILD_LOGS_BUFFER_SIZE || \"500\");\nconst GRIDDO_SSG_VERBOSE_LOGS = envIsTruthy(env.GRIDDO_SSG_VERBOSE_LOGS);\nconst GRIDDO_SEARCH_FEATURE = envIsTruthy(env.GRIDDO_SEARCH_FEATURE);\nconst GRIDDO_ASSET_PREFIX = env.GRIDDO_ASSET_PREFIX || env.ASSET_PREFIX;\nconst GRIDDO_REACT_APP_INSTANCE = env.GRIDDO_REACT_APP_INSTANCE || env.REACT_APP_INSTANCE;\nconst GRIDDO_AI_EMBEDDINGS = envIsTruthy(env.GRIDDO_AI_EMBEDDINGS);\nconst GRIDDO_VERBOSE_LOGS = envIsTruthy(env.GRIDDO_VERBOSE_LOGS);\nconst GRIDDO_USE_DIST_BACKUP = envIsTruthy(env.GRIDDO_USE_DIST_BACKUP);\nconst GRIDDO_SSG_BUNDLE_ANALYZER = envIsTruthy(env.GRIDDO_SSG_BUNDLE_ANALYZER);\n\nexport {\n\tGRIDDO_AI_EMBEDDINGS,\n\tGRIDDO_API_CONCURRENCY_COUNT,\n\tGRIDDO_API_URL,\n\tGRIDDO_ASSET_PREFIX,\n\tGRIDDO_BOT_PASSWORD,\n\tGRIDDO_BOT_USER,\n\tGRIDDO_BUILD_LOGS,\n\tGRIDDO_BUILD_LOGS_BUFFER_SIZE,\n\tGRIDDO_PUBLIC_API_URL,\n\tGRIDDO_REACT_APP_INSTANCE,\n\tGRIDDO_SEARCH_FEATURE,\n\tGRIDDO_SKIP_BUILD_CHECKS,\n\tGRIDDO_SSG_BUNDLE_ANALYZER,\n\tGRIDDO_SSG_VERBOSE_LOGS,\n\tGRIDDO_USE_DIST_BACKUP,\n\tGRIDDO_VERBOSE_LOGS,\n};\n", "import { GRIDDO_BUILD_LOGS, GRIDDO_VERBOSE_LOGS } from \"../shared/envs\";\nimport { brush } from \"../shared/npm-modules/brush\";\n\n/**\n * Clase est\u00E1tica para gestionar los logs de la aplicaci\u00F3n.\n * No se puede instanciar, se usa directamente: GriddoLogs.info(\"mensaje\").\n */\nclass GriddoLog {\n\t/** El constructor es privado para prevenir la instanciaci\u00F3n de la clase. */\n\tprivate constructor() {}\n\n\tpublic static verbose(...str: unknown[]): void {\n\t\tif (GRIDDO_VERBOSE_LOGS) {\n\t\t\tconsole.log(brush.yellow(\"verbose\"), brush.dim(str.join(\" \")));\n\t\t}\n\t}\n\n\tpublic static build(...str: unknown[]): void {\n\t\tif (GRIDDO_BUILD_LOGS) {\n\t\t\tGriddoLog.log(...str);\n\t\t}\n\t}\n\n\tpublic static info(...str: unknown[]): void {\n\t\tconsole.log(`${brush.blue(\"info\")} ${str.join(\" \")}`);\n\t}\n\n\tpublic static success(...str: unknown[]): void {\n\t\tconsole.log(`${brush.green(\"success\")} ${str.join(\" \")}`);\n\t}\n\n\tpublic static error(...str: unknown[]): void {\n\t\tconsole.error(`${brush.red(\"error\")} ${str.join(\" \")}`);\n\t}\n\n\tpublic static warn(...str: unknown[]): void {\n\t\tconsole.warn(`${brush.yellow(\"warn\")} ${str.join(\" \")}`);\n\t}\n\n\tpublic static log(...args: Parameters<typeof console.log>): void {\n\t\tconsole.log(...args);\n\t}\n}\n\nexport { GriddoLog };\n", "import fsp from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { readDB } from \"./db\";\nimport { pathExists } from \"./fs\";\nimport { GriddoLog } from \"./GriddoLog\";\n\n/**\n * Rolls back the exports directory for the given domain.\n *\n * - Deletes the potentially corrupt exports directory for the domain.\n * - If a backup exists, it restores the directory from the backup location.\n * - If no backup is found, it informs that a fresh exports directory will be created on the next render.\n *\n * @param domain The domain for which to rollback the exports directory.\n */\nasync function distRollback(domain: string): Promise<void> {\n\tconst data = await readDB();\n\tconst { exportsDir, exportsDirBackup } = data.paths;\n\n\tGriddoLog.info(`Cleaning exports dir for the domain ${domain}`);\n\tGriddoLog.verbose(`Deleting ${path.join(exportsDir, domain)}...`);\n\n\t// TODO: Probar rsync en lugar de borrar y copiar\n\n\t// 1 - Borrar dist corrupto\n\tawait fsp.rm(path.join(exportsDir, domain), {\n\t\trecursive: true,\n\t\tforce: true,\n\t});\n\n\t// 2 - Si hay backup, restaurar\n\tif (await pathExists(path.join(exportsDirBackup, domain))) {\n\t\tawait fsp.cp(path.join(exportsDirBackup, domain), path.join(exportsDir, domain), {\n\t\t\trecursive: true,\n\t\t});\n\n\t\tGriddoLog.info(`export-backup dir for the domain ${domain} found. Restoring before exit...`);\n\t\tGriddoLog.verbose(\n\t\t\t`Copying ${path.join(exportsDirBackup, domain)} -> ${path.join(exportsDir, domain)}...`,\n\t\t);\n\t} else {\n\t\tGriddoLog.info(\n\t\t\t\"No export-backup found, skipping rollback. Next render will create a new exports dir from scratch...\",\n\t\t);\n\t}\n}\n\nexport { distRollback };\n", "import type { MakeDirectoryOptions } from \"node:fs\";\n\nimport fsp from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { ArtifactError } from \"../shared/errors\";\nimport { throwError } from \"./errors\";\nimport { GriddoLog } from \"./GriddoLog\";\n\n/**\n * Remove an empty directory from the basePath recursively.\n * If the directory has only .xml files it will handle as empty too (empty site)\n *\n * @param baseDir - The base directory.\n */\nasync function deleteDisposableSiteDirs(baseDir: string) {\n\tif (!(await pathExists(baseDir))) {\n\t\treturn;\n\t}\n\n\tconst sitesDirs = (await fsp.readdir(baseDir, { withFileTypes: true })).filter((file) =>\n\t\tfile.isDirectory(),\n\t);\n\n\tfor (const siteDir of sitesDirs) {\n\t\tconst sitePath = path.join(baseDir, siteDir.name);\n\t\tif (await siteIsEmpty(sitePath)) {\n\t\t\tawait fsp.rm(sitePath, { recursive: true });\n\t\t}\n\t}\n}\n\n/**\n * Creates multiple artifact directories.\n *\n * @param dirs - An array of directory paths.\n * @param options - Same option as `fs.mkdirSync()`\n */\nasync function mkDirs(dirs: string[], options?: MakeDirectoryOptions) {\n\tfor (const dir of dirs) {\n\t\ttry {\n\t\t\tif (!(await pathExists(dir))) {\n\t\t\t\tawait fsp.mkdir(dir, { recursive: true, ...options });\n\t\t\t\tGriddoLog.verbose(`create directory: ${dir}`);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrowError(ArtifactError, error);\n\t\t}\n\t}\n}\n\nasync function renamePath(src: string, dst: string) {\n\ttry {\n\t\tif (await pathExists(src)) {\n\t\t\tawait fsp.rename(src, dst);\n\t\t\tGriddoLog.verbose(`rename ${src} to ${dst}`);\n\t\t}\n\t} catch (error) {\n\t\tthrowError(ArtifactError, error);\n\t}\n}\n\n/**\n * Copy multiple directories with backup option.\n *\n * @param src - Source directory.\n * @param dst - Destination directory.\n * @param dirs - Directories to copy.\n * @param options.withBackup - Create a previous backup before copy.\n */\nasync function cpDirs(\n\tsrc: string,\n\tdst: string,\n\tdirs: string[],\n\toptions = {\n\t\twithBackup: false,\n\t},\n) {\n\tconst { withBackup } = options;\n\tfor (const dir of dirs) {\n\t\tconst srcCompose = path.join(src, dir);\n\t\tconst dstCompose = path.join(dst, dir);\n\n\t\t// The dir we want to copy, doesn't exist.\n\t\tif (!(await pathExists(srcCompose))) {\n\t\t\tGriddoLog.info(`(Maybe first render) Source directory does not exist: ${srcCompose}`);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Create the backup\n\t\tif (withBackup) {\n\t\t\tawait createBackup(dstCompose);\n\t\t\tGriddoLog.verbose(`create backup: ${dstCompose}`);\n\t\t}\n\n\t\t// Copy directory\n\t\ttry {\n\t\t\t// First clean destination\n\t\t\tif (await pathExists(dstCompose)) {\n\t\t\t\tawait fsp.rm(dstCompose, { recursive: true, force: true });\n\t\t\t\tGriddoLog.verbose(`clean destination: ${dstCompose}`);\n\t\t\t}\n\n\t\t\t// Then copy src to dst\n\t\t\tawait fsp.cp(srcCompose, dstCompose, {\n\t\t\t\trecursive: true,\n\t\t\t\tpreserveTimestamps: true,\n\t\t\t});\n\t\t\tGriddoLog.verbose(`copy: ${srcCompose} to ${dstCompose}`);\n\n\t\t\tif (withBackup) {\n\t\t\t\tawait deleteBackup(dstCompose);\n\t\t\t\tGriddoLog.verbose(`delete backup: ${dstCompose}`);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (withBackup) {\n\t\t\t\tawait restoreBackup(dstCompose);\n\t\t\t\tGriddoLog.verbose(\"Backup has been restored.\");\n\t\t\t}\n\n\t\t\tthrowError(ArtifactError, error);\n\t\t}\n\t}\n}\n\n/**\n * Move artifacts between cx-paths\n *\n * @param src - Source directory.\n * @param dst - Destination directory.\n * @param dirs - Directories to move.\n * @param options - Options.\n */\nasync function mvDirs(\n\tsrc: string,\n\tdst: string,\n\tdirs: string[],\n\toptions?: { withBackup?: boolean; override?: boolean },\n) {\n\tconst { override, withBackup } = options || {};\n\n\tfor (const dir of dirs) {\n\t\tconst srcCompose = path.join(src, dir);\n\t\tconst dstCompose = path.join(dst, dir);\n\n\t\tif (!(await pathExists(srcCompose))) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (withBackup) {\n\t\t\tawait createBackup(dstCompose);\n\t\t}\n\n\t\ttry {\n\t\t\t// Clean destination\n\t\t\tif (override && (await pathExists(dstCompose))) {\n\t\t\t\tawait fsp.rm(dstCompose, { recursive: true, force: true });\n\t\t\t}\n\n\t\t\tawait fsp.rename(srcCompose, dstCompose);\n\t\t\tGriddoLog.verbose(`moved: ${srcCompose} to ${dstCompose}`);\n\n\t\t\tif (withBackup) {\n\t\t\t\tawait deleteBackup(dstCompose);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (withBackup) {\n\t\t\t\tawait restoreBackup(dstCompose);\n\t\t\t\tGriddoLog.info(\"Backup has been restored.\");\n\t\t\t}\n\n\t\t\tthrowError(ArtifactError, error);\n\t\t}\n\t}\n}\n\n/**\n * Removes multiple artifact directories.\n *\n * @param dirs - An array of directory paths.\n */\nasync function rmDirs(dirs: string[]) {\n\tfor (const dir of dirs) {\n\t\ttry {\n\t\t\tawait fsp.rm(dir, { recursive: true, force: true });\n\t\t\tGriddoLog.verbose(`artifact removed: ${dir}`);\n\t\t} catch (error) {\n\t\t\tthrowError(ArtifactError, error);\n\t\t}\n\t}\n}\n\nasync function restoreBackup(src: string, suffix = \"-BACKUP\") {\n\tconst dst = src + suffix;\n\ttry {\n\t\tawait fsp.rename(dst, src);\n\t\tGriddoLog.info(`Backup ${dst} has been restored`);\n\t} catch (_error) {\n\t\tthrow new Error(`Error while delete ${dst} backup`);\n\t}\n}\n\nasync function deleteBackup(src: string, suffix = \"-BACKUP\") {\n\tconst dst = src + suffix;\n\n\tif (!(await pathExists(dst))) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\tawait fsp.rm(dst, { recursive: true, force: true });\n\t\tGriddoLog.verbose(`Backup ${dst} has been deleted`);\n\t} catch (_error) {\n\t\tthrow new Error(`Error while delete ${dst} backup`);\n\t}\n}\n\nasync function createBackup(src: string, suffix = \"-BACKUP\") {\n\tconst dst = src + suffix;\n\n\tif (!(await pathExists(src))) {\n\t\treturn;\n\t}\n\n\tif (await pathExists(dst)) {\n\t\tGriddoLog.warn(`Destination ${dst} already exists`);\n\t\treturn;\n\t}\n\n\ttry {\n\t\tawait fsp.rename(src, dst);\n\t\tGriddoLog.verbose(`Backup of ${src} has been created in ${dst}`);\n\t} catch (error) {\n\t\tGriddoLog.error(`Error while coping ${src} to ${dst} backup`);\n\t\tthrowError(ArtifactError, error);\n\t}\n}\n\n/**\n * Return true if the site folder is empty or only has xml files. (Recursively)\n */\nasync function siteIsEmpty(sitePath: string) {\n\tconst siteFiles = (\n\t\tawait fsp.readdir(sitePath, {\n\t\t\twithFileTypes: true,\n\t\t\trecursive: true,\n\t\t})\n\t).filter((file) => file.isFile() && !path.basename(file.name).startsWith(\".\"));\n\n\tconst xmlFiles = siteFiles.filter((file) => file.name.endsWith(\".xml\"));\n\n\tif (siteFiles.length === xmlFiles.length) {\n\t\treturn true;\n\t}\n}\n\n/**\n * Delete empty directories from the given directory in a recursive way.\n */\nasync function deleteEmptyDirectories(dirPath: string) {\n\ttry {\n\t\tconst stats = await fsp.stat(dirPath);\n\n\t\t// Si no es un directorio, no hacemos nada\n\t\tif (!stats.isDirectory()) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet filesInDirectory: string[];\n\t\ttry {\n\t\t\tfilesInDirectory = await fsp.readdir(dirPath);\n\t\t} catch (err: any) {\n\t\t\t// Si el directorio no existe o no se puede leer (ej. permisos), lo saltamos.\n\t\t\tif (err.code === \"ENOENT\") {\n\t\t\t\tGriddoLog.warn(`The directory \"${dirPath}\" does not exist, skipping it.`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tGriddoLog.error(`Error al leer el directorio \"${dirPath}\":`, err);\n\t\t\tthrow err; // Re-lanza el error para que sea manejado por el llamador\n\t\t}\n\n\t\t// Recorrer los contenidos del directorio\n\t\tfor (const file of filesInDirectory) {\n\t\t\tconst fullPath = path.join(dirPath, file);\n\t\t\tawait deleteEmptyDirectories(fullPath); // Llamada recursiva s\u00EDncrona\n\t\t}\n\n\t\t// Despu\u00E9s de procesar todos los subdirectorios, verifica si el directorio actual est\u00E1 vac\u00EDo\n\t\tconst remainingFiles = await fsp.readdir(dirPath);\n\n\t\tif (remainingFiles.length === 0) {\n\t\t\ttry {\n\t\t\t\tawait fsp.rmdir(dirPath);\n\t\t\t\tGriddoLog.verbose(`Remove empty directory: ${dirPath}`);\n\t\t\t} catch (err: any) {\n\t\t\t\t// Puede que haya habido un problema de concurrencia o permisos\n\t\t\t\tif (err.code === \"ENOENT\") {\n\t\t\t\t\tGriddoLog.warn(\n\t\t\t\t\t\t`El directorio \"${dirPath}\" ya no existe. Posiblemente fue borrado por otra operaci\u00F3n.`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tGriddoLog.error(`Error al borrar el directorio \"${dirPath}\":`, err);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch (err: any) {\n\t\tif (err.code === \"ENOENT\") {\n\t\t\t// El directorio ya no existe, no es un error para nosotros en este contexto\n\t\t\tGriddoLog.warn(`The directory \"${dirPath}\" does not exist or has already been processed.`);\n\t\t} else {\n\t\t\tGriddoLog.error(`General error general while processing \"${dirPath}\":`, err);\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\nasync function pathExists(dir: string) {\n\ttry {\n\t\tawait fsp.access(dir);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Busca recursivamente archivos que terminen con un sufijo espec\u00EDfico dentro de un directorio.\n * Esta funci\u00F3n es un generador as\u00EDncrono, lo que la hace muy eficiente en uso de memoria.\n *\n * @param dir El directorio base para comenzar la b\u00FAsqueda.\n * @param suffix El sufijo con el que deben terminar los nombres de archivo (ej: 'page-data.json').\n * @returns Un generador as\u00EDncrono que produce la ruta completa de cada archivo encontrado.\n * @throws Si el directorio inicial `dir` no existe o no se puede leer.\n */\nasync function* findFilesBySuffix(dir: string, suffix: string): AsyncGenerator<string> {\n\tconst dirHandle = await fsp.opendir(dir);\n\tfor await (const item of dirHandle) {\n\t\tconst fullPath = path.join(dir, item.name);\n\t\tif (item.isDirectory()) {\n\t\t\t// yield* para encadenar otro generator.\n\t\t\tyield* findFilesBySuffix(fullPath, suffix);\n\t\t} else if (item.isFile() && item.name.endsWith(suffix)) {\n\t\t\tyield fullPath;\n\t\t}\n\t}\n}\n\n/**\n * Walk a directory and returns the JSON file absolute paths with one level of depth.\n * /abs/.../sotre/331/158.json\n * /abs/.../sotre/114/443.json\n * /abs/.../sotre/131/217.json\n * /abs/.../sotre/191/281.json\n */\nasync function* walkStore(storeDir: string): AsyncGenerator<string> {\n\tconst storeDirHandle = await fsp.opendir(storeDir);\n\n\tfor await (const siteDirent of storeDirHandle) {\n\t\tif (siteDirent.isDirectory()) {\n\t\t\tconst siteDirPath = path.join(storeDir, siteDirent.name);\n\t\t\tconst siteDirHandle = await fsp.opendir(siteDirPath);\n\n\t\t\tfor await (const fileDirent of siteDirHandle) {\n\t\t\t\tconst filePath = path.join(siteDirPath, fileDirent.name);\n\n\t\t\t\tif (fileDirent.isFile() && path.extname(filePath) === \".json\") {\n\t\t\t\t\tyield filePath;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport {\n\tcpDirs,\n\tdeleteDisposableSiteDirs,\n\tdeleteEmptyDirectories,\n\tfindFilesBySuffix,\n\tmkDirs,\n\tmvDirs,\n\tpathExists,\n\trenamePath,\n\trmDirs,\n\twalkStore,\n};\n", "/**\n * Do you want to add a new error to the list?\n *\n * 1 - Add the new error type name to the `ErrorsType` union type.\n * 2 - Export a new ErrorData object (or a function that returns one) in this\n * file by completing the `error` (ErrosType) and `message` (string) properties\n * obligatorily.\n */\n\nimport type { SpawnSyncReturns } from \"node:child_process\";\nimport type { ErrorData } from \"../core/errors\";\n\ntype ErrorsType =\n\t| \"ArtifactError\"\n\t| \"BundlesInconsistencyError\"\n\t| \"CheckHealthError\"\n\t| \"ErrorInSSGBuildProcess\"\n\t| \"LifecycleExecutionError\"\n\t| \"LoginError\"\n\t| \"NoDomainsFoundError\"\n\t| \"NoJSConfigFileFound\"\n\t| \"ReadFromStoreError\"\n\t| \"ReferenceFieldSourcesNotFoundError\"\n\t| \"RenderUUIDError\"\n\t| \"UploadSearchError\"\n\t| \"WriteToStoreError\";\n\nconst ArtifactError: ErrorData = {\n\terror: \"ArtifactError\",\n\tmessage: \"There was a problem with an artifact\",\n\texpected:\n\t\t\"An external process may have has modified or deleted one of the artifacts (files and directories).\",\n\thint: \"Have there been any recent deployments? These can delete directories from the current render.\",\n};\n\nconst ErrorInSSGBuildProcess = (command: SpawnSyncReturns<string>): ErrorData => ({\n\terror: \"ErrorInSSGBuildProcess\",\n\tmessage: `Error in SSG build process: ${JSON.stringify(command)}`,\n\texpected: \"This can happen if there was a problem with the SSG build process.\",\n});\n\nconst LifecycleExecutionError = (attempts: number, name: string): ErrorData => ({\n\terror: \"LifecycleExecutionError\",\n\tmessage: `Exceeded maximum retry attempts (${attempts}) for ${name} LifeCycle`,\n});\n\nconst LoginError: ErrorData = {\n\terror: \"LoginError\",\n\tmessage: \"There was a problem logging in to the API\",\n\texpected: \"This happens if the API is currently not working or the credentials are incorrect.\",\n};\n\nconst NoDomainsFoundError: ErrorData = {\n\terror: \"NoDomainsFoundError\",\n\tmessage: \"No domains were found in this instance. The process cannot continue.\",\n\texpected:\n\t\t\"This may happen if the API is not functioning, or the site is not properly configured, or the domains are not registered.\",\n\thint: \"You can contact the instance administrator.\",\n};\n\nconst NoJSConfigFileFound: ErrorData = {\n\terror: \"NoJSConfigFileFound\",\n\tmessage: \"Could not find jsconfig.json or tsconfig.json\",\n\texpected:\n\t\t\"This can happen if the instance is not properly configured with a jsconfig.json or tsconfig.json file.\",\n};\n\nconst ReadFromStoreError: ErrorData = {\n\terror: \"ReadFromStoreError\",\n\tmessage: \"There was an error reading a file to the Store directory\",\n\thint: \"There may be an issue such as permissions preventing the file from being read.\",\n};\n\nconst ReferenceFieldSourcesNotFoundError: ErrorData = {\n\terror: \"ReferenceFieldSourcesNotFoundError\",\n\tmessage: \"The distributor has no sources defined.\",\n\texpected:\n\t\t\"It is expected to have at least one data source in the `sources` property, even if it is empty.\",\n};\n\nconst RenderUUIDError: ErrorData = {\n\terror: \"RenderUUIDError\",\n\tmessage: `Render sentinel file does not exist.\nThe rendering UUID cannot be read safely.\nThere was probably an instance deployment during the render, and files were deleted.\n\nThe files generated in this render will not be published.`,\n};\n\nconst WriteToStoreError: ErrorData = {\n\terror: \"WriteToStoreError\",\n\tmessage: \"There was an error writing a file to the Store directory\",\n\thint: \"There may be an issue such as lack of space or permissions preventing the file from being written.\",\n};\n\nconst UploadSearchError: ErrorData = {\n\terror: \"UploadSearchError\",\n\tmessage: \"There was an error uploading content to API for search\",\n\thint: \"This happens if the API is currently not working or the credentials are incorrect.\",\n};\n\nconst CheckHealthError: ErrorData = {\n\terror: \"CheckHealthError\",\n\tmessage: \"There was a problem with environment vars configuration.\",\n\texpected: \"Some of the required environment variables are not set correctly or are missing\",\n\thint: \"Are the environment variables correctly set?\",\n};\n\nexport {\n\tArtifactError,\n\tCheckHealthError,\n\tErrorInSSGBuildProcess,\n\tLifecycleExecutionError,\n\tLoginError,\n\tNoDomainsFoundError,\n\tNoJSConfigFileFound,\n\tReadFromStoreError,\n\tReferenceFieldSourcesNotFoundError,\n\tRenderUUIDError,\n\tUploadSearchError,\n\tWriteToStoreError,\n\ttype ErrorsType,\n};\n", "const GRIDDO_API_URL = process.env.GRIDDO_API_URL;\nconst GRIDDO_PUBLIC_API_URL = process.env.GRIDDO_PUBLIC_API_URL;\n\nconst AI_EMBEDDINGS = `${GRIDDO_API_URL}/ai/embeddings`;\nconst ALERT = `${GRIDDO_PUBLIC_API_URL}/alert`;\nconst DOMAINS = `${GRIDDO_API_URL}/domains`;\nconst GET_ALL = `${GRIDDO_API_URL}/sites/all`;\nconst GET_PAGE = `${GRIDDO_API_URL}/page`;\nconst LOGIN = `${GRIDDO_API_URL}/login_check`;\nconst RESET_RENDER = `${GRIDDO_API_URL}/debug/reset-render`;\nconst ROBOTS = `${GRIDDO_API_URL}/domains/robots`;\nconst SEARCH = `${GRIDDO_API_URL}/search`;\nconst SETTINGS = `${GRIDDO_API_URL}/settings`;\n\n// Site\nconst SITE_URI = `${GRIDDO_API_URL}/site/`;\nconst BUILD_END = [SITE_URI, \"/build/end\"];\nconst BUILD_START = [SITE_URI, \"/build/start\"];\nconst GET_PAGES = [SITE_URI, \"/pages?pagination=false\"];\nconst GET_REFERENCE_FIELD_DATA = [SITE_URI, \"/distributor\"];\nconst GET_SITEMAP = [SITE_URI, \"/sitemap\"];\nconst INFO = [SITE_URI, \"/all\"];\nconst LANGUAGES = [SITE_URI, \"/languages\"];\nconst SOCIALS = [SITE_URI, \"/socials\"];\n\nexport {\n\tAI_EMBEDDINGS,\n\tALERT,\n\tBUILD_END,\n\tBUILD_START,\n\tDOMAINS,\n\tGET_ALL,\n\tGET_PAGE,\n\tGET_PAGES,\n\tGET_REFERENCE_FIELD_DATA,\n\tGET_SITEMAP,\n\tINFO,\n\tLANGUAGES,\n\tLOGIN,\n\tRESET_RENDER,\n\tROBOTS,\n\tSEARCH,\n\tSETTINGS,\n\tSOCIALS,\n};\n", "import type { AuthHeaders } from \"../shared/types/api\";\n\nimport { throwError } from \"../core/errors\";\nimport { LOGIN } from \"../shared/endpoints\";\nimport { GRIDDO_BOT_PASSWORD, GRIDDO_BOT_USER } from \"../shared/envs\";\nimport { LoginError } from \"../shared/errors\";\n\nclass AuthService {\n\theaders: AuthHeaders | undefined;\n\n\tasync login() {\n\t\ttry {\n\t\t\tconst response = await fetch(LOGIN, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: { \"Content-Type\": \"application/json\", Connection: \"close\" },\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tusername: GRIDDO_BOT_USER,\n\t\t\t\t\tpassword: GRIDDO_BOT_PASSWORD,\n\t\t\t\t}),\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(\"Error while login in the API\");\n\t\t\t}\n\n\t\t\tconst { token } = await response.json();\n\t\t\tthis.headers = {\n\t\t\t\tAuthorization: `bearer ${token}`,\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t};\n\n\t\t\treturn this.headers;\n\t\t} catch (e) {\n\t\t\tthrowError(LoginError, e);\n\t\t}\n\t}\n}\n\nconst authService = new AuthService();\n\nexport { authService as AuthService };\n", "import type { RenderModeTuple } from \"../shared/types/render\";\n\nimport { execSync } from \"node:child_process\";\nimport fsp from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { readDB, writeDB } from \"../core/db\";\nimport { throwError } from \"../core/errors\";\nimport { pathExists } from \"../core/fs\";\nimport { GriddoLog } from \"../core/GriddoLog\";\nimport { RenderUUIDError } from \"../shared/errors\";\nimport { brush } from \"../shared/npm-modules/brush\";\nimport { RENDER_MODE } from \"../shared/types/render\";\nimport { AuthService } from \"./auth\";\nimport { getBuildMetadata } from \"./manage-store\";\n\n/**\n * Creates a sentinel file with the current date and time.\n * This file is used to track later if node_modules/@griddo/cx was cleaned by a\n * npm install coming from a deploy.\n */\nasync function markRenderAsStarted(options: { domain: string; basePath: string }) {\n\tconst { domain } = options;\n\n\tconst db = await readDB();\n\tdb.domains[domain].isRendering = true;\n\tawait writeDB(db);\n\n\t// Creamos un archivo centinela, si al terminar el render este archivo no\n\t// existe es que ha habido un deploy por medio y hay que invalidar el render\n\tconst { __ssg } = await getRenderPathsHydratedWithDomainFromDB();\n\n\tconst renderSentinelFile = path.join(__ssg, `.render-sentinel-${domain}`);\n\tawait fsp.writeFile(renderSentinelFile, new Date().toISOString());\n}\n\nasync function markRenderAsCompleted(domain: string) {\n\tconst db = await readDB();\n\tdb.domains[domain].isRendering = false;\n\tdb.currentRenderingDomain = null;\n\tdb.domains[domain].renderMode = RENDER_MODE.COMPLETED;\n\t// db.domains[domain].shouldBeRendered = false;\n\tawait writeDB(db);\n\n\t// Borramos finalmente el archivo centinela\n\tconst { __ssg } = await getRenderPathsHydratedWithDomainFromDB();\n\tconst renderSentinelFile = path.join(__ssg, `.render-sentinel-${domain}`);\n\tawait fsp.unlink(renderSentinelFile);\n}\n\nasync function assertRenderIsValid(domain: string) {\n\t// Comprobamos que .render-sentinel exista, si no es que un deploy lo borro\n\t// y hay que invalidar el render.\n\tconst { __ssg } = await getRenderPathsHydratedWithDomainFromDB();\n\tconst renderSentinelFile = path.join(__ssg, `.render-sentinel-${domain}`);\n\tif (!(await pathExists(renderSentinelFile))) {\n\t\tthrowError(RenderUUIDError);\n\t}\n}\n\n/**\n * Determines the appropriate render mode for a given domain based on its current state,\n * previous render errors, deployment status, and whether rendering is required.\n *\n * @param options - An object containing:\n * - `domain`: The domain name to resolve the render mode for.\n * - `shouldBeRendered`: A boolean indicating if the domain should be rendered.\n * @returns An object with:\n * - `renderMode`: The resolved render mode (`FROM_SCRATCH`, `INCREMENTAL`, or `IDLE`).\n * - `reason`: A string describing the reason for the chosen render mode.\n *\n * @remarks\n * The function checks for missing exports, previous render errors, new deployments,\n * and whether rendering is necessary to decide the render mode.\n *\n * @todo\n * Improve ifs and reason concatenations...\n */\nasync function resolveDomainRenderMode(options: { domain: string; shouldBeRendered: boolean }) {\n\tconst { domain, shouldBeRendered } = options;\n\n\tconst db = await readDB();\n\n\tconst { __cache, __exports } = await getRenderPathsHydratedWithDomainFromDB({ domain });\n\tconst exportsAreMissing = !(await pathExists(path.join(__exports)));\n\tconst previousRenderFailed = db.domains[domain]?.isRendering;\n\tconst newDeployDetected = await hasNewCommit(__cache);\n\n\tif (exportsAreMissing) {\n\t\treturn {\n\t\t\trenderMode: RENDER_MODE.FROM_SCRATCH,\n\t\t\treason: \"missing exports directory\",\n\t\t};\n\t}\n\n\tif (previousRenderFailed) {\n\t\treturn {\n\t\t\trenderMode: RENDER_MODE.FROM_SCRATCH,\n\t\t\treason: \"error in previous render\",\n\t\t};\n\t}\n\n\tif (newDeployDetected) {\n\t\treturn {\n\t\t\trenderMode: RENDER_MODE.FROM_SCRATCH,\n\t\t\treason: \"new commit hash\",\n\t\t};\n\t}\n\n\tif (!shouldBeRendered) {\n\t\treturn {\n\t\t\trenderMode: RENDER_MODE.IDLE,\n\t\t\treason: \"no activity\",\n\t\t};\n\t}\n\n\treturn {\n\t\trenderMode: RENDER_MODE.INCREMENTAL,\n\t\treason: \"has changes\",\n\t};\n}\n\nasync function hasNewCommit(basePath: string): Promise<boolean> {\n\tconst commitFile = path.join(basePath, \"commit\");\n\tconst currentCommit = execSync(\"git rev-parse HEAD\").toString().trim();\n\n\tif (await pathExists(commitFile)) {\n\t\tconst savedCommit = (await fsp.readFile(commitFile, \"utf-8\")).trim();\n\t\tif (savedCommit === currentCommit) {\n\t\t\treturn false; // No hay nuevo commit\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn true;\n}\n\nasync function updateCommitFile(options: { basePath: string }) {\n\tconst { basePath } = options;\n\tconst currentCommit = execSync(\"git rev-parse HEAD\").toString().trim();\n\tawait fsp.writeFile(path.join(basePath, \"commit\"), currentCommit);\n}\n\nasync function getRenderModeFromDB(domain: string): Promise<RenderModeTuple> {\n\tconst db = await readDB();\n\n\tif (!db.domains[domain]) {\n\t\tthrow new Error(brush.red(`[!] Error: Domain ${domain} not found in DB`));\n\t}\n\n\tif (!db.domains[domain].renderMode) {\n\t\tthrow new Error(brush.red(`[!] Error: Render mode not found for domain ${domain}`));\n\t}\n\n\treturn {\n\t\trenderMode: db.domains[domain].renderMode,\n\t\treason: db.domains[domain].renderModeReason,\n\t};\n}\n\nasync function getRenderPathsHydratedWithDomainFromDB(options?: {\n\tdomain?: string;\n\tdbFilePath?: string;\n}) {\n\tconst { domain, dbFilePath } = options || {};\n\n\tconst db = await readDB(dbFilePath);\n\tconst paths = db.paths;\n\n\treturn {\n\t\t__root: paths.root,\n\t\t__cache: path.join(paths.cxCache, domain || \"\"),\n\t\t__components: paths.components,\n\t\t__cx: paths.cx,\n\t\t__sites: paths.exportsDir,\n\t\t__exports: path.join(paths.exportsDir, domain || \"\"),\n\t\t__exports_backup: path.join(paths.exportsDirBackup, domain || \"\"),\n\t\t__ssg: paths.ssg,\n\t\t__exports_dist: path.join(paths.exportsDir, domain || \"\", \"dist\"),\n\t};\n}\n\nasync function getRenderMetadataFromDB() {\n\tconst db = await readDB();\n\treturn {\n\t\tgriddoVersion: db.griddoVersion,\n\t\tbuildReportFileName: db.buildReportFileName,\n\t};\n}\n\n/**\n * Save a file with the end of build process to use as `end-render` signal.\n */\nasync function generateBuildReport(domain: string) {\n\tconst authControl = await AuthService.login();\n\n\tconst { __root } = await getRenderPathsHydratedWithDomainFromDB();\n\tconst { buildReportFileName } = await getRenderMetadataFromDB();\n\tconst { buildProcessData } = await getBuildMetadata(domain);\n\n\tconst buildSitesInfo = Object.keys(buildProcessData).map((siteID) => ({\n\t\t...buildProcessData[siteID],\n\t\tsiteId: Number.parseInt(siteID),\n\t}));\n\n\tconst report = {\n\t\tauthControl,\n\t\tsites: buildSitesInfo,\n\t};\n\n\tconst reportFilePath = path.join(__root, \"current-dist\", buildReportFileName);\n\n\tawait fsp.writeFile(reportFilePath, JSON.stringify(report));\n\n\tGriddoLog.verbose(`build report saved in ${reportFilePath}`);\n}\n\nexport {\n\tassertRenderIsValid,\n\tgenerateBuildReport,\n\tgetRenderMetadataFromDB,\n\tgetRenderModeFromDB,\n\tgetRenderPathsHydratedWithDomainFromDB,\n\tmarkRenderAsCompleted,\n\tmarkRenderAsStarted,\n\tresolveDomainRenderMode,\n\tupdateCommitFile,\n};\n", "import type {\n\tAPIRequest,\n\tAPIResponses,\n\tGetAPI,\n\tPostAPI,\n\tPutAPI,\n\tShowApiErrorOptions,\n} from \"../shared/types/api\";\nimport type { Petition } from \"../shared/types/global\";\n\nimport crypto from \"node:crypto\";\nimport fsp from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { RenderError } from \"../core/errors\";\nimport { pathExists } from \"../core/fs\";\nimport { GriddoLog } from \"../core/GriddoLog\";\nimport { addLogToBuffer } from \"../core/logger\";\nimport { brush } from \"../shared/npm-modules/brush\";\nimport { AuthService } from \"./auth\";\nimport { getRenderPathsHydratedWithDomainFromDB } from \"./render\";\n\n// Envs\nconst { env } = process;\nconst { RETRY_WAIT_SECONDS = \"4\", RETRY_ATTEMPTS = \"4\" } = env;\n\n/**\n * Make a GET/PUT/POST request to the Griddo API.\n *\n * @template T Response Type returned.\n * @returns {Promise<T>} A promise that is resolved with the data from the API response.\n *\n * @example\n *\tconst response = await requestAPI<Site>(\n *\t\t{ endpoint: \"...\", cacheKey: \"...\", ... },\n *\t\t\"get\",\n *\t\t\"...\"\n *\t);\n */\nasync function requestAPI<T extends APIResponses>(\n\tprops: APIRequest,\n\tmethod: string,\n\tappendToLog = \"\",\n): Promise<T> {\n\tconst {\n\t\tendpoint,\n\t\tbody,\n\t\tcacheKey = \"\",\n\t\tattempt = 1,\n\t\theaders,\n\t\tuseApiCacheDir = true,\n\t\tlogToFile = true,\n\t} = props;\n\tconst cacheOptions = { endpoint, body, headers, cacheKey };\n\n\t// Cache\n\tif (cacheKey && useApiCacheDir) {\n\t\tconst start = new Date();\n\t\tconst cacheData = await searchCacheData<T>(cacheOptions);\n\n\t\tif (cacheData) {\n\t\t\tif (logToFile) {\n\t\t\t\tconst siteId = getSafeSiteId(cacheData);\n\t\t\t\tconst siteIdMsg = siteId ? `site: ${siteId}` : \"\";\n\t\t\t\tconst duration = msToSec(Date.now() - start.getTime());\n\t\t\t\taddLogToBuffer(`${method} (cache) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`);\n\t\t\t}\n\t\t\treturn cacheData;\n\t\t}\n\t}\n\n\t// Network\n\ttry {\n\t\tconst start = new Date();\n\n\t\t// Prepare fetch options\n\t\tconst fetchOptions: RequestInit = {\n\t\t\tmethod: method.toUpperCase(),\n\t\t\theaders: Object.assign({}, headers, AuthService.headers) as Record<string, string>,\n\t\t};\n\n\t\t// Add body for non-GET requests\n\t\tif (method.toLowerCase() !== \"get\" && body) {\n\t\t\tfetchOptions.body = JSON.stringify(body);\n\t\t\tif (!fetchOptions.headers) fetchOptions.headers = {};\n\t\t\t(fetchOptions.headers as Record<string, string>)[\"Content-Type\"] = \"application/json\";\n\t\t}\n\n\t\tconst response = await fetch(endpoint, fetchOptions);\n\n\t\t// Handle non-2xx responses\n\t\tif (!response.ok) {\n\t\t\tif (response.status === 404) {\n\t\t\t\t// @ts-expect-error page maybe will be 404\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tthrow new Error(`HTTP ${response.status}: ${response.statusText}`);\n\t\t}\n\n\t\tconst data: T = await response.json();\n\n\t\tif (logToFile) {\n\t\t\tconst siteId = getSafeSiteId(data);\n\t\t\tconst siteIdMsg = siteId ? `site: ${siteId}` : \"\";\n\t\t\tconst duration = msToSec(Date.now() - start.getTime());\n\t\t\taddLogToBuffer(`${method} (fetch) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`);\n\t\t}\n\n\t\tif (useApiCacheDir) {\n\t\t\tawait saveCache(cacheOptions, data);\n\t\t}\n\n\t\treturn data;\n\t} catch (e) {\n\t\tconst error = e as Error;\n\n\t\tif (attempt > parseInt(RETRY_ATTEMPTS)) {\n\t\t\tGriddoLog.log(`\nMax attempts ${RETRY_ATTEMPTS} reached\n--------------------------------------\n- ${method.toUpperCase()} ${endpoint}\n- BODY: ${JSON.stringify(body)}\n- HEADERS: ${JSON.stringify(headers)}\n- ERROR: ${error.message}\n--------------------------------------\n`);\n\t\t\tthrow new RenderError(error);\n\t\t}\n\n\t\tshowApiError(error, {\n\t\t\tcallInfo: { endpoint, body },\n\t\t});\n\n\t\tGriddoLog.warn(`Waiting for retry: ${method}`, endpoint);\n\n\t\tawait delay(parseInt(RETRY_WAIT_SECONDS) * 1000);\n\n\t\treturn requestAPI<T>(\n\t\t\t{\n\t\t\t\tendpoint,\n\t\t\t\tbody,\n\t\t\t\theaders,\n\t\t\t\tcacheKey,\n\t\t\t\tattempt: attempt + 1,\n\t\t\t},\n\t\t\tmethod,\n\t\t\tappendToLog,\n\t\t);\n\t}\n}\n\n/**\n * Make a GET request to the Griddo API.\n *\n * @template T Response Type returned.\n * @returns A promise that is resolved with the data from the API response.\n */\nasync function getApi<T extends APIResponses>(props: GetAPI) {\n\treturn requestAPI<T>(props, \"get\");\n}\n\n/**\n * Make a PUT request to the Griddo API.\n *\n * @template T Response Type returned.\n * @returns A promise that is resolved with the data from the API response.\n */\nasync function putApi<T extends APIResponses>(props: PutAPI) {\n\treturn requestAPI<T>(props, \"put\");\n}\n\n/**\n * Make a POST request to the Griddo API.\n *\n * @template T Response Type returned.\n * @returns A promise that is resolved with the data from the API response.\n */\nasync function postApi<T extends APIResponses>(props: PostAPI) {\n\tconst { endpoint, body, headers } = props;\n\tconst referenceFieldBodyParams =\n\t\tendpoint.endsWith(\"/distributor\") &&\n\t\t`# ReferenceField body: ${JSON.stringify(body)} lang: ${JSON.stringify(headers?.lang)}`;\n\n\treturn requestAPI<T>(props, \"post\", referenceFieldBodyParams || \"\");\n}\n\n/**\n * Shows an API error through the terminal.\n */\nfunction showApiError(error: Error, options: ShowApiErrorOptions) {\n\tconst { message, stack } = error;\n\tconst { callInfo } = options;\n\tconst callInfoArray = [];\n\n\tfor (const item of Object.keys(callInfo) as (keyof typeof callInfo)[]) {\n\t\tcallInfoArray.push(\n\t\t\t`${item}: ${\n\t\t\t\ttypeof callInfo[item] === \"object\" ? JSON.stringify(callInfo[item]) : callInfo[item]\n\t\t\t}`,\n\t\t);\n\t}\n\n\t// Compose the errors output\n\tconst callInfoStr = callInfoArray.join(\"\\n\");\n\tconst errorDetailsStr = `${message}\\n${stack}`;\n\n\t// Print the error\n\tGriddoLog.warn(\n\t\tbrush.red(`\n=============\n\n{ Call info }\n${callInfoStr}\n\n{ Error details }\n${errorDetailsStr}\n\n=============\n`),\n\t);\n}\n\n/**\n * Return a siteID from a response object if exist\n * @param response A response object\n */\nfunction getSafeSiteId(response: APIResponses) {\n\tif (typeof response !== \"object\" || response === null || Array.isArray(response)) {\n\t\treturn undefined;\n\t}\n\n\treturn \"site\" in response && response.site ? response.site : undefined;\n}\n\n/**\n * Custom delay using the \"promise hack\",\n *\n * @param ms Amount of miliseconds to be delayed\n */\nfunction delay(ms: number): Promise<void> {\n\treturn new Promise((res) => setTimeout(res, ms));\n}\n\n/**\n * Converts milliseconds to seconds with a fixed number of decimals.\n *\n * @param ms The number in milliseconds.\n * @param fixed The amount of fixed decimals.\n * @returns The converted number in seconds with the fixed number of decimals.\n */\nfunction msToSec(ms: number, decimals = 3): number {\n\treturn Number.parseFloat((ms / 1000).toFixed(decimals));\n}\n\n/**\n * Generate a filename with a hash using a Petition object\n * @param petition An object\n */\nasync function generateFilenameWithHash(petition: Petition) {\n\tconst { __root } = await getRenderPathsHydratedWithDomainFromDB();\n\tconst apiCacheDir = path.join(__root, \"apiCache\");\n\n\tconst hashSum = crypto.createHash(\"sha256\");\n\thashSum.update(JSON.stringify(petition));\n\n\treturn `${apiCacheDir}/${hashSum.digest(\"hex\")}`;\n}\n\n/**\n * Save a file using a hash name.\n *\n * @param petition An object.\n * @param content Content to be saved.\n */\nasync function saveCache<T>(petition: Petition, content: T) {\n\tconst stringContent = typeof content === \"string\" ? content : JSON.stringify(content);\n\tconst filename = await generateFilenameWithHash(petition);\n\tconst filepath = path.dirname(filename);\n\n\tif (!(await pathExists(filepath))) {\n\t\tawait fsp.mkdir(filepath, { recursive: true });\n\t}\n\n\tawait fsp.writeFile(filename, stringContent, \"utf8\");\n}\n\n/**\n * Search in the `apiCache` dir for a file using the petition as hash generator.\n * Return the file content if found or null if not.\n *\n * @param petition An object\n */\nasync function searchCacheData<T>(petition: Petition) {\n\ttry {\n\t\tconst file = await generateFilenameWithHash(petition);\n\t\tconst fileContent = await fsp.readFile(file, \"utf8\");\n\t\tconst jsonData = JSON.parse(fileContent) as T;\n\n\t\treturn jsonData;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport { getApi as get, postApi as post, putApi as put };\n", "import type { RenderDB } from \"../shared/types/render\";\n\nimport fsp from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { GRIDDO_BUILD_LOGS, GRIDDO_BUILD_LOGS_BUFFER_SIZE } from \"../shared/envs\";\nimport { readDB } from \"./db\";\nimport { GriddoLog } from \"./GriddoLog\";\n\nconst logBuffer: string[] = [];\nlet logFilePath: string | null = null;\nlet flushPromise: Promise<void> | null = null;\nconst LOG_BUFFER_FLUSH_THRESHOLD = GRIDDO_BUILD_LOGS_BUFFER_SIZE;\nconst LOG_FILENAME = \"render-detail-log.txt\";\nconst LOG_TO_FILE_IS_DISABLED = !GRIDDO_BUILD_LOGS;\n\nlet dbData: RenderDB | null = null;\n\n// Universal data cache for this module...\nasync function getDBData() {\n\tif (!dbData) {\n\t\tdbData = await readDB();\n\t}\n\treturn dbData;\n}\n\nasync function initializeLogFile() {\n\tif (LOG_TO_FILE_IS_DISABLED) {\n\t\treturn;\n\t}\n\n\tconst data = await getDBData();\n\tlogFilePath = path.join(data.paths.root, LOG_FILENAME);\n\n\tawait fsp.rm(logFilePath, { force: true });\n}\n\nfunction addLogToBuffer(lineContent: string) {\n\tif (LOG_TO_FILE_IS_DISABLED) {\n\t\treturn;\n\t}\n\n\tlogBuffer.push(lineContent.toString());\n\n\tif (logBuffer.length >= LOG_BUFFER_FLUSH_THRESHOLD) {\n\t\t// Fire-and-forget flush to avoid blocking the main thread.\n\t\tflushLogsToFile().catch((error) => {\n\t\t\tGriddoLog.error(\"Background log flush failed:\", error);\n\t\t});\n\t}\n}\n\n/**\n * Vuelca el contenido del buffer de logs al archivo de logs en disco.\n * Si el buffer est\u00E1 vac\u00EDo, ya se est\u00E1 volcando, o no hay ruta de archivo, no hace nada.\n * Si ocurre un error al escribir, los logs se reinsertan al buffer para reintentar en el siguiente flush.\n */\nasync function flushLogsToFile() {\n\t// Si ya hay un volcado en curso, espera a que termine.\n\tif (flushPromise) {\n\t\tawait flushPromise;\n\t}\n\n\tif (logBuffer.length === 0 || !logFilePath) {\n\t\treturn;\n\t}\n\n\tconst performFlush = async () => {\n\t\tconst logsToFlush = [...logBuffer];\n\t\tlogBuffer.length = 0;\n\n\t\ttry {\n\t\t\tawait fsp.appendFile(logFilePath!, `${logsToFlush.join(\"\\n\")}\\n`);\n\t\t} catch (error) {\n\t\t\tlogBuffer.unshift(...logsToFlush);\n\t\t\tGriddoLog.error(\"Error flushing logs:\", error);\n\t\t\t// No relanzamos el error para no detener el \"fire-and-forget\"\n\t\t}\n\t};\n\n\tflushPromise = performFlush();\n\n\ttry {\n\t\tawait flushPromise;\n\t} finally {\n\t\tflushPromise = null;\n\t}\n}\n\n/**\n * Copia el archivo de log detallado de renderizado (\"render-detail-log.txt\")\n * desde el directorio ra\u00EDz del proyecto al directorio de logs del dominio en exports,\n * usando una marca de tiempo en el nombre de destino.\n * Si el archivo no existe, ignora el error salvo que sea distinto de ENOENT.\n *\n * @param domain - Nombre del dominio para el que se guarda el log.\n */\nasync function saveDetailRenderLog(domain: string) {\n\tawait flushLogsToFile();\n\n\tconst data = await getDBData();\n\n\tconst dateString = getFormattedDateTime();\n\tconst debugDir = path.join(data.paths.exportsDir, domain, \"logs\");\n\n\tawait fsp.mkdir(debugDir, { recursive: true });\n\n\tconst src = path.join(data.paths.root, LOG_FILENAME);\n\tconst dst = path.join(debugDir, `${dateString}-${LOG_FILENAME}`);\n\n\t// Move log to exports\n\ttry {\n\t\tawait fsp.cp(src, dst);\n\t} catch (error) {\n\t\t// It's possible the file doesn't exist if GRIDDO_BUILD_LOGS is false\n\t\t// or if no logs were ever added.\n\t\tif (error instanceof Error && \"code\" in error && error.code !== \"ENOENT\") {\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n\nfunction getFormattedDateTime() {\n\tconst now = new Date();\n\tconst year = now.getFullYear();\n\tconst month = String(now.getMonth() + 1).padStart(2, \"0\");\n\tconst day = String(now.getDate()).padStart(2, \"0\");\n\n\tconst hours = String(now.getHours()).padStart(2, \"0\");\n\tconst minutes = String(now.getMinutes()).padStart(2, \"0\");\n\tconst seconds = String(now.getSeconds()).padStart(2, \"0\");\n\n\t// Formato recomendado para ordenaci\u00F3n de archivos: YYYY-MM-DD_HH-mm-ss\n\treturn `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`;\n}\n\nexport { addLogToBuffer, flushLogsToFile, initializeLogFile, saveDetailRenderLog };\n", "import type { Core } from \"@griddo/core\";\nimport type {\n\tAllSitesReponse,\n\tEndPageInfoResponse,\n\tEndSiteRenderBody,\n\tLanguagesResponse,\n\tPageResponse,\n\tReferenceFieldBody,\n\tReferenceFieldResponse,\n\tSitemapAPIResponse,\n\tSocialsResponse,\n\tStartPageRenderResponse,\n} from \"../shared/types/api\";\nimport type { Site } from \"../shared/types/sites\";\n\nimport {\n\tBUILD_END,\n\tBUILD_START,\n\tGET_ALL,\n\tGET_PAGE,\n\tGET_REFERENCE_FIELD_DATA,\n\tGET_SITEMAP,\n\tINFO,\n\tLANGUAGES,\n\tSOCIALS,\n} from \"../shared/endpoints\";\nimport { get, post } from \"./api\";\n\n/**\n * Get a list of site objects.\n */\nasync function getAllSites(domain: string) {\n\treturn get<AllSitesReponse>({\n\t\tendpoint: `${GET_ALL}?domainSlug=${domain}`,\n\t});\n}\n\n/**\n * Get a list of site objects from a domain.\n */\nasync function getAllSitesFromDomain(domain: string) {\n\tconst allSites = await get<AllSitesReponse>({ endpoint: GET_ALL });\n\n\tif (allSites.length) {\n\t\tfor (const site of allSites) {\n\t\t\tconst { items } = await getSiteLanguages(site.id);\n\n\t\t\t// A\u00F1adimos la prop domains con el dominio \"cocinado\" con los\n\t\t\t// idiomas y teniendo en cuenta solo el dominio actual.\n\t\t\tsite.domains = items\n\t\t\t\t.filter(\n\t\t\t\t\t(item) =>\n\t\t\t\t\t\titem.domain && (item.domain.slug === domain || item.domain.slug === `/${domain}`),\n\t\t\t\t)\n\t\t\t\t.map((item) => ({ [item.id]: `${item.domain.slug}${item.path}` }));\n\t\t}\n\t}\n\n\treturn allSites.filter((site) => site.domains.length > 0);\n}\n\n/**\n * Fetch a page object from API.\n */\nasync function getPage(id: number, cacheKey: string) {\n\treturn get<PageResponse>({\n\t\tendpoint: `${GET_PAGE}/${id}`,\n\t\tcacheKey,\n\t});\n}\n\n/**\n * Get site info\n */\nasync function getSiteInfo(id: number, cacheKey = \"\") {\n\tconst [prefix, suffix] = INFO;\n\n\treturn get<Site>({\n\t\tendpoint: `${prefix}${id}${suffix}`,\n\t\tcacheKey,\n\t});\n}\n\nasync function getSiteLanguages(id: number, cacheKey = \"\") {\n\tconst [prefix, suffix] = LANGUAGES;\n\n\treturn get<LanguagesResponse>({\n\t\tendpoint: `${prefix}${id}${suffix}`,\n\t\tcacheKey,\n\t});\n}\n\nasync function startSiteRender(id: number) {\n\tconst [prefix, suffix] = BUILD_START;\n\n\treturn get<StartPageRenderResponse>({\n\t\tendpoint: `${prefix}${id}${suffix}`,\n\t});\n}\n\n/**\n * Send the end signal to API for a render site.\n */\nasync function endSiteRender(id: number, body: EndSiteRenderBody) {\n\tconst [prefix, suffix] = BUILD_END;\n\n\tawait post<EndPageInfoResponse>({\n\t\tendpoint: `${prefix}${id}${suffix}`,\n\t\tbody,\n\t\tuseApiCacheDir: false,\n\t\tlogToFile: false,\n\t});\n}\n\nasync function getReferenceFieldSiteData(\n\tpage: Core.Page,\n\tbody: ReferenceFieldBody,\n\tcacheKey: string,\n\tdataSiteId?: number,\n\tdataLangID?: number,\n) {\n\tconst [prefix, suffix] = GET_REFERENCE_FIELD_DATA;\n\tconst site = dataSiteId || page.site;\n\tconst lang = dataLangID || page.language;\n\n\treturn post<ReferenceFieldResponse>({\n\t\tendpoint: `${prefix}${site}${suffix}`,\n\t\tbody,\n\t\theaders: { lang },\n\t\tcacheKey,\n\t});\n}\n\nasync function getSitemap(options: { siteId: number; headers?: Record<string, string> }) {\n\tconst { siteId, headers } = options;\n\tconst [prefix, suffix] = GET_SITEMAP;\n\n\treturn get<SitemapAPIResponse>({\n\t\tendpoint: `${prefix}${siteId}${suffix}`,\n\t\theaders,\n\t});\n}\n\nasync function getSiteSocials(id: number, cacheKey = \"\") {\n\tconst [prefix, suffix] = SOCIALS;\n\n\treturn get<SocialsResponse>({\n\t\tendpoint: `${prefix}${id}${suffix}`,\n\t\tcacheKey,\n\t});\n}\n\nexport {\n\tendSiteRender,\n\tgetAllSites,\n\tgetAllSitesFromDomain,\n\tgetPage,\n\tgetReferenceFieldSiteData,\n\tgetSiteInfo,\n\tgetSiteLanguages,\n\tgetSitemap,\n\tgetSiteSocials,\n\tstartSiteRender,\n};\n"],
|
|
5
|
+
"mappings": "oeAAA,IAAAA,GAAgB,+BAChBC,GAAiB,wBCCjB,IAAAC,GAAiB,wBCKjB,IAAMC,GAAQ,UACRC,EAAQ,CACb,MAAO,WACP,IAAK,WACL,MAAO,WACP,OAAQ,WACR,KAAM,WACN,QAAS,WACT,KAAM,WACN,MAAO,WACP,KAAM,WACN,KAAM,UACN,IAAK,SACN,EAMMC,EAAQ,CAAC,EAEf,QAAWC,KAASF,EAAO,CAC1B,IAAMG,EAAMD,EACZD,EAAME,CAAG,EAAKC,GAA0B,GAAGJ,EAAMG,CAAG,CAAC,GAAGC,CAAI,GAAGL,EAAK,EACrE,CC7BA,IAAMM,EAAc,CACnB,aAAc,eACd,YAAa,cACb,KAAM,OACN,MAAO,QACP,UAAW,WACZ,ECNA,IAAAC,EAAgB,+BAChBC,EAAiB,wBCHjB,IAAAC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G,EAAS,MAAMrB,GAAgB,CACpC,OAAAG,EACA,eAAgBW,EAChB,oBAAAZ,CACD,CAAC,EAEDM,EAAU,KAAK,0BAA0BL,CAAM,QAAQ,EAEvD,QAAWmB,KAAQD,EAAO,MAAO,CAChCC,EAAK,cAAgB,CAAC,GAAG,IAAI,IAAIA,EAAK,aAAa,CAAC,EACpDA,EAAK,gBAAkB,CAAC,GAAG,IAAI,IAAIA,EAAK,eAAe,CAAC,EAExD,GAAM,CAAE,OAAAC,EAAQ,GAAGC,CAAK,EAAIF,EAC5Bd,EAAU,KAAK,SAASe,CAAM,GAAG,EACjC,MAAME,GAAcF,EAAQC,CAAI,CACjC,CACD,CAEA,eAAeE,IAAO,CACrB,MAAMd,GAAU,CACjB,CAEAe,GAAiBD,EAAI",
|
|
6
|
+
"names": ["import_promises", "import_node_path", "import_node_path", "RESET", "CODES", "brush", "color", "key", "text", "RENDER_MODE", "import_promises", "import_node_path", "import_node_path", "import_node_fs", "import_node_path", "import_node_process", "import_node_url", "toPath", "urlOrPath", "findUpSync", "name", "options", "cwd", "process", "type", "stopAtOption", "directory", "path", "toPath", "root", "stopAt", "isAbsoluteName", "filePath", "stats", "fs", "pkgDirSync", "options", "cwd", "filePath", "findUpSync", "path", "env", "envIsTruthy", "value", "GRIDDO_API_URL", "GRIDDO_PUBLIC_API_URL", "GRIDDO_BOT_USER", "GRIDDO_BOT_PASSWORD", "GRIDDO_API_CONCURRENCY_COUNT", "GRIDDO_SKIP_BUILD_CHECKS", "GRIDDO_BUILD_LOGS", "GRIDDO_BUILD_LOGS_BUFFER_SIZE", "GRIDDO_SSG_VERBOSE_LOGS", "GRIDDO_SEARCH_FEATURE", "GRIDDO_ASSET_PREFIX", "GRIDDO_REACT_APP_INSTANCE", "GRIDDO_AI_EMBEDDINGS", "GRIDDO_VERBOSE_LOGS", "GRIDDO_USE_DIST_BACKUP", "GRIDDO_SSG_BUNDLE_ANALYZER", "GriddoLog", "_GriddoLog", "str", "GRIDDO_VERBOSE_LOGS", "brush", "GRIDDO_BUILD_LOGS", "args", "root", "pkgDirSync", "path", "cache", "dbFilePath", "readDB", "customDBPath", "file", "fsp", "error", "GriddoLog", "writeDB", "renderDB", "import_promises", "import_node_path", "import_promises", "ArtifactError", "LoginError", "pathExists", "dir", "fsp", "distRollback", "domain", "data", "readDB", "exportsDir", "exportsDirBackup", "GriddoLog", "path", "fsp", "pathExists", "RenderError", "originalError", "throwError", "options", "stack", "error", "message", "expected", "hint", "errorColor", "GriddoLog", "brush", "extraText", "withErrorHandler", "fn", "data", "readDB", "root", "path", "distRollback", "RENDER_MODE", "writeDB", "GRIDDO_API_URL", "GRIDDO_PUBLIC_API_URL", "AI_EMBEDDINGS", "ALERT", "DOMAINS", "GET_ALL", "GET_PAGE", "LOGIN", "RESET_RENDER", "ROBOTS", "SEARCH", "SETTINGS", "SITE_URI", "BUILD_END", "AuthService", "response", "LOGIN", "GRIDDO_BOT_USER", "GRIDDO_BOT_PASSWORD", "token", "throwError", "LoginError", "authService", "import_node_path", "getRenderModeFromDB", "domain", "db", "readDB", "brush", "getRenderPathsHydratedWithDomainFromDB", "options", "dbFilePath", "paths", "path", "getRenderMetadataFromDB", "import_node_crypto", "import_promises", "import_node_path", "import_promises", "logBuffer", "logFilePath", "flushPromise", "LOG_BUFFER_FLUSH_THRESHOLD", "GRIDDO_BUILD_LOGS_BUFFER_SIZE", "LOG_TO_FILE_IS_DISABLED", "GRIDDO_BUILD_LOGS", "addLogToBuffer", "lineContent", "LOG_TO_FILE_IS_DISABLED", "logBuffer", "LOG_BUFFER_FLUSH_THRESHOLD", "flushLogsToFile", "error", "GriddoLog", "flushPromise", "logFilePath", "logsToFlush", "fsp", "env", "RETRY_WAIT_SECONDS", "RETRY_ATTEMPTS", "requestAPI", "props", "method", "appendToLog", "endpoint", "body", "cacheKey", "attempt", "headers", "useApiCacheDir", "logToFile", "cacheOptions", "start", "cacheData", "searchCacheData", "siteId", "getSafeSiteId", "siteIdMsg", "duration", "msToSec", "addLogToBuffer", "fetchOptions", "authService", "response", "data", "saveCache", "e", "error", "GriddoLog", "RenderError", "showApiError", "delay", "postApi", "props", "endpoint", "body", "headers", "referenceFieldBodyParams", "requestAPI", "showApiError", "error", "options", "message", "stack", "callInfo", "callInfoArray", "item", "callInfoStr", "errorDetailsStr", "GriddoLog", "brush", "getSafeSiteId", "response", "delay", "ms", "res", "msToSec", "decimals", "generateFilenameWithHash", "petition", "__root", "getRenderPathsHydratedWithDomainFromDB", "apiCacheDir", "path", "hashSum", "crypto", "saveCache", "content", "stringContent", "filename", "filepath", "pathExists", "fsp", "searchCacheData", "file", "fileContent", "endSiteRender", "id", "body", "prefix", "suffix", "BUILD_END", "postApi", "getRenderReport", "options", "buildReportFileName", "domain", "exportsSiteDir", "buildReportFile", "path", "pathExists", "GriddoLog", "throwError", "ArtifactError", "fsp", "endRender", "getRenderMetadataFromDB", "__sites", "getRenderPathsHydratedWithDomainFromDB", "authService", "renderMode", "reason", "getRenderModeFromDB", "RENDER_MODE", "report", "site", "siteId", "body", "endSiteRender", "main", "withErrorHandler"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";var rr=Object.create;var v=Object.defineProperty;var er=Object.getOwnPropertyDescriptor;var tr=Object.getOwnPropertyNames;var or=Object.getPrototypeOf,nr=Object.prototype.hasOwnProperty;var ir=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of tr(r))!nr.call(e,n)&&n!==t&&v(e,n,{get:()=>r[n],enumerable:!(i=er(r,n))||i.enumerable});return e};var c=(e,r,t)=>(t=e!=null?rr(or(e)):{},ir(r||!e||!e.__esModule?v(t,"default",{value:e,enumerable:!0}):t,e));var x=c(require("node:fs/promises")),T=c(require("node:path"));var X=c(require("node:path"));var sr="\x1B[0m",G={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",gray:"\x1B[90m",bold:"\x1B[1m",dim:"\x1B[2m"},a={};for(let e in G){let r=e;a[r]=t=>`${G[r]}${t}${sr}`}var g={FROM_SCRATCH:"FROM_SCRATCH",INCREMENTAL:"INCREMENTAL",IDLE:"IDLE",ERROR:"ERROR",COMPLETED:"COMPLETED"};var S=c(require("node:fs/promises")),y=c(require("node:path"));var L=c(require("node:path"));var F=c(require("node:fs"));var u=c(require("node:path")),N=c(require("node:process")),P=require("node:url"),$=e=>e instanceof URL?(0,P.fileURLToPath)(e):e;function k(e,r={}){let{cwd:t=N.default.cwd(),type:i="file",stopAt:n}=r,p=u.default.resolve($(t)??""),{root:E}=u.default.parse(p),b=n?u.default.resolve(p,$(n)):E,Q=u.default.isAbsolute(e);for(;;){let B=Q?e:u.default.join(p,e);try{let C=F.default.statSync(B,{throwIfNoEntry:!1});if(i==="file"&&C?.isFile()||i==="directory"&&C?.isDirectory())return B}catch{}if(p===b||p===E)break;p=u.default.dirname(p)}}function U(e){let{cwd:r}=e||{},t=k("package.json",{cwd:r});return t&&L.default.dirname(t)}var{env:s}=process;function m(e){if(!e)return!1;switch(e.trim().toLowerCase()){case"1":case"true":case"yes":case"y":case"on":return!0;default:return!1}}var yr=s.GRIDDO_API_URL||s.API_URL,Rr=s.GRIDDO_PUBLIC_API_URL||s.PUBLIC_API_URL,j=s.botEmail||s.GRIDDO_BOT_USER,M=s.botPassword||s.GRIDDO_BOT_PASSWORD,_r=Number.parseInt(s.GRIDDO_API_CONCURRENCY_COUNT||"10"),br=m(s.GRIDDO_SKIP_BUILD_CHECKS),H=m(s.GRIDDO_BUILD_LOGS),Sr=Number.parseInt(s.GRIDDO_BUILD_LOGS_BUFFER_SIZE||"500"),Ir=m(s.GRIDDO_SSG_VERBOSE_LOGS),Or=m(s.GRIDDO_SEARCH_FEATURE),Ar=s.GRIDDO_ASSET_PREFIX||s.ASSET_PREFIX,xr=s.GRIDDO_REACT_APP_INSTANCE||s.REACT_APP_INSTANCE,Tr=m(s.GRIDDO_AI_EMBEDDINGS),W=m(s.GRIDDO_VERBOSE_LOGS),Br=m(s.GRIDDO_USE_DIST_BACKUP),Cr=m(s.GRIDDO_SSG_BUNDLE_ANALYZER);var o=class e{constructor(){}static verbose(...r){W&&console.log(a.yellow("verbose"),a.dim(r.join(" ")))}static build(...r){H&&e.log(...r)}static info(...r){console.log(`${a.blue("info")} ${r.join(" ")}`)}static success(...r){console.log(`${a.green("success")} ${r.join(" ")}`)}static error(...r){console.error(`${a.red("error")} ${r.join(" ")}`)}static warn(...r){console.warn(`${a.yellow("warn")} ${r.join(" ")}`)}static log(...r){console.log(...r)}};var ar=U({cwd:y.default.resolve(__dirname,"../../..")})||"",cr=y.default.join(ar,".griddo/cache"),J=y.default.join(cr,"db.json");async function f(e=""){let r=e||J;try{return JSON.parse(await S.default.readFile(r,"utf-8"))}catch(t){throw o.error(`Failed to read DB file at ${r}:`,t),t}}async function R(e,r=""){let t=r||J;try{await S.default.writeFile(t,JSON.stringify(e,null," "))}catch(i){throw o.error(`Failed to write DB file at ${t}:`,i),i}}var I=c(require("node:fs/promises")),l=c(require("node:path"));var V=c(require("node:fs/promises"));var K={error:"LoginError",message:"There was a problem logging in to the API",expected:"This happens if the API is currently not working or the credentials are incorrect."};async function h(e){try{return await V.default.access(e),!0}catch{return!1}}async function Y(e){let r=await f(),{exportsDir:t,exportsDirBackup:i}=r.paths;o.info(`Cleaning exports dir for the domain ${e}`),o.verbose(`Deleting ${l.default.join(t,e)}...`),await I.default.rm(l.default.join(t,e),{recursive:!0,force:!0}),await h(l.default.join(i,e))?(await I.default.cp(l.default.join(i,e),l.default.join(t,e),{recursive:!0}),o.info(`export-backup dir for the domain ${e} found. Restoring before exit...`),o.verbose(`Copying ${l.default.join(i,e)} -> ${l.default.join(t,e)}...`)):o.info("No export-backup found, skipping rollback. Next render will create a new exports dir from scratch...")}var _=class extends Error{constructor(r){super(r instanceof Error?r.message:String(r)),this.name="InternalCXError",this.stack=r instanceof Error?r.stack:""}};function D(e,r){let{error:t,message:i,expected:n,hint:p}=e,E=o.log(a.red(`[ ${t} ]`)),b=[n,p].filter(Boolean).join(`
|
|
2
|
+
`);throw o.log(`
|
|
3
|
+
${E}
|
|
4
|
+
${i}
|
|
5
|
+
${b}
|
|
6
|
+
|
|
7
|
+
${a.red("stack")}
|
|
8
|
+
${JSON.stringify(r,null,2)}`),new _(r)}async function Z(e){try{await e()}catch(r){r instanceof _?o.error("Internal Griddo RenderError"):r instanceof Error?o.error(r.message):o.error(`An unexpected error occurred ${r}`);try{let i=await f(),{root:n}=i.paths;i.needsRollbackOnError?(o.info("Cleaning exports dir..."),o.verbose(`Deleting ${X.default.join(n,"exports")}...`),await Y(i.currentRenderingDomain)):o.info("No rollback needed, skipping...")}catch{o.info("Early render stage, no db.json created yet...")}let t=await f();throw t.domains[t.currentRenderingDomain].isRendering=!1,t.domains[t.currentRenderingDomain].renderMode=g.ERROR,await R(t),r}}var w=c(require("node:path"));var d=process.env.GRIDDO_API_URL,dr=process.env.GRIDDO_PUBLIC_API_URL,ee=`${d}/ai/embeddings`,te=`${dr}/alert`,oe=`${d}/domains`,ne=`${d}/sites/all`,ie=`${d}/page`,q=`${d}/login_check`,se=`${d}/debug/reset-render`,ae=`${d}/domains/robots`,ce=`${d}/search`,de=`${d}/settings`,pe=`${d}/site/`;var O=class{headers;async login(){try{let r=await fetch(q,{method:"POST",headers:{"Content-Type":"application/json",Connection:"close"},body:JSON.stringify({username:j,password:M})});if(!r.ok)throw new Error("Error while login in the API");let{token:t}=await r.json();return this.headers={Authorization:`bearer ${t}`,"Cache-Control":"no-store"},this.headers}catch(r){D(K,r)}}},pr=new O;async function z(e){let r=await f();if(!r.domains[e])throw new Error(a.red(`[!] Error: Domain ${e} not found in DB`));if(!r.domains[e].renderMode)throw new Error(a.red(`[!] Error: Render mode not found for domain ${e}`));return{renderMode:r.domains[e].renderMode,reason:r.domains[e].renderModeReason}}async function A(e){let{domain:r,dbFilePath:t}=e||{},n=(await f(t)).paths;return{__root:n.root,__cache:w.default.join(n.cxCache,r||""),__components:n.components,__cx:n.cx,__sites:n.exportsDir,__exports:w.default.join(n.exportsDir,r||""),__exports_backup:w.default.join(n.exportsDirBackup,r||""),__ssg:n.ssg,__exports_dist:w.default.join(n.exportsDir,r||"","dist")}}async function fr(){let[e]=process.argv.slice(2),{renderMode:r}=await z(e);if(r===g.IDLE)return;let{__exports:t}=await A({domain:e}),i=T.default.join(t,"assets"),n=T.default.join(t,e);await h(i)?(await x.default.rm(n,{force:!0,recursive:!0}),await x.default.rename(i,n)):o.warn("Assets directory not found")}async function mr(){await fr()}Z(mr);
|
|
9
|
+
//# sourceMappingURL=prepare-assets-directory.js.map
|