@griddo/cx 11.7.7-rc.0 → 11.7.7-rc.3
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 +226 -27
- package/build/adapters/gatsby/index.d.ts +4 -0
- package/build/adapters/gatsby/utils.d.ts +22 -0
- package/build/artifacts/index.d.ts +6 -0
- package/build/commands/end-render.d.ts +2 -0
- package/build/commands/move-assets.d.ts +1 -0
- package/build/commands/prepare-domains-render.d.ts +1 -0
- package/build/commands/reset-render.d.ts +2 -0
- package/build/commands/start-render.d.ts +2 -0
- package/build/commands/upload-search-content.d.ts +2 -0
- package/build/constants/endpoints.d.ts +19 -0
- package/build/constants/envs.d.ts +37 -0
- package/build/constants/index.d.ts +57 -0
- package/build/end-render.js +74 -0
- package/build/end-render.js.map +7 -0
- package/build/errors/errors-data.d.ts +22 -0
- package/build/errors/index.d.ts +15 -0
- package/build/index.d.ts +29 -0
- package/build/index.js +73 -0
- package/build/index.js.map +7 -0
- package/build/prepare-domains-render.js +73 -0
- package/build/prepare-domains-render.js.map +7 -0
- package/build/react/Favicon/index.d.ts +5 -0
- package/build/react/Favicon/utils.d.ts +9 -0
- package/build/react/GriddoIntegrations/index.d.ts +20 -0
- package/build/react/GriddoIntegrations/utils.d.ts +26 -0
- package/{react/index.tsx → build/react/index.d.ts} +0 -1
- package/build/react/index.js +3 -0
- package/build/registers/api.d.ts +9 -0
- package/build/registers/gatsby.d.ts +9 -0
- package/build/registers/index.d.ts +3 -0
- package/build/reset-render.js +74 -0
- package/build/reset-render.js.map +7 -0
- package/build/services/auth.d.ts +10 -0
- package/build/services/domains.d.ts +6 -0
- package/build/services/navigation.d.ts +50 -0
- package/build/services/reference-fields.d.ts +20 -0
- package/build/services/register.d.ts +36 -0
- package/build/services/robots.d.ts +19 -0
- package/build/services/settings.d.ts +4 -0
- package/build/services/sites.d.ts +29 -0
- package/build/services/store.d.ts +6 -0
- package/build/start-render.js +100 -0
- package/build/start-render.js.map +7 -0
- package/build/types/api.d.ts +142 -0
- package/build/types/global.d.ts +84 -0
- package/build/types/navigation.d.ts +28 -0
- package/build/types/pages.d.ts +144 -0
- package/build/types/sites.d.ts +57 -0
- package/build/types/templates.d.ts +8 -0
- package/build/upload-search-content.js +74 -0
- package/build/upload-search-content.js.map +7 -0
- package/build/utils/alerts.d.ts +3 -0
- package/build/utils/api.d.ts +23 -0
- package/build/utils/cache.d.ts +35 -0
- package/build/utils/core-utils.d.ts +107 -0
- package/build/utils/create-build-data.d.ts +8 -0
- package/build/utils/domains.d.ts +13 -0
- package/build/utils/folders.d.ts +53 -0
- package/build/utils/health-checks.d.ts +7 -0
- package/build/utils/images.d.ts +16 -0
- package/build/utils/instance.d.ts +21 -0
- package/build/utils/loggin.d.ts +51 -0
- package/build/utils/pages.d.ts +34 -0
- package/build/utils/render.d.ts +13 -0
- package/build/utils/searches.d.ts +15 -0
- package/build/utils/sites.d.ts +31 -0
- package/build/utils/store.d.ts +81 -0
- package/cx.config.d.ts +5 -0
- package/cx.config.js +36 -0
- package/exporter/adapters/gatsby/index.ts +147 -67
- package/exporter/adapters/gatsby/utils.ts +161 -0
- package/exporter/artifacts/README.md +34 -0
- package/exporter/artifacts/index.ts +33 -0
- package/exporter/build.sh +38 -4
- package/exporter/commands/end-render.ts +69 -73
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +31 -144
- package/exporter/commands/reset-render.ts +1 -10
- package/exporter/commands/start-render.ts +44 -23
- package/exporter/commands/upload-search-content.ts +20 -194
- package/exporter/constants/envs.ts +55 -57
- package/exporter/constants/index.ts +129 -0
- package/exporter/{constants/errors.ts → errors/errors-data.ts} +14 -24
- package/exporter/{utils/errors.ts → errors/index.ts} +9 -10
- package/exporter/index.ts +82 -0
- package/{react → exporter/react}/Favicon/index.tsx +7 -1
- package/{react → exporter/react}/GriddoIntegrations/index.tsx +14 -6
- package/{react → exporter/react}/GriddoIntegrations/utils.ts +9 -4
- package/exporter/react/index.tsx +11 -0
- package/exporter/registers/api.ts +14 -0
- package/exporter/registers/gatsby.ts +14 -0
- package/exporter/registers/index.ts +4 -0
- package/exporter/services/auth.ts +6 -7
- package/exporter/services/domains.ts +16 -0
- package/exporter/services/navigation.ts +10 -4
- package/exporter/services/reference-fields.ts +23 -8
- package/exporter/services/register.ts +113 -0
- package/exporter/services/robots.ts +16 -9
- package/exporter/services/settings.ts +17 -0
- package/exporter/services/sites.ts +24 -35
- package/exporter/services/store.ts +78 -120
- package/exporter/types/api.ts +27 -24
- package/exporter/types/global.ts +10 -7
- package/exporter/types/navigation.ts +1 -1
- package/exporter/types/pages.ts +3 -2
- package/exporter/types/sites.ts +2 -1
- package/exporter/utils/alerts.ts +29 -0
- package/exporter/utils/api.ts +82 -46
- package/exporter/utils/cache.ts +62 -37
- package/exporter/utils/core-utils.ts +248 -129
- package/exporter/utils/create-build-data.ts +17 -0
- package/exporter/utils/domains.ts +7 -10
- package/exporter/utils/folders.ts +95 -187
- package/exporter/utils/health-checks.ts +64 -0
- package/exporter/utils/images.ts +6 -1
- package/exporter/utils/instance.ts +12 -9
- package/exporter/utils/loggin.ts +91 -32
- package/exporter/utils/pages.ts +88 -23
- package/exporter/utils/render.ts +48 -149
- package/exporter/utils/searches.ts +156 -0
- package/exporter/utils/sites.ts +90 -81
- package/exporter/utils/store.ts +180 -87
- package/gatsby-browser.tsx +58 -41
- package/gatsby-config.ts +12 -6
- package/gatsby-node.ts +77 -15
- package/gatsby-ssr.tsx +1 -2
- package/package.json +78 -36
- package/src/README.md +7 -0
- package/src/components/Head.tsx +46 -13
- package/src/components/template.tsx +30 -8
- package/src/gatsby-node-utils.ts +2 -91
- package/src/html.tsx +11 -2
- package/src/types.ts +5 -5
- package/start-render.js +7 -0
- package/tsconfig.json +3 -5
- package/build/adapters/gatsby/actions/clean.js +0 -10
- package/build/adapters/gatsby/actions/clean.js.map +0 -1
- package/build/adapters/gatsby/actions/close.js +0 -12
- package/build/adapters/gatsby/actions/close.js.map +0 -1
- package/build/adapters/gatsby/actions/data.js +0 -18
- package/build/adapters/gatsby/actions/data.js.map +0 -1
- package/build/adapters/gatsby/actions/healthCheck.js +0 -10
- package/build/adapters/gatsby/actions/healthCheck.js.map +0 -1
- package/build/adapters/gatsby/actions/init.js +0 -9
- package/build/adapters/gatsby/actions/init.js.map +0 -1
- package/build/adapters/gatsby/actions/meta.js +0 -14
- package/build/adapters/gatsby/actions/meta.js.map +0 -1
- package/build/adapters/gatsby/actions/prepare.js +0 -9
- package/build/adapters/gatsby/actions/prepare.js.map +0 -1
- package/build/adapters/gatsby/actions/relocation.js +0 -15
- package/build/adapters/gatsby/actions/relocation.js.map +0 -1
- package/build/adapters/gatsby/actions/restore.js +0 -26
- package/build/adapters/gatsby/actions/restore.js.map +0 -1
- package/build/adapters/gatsby/actions/ssg.js +0 -9
- package/build/adapters/gatsby/actions/ssg.js.map +0 -1
- package/build/adapters/gatsby/actions/sync.js +0 -51
- package/build/adapters/gatsby/actions/sync.js.map +0 -1
- package/build/adapters/gatsby/index.js +0 -79
- package/build/adapters/gatsby/index.js.map +0 -1
- package/build/adapters/gatsby/shared/context.js +0 -31
- package/build/adapters/gatsby/shared/context.js.map +0 -1
- package/build/adapters/gatsby/shared/diff-assets.js +0 -101
- package/build/adapters/gatsby/shared/diff-assets.js.map +0 -1
- package/build/adapters/gatsby/shared/extract-assets.js +0 -58
- package/build/adapters/gatsby/shared/extract-assets.js.map +0 -1
- package/build/adapters/gatsby/shared/gatsby-build.js +0 -49
- package/build/adapters/gatsby/shared/gatsby-build.js.map +0 -1
- package/build/adapters/gatsby/shared/sync-render.js +0 -210
- package/build/adapters/gatsby/shared/sync-render.js.map +0 -1
- package/build/adapters/gatsby/shared/types.js +0 -3
- package/build/adapters/gatsby/shared/types.js.map +0 -1
- package/build/commands/end-render.js +0 -88
- package/build/commands/end-render.js.map +0 -1
- package/build/commands/prepare-assets-directory.js +0 -32
- package/build/commands/prepare-assets-directory.js.map +0 -1
- package/build/commands/prepare-domains-render.js +0 -133
- package/build/commands/prepare-domains-render.js.map +0 -1
- package/build/commands/reset-render.js +0 -22
- package/build/commands/reset-render.js.map +0 -1
- package/build/commands/start-render.js +0 -45
- package/build/commands/start-render.js.map +0 -1
- package/build/commands/upload-search-content.js +0 -180
- package/build/commands/upload-search-content.js.map +0 -1
- package/build/constants/endpoints.js +0 -42
- package/build/constants/endpoints.js.map +0 -1
- package/build/constants/envs.js +0 -68
- package/build/constants/envs.js.map +0 -1
- package/build/constants/errors.js +0 -81
- package/build/constants/errors.js.map +0 -1
- package/build/services/auth.js +0 -40
- package/build/services/auth.js.map +0 -1
- package/build/services/db-class.js +0 -49
- package/build/services/db-class.js.map +0 -1
- package/build/services/db.js +0 -34
- package/build/services/db.js.map +0 -1
- package/build/services/navigation.js +0 -96
- package/build/services/navigation.js.map +0 -1
- package/build/services/reference-fields.js +0 -131
- package/build/services/reference-fields.js.map +0 -1
- package/build/services/robots.js +0 -60
- package/build/services/robots.js.map +0 -1
- package/build/services/sites.js +0 -109
- package/build/services/sites.js.map +0 -1
- package/build/services/store.js +0 -282
- package/build/services/store.js.map +0 -1
- package/build/types/api.js +0 -3
- package/build/types/api.js.map +0 -1
- package/build/types/global.js +0 -3
- package/build/types/global.js.map +0 -1
- package/build/types/navigation.js +0 -3
- package/build/types/navigation.js.map +0 -1
- package/build/types/pages.js +0 -3
- package/build/types/pages.js.map +0 -1
- package/build/types/render.js +0 -10
- package/build/types/render.js.map +0 -1
- package/build/types/sites.js +0 -3
- package/build/types/sites.js.map +0 -1
- package/build/types/templates.js +0 -3
- package/build/types/templates.js.map +0 -1
- package/build/utils/api.js +0 -161
- package/build/utils/api.js.map +0 -1
- package/build/utils/artifacts.js +0 -34
- package/build/utils/artifacts.js.map +0 -1
- package/build/utils/brush.js +0 -30
- package/build/utils/brush.js.map +0 -1
- package/build/utils/cache.js +0 -106
- package/build/utils/cache.js.map +0 -1
- package/build/utils/check-health.js +0 -68
- package/build/utils/check-health.js.map +0 -1
- package/build/utils/core-utils.js +0 -283
- package/build/utils/core-utils.js.map +0 -1
- package/build/utils/domains.js +0 -37
- package/build/utils/domains.js.map +0 -1
- package/build/utils/errors.js +0 -30
- package/build/utils/errors.js.map +0 -1
- package/build/utils/folders.js +0 -362
- package/build/utils/folders.js.map +0 -1
- package/build/utils/images.js +0 -45
- package/build/utils/images.js.map +0 -1
- package/build/utils/instance.js +0 -66
- package/build/utils/instance.js.map +0 -1
- package/build/utils/loggin.js +0 -108
- package/build/utils/loggin.js.map +0 -1
- package/build/utils/pages.js +0 -359
- package/build/utils/pages.js.map +0 -1
- package/build/utils/render.js +0 -144
- package/build/utils/render.js.map +0 -1
- package/build/utils/sites.js +0 -240
- package/build/utils/sites.js.map +0 -1
- package/build/utils/store.js +0 -193
- package/build/utils/store.js.map +0 -1
- package/exporter/adapters/gatsby/actions/clean.ts +0 -14
- package/exporter/adapters/gatsby/actions/close.ts +0 -17
- package/exporter/adapters/gatsby/actions/data.ts +0 -25
- package/exporter/adapters/gatsby/actions/healthCheck.ts +0 -10
- package/exporter/adapters/gatsby/actions/init.ts +0 -12
- package/exporter/adapters/gatsby/actions/meta.ts +0 -18
- package/exporter/adapters/gatsby/actions/prepare.ts +0 -9
- package/exporter/adapters/gatsby/actions/relocation.ts +0 -15
- package/exporter/adapters/gatsby/actions/restore.ts +0 -36
- package/exporter/adapters/gatsby/actions/ssg.ts +0 -12
- package/exporter/adapters/gatsby/actions/sync.ts +0 -71
- package/exporter/adapters/gatsby/shared/context.ts +0 -50
- package/exporter/adapters/gatsby/shared/diff-assets.ts +0 -113
- package/exporter/adapters/gatsby/shared/extract-assets.ts +0 -61
- package/exporter/adapters/gatsby/shared/gatsby-build.ts +0 -54
- package/exporter/adapters/gatsby/shared/sync-render.ts +0 -276
- package/exporter/adapters/gatsby/shared/types.ts +0 -35
- package/exporter/build-esbuild.noop +0 -42
- package/exporter/commands/prepare-assets-directory.ts +0 -33
- package/exporter/services/db-class.ts +0 -54
- package/exporter/services/db.ts +0 -32
- package/exporter/types/render.ts +0 -59
- package/exporter/utils/artifacts.ts +0 -34
- package/exporter/utils/brush.ts +0 -34
- package/exporter/utils/check-health.ts +0 -79
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- /package/{react → exporter/react}/Favicon/utils.ts +0 -0
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { RenderContext } from "../shared/context";
|
|
2
|
-
import type { SSG } from "../shared/types";
|
|
3
|
-
|
|
4
|
-
import fsp from "node:fs/promises";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
|
|
7
|
-
import { RENDER_MODE } from "../../../types/render";
|
|
8
|
-
import {
|
|
9
|
-
deleteDisposableSiteDirs,
|
|
10
|
-
deleteEmptyDirectories,
|
|
11
|
-
moveDirs,
|
|
12
|
-
removeVirtualPages,
|
|
13
|
-
} from "../../../utils/folders";
|
|
14
|
-
import { extractAssetsFromDist } from "../shared/extract-assets";
|
|
15
|
-
import { SyncRender } from "../shared/sync-render";
|
|
16
|
-
|
|
17
|
-
export async function syncAction(context: RenderContext<SSG>) {
|
|
18
|
-
const {
|
|
19
|
-
renderMode,
|
|
20
|
-
cxArtifacts,
|
|
21
|
-
domain,
|
|
22
|
-
pagesToCreate,
|
|
23
|
-
pagesToDelete,
|
|
24
|
-
paths: { __root, __ssg, __cache, __exports },
|
|
25
|
-
ssg: { ssgArtifacts, assetPrefix },
|
|
26
|
-
} = context;
|
|
27
|
-
|
|
28
|
-
const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
|
|
29
|
-
const distDir = path.join(__root, "dist");
|
|
30
|
-
const distRestoredDir = path.join(__root, "dist-restored");
|
|
31
|
-
const storeDir = path.join(__root, "store");
|
|
32
|
-
|
|
33
|
-
// ESTO YA NO TIENE SENTIDO??? EL STORE???
|
|
34
|
-
await removeVirtualPages(storeDir);
|
|
35
|
-
// caching...
|
|
36
|
-
await moveDirs(__root, __cache, cxArtifacts.cacheables);
|
|
37
|
-
await moveDirs(__ssg, __cache, ssgArtifacts.cacheables);
|
|
38
|
-
|
|
39
|
-
if (renderMode === RENDER_MODE.FROM_SCRATCH) {
|
|
40
|
-
await deleteDisposableSiteDirs(distDir);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (renderMode === RENDER_MODE.INCREMENTAL) {
|
|
44
|
-
await deleteDisposableSiteDirs(distRestoredDir);
|
|
45
|
-
|
|
46
|
-
const syncRender = new SyncRender({
|
|
47
|
-
src: distDir,
|
|
48
|
-
dst: distRestoredDir,
|
|
49
|
-
pagesToCreate,
|
|
50
|
-
pagesToDelete,
|
|
51
|
-
artifactsToCopyToExports: ["build-report.json"],
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
await syncRender.execute();
|
|
55
|
-
|
|
56
|
-
// elimina el dist recién creado, ya no hace falta porque lo hemos utilizado en syncRender.execute()
|
|
57
|
-
await fsp.rm(distDir, { force: true, recursive: true });
|
|
58
|
-
// renombra el nuevo dist-temporal que es el que aglutina todos los cambios -> dist
|
|
59
|
-
await fsp.rename(distRestoredDir, distDir);
|
|
60
|
-
await deleteEmptyDirectories(distDir);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (needsAssetPrefix) {
|
|
64
|
-
await extractAssetsFromDist(domain);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// archiving...
|
|
68
|
-
await moveDirs(__root, __exports, cxArtifacts.archivables, {
|
|
69
|
-
withBackup: true,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Artifacts, PlaceholderPath } from "../../../types/global";
|
|
2
|
-
import type { RenderMode } from "../../../types/render";
|
|
3
|
-
|
|
4
|
-
interface RenderContextProps<T> {
|
|
5
|
-
domain: string;
|
|
6
|
-
renderMode: RenderMode;
|
|
7
|
-
paths: Record<string, string>;
|
|
8
|
-
ssg: T;
|
|
9
|
-
renderMetadata: {
|
|
10
|
-
proDomain: string;
|
|
11
|
-
griddoVersion: string;
|
|
12
|
-
buildReportFileName: string;
|
|
13
|
-
};
|
|
14
|
-
cxArtifacts: Artifacts;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Encapsulates the state, configuration, and artifacts for a single SSG
|
|
19
|
-
* render process.
|
|
20
|
-
*
|
|
21
|
-
* This class is instantiated at the beginning of a render and passed through
|
|
22
|
-
* each lifecycle step, providing a centralized and consistent context for all
|
|
23
|
-
* operations. It is agnostic to the specific SSG being used.
|
|
24
|
-
*/
|
|
25
|
-
export class RenderContext<T = unknown> {
|
|
26
|
-
readonly domain: string;
|
|
27
|
-
readonly renderMode: RenderMode;
|
|
28
|
-
readonly paths: Record<PlaceholderPath, string>;
|
|
29
|
-
pagesToCreate: number[] = [];
|
|
30
|
-
pagesToDelete: number[] = [];
|
|
31
|
-
ssg: T;
|
|
32
|
-
renderMetadata: { proDomain: string; griddoVersion: string; buildReportFileName: string };
|
|
33
|
-
cxArtifacts: Artifacts;
|
|
34
|
-
|
|
35
|
-
constructor({
|
|
36
|
-
domain,
|
|
37
|
-
renderMode,
|
|
38
|
-
ssg,
|
|
39
|
-
paths,
|
|
40
|
-
renderMetadata,
|
|
41
|
-
cxArtifacts,
|
|
42
|
-
}: RenderContextProps<T>) {
|
|
43
|
-
this.domain = domain;
|
|
44
|
-
this.renderMode = renderMode;
|
|
45
|
-
this.paths = paths;
|
|
46
|
-
this.renderMetadata = renderMetadata;
|
|
47
|
-
this.cxArtifacts = cxArtifacts;
|
|
48
|
-
this.ssg = ssg;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import fsp from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
// Lista de patrones de los ficheros de assets más importantes.
|
|
6
|
-
// Si estos no cambian, el webpackCompilationHash no debería cambiar.
|
|
7
|
-
const _KEY_ASSET_PATTERNS = [/^app-.*\.js$/, /^framework-.*\.js$/, /^webpack-runtime-.*\.js$/];
|
|
8
|
-
|
|
9
|
-
const KEY_ASSET_PATTERNS = [/\.js$/];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Calcula los hashes SHA256 del contenido de los assets clave en un directorio.
|
|
13
|
-
* @param dir La ruta al directorio (ej. './public')
|
|
14
|
-
* @returns Un Map donde la clave es el nombre del fichero y el valor es su hash.
|
|
15
|
-
*/
|
|
16
|
-
async function getAssetHashes(dir: string): Promise<Map<string, string>> {
|
|
17
|
-
const assetHashes = new Map<string, string>();
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const allFiles = await fsp.readdir(dir);
|
|
21
|
-
const keyAssetFiles = allFiles.filter((fileName) =>
|
|
22
|
-
KEY_ASSET_PATTERNS.some((pattern) => pattern.test(fileName)),
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
for (const fileName of keyAssetFiles) {
|
|
26
|
-
const filePath = join(dir, fileName);
|
|
27
|
-
const fileContent = await fsp.readFile(filePath);
|
|
28
|
-
const hash = createHash("sha256").update(fileContent).digest("hex");
|
|
29
|
-
assetHashes.set(fileName, hash);
|
|
30
|
-
}
|
|
31
|
-
} catch (error) {
|
|
32
|
-
console.error(`Error procesando el directorio ${dir}:`, error);
|
|
33
|
-
// Si un directorio no existe (ej. el de producción la primera vez),
|
|
34
|
-
// lo tratamos como si no tuviera assets.
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return assetHashes;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Compara los assets clave entre dos directorios de build de Gatsby.
|
|
42
|
-
* @param dir1 Ruta al primer directorio (ej. el de producción)
|
|
43
|
-
* @param dir2 Ruta al segundo directorio (ej. el del nuevo build)
|
|
44
|
-
* @returns `true` si hay diferencias, `false` si son idénticos.
|
|
45
|
-
*/
|
|
46
|
-
export async function getAssetsDiffBetweenRenders(dir1: string, dir2: string): Promise<boolean> {
|
|
47
|
-
const [hashes1, hashes2] = await Promise.all([getAssetHashes(dir1), getAssetHashes(dir2)]);
|
|
48
|
-
|
|
49
|
-
// Si el número de assets clave es diferente, hay cambios.
|
|
50
|
-
if (hashes1.size !== hashes2.size) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Comparamos los hashes de cada fichero.
|
|
55
|
-
for (const [fileName, hash1] of hashes1.entries()) {
|
|
56
|
-
const hash2 = hashes2.get(fileName);
|
|
57
|
-
|
|
58
|
-
// Si un fichero existe en el primero pero no en el segundo, hay cambios.
|
|
59
|
-
if (!hash2) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Si el contenido (hash) de un fichero ha cambiado.
|
|
64
|
-
if (hash1 !== hash2) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Actualiza el webpackCompilationHash en un único fichero HTML.
|
|
74
|
-
* @param filePath Ruta al fichero HTML.
|
|
75
|
-
* @param newHash El nuevo hash a insertar.
|
|
76
|
-
*/
|
|
77
|
-
export async function patchHtmlFile(filePath: string, newHash: string): Promise<void> {
|
|
78
|
-
try {
|
|
79
|
-
const content = await fsp.readFile(filePath, "utf-8");
|
|
80
|
-
|
|
81
|
-
// Esta expresión regular captura tres grupos:
|
|
82
|
-
// 1. La parte ANTES del hash (window.___webpackCompilationHash=")
|
|
83
|
-
// 2. El hash ANTIGUO ([^"]*)
|
|
84
|
-
// 3. La parte DESPUÉS del hash (";</script>)
|
|
85
|
-
const regex = /(window\.___webpackCompilationHash=")([^"]*)(";<\/script>)/;
|
|
86
|
-
|
|
87
|
-
// Solo reemplazamos el segundo grupo (el hash)
|
|
88
|
-
const newContent = content.replace(regex, `$1${newHash}$3`);
|
|
89
|
-
|
|
90
|
-
if (content === newContent) {
|
|
91
|
-
console.warn(`WARN: No se encontró el hash en ${filePath}. El fichero no fue modificado.`);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
await fsp.writeFile(filePath, newContent, "utf-8");
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.error(`ERROR: Fallo al procesar el fichero ${filePath}:`, error);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// --- Ejemplo de uso ---
|
|
102
|
-
// async function miScriptDeDeploy() {
|
|
103
|
-
// const dirProduccion = '/ruta/a/produccion/public';
|
|
104
|
-
// const dirNuevoBuild = './public';
|
|
105
|
-
|
|
106
|
-
// const hayDiferencias = await getAssetsDiffBetweenRenders(dirProduccion, dirNuevoBuild);
|
|
107
|
-
|
|
108
|
-
// if (hayDiferencias) {
|
|
109
|
-
// // Lógica para el CAMINO A (cambio de código)
|
|
110
|
-
// } else {
|
|
111
|
-
// // Lógica para el CAMINO B (solo contenido)
|
|
112
|
-
// }
|
|
113
|
-
// }
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import fsp from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { pathExists } from "../../../utils/folders";
|
|
5
|
-
import { getRenderPathsFromDB } from "../../../utils/render";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Update the Griddo's `/dist` dir with the contents from `public` dir only
|
|
9
|
-
* with files of type: js, json and css.
|
|
10
|
-
* TODO: Explicar que el static se copia a assets porque el js va en el subdominio de assets.
|
|
11
|
-
*/
|
|
12
|
-
async function extractAssetsFromDist(domain: string) {
|
|
13
|
-
const { __root } = await getRenderPathsFromDB({ domain });
|
|
14
|
-
|
|
15
|
-
// Archivos (no carpetas) válidos de public
|
|
16
|
-
const filesFromDist = (await fsp.readdir(path.join(__root, "dist"))).filter(
|
|
17
|
-
(file) =>
|
|
18
|
-
path.extname(file) === ".js" ||
|
|
19
|
-
path.extname(file) === ".json" ||
|
|
20
|
-
path.extname(file) === ".css",
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
// Creamos assets si es necesario (needsAssetPrefix)
|
|
24
|
-
await fsp.mkdir(path.join(__root, "assets"), { recursive: true });
|
|
25
|
-
// page-data folder
|
|
26
|
-
await fsp.cp(path.join(__root, "dist", "page-data"), path.join(__root, "assets", "page-data"), {
|
|
27
|
-
preserveTimestamps: true,
|
|
28
|
-
recursive: true,
|
|
29
|
-
});
|
|
30
|
-
// static folder si existe
|
|
31
|
-
if (await pathExists(path.join(__root, "static"))) {
|
|
32
|
-
await fsp.cp(path.join(__root, "static"), path.join(__root, "assets"), {
|
|
33
|
-
force: false,
|
|
34
|
-
preserveTimestamps: true,
|
|
35
|
-
recursive: true,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
// dist/static -> assets/static
|
|
39
|
-
await fsp.cp(path.join(__root, "dist", "static"), path.join(__root, "assets", "static"), {
|
|
40
|
-
force: false,
|
|
41
|
-
preserveTimestamps: true,
|
|
42
|
-
recursive: true,
|
|
43
|
-
});
|
|
44
|
-
// otro static...
|
|
45
|
-
if (await pathExists(path.join(__root, "static"))) {
|
|
46
|
-
await fsp.cp(path.join(__root, "static"), path.join(__root, "dist", domain), {
|
|
47
|
-
preserveTimestamps: true,
|
|
48
|
-
recursive: true,
|
|
49
|
-
force: false,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Copia el resto de archivos...
|
|
54
|
-
for (const file of filesFromDist) {
|
|
55
|
-
const fileSrc = path.join(__root, "dist", file);
|
|
56
|
-
const fileDest = path.join(__root, "assets", file);
|
|
57
|
-
await fsp.cp(fileSrc, fileDest, { preserveTimestamps: true, recursive: true });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { extractAssetsFromDist };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
|
|
3
|
-
import { GRIDDO_SSG_VERBOSE_LOGS } from "../../../constants/envs";
|
|
4
|
-
import { verboseLog } from "../../../utils/loggin";
|
|
5
|
-
import { getRenderPathsFromDB } from "../../../utils/render";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Spawn a new node process `yarn gatsby-build`
|
|
9
|
-
* @note This proccess (`yarn gatsby-build`) can not access to the custom Griddo
|
|
10
|
-
* `process.env` so it needs variables passed to it via the `env` prop.
|
|
11
|
-
*/
|
|
12
|
-
async function gatsbyBuild(assetPrefixWithDomain: string): Promise<void> {
|
|
13
|
-
verboseLog(`read assetPrefixWithDomain, ${assetPrefixWithDomain}`);
|
|
14
|
-
verboseLog(`using this NODE_OPTIONS in gatsby command: ${process.env.NODE_OPTIONS}`);
|
|
15
|
-
|
|
16
|
-
const { __ssg } = await getRenderPathsFromDB();
|
|
17
|
-
|
|
18
|
-
// Remove `--openssl-legacy-provider` from NODE_OPTIONS because this value
|
|
19
|
-
// break Gatsby render.
|
|
20
|
-
const nodeOptionsWithoutLegacyOpenSSL = process.env.NODE_OPTIONS
|
|
21
|
-
? process.env.NODE_OPTIONS.replace(/--openssl-legacy-provider\s*/g, "").trim()
|
|
22
|
-
: "";
|
|
23
|
-
|
|
24
|
-
const args = ["gatsby-build"];
|
|
25
|
-
if (GRIDDO_SSG_VERBOSE_LOGS) {
|
|
26
|
-
args.push("--verbose");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
const child = spawn("yarn", args, {
|
|
31
|
-
cwd: __ssg,
|
|
32
|
-
stdio: ["ignore", "inherit", "inherit"], // stdout y stderr van a consola directamente
|
|
33
|
-
env: Object.assign(process.env, {
|
|
34
|
-
GRIDDO_EXPORTER: "true",
|
|
35
|
-
SPAWN_ASSET_PREFIX_WITH_DOMAIN: assetPrefixWithDomain,
|
|
36
|
-
NODE_OPTIONS: nodeOptionsWithoutLegacyOpenSSL,
|
|
37
|
-
}),
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
child.on("close", (code) => {
|
|
41
|
-
if (code === 0) {
|
|
42
|
-
resolve();
|
|
43
|
-
} else {
|
|
44
|
-
reject(new Error(`Gatsby build failed with exit code ${code}`));
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
child.on("error", (error) => {
|
|
49
|
-
reject(new Error(`Failed to start Gatsby build process: ${error.message}`));
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export { gatsbyBuild };
|
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import fsp from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { findFilesBySuffix } from "../../../utils/folders";
|
|
5
|
-
import { infoLog, verboseLog } from "../../../utils/loggin";
|
|
6
|
-
import { getAssetsDiffBetweenRenders, patchHtmlFile } from "./diff-assets";
|
|
7
|
-
|
|
8
|
-
interface SyncRenderConfig {
|
|
9
|
-
src: string;
|
|
10
|
-
dst: string;
|
|
11
|
-
pagesToCreate: Array<number>;
|
|
12
|
-
pagesToDelete: Array<number>;
|
|
13
|
-
artifactsToCopyToExports: Array<string>;
|
|
14
|
-
}
|
|
15
|
-
interface CopyFilePath {
|
|
16
|
-
from: string;
|
|
17
|
-
to: string;
|
|
18
|
-
}
|
|
19
|
-
interface SyncState {
|
|
20
|
-
htmlToAdd: Array<CopyFilePath>;
|
|
21
|
-
jsonToAdd: Array<CopyFilePath>;
|
|
22
|
-
htmlToDelete: Array<string>;
|
|
23
|
-
jsonToDelete: Array<string>;
|
|
24
|
-
}
|
|
25
|
-
interface PageInfo {
|
|
26
|
-
id: number;
|
|
27
|
-
composePath: string; // p.ej. '/about-us' o '/'
|
|
28
|
-
htmlPath: string; // p.ej. '/path/to/public/about-us/index.html'
|
|
29
|
-
jsonPath: string; // p.ej. '/path/to/public/page-data/about-us/page-data.json'
|
|
30
|
-
}
|
|
31
|
-
interface GatsbyPageData {
|
|
32
|
-
result: {
|
|
33
|
-
pageContext: {
|
|
34
|
-
id: number;
|
|
35
|
-
fullPath: {
|
|
36
|
-
site: string;
|
|
37
|
-
domain: string;
|
|
38
|
-
domainUrl: string;
|
|
39
|
-
language: string;
|
|
40
|
-
page: string;
|
|
41
|
-
compose: string;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class SyncRender {
|
|
48
|
-
private bundleDir: string;
|
|
49
|
-
private currentRenderDir: string;
|
|
50
|
-
private pagesToCreate: Array<number>;
|
|
51
|
-
private pagesToDelete: Array<number>;
|
|
52
|
-
private assetArtifacts: Array<string>;
|
|
53
|
-
|
|
54
|
-
private state: SyncState = {
|
|
55
|
-
htmlToAdd: [],
|
|
56
|
-
jsonToAdd: [],
|
|
57
|
-
htmlToDelete: [],
|
|
58
|
-
jsonToDelete: [],
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
constructor(config: SyncRenderConfig) {
|
|
62
|
-
this.bundleDir = config.dst;
|
|
63
|
-
this.currentRenderDir = config.src;
|
|
64
|
-
this.pagesToCreate = config.pagesToCreate;
|
|
65
|
-
this.pagesToDelete = config.pagesToDelete;
|
|
66
|
-
this.assetArtifacts = config.artifactsToCopyToExports;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public async execute() {
|
|
70
|
-
await this.setPagesToDelete();
|
|
71
|
-
await this.setPagesToAdd();
|
|
72
|
-
await this.sync();
|
|
73
|
-
await this.assertAssetsAreValid();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private async assertAssetsAreValid() {
|
|
77
|
-
const isDifferent = await getAssetsDiffBetweenRenders(this.currentRenderDir, this.bundleDir);
|
|
78
|
-
if (isDifferent) {
|
|
79
|
-
infoLog(
|
|
80
|
-
"Warning: JavaScript and CSS bundles must have the same files and content. You can ignore this warning if the rendering process only has pages to unpublish.",
|
|
81
|
-
);
|
|
82
|
-
} else {
|
|
83
|
-
infoLog("Previous and current JavaScript and CSS packages successfully matched");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private async setPagesToDelete() {
|
|
88
|
-
// ¿Por qué se incluyen this.pagesToCreate en las candidatas para borrarse?
|
|
89
|
-
// El set de ids incluye tanto las páginas a borrar como las que se van
|
|
90
|
-
// a crear para manejar correctamente por ejemplo los cambios de slug.
|
|
91
|
-
// Si la página `id=3` tiene slug `slug=about` y despues viene con
|
|
92
|
-
// `slug=about-us` borramos la página `id=3` en el render previo y la
|
|
93
|
-
// volvemos a crear.
|
|
94
|
-
// Resumido lo que pasará es que las páginas que se van a crear se
|
|
95
|
-
// borran previamente por si ha cambiado el slug. Porque el slug hace
|
|
96
|
-
// que se guarden en otro directorio.
|
|
97
|
-
// ¿Qué pasaría si no la borrásemos? que tendríamos las dos páginas
|
|
98
|
-
// `/about/index.html` y `/about-us/index.html`
|
|
99
|
-
const candidateIdsToDelete = new Set<number>([...this.pagesToDelete, ...this.pagesToCreate]);
|
|
100
|
-
const existingPreviousPages = await this.scanPages(this.bundleDir);
|
|
101
|
-
|
|
102
|
-
for (const page of existingPreviousPages) {
|
|
103
|
-
if (candidateIdsToDelete.has(page.id)) {
|
|
104
|
-
this.state.htmlToDelete.push(page.htmlPath);
|
|
105
|
-
this.state.jsonToDelete.push(page.jsonPath);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
verboseLog(`${this.state.htmlToDelete.length} pages HTML to delete`);
|
|
110
|
-
verboseLog(`${this.state.jsonToDelete.length} pages JSON to delete`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private async setPagesToAdd() {
|
|
114
|
-
const candidateIdsToCreate = new Set<number>(this.pagesToCreate);
|
|
115
|
-
const newPages = await this.scanPages(this.currentRenderDir);
|
|
116
|
-
|
|
117
|
-
for (const page of newPages) {
|
|
118
|
-
if (candidateIdsToCreate.has(page.id)) {
|
|
119
|
-
const htmlTo = path.join(this.bundleDir, page.composePath, "index.html");
|
|
120
|
-
const normalizedCompose = page.composePath === "/" ? "index" : page.composePath;
|
|
121
|
-
const jsonTo = path.join(this.bundleDir, "page-data", normalizedCompose, "page-data.json");
|
|
122
|
-
|
|
123
|
-
this.state.htmlToAdd.push({ from: page.htmlPath, to: htmlTo });
|
|
124
|
-
this.state.jsonToAdd.push({ from: page.jsonPath, to: jsonTo });
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
verboseLog(`${this.state.htmlToAdd.length} pages HTML to create`);
|
|
129
|
-
verboseLog(`${this.state.jsonToAdd.length} pages JSON to create`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private async sync() {
|
|
133
|
-
// Delete...
|
|
134
|
-
const allFilesToDelete = [...this.state.htmlToDelete, ...this.state.jsonToDelete];
|
|
135
|
-
for (const file of allFilesToDelete) {
|
|
136
|
-
try {
|
|
137
|
-
// Usar `force: true` para no fallar si el archivo ya no existe.
|
|
138
|
-
await fsp.rm(file, { force: true });
|
|
139
|
-
verboseLog(`Sync (remove) : ${file}`);
|
|
140
|
-
} catch (e) {
|
|
141
|
-
// El error solo se registraría si es un problema de permisos, etc.
|
|
142
|
-
console.error(`Failed to remove ${file}:`, e);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
await this.restoreWebpackCompilationHash();
|
|
147
|
-
|
|
148
|
-
// Copy...
|
|
149
|
-
const allFilesToAdd = [...this.state.htmlToAdd, ...this.state.jsonToAdd];
|
|
150
|
-
for (const file of allFilesToAdd) {
|
|
151
|
-
try {
|
|
152
|
-
await fsp.mkdir(path.dirname(file.to), { recursive: true });
|
|
153
|
-
await fsp.copyFile(file.from, file.to);
|
|
154
|
-
verboseLog(`Sync (copy) : ${file.from} -> ${file.to}`);
|
|
155
|
-
} catch (e) {
|
|
156
|
-
console.error(`Failed to copy ${file.from} to ${file.to}:`, e);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// AVOID TO RESTORE webpackCompilationHash
|
|
161
|
-
// await this.copyAppDataJsonFile();
|
|
162
|
-
await this.copyAssetArtifacts();
|
|
163
|
-
await this.copySitemaps();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private async restoreWebpackCompilationHash() {
|
|
167
|
-
const appDataJson = path.join(this.bundleDir, "page-data", "app-data.json");
|
|
168
|
-
const webpackCompilationHash = JSON.parse(
|
|
169
|
-
await fsp.readFile(appDataJson, "utf8"),
|
|
170
|
-
).webpackCompilationHash;
|
|
171
|
-
console.log(
|
|
172
|
-
"Leyendo el webpackCompilationHash desde",
|
|
173
|
-
appDataJson,
|
|
174
|
-
"=",
|
|
175
|
-
webpackCompilationHash,
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
const changedHtmlFilePaths = this.state.htmlToAdd.map(({ from }) => from);
|
|
179
|
-
|
|
180
|
-
for (const htmlFilePath of changedHtmlFilePaths) {
|
|
181
|
-
await patchHtmlFile(htmlFilePath, webpackCompilationHash);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// private async copyAppDataJsonFile() {
|
|
186
|
-
// try {
|
|
187
|
-
// const src = path.join(this.currentRenderDir, "page-data", "app-data.json");
|
|
188
|
-
// const dst = path.join(this.bundleDir, "page-data", "app-data.json");
|
|
189
|
-
// await fsp.copyFile(src, dst);
|
|
190
|
-
// verboseLog("Copied app-data.json");
|
|
191
|
-
// } catch (e) {
|
|
192
|
-
// console.error("Failed to copy app-data.json:", e);
|
|
193
|
-
// }
|
|
194
|
-
// }
|
|
195
|
-
|
|
196
|
-
private async copyAssetArtifacts() {
|
|
197
|
-
for (const assetArtifact of this.assetArtifacts) {
|
|
198
|
-
const src = path.join(this.currentRenderDir, assetArtifact);
|
|
199
|
-
const dst = path.join(this.bundleDir, assetArtifact);
|
|
200
|
-
try {
|
|
201
|
-
await fsp.mkdir(path.dirname(dst), { recursive: true });
|
|
202
|
-
await fsp.copyFile(src, dst);
|
|
203
|
-
verboseLog(`Copied artifact: ${assetArtifact}`);
|
|
204
|
-
} catch (e) {
|
|
205
|
-
console.error(`Failed to copy artifact ${src} to ${dst}:`, e);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private async copySitemaps() {
|
|
211
|
-
const renderSrc = path.resolve(this.currentRenderDir);
|
|
212
|
-
const renderDst = path.resolve(this.bundleDir);
|
|
213
|
-
|
|
214
|
-
// Primero, elimina los sitemaps existentes en el destino
|
|
215
|
-
const xmlFilesInDst = findFilesBySuffix(renderDst, ".xml");
|
|
216
|
-
for await (const xmlFile of xmlFilesInDst) {
|
|
217
|
-
const basename = path.basename(xmlFile);
|
|
218
|
-
if (basename.startsWith("sitemap-") || basename === "sitemap.xml") {
|
|
219
|
-
await fsp.rm(xmlFile, { force: true });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Segundo, copia los nuevos sitemaps desde el origen
|
|
224
|
-
const xmlFilesInSrc = findFilesBySuffix(renderSrc, ".xml");
|
|
225
|
-
for await (const src of xmlFilesInSrc) {
|
|
226
|
-
// Reconstruye la ruta de destino de forma más robusta
|
|
227
|
-
const relativePath = path.relative(renderSrc, src);
|
|
228
|
-
const dst = path.join(renderDst, relativePath);
|
|
229
|
-
|
|
230
|
-
try {
|
|
231
|
-
await fsp.mkdir(path.dirname(dst), { recursive: true });
|
|
232
|
-
await fsp.copyFile(src, dst);
|
|
233
|
-
} catch (e) {
|
|
234
|
-
console.error(`Failed to copy sitemap ${src} to ${dst}:`, e);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
verboseLog(`Copied sitemap files.`);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Escanea un directorio de build de Gatsby y extrae la información esencial de cada página.
|
|
243
|
-
* Lee cada page-data.json una sola vez para optimizar el rendimiento.
|
|
244
|
-
* @param dir Directorio a escanear (src o dst).
|
|
245
|
-
* @returns Un array con la información de cada página encontrada.
|
|
246
|
-
*/
|
|
247
|
-
private async scanPages(dir: string): Promise<Array<PageInfo>> {
|
|
248
|
-
// Array de paths de page-data.json
|
|
249
|
-
const gatsbyPageDataFiles = findFilesBySuffix(path.join(dir, "page-data"), "page-data.json");
|
|
250
|
-
const pagesFound: Array<PageInfo> = [];
|
|
251
|
-
|
|
252
|
-
for await (const jsonFile of gatsbyPageDataFiles) {
|
|
253
|
-
try {
|
|
254
|
-
const content = JSON.parse(await fsp.readFile(jsonFile, "utf-8")) as GatsbyPageData;
|
|
255
|
-
const id = content.result.pageContext.id;
|
|
256
|
-
const composePath = content.result.pageContext.fullPath.compose;
|
|
257
|
-
// Esto es necesario porque Gatsby convierte la ruta "/" en un
|
|
258
|
-
// directorio llamado "index" en lo que archivos page-data.json
|
|
259
|
-
// se refiere.
|
|
260
|
-
const normalizedCompose = composePath === "/" ? "index" : composePath;
|
|
261
|
-
|
|
262
|
-
pagesFound.push({
|
|
263
|
-
id,
|
|
264
|
-
composePath,
|
|
265
|
-
htmlPath: path.join(dir, composePath, "index.html"),
|
|
266
|
-
jsonPath: path.join(dir, "page-data", normalizedCompose, "page-data.json"),
|
|
267
|
-
});
|
|
268
|
-
} catch (e) {
|
|
269
|
-
console.error(`Error reading or parsing page data from ${jsonFile}:`, e);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return pagesFound;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export { SyncRender };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
interface SSG {
|
|
2
|
-
assetPrefix: string;
|
|
3
|
-
ssgArtifacts: {
|
|
4
|
-
disposables: string[];
|
|
5
|
-
cacheables: string[];
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Minimal representation of the page structure
|
|
10
|
-
interface GatsbyPageData {
|
|
11
|
-
path: string;
|
|
12
|
-
result: {
|
|
13
|
-
pageContext: {
|
|
14
|
-
id: number;
|
|
15
|
-
title: string;
|
|
16
|
-
path: string;
|
|
17
|
-
openGraph: any;
|
|
18
|
-
pageMetadata: any;
|
|
19
|
-
page: {
|
|
20
|
-
site: number;
|
|
21
|
-
id: number;
|
|
22
|
-
fullPath: { compose: string };
|
|
23
|
-
language: number;
|
|
24
|
-
title: string;
|
|
25
|
-
fullUrl: string;
|
|
26
|
-
templateId: string;
|
|
27
|
-
template: {
|
|
28
|
-
templateType: string;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type { GatsbyPageData, SSG };
|