@griddo/cx 11.7.10 → 11.7.12-rc.0
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 +27 -226
- package/build/adapters/gatsby/actions/clean.js +10 -0
- package/build/adapters/gatsby/actions/clean.js.map +1 -0
- package/build/adapters/gatsby/actions/close.js +14 -0
- package/build/adapters/gatsby/actions/close.js.map +1 -0
- package/build/adapters/gatsby/actions/data.js +18 -0
- package/build/adapters/gatsby/actions/data.js.map +1 -0
- package/build/adapters/gatsby/actions/healthCheck.js +10 -0
- package/build/adapters/gatsby/actions/healthCheck.js.map +1 -0
- package/build/adapters/gatsby/actions/init.js +22 -0
- package/build/adapters/gatsby/actions/init.js.map +1 -0
- package/build/adapters/gatsby/actions/logs.js +9 -0
- package/build/adapters/gatsby/actions/logs.js.map +1 -0
- package/build/adapters/gatsby/actions/meta.js +13 -0
- package/build/adapters/gatsby/actions/meta.js.map +1 -0
- package/build/adapters/gatsby/actions/prepare.js +9 -0
- package/build/adapters/gatsby/actions/prepare.js.map +1 -0
- package/build/adapters/gatsby/actions/relocation.js +15 -0
- package/build/adapters/gatsby/actions/relocation.js.map +1 -0
- package/build/adapters/gatsby/actions/restore.js +26 -0
- package/build/adapters/gatsby/actions/restore.js.map +1 -0
- package/build/adapters/gatsby/actions/ssg.js +9 -0
- package/build/adapters/gatsby/actions/ssg.js.map +1 -0
- package/build/adapters/gatsby/actions/sync.js +51 -0
- package/build/adapters/gatsby/actions/sync.js.map +1 -0
- package/build/adapters/gatsby/index.js +78 -0
- package/build/adapters/gatsby/index.js.map +1 -0
- package/build/adapters/gatsby/shared/artifacts.js +20 -0
- package/build/adapters/gatsby/shared/artifacts.js.map +1 -0
- package/build/adapters/gatsby/shared/context.js +31 -0
- package/build/adapters/gatsby/shared/context.js.map +1 -0
- package/build/adapters/gatsby/shared/diff-assets.js +101 -0
- package/build/adapters/gatsby/shared/diff-assets.js.map +1 -0
- package/build/adapters/gatsby/shared/extract-assets.js +58 -0
- package/build/adapters/gatsby/shared/extract-assets.js.map +1 -0
- package/build/adapters/gatsby/shared/gatsby-build.js +55 -0
- package/build/adapters/gatsby/shared/gatsby-build.js.map +1 -0
- package/build/adapters/gatsby/shared/sync-render.js +210 -0
- package/build/adapters/gatsby/shared/sync-render.js.map +1 -0
- package/build/adapters/gatsby/shared/types.js +3 -0
- package/build/adapters/gatsby/shared/types.js.map +1 -0
- package/build/commands/end-render.js +87 -0
- package/build/commands/end-render.js.map +1 -0
- package/build/commands/prepare-assets-directory.js +30 -0
- package/build/commands/prepare-assets-directory.js.map +1 -0
- package/build/commands/prepare-domains-render.js +133 -0
- package/build/commands/prepare-domains-render.js.map +1 -0
- package/build/commands/reset-render.js +21 -0
- package/build/commands/reset-render.js.map +1 -0
- package/build/commands/start-render.js +44 -0
- package/build/commands/start-render.js.map +1 -0
- package/build/commands/upload-search-content.js +180 -0
- package/build/commands/upload-search-content.js.map +1 -0
- package/build/constants/endpoints.js +43 -0
- package/build/constants/endpoints.js.map +1 -0
- package/build/constants/envs.js +68 -0
- package/build/constants/envs.js.map +1 -0
- package/build/constants/errors.js +81 -0
- package/build/constants/errors.js.map +1 -0
- package/build/services/auth.js +40 -0
- package/build/services/auth.js.map +1 -0
- package/build/services/db-class.js +49 -0
- package/build/services/db-class.js.map +1 -0
- package/build/services/db.js +34 -0
- package/build/services/db.js.map +1 -0
- package/build/services/navigation.js +96 -0
- package/build/services/navigation.js.map +1 -0
- package/build/services/reference-fields.js +131 -0
- package/build/services/reference-fields.js.map +1 -0
- package/build/services/robots.js +60 -0
- package/build/services/robots.js.map +1 -0
- package/build/services/sites.js +110 -0
- package/build/services/sites.js.map +1 -0
- package/build/services/store.js +257 -0
- package/build/services/store.js.map +1 -0
- package/build/types/api.js +3 -0
- package/build/types/api.js.map +1 -0
- package/build/types/global.js +3 -0
- package/build/types/global.js.map +1 -0
- package/build/types/navigation.js +3 -0
- package/build/types/navigation.js.map +1 -0
- package/build/types/pages.js +3 -0
- package/build/types/pages.js.map +1 -0
- package/build/types/render.js +10 -0
- package/build/types/render.js.map +1 -0
- package/build/types/sites.js +3 -0
- package/build/types/sites.js.map +1 -0
- package/build/types/templates.js +3 -0
- package/build/types/templates.js.map +1 -0
- package/build/utils/api.js +165 -0
- package/build/utils/api.js.map +1 -0
- package/build/utils/artifacts.js +38 -0
- package/build/utils/artifacts.js.map +1 -0
- package/build/utils/brush.js +30 -0
- package/build/utils/brush.js.map +1 -0
- package/build/utils/cache.js +106 -0
- package/build/utils/cache.js.map +1 -0
- package/build/utils/check-environment-health.js +69 -0
- package/build/utils/check-environment-health.js.map +1 -0
- package/build/utils/core-utils.js +270 -0
- package/build/utils/core-utils.js.map +1 -0
- package/build/utils/domains.js +37 -0
- package/build/utils/domains.js.map +1 -0
- package/build/utils/errors.js +30 -0
- package/build/utils/errors.js.map +1 -0
- package/build/utils/folders.js +341 -0
- package/build/utils/folders.js.map +1 -0
- package/build/utils/images.js +45 -0
- package/build/utils/images.js.map +1 -0
- package/build/utils/instance.js +66 -0
- package/build/utils/instance.js.map +1 -0
- package/build/utils/loggin.js +119 -0
- package/build/utils/loggin.js.map +1 -0
- package/build/utils/npm-deps/find-up-simple.js +75 -0
- package/build/utils/npm-deps/find-up-simple.js.map +1 -0
- package/build/utils/npm-deps/pkg-dir.js +20 -0
- package/build/utils/npm-deps/pkg-dir.js.map +1 -0
- package/build/utils/npm-deps/xml-parser.js +49 -0
- package/build/utils/npm-deps/xml-parser.js.map +1 -0
- package/build/utils/pages.js +359 -0
- package/build/utils/pages.js.map +1 -0
- package/build/utils/render.js +168 -0
- package/build/utils/render.js.map +1 -0
- package/build/utils/sitemaps.js +110 -0
- package/build/utils/sitemaps.js.map +1 -0
- package/build/utils/sites.js +105 -0
- package/build/utils/sites.js.map +1 -0
- package/build/utils/store.js +193 -0
- package/build/utils/store.js.map +1 -0
- package/exporter/adapters/gatsby/actions/clean.ts +14 -0
- package/exporter/adapters/gatsby/actions/close.ts +20 -0
- package/exporter/adapters/gatsby/actions/data.ts +25 -0
- package/exporter/adapters/gatsby/actions/healthCheck.ts +10 -0
- package/exporter/adapters/gatsby/actions/init.ts +26 -0
- package/exporter/adapters/gatsby/actions/logs.ts +10 -0
- package/exporter/adapters/gatsby/actions/meta.ts +16 -0
- package/exporter/adapters/gatsby/actions/prepare.ts +9 -0
- package/exporter/adapters/gatsby/actions/relocation.ts +15 -0
- package/exporter/adapters/gatsby/actions/restore.ts +36 -0
- package/exporter/adapters/gatsby/actions/ssg.ts +12 -0
- package/exporter/adapters/gatsby/actions/sync.ts +71 -0
- package/exporter/adapters/gatsby/index.ts +73 -153
- package/exporter/adapters/gatsby/shared/artifacts.ts +16 -0
- package/exporter/adapters/gatsby/shared/context.ts +50 -0
- package/exporter/adapters/gatsby/shared/diff-assets.ts +113 -0
- package/exporter/adapters/gatsby/shared/extract-assets.ts +61 -0
- package/exporter/adapters/gatsby/shared/gatsby-build.ts +58 -0
- package/exporter/adapters/gatsby/shared/sync-render.ts +276 -0
- package/exporter/adapters/gatsby/shared/types.ts +35 -0
- package/exporter/build-esbuild.noop +42 -0
- package/exporter/build.sh +4 -38
- package/exporter/commands/end-render.ts +72 -70
- package/exporter/commands/prepare-assets-directory.ts +30 -0
- package/exporter/commands/prepare-domains-render.ts +143 -31
- package/exporter/commands/reset-render.ts +10 -3
- package/exporter/commands/start-render.ts +22 -45
- package/exporter/commands/upload-search-content.ts +194 -21
- package/exporter/constants/endpoints.ts +2 -1
- package/exporter/constants/envs.ts +57 -55
- package/exporter/{errors/errors-data.ts → constants/errors.ts} +24 -14
- package/exporter/services/auth.ts +7 -6
- package/exporter/services/db-class.ts +54 -0
- package/exporter/services/db.ts +32 -0
- package/exporter/services/navigation.ts +4 -10
- package/exporter/services/reference-fields.ts +9 -24
- package/exporter/services/robots.ts +9 -16
- package/exporter/services/sites.ts +36 -24
- package/exporter/services/store.ts +107 -96
- package/exporter/types/api.ts +27 -28
- package/exporter/types/global.ts +8 -11
- package/exporter/types/navigation.ts +1 -1
- package/exporter/types/pages.ts +2 -3
- package/exporter/types/render.ts +59 -0
- package/exporter/types/sites.ts +1 -2
- package/exporter/utils/api.ts +55 -75
- package/exporter/utils/artifacts.ts +38 -0
- package/exporter/utils/brush.ts +34 -0
- package/exporter/utils/cache.ts +37 -62
- package/exporter/utils/check-environment-health.ts +80 -0
- package/exporter/utils/core-utils.ts +133 -272
- package/exporter/utils/domains.ts +10 -7
- package/exporter/{errors/index.ts → utils/errors.ts} +10 -9
- package/exporter/utils/folders.ts +163 -98
- package/exporter/utils/images.ts +1 -6
- package/exporter/utils/instance.ts +9 -13
- package/exporter/utils/loggin.ts +44 -91
- package/exporter/utils/npm-deps/find-up-simple.ts +100 -0
- package/exporter/utils/npm-deps/pkg-dir.ts +17 -0
- package/exporter/utils/npm-deps/xml-parser.ts +57 -0
- package/exporter/utils/pages.ts +23 -88
- package/exporter/utils/render.ts +180 -48
- package/exporter/utils/sitemaps.ts +129 -0
- package/exporter/utils/sites.ts +19 -197
- package/exporter/utils/store.ts +87 -180
- package/gatsby-browser.tsx +41 -58
- package/gatsby-config.ts +10 -17
- package/gatsby-node.ts +17 -78
- package/gatsby-ssr.tsx +2 -1
- package/package.json +35 -86
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
- package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
- package/react/DynamicScript/index.tsx +33 -0
- package/{exporter/react → react}/Favicon/index.tsx +1 -7
- package/{exporter/react → react}/GriddoIntegrations/index.tsx +16 -22
- package/{exporter/react → react}/GriddoIntegrations/utils.ts +21 -9
- package/{build/react/index.d.ts → react/index.tsx} +1 -0
- package/src/components/Head.tsx +13 -46
- package/src/components/template.tsx +8 -30
- package/src/gatsby-node-utils.ts +73 -2
- package/src/html.tsx +2 -11
- package/src/types.ts +5 -5
- package/tsconfig.commands.json +36 -0
- package/tsconfig.exporter.json +19 -0
- package/tsconfig.json +5 -3
- package/build/adapters/gatsby/index.d.ts +0 -4
- package/build/adapters/gatsby/utils.d.ts +0 -22
- package/build/artifacts/index.d.ts +0 -6
- package/build/commands/end-render.d.ts +0 -2
- package/build/commands/move-assets.d.ts +0 -1
- package/build/commands/prepare-domains-render.d.ts +0 -1
- package/build/commands/reset-render.d.ts +0 -2
- package/build/commands/start-render.d.ts +0 -2
- package/build/commands/upload-search-content.d.ts +0 -2
- package/build/constants/endpoints.d.ts +0 -19
- 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/errors-data.d.ts +0 -22
- package/build/errors/index.d.ts +0 -15
- package/build/index.d.ts +0 -29
- package/build/index.js +0 -73
- 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/react/Favicon/utils.d.ts +0 -9
- package/build/react/GriddoIntegrations/index.d.ts +0 -20
- package/build/react/GriddoIntegrations/utils.d.ts +0 -26
- package/build/react/index.js +0 -3
- 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/auth.d.ts +0 -10
- package/build/services/domains.d.ts +0 -6
- package/build/services/navigation.d.ts +0 -50
- package/build/services/reference-fields.d.ts +0 -20
- package/build/services/register.d.ts +0 -36
- package/build/services/robots.d.ts +0 -19
- package/build/services/settings.d.ts +0 -4
- package/build/services/sites.d.ts +0 -29
- package/build/services/store.d.ts +0 -6
- package/build/start-render.js +0 -100
- package/build/start-render.js.map +0 -7
- package/build/types/api.d.ts +0 -142
- package/build/types/global.d.ts +0 -84
- package/build/types/navigation.d.ts +0 -28
- package/build/types/pages.d.ts +0 -144
- package/build/types/sites.d.ts +0 -57
- package/build/types/templates.d.ts +0 -8
- 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/api.d.ts +0 -23
- 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/health-checks.d.ts +0 -7
- package/build/utils/images.d.ts +0 -16
- package/build/utils/instance.d.ts +0 -21
- package/build/utils/loggin.d.ts +0 -51
- package/build/utils/pages.d.ts +0 -34
- 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/utils.ts +0 -161
- 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/index.ts +0 -129
- package/exporter/index.ts +0 -82
- package/exporter/react/index.tsx +0 -11
- package/exporter/registers/api.ts +0 -14
- package/exporter/registers/gatsby.ts +0 -14
- package/exporter/registers/index.ts +0 -4
- package/exporter/services/domains.ts +0 -16
- package/exporter/services/register.ts +0 -113
- package/exporter/services/settings.ts +0 -17
- package/exporter/utils/alerts.ts +0 -29
- package/exporter/utils/create-build-data.ts +0 -17
- package/exporter/utils/health-checks.ts +0 -64
- package/exporter/utils/searches.ts +0 -156
- package/src/README.md +0 -7
- package/start-render.js +0 -7
- /package/{exporter/react → react}/Favicon/utils.ts +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
|
|
3
|
+
import { createStore } from "../../../services/store";
|
|
4
|
+
import { createAPICacheDir } from "../../../utils/cache";
|
|
5
|
+
|
|
6
|
+
export async function dataAction(context: RenderContext) {
|
|
7
|
+
const {
|
|
8
|
+
domain,
|
|
9
|
+
renderMode,
|
|
10
|
+
renderMetadata: { griddoVersion },
|
|
11
|
+
paths: { __root },
|
|
12
|
+
} = context;
|
|
13
|
+
|
|
14
|
+
await createAPICacheDir({ basePath: __root });
|
|
15
|
+
|
|
16
|
+
const { pagesToCreate, pagesToDelete } = await createStore({
|
|
17
|
+
domain,
|
|
18
|
+
renderMode,
|
|
19
|
+
griddoVersion,
|
|
20
|
+
basePath: __root,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
context.pagesToCreate = pagesToCreate;
|
|
24
|
+
context.pagesToDelete = pagesToDelete;
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
|
|
3
|
+
import { assertRenderIsValid, markRenderAsCompleted } from "../../../utils/render";
|
|
4
|
+
|
|
5
|
+
export async function healthCheckAction(context: RenderContext) {
|
|
6
|
+
const { domain } = context;
|
|
7
|
+
|
|
8
|
+
await assertRenderIsValid(domain);
|
|
9
|
+
await markRenderAsCompleted(domain);
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
|
|
3
|
+
import fsp from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import { infoLog } from "../../../utils/loggin";
|
|
7
|
+
import { markRenderAsStarted } from "../../../utils/render";
|
|
8
|
+
|
|
9
|
+
export async function initAction(context: RenderContext) {
|
|
10
|
+
const {
|
|
11
|
+
domain,
|
|
12
|
+
paths: { __root, __cache, __exports },
|
|
13
|
+
renderMode,
|
|
14
|
+
} = context;
|
|
15
|
+
|
|
16
|
+
if (renderMode === "FROM_SCRATCH") {
|
|
17
|
+
infoLog("Removing old files...\n");
|
|
18
|
+
|
|
19
|
+
fsp.rm(__cache, { force: true, recursive: true });
|
|
20
|
+
fsp.rm(path.join(__exports, "dist"), { force: true, recursive: true });
|
|
21
|
+
fsp.rm(path.join(__exports, "assets"), { force: true, recursive: true });
|
|
22
|
+
fsp.rm(path.join(__exports, domain), { force: true, recursive: true }); // only clocal
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await markRenderAsStarted({ basePath: __root, domain });
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
import type { SSG } from "../shared/types";
|
|
3
|
+
|
|
4
|
+
import { saveDetailRenderLog } from "../../../utils/core-utils";
|
|
5
|
+
|
|
6
|
+
export async function logsAction(context: RenderContext<SSG>) {
|
|
7
|
+
const { domain } = context;
|
|
8
|
+
|
|
9
|
+
await saveDetailRenderLog(domain);
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
|
|
3
|
+
import { RobotsService } from "../../../services/robots";
|
|
4
|
+
import { generateBuildReport } from "../../../utils/render";
|
|
5
|
+
import { generateSitemaps } from "../../../utils/sitemaps";
|
|
6
|
+
|
|
7
|
+
export async function metaAction(context: RenderContext) {
|
|
8
|
+
const {
|
|
9
|
+
domain,
|
|
10
|
+
paths: { __root },
|
|
11
|
+
} = context;
|
|
12
|
+
|
|
13
|
+
await generateBuildReport(domain);
|
|
14
|
+
await generateSitemaps(domain);
|
|
15
|
+
await RobotsService.writeFiles(domain);
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
|
|
3
|
+
import fsp from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
export async function relocationAction(context: RenderContext) {
|
|
7
|
+
const {
|
|
8
|
+
paths: { __root, __ssg },
|
|
9
|
+
} = context;
|
|
10
|
+
|
|
11
|
+
const src = path.join(__ssg, "public");
|
|
12
|
+
const dst = path.join(__root, "dist");
|
|
13
|
+
|
|
14
|
+
await fsp.rename(src, dst);
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
import type { SSG } from "../shared/types";
|
|
3
|
+
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import { RENDER_MODE } from "../../../types/render";
|
|
7
|
+
import { copyDirs, moveDirs, removeDirs, renamePath } from "../../../utils/folders";
|
|
8
|
+
|
|
9
|
+
export async function restoreAction(context: RenderContext<SSG>) {
|
|
10
|
+
const {
|
|
11
|
+
renderMode,
|
|
12
|
+
ssg: { ssgArtifacts },
|
|
13
|
+
cxArtifacts,
|
|
14
|
+
paths: { __components, __root, __cache, __exports, __ssg },
|
|
15
|
+
} = context;
|
|
16
|
+
|
|
17
|
+
await copyDirs(__components, __ssg, ["static"]);
|
|
18
|
+
|
|
19
|
+
if (renderMode === RENDER_MODE.FROM_SCRATCH) {
|
|
20
|
+
// NO RESTAURAMOS NADA!
|
|
21
|
+
// De hecho hay que borrar los cacheables
|
|
22
|
+
await removeDirs(
|
|
23
|
+
cxArtifacts.cacheables.map((artifactName) => path.join(__cache, artifactName)),
|
|
24
|
+
);
|
|
25
|
+
await removeDirs(
|
|
26
|
+
ssgArtifacts.cacheables.map((artifactName) => path.join(__cache, artifactName)),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (renderMode === RENDER_MODE.INCREMENTAL) {
|
|
31
|
+
await moveDirs(__cache, __ssg, ssgArtifacts.cacheables);
|
|
32
|
+
await moveDirs(__cache, __root, cxArtifacts.cacheables);
|
|
33
|
+
await copyDirs(__exports, __root, cxArtifacts.restaurable);
|
|
34
|
+
await renamePath(path.join(__root, "dist"), path.join(__root, "dist-restored"));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
import type { SSG } from "../shared/types";
|
|
3
|
+
|
|
4
|
+
import { gatsbyBuild } from "../shared/gatsby-build";
|
|
5
|
+
|
|
6
|
+
export async function ssgAction(context: RenderContext<SSG>) {
|
|
7
|
+
const {
|
|
8
|
+
ssg: { assetPrefix },
|
|
9
|
+
} = context;
|
|
10
|
+
|
|
11
|
+
await gatsbyBuild(assetPrefix);
|
|
12
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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,162 +1,82 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Artifacts,
|
|
3
|
-
LifeCyclesNames,
|
|
4
|
-
LifeCycleSteps,
|
|
5
|
-
} from "../../types/global";
|
|
1
|
+
import type { SSG } from "./shared/types";
|
|
6
2
|
|
|
7
3
|
import path from "node:path";
|
|
8
4
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "./utils";
|
|
14
|
-
import getCxArtifacts from "../../artifacts";
|
|
15
|
-
import { AuthService } from "../../services/auth";
|
|
16
|
-
import {
|
|
17
|
-
createDomainMetadata,
|
|
18
|
-
doLifeCycle,
|
|
19
|
-
getConfig,
|
|
20
|
-
saveBuildEndLogs,
|
|
21
|
-
} from "../../utils/core-utils";
|
|
22
|
-
import { createDomainRenderData } from "../../utils/create-build-data";
|
|
23
|
-
import {
|
|
24
|
-
copyArtifacts,
|
|
25
|
-
createArtifacts,
|
|
26
|
-
deleteDisposableSiteDirs,
|
|
27
|
-
moveArtifacts,
|
|
28
|
-
removeArtifacts,
|
|
29
|
-
removeVirtualPagesFromStore,
|
|
30
|
-
renameArtifact,
|
|
31
|
-
} from "../../utils/folders";
|
|
5
|
+
import { GRIDDO_ASSET_PREFIX } from "../../constants/envs";
|
|
6
|
+
import { getCxArtifacts } from "../../utils/artifacts";
|
|
7
|
+
import { doLifeCycle } from "../../utils/core-utils";
|
|
8
|
+
import { pathExists } from "../../utils/folders";
|
|
32
9
|
import { infoLog } from "../../utils/loggin";
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} from "
|
|
10
|
+
import { getRenderMetadataFromDB, getRenderMode, getRenderPathsFromDB } from "../../utils/render";
|
|
11
|
+
import { cleanAction } from "./actions/clean";
|
|
12
|
+
import { closeAction } from "./actions/close";
|
|
13
|
+
import { dataAction } from "./actions/data";
|
|
14
|
+
import { healthCheckAction } from "./actions/healthCheck";
|
|
15
|
+
import { initAction } from "./actions/init";
|
|
16
|
+
import { logsAction } from "./actions/logs";
|
|
17
|
+
import { metaAction } from "./actions/meta";
|
|
18
|
+
import { prepareAction } from "./actions/prepare";
|
|
19
|
+
import { relocationAction } from "./actions/relocation";
|
|
20
|
+
import { restoreAction } from "./actions/restore";
|
|
21
|
+
import { ssgAction } from "./actions/ssg";
|
|
22
|
+
import { syncAction } from "./actions/sync";
|
|
23
|
+
import { getGatsbyArtifacts } from "./shared/artifacts";
|
|
24
|
+
import { RenderContext } from "./shared/context";
|
|
38
25
|
|
|
39
26
|
/**
|
|
40
|
-
*
|
|
27
|
+
* Executes a complete Gatsby render process for a given domain.
|
|
28
|
+
*
|
|
29
|
+
* The render process consists of multiple lifecycle steps that handle cleaning,
|
|
30
|
+
* preparing, building and syncing the site. It can run in two modes:
|
|
31
|
+
* - FROM_SCRATCH: Performs a complete rebuild of the site
|
|
32
|
+
* - INCREMENTAL: Only rebuilds changed pages while preserving the rest
|
|
41
33
|
*/
|
|
42
|
-
export async function
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
path.join(__ssg, "public"),
|
|
64
|
-
path.join(__ssg, "static"),
|
|
65
|
-
path.join(__ssg, ".cache"),
|
|
66
|
-
],
|
|
67
|
-
cacheables: [".cache"],
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// These variables are involved in the build for create the dist directory
|
|
71
|
-
// from public and pass to the gatsby-build command via spawnSync.
|
|
72
|
-
const assetPrefix = getGatsbyAssetPrefixWithDomain(domain);
|
|
73
|
-
const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
|
|
74
|
-
|
|
75
|
-
// Compose artifacts
|
|
76
|
-
const disposableArtifacts = [
|
|
77
|
-
...cxArtifacts.disposables,
|
|
78
|
-
...gatsbyArtifacts.disposables,
|
|
79
|
-
];
|
|
80
|
-
|
|
81
|
-
// LifeCycles
|
|
82
|
-
|
|
83
|
-
const allLifeCycles: Array<{
|
|
84
|
-
name: LifeCyclesNames;
|
|
85
|
-
steps: LifeCycleSteps;
|
|
86
|
-
}> = [
|
|
87
|
-
{
|
|
88
|
-
name: "Init",
|
|
89
|
-
steps: [() => createSentinelRenderFile()],
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
name: "Clean",
|
|
94
|
-
steps: [() => removeArtifacts(disposableArtifacts)],
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
{
|
|
98
|
-
name: "Prepare",
|
|
99
|
-
steps: [() => createArtifacts(cxArtifacts.initials)],
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
{
|
|
103
|
-
name: "Restore",
|
|
104
|
-
steps: [
|
|
105
|
-
() => copyArtifacts(__components, __ssg, ["static"]),
|
|
106
|
-
() => copyArtifacts(__exports, __cx, cxArtifacts.archivables),
|
|
107
|
-
() =>
|
|
108
|
-
renameArtifact(path.join(__cx, "dist"), path.join(__ssg, "public")),
|
|
109
|
-
() => moveArtifacts(__cache, __cx, cxArtifacts.cacheables),
|
|
110
|
-
() => moveArtifacts(__cache, __ssg, gatsbyArtifacts.cacheables),
|
|
111
|
-
],
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
name: "Data",
|
|
116
|
-
steps: [() => createDomainRenderData(domain)],
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
{
|
|
120
|
-
name: "SSG",
|
|
121
|
-
steps: [() => runGatsbyBuildCommand(assetPrefix)],
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
{
|
|
125
|
-
name: "Relocation",
|
|
126
|
-
steps: [() => createDistFromGatsbyPublic(domain, needsAssetPrefix)],
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
{
|
|
130
|
-
name: "Meta",
|
|
131
|
-
steps: [() => createDomainMetadata(domain), () => saveBuildEndLogs()],
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
{
|
|
135
|
-
name: "Archive",
|
|
136
|
-
steps: [
|
|
137
|
-
() => removeVirtualPagesFromStore(),
|
|
138
|
-
() => deleteDisposableSiteDirs(),
|
|
139
|
-
() =>
|
|
140
|
-
moveArtifacts(__cx, __exports, cxArtifacts.archivables, {
|
|
141
|
-
withBackup: true,
|
|
142
|
-
}),
|
|
143
|
-
() => moveArtifacts(__cx, __cache, cxArtifacts.cacheables),
|
|
144
|
-
() => moveArtifacts(__ssg, __cache, gatsbyArtifacts.cacheables),
|
|
145
|
-
],
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
name: "Close",
|
|
150
|
-
steps: [() => removeArtifacts(disposableArtifacts)],
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
name: "HealthCheck",
|
|
155
|
-
steps: [() => isValidRender(), () => deleteSentinelRenderFile()],
|
|
156
|
-
},
|
|
157
|
-
];
|
|
158
|
-
|
|
159
|
-
for (const { name, steps } of allLifeCycles) {
|
|
160
|
-
await doLifeCycle(name, steps);
|
|
34
|
+
export async function gatsbyRenderDomain(domain: string) {
|
|
35
|
+
// Render data
|
|
36
|
+
const { renderMode, reason } = await getRenderMode(domain);
|
|
37
|
+
const renderMetadata = await getRenderMetadataFromDB();
|
|
38
|
+
const paths = await getRenderPathsFromDB({ domain });
|
|
39
|
+
|
|
40
|
+
// Artifacts
|
|
41
|
+
const cxArtifacts = await getCxArtifacts(domain);
|
|
42
|
+
const ssgArtifacts = await getGatsbyArtifacts(domain);
|
|
43
|
+
|
|
44
|
+
// Gatsby assetPrefix
|
|
45
|
+
const isProDomain = domain.startsWith(renderMetadata.proDomainPrefix);
|
|
46
|
+
const assetPrefix = GRIDDO_ASSET_PREFIX && isProDomain ? `${GRIDDO_ASSET_PREFIX}/${domain}` : "";
|
|
47
|
+
|
|
48
|
+
// Previous render error management
|
|
49
|
+
const domainSentinelFile = await pathExists(path.join(paths.__ssg, `.render-sentinel-${domain}`));
|
|
50
|
+
const currentRenderMode = domainSentinelFile ? "FROM_SCRATCH" : renderMode;
|
|
51
|
+
const currentReason = domainSentinelFile ? "previous render error" : reason;
|
|
52
|
+
|
|
53
|
+
if (renderMode === "IDLE" && currentRenderMode === "IDLE") {
|
|
54
|
+
return;
|
|
161
55
|
}
|
|
56
|
+
|
|
57
|
+
const renderReason = currentReason ? ` <${currentReason}>` : "";
|
|
58
|
+
infoLog(`Init render (${currentRenderMode})${renderReason} for domain ${domain}\n`);
|
|
59
|
+
|
|
60
|
+
// Render context
|
|
61
|
+
const context = new RenderContext<SSG>({
|
|
62
|
+
domain,
|
|
63
|
+
renderMode: currentRenderMode,
|
|
64
|
+
paths,
|
|
65
|
+
renderMetadata,
|
|
66
|
+
cxArtifacts,
|
|
67
|
+
ssg: { assetPrefix, ssgArtifacts },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await doLifeCycle("Init", async () => initAction(context));
|
|
71
|
+
await doLifeCycle("Clean", async () => cleanAction(context));
|
|
72
|
+
await doLifeCycle("Prepare", async () => prepareAction(context));
|
|
73
|
+
await doLifeCycle("Restore", async () => restoreAction(context));
|
|
74
|
+
await doLifeCycle("Data", async () => dataAction(context));
|
|
75
|
+
await doLifeCycle("SSG", async () => ssgAction(context));
|
|
76
|
+
await doLifeCycle("Relocation", async () => relocationAction(context));
|
|
77
|
+
await doLifeCycle("Meta", async () => metaAction(context));
|
|
78
|
+
await doLifeCycle("Sync", async () => syncAction(context));
|
|
79
|
+
await doLifeCycle("HealthCheck", async () => healthCheckAction(context));
|
|
80
|
+
await doLifeCycle("Logs", async () => logsAction(context));
|
|
81
|
+
await doLifeCycle("Close", async () => closeAction(context));
|
|
162
82
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { getRenderPathsFromDB } from "../../../utils/render";
|
|
4
|
+
|
|
5
|
+
export async function getGatsbyArtifacts(domain: string) {
|
|
6
|
+
const { __ssg } = await getRenderPathsFromDB({ domain });
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
disposables: [
|
|
10
|
+
path.join(__ssg, "public"),
|
|
11
|
+
path.join(__ssg, "static"),
|
|
12
|
+
path.join(__ssg, ".cache"),
|
|
13
|
+
],
|
|
14
|
+
cacheables: [".cache"],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
proDomainPrefix: 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: { proDomainPrefix: 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
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
// }
|