@griddo/cx 11.7.11 → 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,61 @@
|
|
|
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 };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { GRIDDO_SSG_VERBOSE_LOGS } from "../../../constants/envs";
|
|
5
|
+
import { verboseLog } from "../../../utils/loggin";
|
|
6
|
+
import { getRenderPathsFromDB } from "../../../utils/render";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Spawn a new node process `gatsby build`
|
|
10
|
+
* @note This proccess can not access to the custom Griddo `process.env` so it
|
|
11
|
+
* needs variables passed to it via the `env` prop.
|
|
12
|
+
*/
|
|
13
|
+
async function gatsbyBuild(assetPrefixWithDomain: string): Promise<void> {
|
|
14
|
+
verboseLog(`read assetPrefixWithDomain, ${assetPrefixWithDomain}`);
|
|
15
|
+
verboseLog(`using this NODE_OPTIONS in gatsby command: ${process.env.NODE_OPTIONS}`);
|
|
16
|
+
|
|
17
|
+
const { __ssg } = await getRenderPathsFromDB();
|
|
18
|
+
|
|
19
|
+
// Remove `--openssl-legacy-provider` from NODE_OPTIONS because this value
|
|
20
|
+
// break Gatsby render.
|
|
21
|
+
const nodeOptionsWithoutLegacyOpenSSL = process.env.NODE_OPTIONS
|
|
22
|
+
? process.env.NODE_OPTIONS.replace(/--openssl-legacy-provider\s*/g, "").trim()
|
|
23
|
+
: "";
|
|
24
|
+
|
|
25
|
+
// Ruta al ejecutable de Gatsby
|
|
26
|
+
const gatsbyExecutable = path.join(__ssg, "node_modules", ".bin", "gatsby");
|
|
27
|
+
|
|
28
|
+
const args = ["build", "--prefix-paths"];
|
|
29
|
+
if (GRIDDO_SSG_VERBOSE_LOGS) {
|
|
30
|
+
args.push("--verbose");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const child = spawn(gatsbyExecutable, args, {
|
|
35
|
+
cwd: __ssg,
|
|
36
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
37
|
+
env: {
|
|
38
|
+
...process.env,
|
|
39
|
+
SPAWN_ASSET_PREFIX_WITH_DOMAIN: assetPrefixWithDomain,
|
|
40
|
+
NODE_OPTIONS: nodeOptionsWithoutLegacyOpenSSL,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
child.on("close", (code) => {
|
|
45
|
+
if (code === 0) {
|
|
46
|
+
resolve();
|
|
47
|
+
} else {
|
|
48
|
+
reject(new Error(`Gatsby build failed with exit code ${code}`));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
child.on("error", (error) => {
|
|
53
|
+
reject(new Error(`Failed to start Gatsby build process: ${error.message}`));
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { gatsbyBuild };
|
|
@@ -0,0 +1,276 @@
|
|
|
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 };
|
|
@@ -0,0 +1,35 @@
|
|
|
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 };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Build CX script file
|
|
4
|
+
#
|
|
5
|
+
# This file generates the necessary builds for CX.
|
|
6
|
+
# - Setup, to generate necessary elements (tsconfig, etc..)
|
|
7
|
+
# - Library, CX library that will be used by the SSG framework.
|
|
8
|
+
# - Scripts, CX scripts that will be used by infra during the render process.
|
|
9
|
+
#
|
|
10
|
+
# @todo:
|
|
11
|
+
# In the future, we will try to eliminate the bundling processes and use
|
|
12
|
+
# TypeScript or ESModules directly.
|
|
13
|
+
|
|
14
|
+
# start
|
|
15
|
+
echo "📦 Building ..."
|
|
16
|
+
|
|
17
|
+
# CLI options
|
|
18
|
+
log="--log-level=error"
|
|
19
|
+
production_node_opts="--bundle --platform=node --minify --sourcemap"
|
|
20
|
+
debugging_node_opts="--bundle --platform=node --sourcemap"
|
|
21
|
+
# react_opts="--platform=node --external:@griddo-instance --external:react --external:react-dom --bundle --minify"
|
|
22
|
+
|
|
23
|
+
# Manage --minify for debugging
|
|
24
|
+
bundle_node_opts=$production_node_opts
|
|
25
|
+
if [ "$1" = "--debug" ]; then
|
|
26
|
+
bundle_node_opts=$debugging_node_opts
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# library
|
|
30
|
+
# esbuild ${log} ./exporter/index.ts ${bundle_node_opts} --outfile=./build/index.js
|
|
31
|
+
# esbuild ${log} ./exporter/react/index.tsx ${react_opts} --outfile=./build/react/index.js
|
|
32
|
+
|
|
33
|
+
# scripts
|
|
34
|
+
esbuild ${log} ./exporter/commands/end-render.ts ${bundle_node_opts} --outfile=./build/end-render.js
|
|
35
|
+
esbuild ${log} ./exporter/commands/upload-search-content.ts ${bundle_node_opts} --outfile=./build/upload-search-content.js
|
|
36
|
+
esbuild ${log} ./exporter/commands/reset-render.ts ${bundle_node_opts} --outfile=./build/reset-render.js
|
|
37
|
+
esbuild ${log} ./exporter/commands/start-render.ts ${bundle_node_opts} --outfile=./build/start-render.js
|
|
38
|
+
esbuild ${log} ./exporter/commands/prepare-domains-render.ts ${bundle_node_opts} --outfile=./build/prepare-domains-render.js
|
|
39
|
+
esbuild ${log} ./exporter/commands/prepare-assets-directory.ts ${bundle_node_opts} --outfile=./build/prepare-assets-directory.js
|
|
40
|
+
|
|
41
|
+
# types
|
|
42
|
+
tsc --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
|
package/exporter/build.sh
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
3
|
-
# This file generates the necessary builds for CX.
|
|
4
|
-
# - Setup, to generate necessary elements (tsconfig, etc..)
|
|
5
|
-
# - Library, CX library that will be used by the SSG framework.
|
|
6
|
-
# - Scripts, CX scripts that will be used by infra during the render process.
|
|
7
|
-
#
|
|
8
|
-
# @todo:
|
|
9
|
-
# In the future, we will try to eliminate the bundling processes and use
|
|
10
|
-
# TypeScript or ESModules directly.
|
|
1
|
+
#!/usr/bin/env bash
|
|
11
2
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# CLI options
|
|
16
|
-
log="--log-level=error"
|
|
17
|
-
production_node_opts="--bundle --platform=node --minify --sourcemap"
|
|
18
|
-
debugging_node_opts="--bundle --platform=node --sourcemap"
|
|
19
|
-
react_opts="--platform=node --external:@griddo-instance --external:react --external:react-dom --bundle --minify"
|
|
20
|
-
|
|
21
|
-
# Manage --minify for debugging
|
|
22
|
-
bundle_node_opts=$production_node_opts
|
|
23
|
-
if [ "$1" = "--debug" ]; then
|
|
24
|
-
bundle_node_opts=$debugging_node_opts
|
|
25
|
-
fi
|
|
26
|
-
|
|
27
|
-
# library
|
|
28
|
-
esbuild ${log} ./exporter/index.ts ${bundle_node_opts} --outfile=./build/index.js
|
|
29
|
-
esbuild ${log} ./exporter/react/index.tsx ${react_opts} --outfile=./build/react/index.js
|
|
30
|
-
|
|
31
|
-
# scripts
|
|
32
|
-
esbuild ${log} ./exporter/commands/end-render.ts ${bundle_node_opts} --outfile=./build/end-render.js
|
|
33
|
-
esbuild ${log} ./exporter/commands/upload-search-content.ts ${bundle_node_opts} --outfile=./build/upload-search-content.js
|
|
34
|
-
esbuild ${log} ./exporter/commands/reset-render.ts ${bundle_node_opts} --outfile=./build/reset-render.js
|
|
35
|
-
esbuild ${log} ./exporter/commands/start-render.ts ${bundle_node_opts} --outfile=./build/start-render.js
|
|
36
|
-
esbuild ${log} ./exporter/commands/prepare-domains-render.ts ${bundle_node_opts} --outfile=./build/prepare-domains-render.js
|
|
37
|
-
|
|
38
|
-
# types
|
|
39
|
-
tsc --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
|
|
3
|
+
echo "📦 Compiling CX..."
|
|
4
|
+
tsgo --project tsconfig.commands.json
|
|
5
|
+
# tsgo --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
|