@griddo/cx 11.9.9-rc.0 → 11.9.9-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +240 -13
- 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 +1 -0
- package/build/commands/reset-render.d.ts +1 -0
- package/build/commands/start-render.d.ts +1 -0
- package/build/commands/upload-search-content.d.ts +1 -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/{shared/errors.d.ts → errors/errors-data.d.ts} +3 -5
- package/build/errors/index.d.ts +15 -0
- package/build/index.d.ts +29 -10
- package/build/index.js +73 -406
- 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/GriddoIntegrations/index.d.ts +4 -3
- package/build/react/GriddoIntegrations/utils.d.ts +6 -7
- package/build/react/index.d.ts +2 -3
- package/build/react/index.js +3 -1
- 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 +5 -2
- package/build/services/domains.d.ts +4 -3
- package/build/services/navigation.d.ts +16 -16
- package/build/services/reference-fields.d.ts +3 -3
- package/build/services/register.d.ts +36 -0
- package/build/services/robots.d.ts +19 -2
- package/build/services/settings.d.ts +4 -0
- package/build/services/sites.d.ts +5 -8
- package/build/services/store.d.ts +1 -10
- package/build/start-render.js +100 -0
- package/build/start-render.js.map +7 -0
- package/build/{shared/types → types}/api.d.ts +18 -18
- package/build/{shared/types → types}/global.d.ts +16 -15
- package/build/{shared/types → types}/navigation.d.ts +5 -5
- package/build/{shared/types → types}/pages.d.ts +9 -9
- package/build/{shared/types → types}/sites.d.ts +19 -18
- 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/{services → utils}/api.d.ts +1 -1
- 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/{core/check-env-health.d.ts → utils/health-checks.d.ts} +2 -4
- package/build/utils/loggin.d.ts +51 -0
- package/build/{services → utils}/pages.d.ts +3 -3
- 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 +162 -0
- 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 +24 -16
- package/exporter/commands/end-render.ts +86 -65
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +35 -147
- package/exporter/commands/reset-render.ts +8 -13
- package/exporter/commands/start-render.ts +64 -26
- package/exporter/commands/upload-search-content.ts +26 -201
- package/exporter/{shared → constants}/endpoints.ts +11 -12
- package/exporter/constants/envs.ts +94 -0
- package/exporter/constants/index.ts +129 -0
- package/exporter/{shared/errors.ts → errors/errors-data.ts} +14 -24
- package/exporter/errors/index.ts +40 -0
- package/exporter/index.ts +56 -14
- package/exporter/react/{GriddoFavicon → Favicon}/index.tsx +9 -3
- package/exporter/react/GriddoIntegrations/index.tsx +23 -17
- package/exporter/react/GriddoIntegrations/utils.ts +12 -24
- package/exporter/react/index.tsx +9 -3
- 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 +10 -8
- package/exporter/services/domains.ts +8 -23
- package/exporter/services/navigation.ts +18 -12
- package/exporter/services/reference-fields.ts +32 -14
- package/exporter/services/register.ts +113 -0
- package/exporter/services/robots.ts +61 -33
- package/exporter/services/settings.ts +17 -0
- package/exporter/services/sites.ts +28 -40
- package/exporter/services/store.ts +321 -354
- package/exporter/{shared/types → types}/api.ts +41 -40
- package/exporter/{shared/types → types}/global.ts +21 -17
- package/exporter/{shared/types → types}/navigation.ts +3 -3
- package/exporter/{shared/types → types}/pages.ts +11 -10
- package/exporter/{shared/types → types}/sites.ts +19 -18
- package/exporter/utils/alerts.ts +29 -0
- package/exporter/utils/api.ts +243 -0
- package/exporter/utils/cache.ts +142 -0
- package/exporter/utils/core-utils.ts +458 -0
- package/exporter/utils/create-build-data.ts +17 -0
- package/exporter/utils/domains.ts +39 -0
- package/exporter/utils/folders.ts +320 -0
- package/exporter/utils/health-checks.ts +64 -0
- package/exporter/{core → utils}/images.ts +6 -1
- package/exporter/{core → utils}/instance.ts +13 -9
- package/exporter/utils/loggin.ts +184 -0
- package/exporter/{services → utils}/pages.ts +92 -27
- package/exporter/utils/render.ts +71 -0
- package/exporter/utils/searches.ts +156 -0
- package/exporter/utils/sites.ts +312 -0
- package/exporter/utils/store.ts +314 -0
- package/gatsby-browser.tsx +58 -41
- package/gatsby-config.ts +17 -10
- package/gatsby-node.ts +79 -20
- package/gatsby-ssr.tsx +1 -2
- package/package.json +80 -41
- package/src/README.md +7 -0
- package/src/components/Head.tsx +73 -28
- package/src/components/template.tsx +29 -6
- package/src/gatsby-node-utils.ts +2 -76
- package/src/html.tsx +11 -2
- package/src/types.ts +3 -3
- package/start-render.js +7 -0
- package/tsconfig.json +3 -5
- package/build/commands/end-render.js +0 -31
- package/build/commands/end-render.js.map +0 -7
- package/build/commands/prepare-assets-directory.js +0 -9
- package/build/commands/prepare-assets-directory.js.map +0 -7
- package/build/commands/prepare-domains-render.js +0 -38
- package/build/commands/prepare-domains-render.js.map +0 -7
- package/build/commands/reset-render.js +0 -31
- package/build/commands/reset-render.js.map +0 -7
- package/build/commands/single-domain-upload-search-content.d.ts +0 -1
- package/build/commands/start-render.js +0 -66
- package/build/commands/start-render.js.map +0 -7
- package/build/commands/upload-search-content.js +0 -31
- package/build/commands/upload-search-content.js.map +0 -7
- package/build/core/GriddoLog.d.ts +0 -16
- package/build/core/db-class.d.ts +0 -11
- package/build/core/db.d.ts +0 -4
- package/build/core/dist-rollback.d.ts +0 -11
- package/build/core/errors.d.ts +0 -26
- package/build/core/fs.d.ts +0 -69
- package/build/core/life-cycle.d.ts +0 -26
- package/build/core/logger.d.ts +0 -18
- package/build/core/objects.d.ts +0 -11
- package/build/core/print-logos.d.ts +0 -5
- package/build/react/DynamicScript/index.d.ts +0 -4
- package/build/react/GriddoFavicon/index.d.ts +0 -4
- package/build/react/GriddoOpenGraph/index.d.ts +0 -10
- package/build/services/manage-sites.d.ts +0 -22
- package/build/services/manage-store.d.ts +0 -32
- package/build/services/render-artifacts.d.ts +0 -6
- package/build/services/render.d.ts +0 -70
- package/build/services/sitemaps.d.ts +0 -5
- package/build/shared/context.d.ts +0 -36
- package/build/shared/envs.d.ts +0 -19
- package/build/shared/npm-modules/brush.d.ts +0 -18
- package/build/shared/npm-modules/find-up-simple.d.ts +0 -34
- package/build/shared/npm-modules/pkg-dir.d.ts +0 -7
- package/build/shared/npm-modules/xml-parser.d.ts +0 -4
- package/build/shared/types/render.d.ts +0 -54
- package/build/shared/types.d.ts +0 -15
- package/build/ssg-adapters/gatsby/actions/clean.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/close.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/data.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/init.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/logs.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/meta.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/prepare.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/relocation.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/restore.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/ssg.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/sync.d.ts +0 -3
- package/build/ssg-adapters/gatsby/index.d.ts +0 -9
- package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +0 -4
- package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +0 -15
- package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +0 -7
- package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +0 -7
- package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +0 -18
- package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +0 -26
- package/build/ssg-adapters/gatsby/shared/types.d.ts +0 -34
- package/cli.mjs +0 -231
- package/exporter/build-esbuild.noop +0 -42
- package/exporter/commands/README.md +0 -151
- package/exporter/commands/prepare-assets-directory.ts +0 -34
- package/exporter/commands/single-domain-upload-search-content.ts +0 -206
- package/exporter/core/GriddoLog.ts +0 -45
- package/exporter/core/check-env-health.ts +0 -204
- package/exporter/core/db-class.ts +0 -54
- package/exporter/core/db.ts +0 -33
- package/exporter/core/dist-rollback.ts +0 -49
- package/exporter/core/errors.ts +0 -92
- package/exporter/core/fs.ts +0 -385
- package/exporter/core/life-cycle.ts +0 -73
- package/exporter/core/logger.ts +0 -141
- package/exporter/core/objects.ts +0 -37
- package/exporter/core/print-logos.ts +0 -21
- package/exporter/react/DynamicScript/index.tsx +0 -33
- package/exporter/react/GriddoOpenGraph/index.tsx +0 -39
- package/exporter/services/api.ts +0 -306
- package/exporter/services/manage-sites.ts +0 -116
- package/exporter/services/manage-store.ts +0 -173
- package/exporter/services/render-artifacts.ts +0 -44
- package/exporter/services/render.ts +0 -229
- package/exporter/services/sitemaps.ts +0 -129
- package/exporter/shared/context.ts +0 -49
- package/exporter/shared/envs.ts +0 -62
- package/exporter/shared/npm-modules/README.md +0 -36
- package/exporter/shared/npm-modules/brush.ts +0 -34
- package/exporter/shared/npm-modules/find-up-simple.ts +0 -100
- package/exporter/shared/npm-modules/pkg-dir.ts +0 -17
- package/exporter/shared/npm-modules/xml-parser.ts +0 -57
- package/exporter/shared/types/render.ts +0 -63
- package/exporter/shared/types.ts +0 -15
- package/exporter/ssg-adapters/gatsby/actions/clean.ts +0 -26
- package/exporter/ssg-adapters/gatsby/actions/close.ts +0 -17
- package/exporter/ssg-adapters/gatsby/actions/data.ts +0 -22
- package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +0 -10
- package/exporter/ssg-adapters/gatsby/actions/init.ts +0 -12
- package/exporter/ssg-adapters/gatsby/actions/logs.ts +0 -10
- package/exporter/ssg-adapters/gatsby/actions/meta.ts +0 -13
- package/exporter/ssg-adapters/gatsby/actions/prepare.ts +0 -9
- package/exporter/ssg-adapters/gatsby/actions/relocation.ts +0 -15
- package/exporter/ssg-adapters/gatsby/actions/restore.ts +0 -21
- package/exporter/ssg-adapters/gatsby/actions/ssg.ts +0 -12
- package/exporter/ssg-adapters/gatsby/actions/sync.ts +0 -65
- package/exporter/ssg-adapters/gatsby/index.ts +0 -114
- package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +0 -17
- package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +0 -128
- package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +0 -75
- package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +0 -58
- package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +0 -33
- package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +0 -298
- package/exporter/ssg-adapters/gatsby/shared/types.ts +0 -35
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- package/tsconfig.commands.json +0 -36
- package/tsconfig.exporter.json +0 -21
- /package/build/commands/{prepare-assets-directory.d.ts → move-assets.d.ts} +0 -0
- /package/build/{shared → constants}/endpoints.d.ts +0 -0
- /package/build/react/{GriddoFavicon → Favicon}/utils.d.ts +0 -0
- /package/build/{shared/types → types}/templates.d.ts +0 -0
- /package/build/{core → utils}/images.d.ts +0 -0
- /package/build/{core → utils}/instance.d.ts +0 -0
- /package/exporter/react/{GriddoFavicon → Favicon}/utils.ts +0 -0
- /package/exporter/{shared/types → types}/templates.ts +0 -0
|
@@ -1,181 +1,102 @@
|
|
|
1
|
-
import type { BuildProcessData
|
|
1
|
+
import type { BuildProcessData } from "../types/global";
|
|
2
2
|
import type {
|
|
3
3
|
GriddoListPage,
|
|
4
4
|
GriddoMultiPage,
|
|
5
5
|
GriddoPageObject,
|
|
6
6
|
GriddoSinglePage,
|
|
7
7
|
PageAdditionalInfo,
|
|
8
|
-
} from "../
|
|
9
|
-
import type { HashSites, Site, SiteHash } from "../shared/types/sites";
|
|
8
|
+
} from "../types/pages";
|
|
10
9
|
|
|
11
|
-
import
|
|
10
|
+
import fs from "node:fs";
|
|
12
11
|
import path from "node:path";
|
|
13
12
|
|
|
14
13
|
import pLimit from "p-limit";
|
|
15
14
|
|
|
16
|
-
import {
|
|
17
|
-
import { SETTINGS } from "../shared/endpoints";
|
|
18
|
-
import {
|
|
19
|
-
GRIDDO_API_CONCURRENCY_COUNT,
|
|
20
|
-
GRIDDO_API_URL,
|
|
21
|
-
GRIDDO_PUBLIC_API_URL,
|
|
22
|
-
GRIDDO_REACT_APP_INSTANCE,
|
|
23
|
-
} from "../shared/envs";
|
|
24
|
-
import { brush } from "../shared/npm-modules/brush";
|
|
25
|
-
import { RENDER_MODE, type RenderMode } from "../shared/types/render";
|
|
26
|
-
import { get } from "./api";
|
|
27
|
-
import { getSiteData, getSitesToRender, unpublishSites } from "./manage-sites";
|
|
28
|
-
import { removeOrphanSites, saveRenderInfoInStore, saveSitePagesInStore } from "./manage-store";
|
|
15
|
+
import { envs } from "../constants";
|
|
29
16
|
import { NavigationService } from "./navigation";
|
|
17
|
+
import { getReferenceFieldData } from "./reference-fields";
|
|
18
|
+
import { getAllSettings } from "./settings";
|
|
19
|
+
import { getPage } from "./sites";
|
|
20
|
+
import { updatedSiteHash } from "../utils/cache";
|
|
21
|
+
import { getConfig, removeAllSiteDirsFromStore } from "../utils/core-utils";
|
|
22
|
+
import { buildLog, listSitesLog } from "../utils/loggin";
|
|
30
23
|
import {
|
|
31
24
|
createGriddoListPages,
|
|
32
25
|
createGriddoMultiPages,
|
|
33
26
|
createGriddoSinglePage,
|
|
34
27
|
getMultiPageElements,
|
|
35
28
|
getPaginatedPages,
|
|
36
|
-
} from "
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const sitesStr = sites.map((s) => {
|
|
53
|
-
const shouldBeUpdated = s.shouldBeUpdated ? "*" : "";
|
|
54
|
-
const lineLen = s.name.length + shouldBeUpdated.length + s.id.toString().length;
|
|
55
|
-
const padding = " ".repeat(maxline - lineLen);
|
|
56
|
-
return `${brush.bold(s.name)} ${brush.dim(`(${s.id})`)} ${shouldBeUpdated} ${padding}${brush.dim("-")} ${brush.dim(s.slug)}`;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const sitesOutput = sitesStr.length > 0 ? `\n\n${sitesStr.join("\n")}` : brush.dim("--none--\n");
|
|
60
|
-
|
|
61
|
-
GriddoLog.log(`
|
|
62
|
-
${title} ${sitesOutput}`);
|
|
63
|
-
}
|
|
29
|
+
} from "../utils/pages";
|
|
30
|
+
import { getSiteData, getSitesToRender, unpublishSites } from "../utils/sites";
|
|
31
|
+
import {
|
|
32
|
+
getMissingPublishedPagesInStore,
|
|
33
|
+
getZombiePagesInStore,
|
|
34
|
+
removeOrphanSites,
|
|
35
|
+
removeSitePagesFromStore,
|
|
36
|
+
saveRenderInfoInStore,
|
|
37
|
+
saveSitePagesInStore,
|
|
38
|
+
} from "../utils/store";
|
|
39
|
+
|
|
40
|
+
const renderId = new Date().valueOf().toString();
|
|
41
|
+
const { griddoVersion, paths } = getConfig();
|
|
42
|
+
const { __cx } = paths();
|
|
43
|
+
const storeDir = path.join(__cx, "store");
|
|
64
44
|
|
|
65
45
|
/**
|
|
66
46
|
* Fetch, process and save object pages and sites data into the file system to
|
|
67
47
|
* be consumed by other services (Griddo itself, Adapters, etc.)
|
|
68
48
|
*/
|
|
69
|
-
async function createStore(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
griddoVersion: string;
|
|
73
|
-
basePath: string;
|
|
74
|
-
}) {
|
|
75
|
-
console.info(`API calls with ${GRIDDO_API_CONCURRENCY_COUNT} threads`);
|
|
76
|
-
console.info(`API URL ${GRIDDO_API_URL as string}`);
|
|
77
|
-
|
|
78
|
-
const { renderMode, domain, griddoVersion, basePath } = options;
|
|
79
|
-
const renderFromScratch = renderMode === RENDER_MODE.FROM_SCRATCH;
|
|
80
|
-
const storeDir = path.join(basePath, "store");
|
|
81
|
-
|
|
82
|
-
// Vars to save later in the report file
|
|
83
|
-
const createdPages: number[] = [];
|
|
84
|
-
const buildProcessData: BuildProcessData = {};
|
|
85
|
-
|
|
86
|
-
// Get sites objects to publish and unpublish from this domain
|
|
87
|
-
const { sitesToPublish, sitesToUnpublish } = await getSitesToRender(domain);
|
|
88
|
-
|
|
89
|
-
listSitesLog("Sites to publish:", sitesToPublish);
|
|
90
|
-
listSitesLog("Sites to unpublish:", sitesToUnpublish);
|
|
91
|
-
|
|
92
|
-
// Send unpublished sites to API.
|
|
93
|
-
await unpublishSites(sitesToUnpublish);
|
|
94
|
-
|
|
95
|
-
// Eliminamos posibles sites que estén en el store pero que no deberían
|
|
96
|
-
// porque han sido cambiados de dominio. Si han sido despublicados ya se
|
|
97
|
-
// despublican bien porque entran en `sitesToUnpublish`
|
|
98
|
-
await removeOrphanSites(sitesToPublish, domain);
|
|
99
|
-
|
|
100
|
-
const allPagesToRemoveFromBuild: number[] = [];
|
|
101
|
-
// let numberOfFinalActivePages: number[] = [];
|
|
102
|
-
|
|
103
|
-
for (const site of sitesToUnpublish) {
|
|
104
|
-
const { pagesStatus } = site;
|
|
105
|
-
|
|
106
|
-
// Añadimos a allPagesToRemoveFromBuild todas las páginas de un site
|
|
107
|
-
// para despublicar.
|
|
108
|
-
allPagesToRemoveFromBuild.push(
|
|
109
|
-
...pagesStatus.active,
|
|
110
|
-
...pagesStatus.offlinePending,
|
|
111
|
-
...pagesStatus.uploadPending,
|
|
112
|
-
...pagesStatus.deleted,
|
|
113
|
-
...pagesStatus.offline,
|
|
114
|
-
);
|
|
115
|
-
}
|
|
49
|
+
async function createStore(domain: string) {
|
|
50
|
+
console.info(`API calls with ${envs.GRIDDO_API_CONCURRENCY_COUNT} threads`);
|
|
51
|
+
console.info(`API URL ${envs.GRIDDO_API_URL as string}`);
|
|
116
52
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
favicon,
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const additionalInfo = {
|
|
168
|
-
baseUrl: GRIDDO_API_URL,
|
|
169
|
-
publicBaseUrl: GRIDDO_PUBLIC_API_URL,
|
|
170
|
-
instance: GRIDDO_REACT_APP_INSTANCE,
|
|
171
|
-
siteSlug,
|
|
172
|
-
theme,
|
|
173
|
-
siteMetadata,
|
|
174
|
-
socials,
|
|
175
|
-
siteLangs,
|
|
176
|
-
cloudinaryName,
|
|
177
|
-
griddoVersion,
|
|
178
|
-
siteOptions: {
|
|
53
|
+
try {
|
|
54
|
+
// Vars to save later in the report file
|
|
55
|
+
const createdPages: Array<number> = [];
|
|
56
|
+
const buildProcessData: BuildProcessData = {};
|
|
57
|
+
|
|
58
|
+
// Get sites objects to publish and unpublish from this domain
|
|
59
|
+
const { sitesToPublish, sitesToUnpublish } = await getSitesToRender(domain);
|
|
60
|
+
|
|
61
|
+
const domainHasSites =
|
|
62
|
+
sitesToPublish.length > 0 || sitesToUnpublish.length > 0;
|
|
63
|
+
|
|
64
|
+
if (!domainHasSites) {
|
|
65
|
+
console.warn(`There are no sites to update in the domain ${domain}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
listSitesLog("Sites to publish:", sitesToPublish);
|
|
69
|
+
listSitesLog("Sites to unpublish:", sitesToUnpublish);
|
|
70
|
+
|
|
71
|
+
// Send unpublished sites to API.
|
|
72
|
+
// @todo ¿mover esta llamada al final del proceso de render?
|
|
73
|
+
// Aquí también se están eliminado físicamente los archivos json del
|
|
74
|
+
// store de los sites para despublicar.
|
|
75
|
+
await unpublishSites(sitesToUnpublish);
|
|
76
|
+
|
|
77
|
+
// Eliminamos posibles sites que estén en el store pero que no deberían
|
|
78
|
+
// porque han sido cambiados de dominio. Si han sido despublicados ya se
|
|
79
|
+
// despublican bien porque entran en `sitesToUnpublish`
|
|
80
|
+
removeOrphanSites(sitesToPublish, domain);
|
|
81
|
+
|
|
82
|
+
// Solo los sites to publish...
|
|
83
|
+
for (const site of sitesToPublish) {
|
|
84
|
+
const { id: siteId, slug: siteSlug, theme, favicon, pagesStatus } = site;
|
|
85
|
+
const siteDirName = siteId.toString();
|
|
86
|
+
|
|
87
|
+
const {
|
|
88
|
+
siteInfo,
|
|
89
|
+
siteHash,
|
|
90
|
+
unpublishHashes,
|
|
91
|
+
siteLangs,
|
|
92
|
+
defaultLang,
|
|
93
|
+
headers,
|
|
94
|
+
footers,
|
|
95
|
+
socials,
|
|
96
|
+
} = await getSiteData(siteId);
|
|
97
|
+
|
|
98
|
+
const {
|
|
99
|
+
cloudinaryName,
|
|
179
100
|
useMetaTitle,
|
|
180
101
|
useMetaKeywords,
|
|
181
102
|
showBasicMetaRobots,
|
|
@@ -183,211 +104,257 @@ async function createStore(options: {
|
|
|
183
104
|
avoidSelfReferenceCanonicals,
|
|
184
105
|
avoidHrefLangXDefault,
|
|
185
106
|
avoidDebugMetas,
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
107
|
+
} = await getAllSettings();
|
|
108
|
+
|
|
109
|
+
buildProcessData[siteId] = {
|
|
110
|
+
siteHash,
|
|
111
|
+
unpublishHashes,
|
|
112
|
+
publishHashes: [],
|
|
113
|
+
publishPagesIds: [],
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const NavService = new NavigationService();
|
|
117
|
+
NavService.navigations = { headers, footers };
|
|
118
|
+
|
|
119
|
+
site.languages = siteLangs;
|
|
120
|
+
|
|
121
|
+
const shouldUpdateSite = updatedSiteHash(siteId, siteHash);
|
|
122
|
+
|
|
123
|
+
const siteScript = siteInfo.siteScript;
|
|
124
|
+
|
|
125
|
+
const siteMetadata = {
|
|
126
|
+
siteUrl: siteInfo.slug,
|
|
127
|
+
title: siteInfo.name,
|
|
128
|
+
favicon,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const additionalInfo = {
|
|
132
|
+
baseUrl: envs.GRIDDO_API_URL,
|
|
133
|
+
publicBaseUrl: envs.GRIDDO_PUBLIC_API_URL,
|
|
134
|
+
instance: envs.GRIDDO_REACT_APP_INSTANCE,
|
|
135
|
+
siteSlug,
|
|
136
|
+
theme,
|
|
137
|
+
siteMetadata,
|
|
138
|
+
socials,
|
|
139
|
+
siteLangs,
|
|
140
|
+
cloudinaryName,
|
|
141
|
+
griddoVersion,
|
|
142
|
+
siteOptions: {
|
|
143
|
+
useMetaTitle,
|
|
144
|
+
useMetaKeywords,
|
|
145
|
+
showBasicMetaRobots,
|
|
146
|
+
avoidHrefLangsOnCanonicals,
|
|
147
|
+
avoidSelfReferenceCanonicals,
|
|
148
|
+
avoidHrefLangXDefault,
|
|
149
|
+
avoidDebugMetas,
|
|
150
|
+
},
|
|
151
|
+
siteScript,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
buildLog(`${site.name} site`);
|
|
155
|
+
|
|
156
|
+
/// Creates the store directory for each site using the id
|
|
157
|
+
fs.mkdirSync(path.join(storeDir, siteDirName), {
|
|
158
|
+
recursive: true,
|
|
234
159
|
});
|
|
235
160
|
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
// in
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
//
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
//
|
|
287
|
-
//
|
|
288
|
-
//
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
161
|
+
// -------------------------------------------------------------------------
|
|
162
|
+
// Pages loop promise creation
|
|
163
|
+
// -------------------------------------------------------------------------
|
|
164
|
+
// Async function that process every page for one site to use later in the
|
|
165
|
+
// `Promise.all` with pLimit.
|
|
166
|
+
const fetchSitePageAndSaveInStore = async (
|
|
167
|
+
siteIdName: string,
|
|
168
|
+
pageId: number,
|
|
169
|
+
) => {
|
|
170
|
+
// Here will be store every page returned by the API and processed
|
|
171
|
+
let griddoPageObjects: Array<GriddoPageObject> = [];
|
|
172
|
+
|
|
173
|
+
// Get page data
|
|
174
|
+
const page = await getPage(pageId, shouldUpdateSite);
|
|
175
|
+
|
|
176
|
+
// Probably a 404
|
|
177
|
+
if (!page) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Update Array of page ids
|
|
182
|
+
createdPages.push(pageId);
|
|
183
|
+
|
|
184
|
+
// TODO: Use structuredClone() when node 18 is available.
|
|
185
|
+
// SHAME: This new pageAdditionalInfo needs to be a copy because
|
|
186
|
+
// additionalInfo referenced from outside this function and
|
|
187
|
+
// its used by other pages.
|
|
188
|
+
const pageAdditionalInfo = JSON.parse(
|
|
189
|
+
JSON.stringify(additionalInfo),
|
|
190
|
+
) as PageAdditionalInfo;
|
|
191
|
+
|
|
192
|
+
// Updated with navigations (header & footer)
|
|
193
|
+
pageAdditionalInfo.navigations = NavService.getPageNavigations(page);
|
|
194
|
+
|
|
195
|
+
// Content Type Data Query.
|
|
196
|
+
// Where the pair `hasDistributorData:true` /
|
|
197
|
+
// `getStaticData:true` and `data` prop exists, this function
|
|
198
|
+
// will attach a `queriedItems` prop with the result of the
|
|
199
|
+
// fetch for the data.
|
|
200
|
+
const template = await getReferenceFieldData({
|
|
201
|
+
page,
|
|
202
|
+
cacheKey: renderId,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// MultiPage Query
|
|
206
|
+
// Where the pair `hasGriddoMultiPage:true` prop exists, this function
|
|
207
|
+
// will process the schema and return a multiPageElemtens array to use
|
|
208
|
+
// in `createGriddoMultiPages()`
|
|
209
|
+
const multiPageElements = await getMultiPageElements(template);
|
|
210
|
+
|
|
211
|
+
// -----------------------------------------------------------------------
|
|
212
|
+
// Build Griddo page objects.
|
|
213
|
+
// -----------------------------------------------------------------------
|
|
214
|
+
// A page from the API could be one of those:
|
|
215
|
+
// - List with pagination (static list template): needs to be splitted in n pages
|
|
216
|
+
// - Multi-page module: needs to be splitted in n pages
|
|
217
|
+
// - Single: just one page
|
|
218
|
+
|
|
219
|
+
// Griddo page types
|
|
220
|
+
const isStaticListPage =
|
|
221
|
+
page?.mode === "list" || page?.mode === "paginated-data";
|
|
222
|
+
const isMultiPage = !isStaticListPage && multiPageElements;
|
|
223
|
+
const isSinglePage = !isMultiPage && !isStaticListPage;
|
|
224
|
+
|
|
225
|
+
// >> List (static list template) <<
|
|
226
|
+
if (isStaticListPage) {
|
|
227
|
+
const griddoListPage = {
|
|
228
|
+
page: page,
|
|
229
|
+
pages: getPaginatedPages(template),
|
|
230
|
+
isRoot: false,
|
|
231
|
+
defaultLang: defaultLang,
|
|
232
|
+
template: template,
|
|
233
|
+
totalQueriedItems: template.queriedItems,
|
|
234
|
+
} as GriddoListPage;
|
|
235
|
+
|
|
236
|
+
// pageObjects = await createGriddoListPages({ adapter: "Gatsby" })
|
|
237
|
+
griddoPageObjects = await createGriddoListPages(
|
|
238
|
+
griddoListPage,
|
|
239
|
+
pageAdditionalInfo,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// >> Multi-page <<
|
|
244
|
+
if (isMultiPage) {
|
|
245
|
+
const griddoMultipage = page as GriddoMultiPage;
|
|
246
|
+
|
|
247
|
+
// The `template` key with the (maybe) data (ReferenceField) items queried
|
|
248
|
+
griddoMultipage.template = template;
|
|
249
|
+
griddoMultipage.multiPageElements = multiPageElements;
|
|
250
|
+
griddoMultipage.defaultLang = defaultLang;
|
|
251
|
+
|
|
252
|
+
griddoPageObjects = await createGriddoMultiPages(
|
|
253
|
+
griddoMultipage,
|
|
254
|
+
pageAdditionalInfo,
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// >> Single template <<
|
|
259
|
+
if (isSinglePage) {
|
|
260
|
+
const griddoSinglePage = page as GriddoSinglePage;
|
|
261
|
+
|
|
262
|
+
// The `template` key with the (maybe) data (ReferenceField) items queried
|
|
263
|
+
griddoSinglePage.template = template;
|
|
264
|
+
griddoSinglePage.defaultLang = defaultLang;
|
|
265
|
+
|
|
266
|
+
griddoPageObjects = [
|
|
267
|
+
await createGriddoSinglePage(griddoSinglePage, pageAdditionalInfo),
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Upload only the valid pages hashes or ids of pages that has
|
|
272
|
+
// been changed or created.
|
|
273
|
+
if (page.hash !== null) {
|
|
274
|
+
buildProcessData[siteId].publishHashes.push(page.hash);
|
|
275
|
+
buildProcessData[siteId].publishPagesIds.push(page.id);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Save build data to store
|
|
279
|
+
saveSitePagesInStore(siteIdName, griddoPageObjects);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// Pages that needs to be fetched from the API and written to the
|
|
283
|
+
// store.
|
|
284
|
+
const pagesToFetchFromAPI = [
|
|
285
|
+
// These pages are news or has been updated.
|
|
286
|
+
...pagesStatus.uploadPending,
|
|
287
|
+
// You should take into account the pages that, even though they are
|
|
288
|
+
// already published and therefore should be avoided from requesting
|
|
289
|
+
// them to the API, are not in the store, probably due to a failed
|
|
290
|
+
// render. In that case, you have to request them again from the API
|
|
291
|
+
// to include them in the store.
|
|
292
|
+
...getMissingPublishedPagesInStore(siteDirName, pagesStatus.active),
|
|
293
|
+
];
|
|
294
|
+
|
|
295
|
+
// Create pages to the store. First requesting from API,
|
|
296
|
+
// transform, etc., and then writing them to disk.
|
|
297
|
+
const limit = pLimit(envs.GRIDDO_API_CONCURRENCY_COUNT);
|
|
298
|
+
const pagesToStore = pagesToFetchFromAPI.map((id: number) =>
|
|
299
|
+
limit(() => fetchSitePageAndSaveInStore(siteDirName, id)),
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
await Promise.all(pagesToStore);
|
|
303
|
+
|
|
304
|
+
// @ts-expect-error Mutate pagesStatus for reading pourposes.
|
|
305
|
+
pagesStatus.zombie = getZombiePagesInStore(siteDirName, [
|
|
306
|
+
...pagesStatus.active,
|
|
307
|
+
...pagesStatus.uploadPending,
|
|
308
|
+
]);
|
|
309
|
+
|
|
310
|
+
// Delete pages from the store removing them from disk.
|
|
311
|
+
removeSitePagesFromStore(siteDirName, [
|
|
312
|
+
pagesStatus.deleted,
|
|
313
|
+
pagesStatus.offline,
|
|
314
|
+
pagesStatus.offlinePending,
|
|
315
|
+
// @ts-expect-error Mutate pagesStatus for reading pourposes.
|
|
316
|
+
pagesStatus.zombie,
|
|
317
|
+
]);
|
|
326
318
|
}
|
|
327
319
|
|
|
328
|
-
//
|
|
329
|
-
//
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Update (write) the site hash file.
|
|
370
|
-
*
|
|
371
|
-
* @param siteId The id of the site.
|
|
372
|
-
* @param siteHash The has of the site.
|
|
373
|
-
*/
|
|
374
|
-
async function updatedSiteHash(siteId: number, siteHash: SiteHash) {
|
|
375
|
-
const allHash = await getHashSites();
|
|
376
|
-
const lastHash = allHash[siteId];
|
|
377
|
-
const currentHash = siteHash || lastHash || Date.now();
|
|
378
|
-
|
|
379
|
-
const { __root } = await getRenderPathsHydratedWithDomainFromDB();
|
|
380
|
-
const apiCacheDir = path.join(__root, "apiCache");
|
|
381
|
-
const siteHasFilename = `${apiCacheDir}/siteHash.json`;
|
|
382
|
-
|
|
383
|
-
if (currentHash !== lastHash) {
|
|
384
|
-
allHash[siteId] = currentHash;
|
|
385
|
-
await fsp.writeFile(siteHasFilename, JSON.stringify(allHash), {
|
|
386
|
-
encoding: "utf-8",
|
|
387
|
-
});
|
|
320
|
+
// Después de guardar en el store todos los sites y sus páginas (las que
|
|
321
|
+
// sean que hayan cambiado etc.) guardamos un archivo con la información
|
|
322
|
+
// del render para usos posteriores.
|
|
323
|
+
|
|
324
|
+
// Tenemos dos casos:
|
|
325
|
+
|
|
326
|
+
// ( 1 ) - Render de dominios con sites para publicar o despublicar. Se
|
|
327
|
+
// guarda la infor del render normalmente.
|
|
328
|
+
|
|
329
|
+
// ( 2 ) - Render de un dominio que no tiene sites ni para publicar ni para
|
|
330
|
+
// despublicar, lo que llamamos un dominio "vacío".
|
|
331
|
+
// Entonces se eliminan las páginas "huérfanas" de la carpeta `store`
|
|
332
|
+
// así el proceso de SSG se encontrará efectivamente con un dominio "sin
|
|
333
|
+
// páginas" y "borrará" lo que exista en ese momento en el store para
|
|
334
|
+
// ese dominio y se guarda la información del render con arrays vacíos
|
|
335
|
+
// directamente en `createdPages` y `sitesToPublish`.
|
|
336
|
+
|
|
337
|
+
if (domainHasSites) {
|
|
338
|
+
// ( 1 )
|
|
339
|
+
saveRenderInfoInStore({
|
|
340
|
+
buildProcessData,
|
|
341
|
+
createdPages,
|
|
342
|
+
sitesToPublish,
|
|
343
|
+
});
|
|
344
|
+
} else {
|
|
345
|
+
// ( 2 )
|
|
346
|
+
removeAllSiteDirsFromStore();
|
|
347
|
+
saveRenderInfoInStore({
|
|
348
|
+
buildProcessData,
|
|
349
|
+
createdPages: [],
|
|
350
|
+
sitesToPublish: [],
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
} catch (e) {
|
|
354
|
+
const error = e as { message: string };
|
|
355
|
+
console.error(error.message);
|
|
356
|
+
process.exit(1);
|
|
388
357
|
}
|
|
389
|
-
|
|
390
|
-
return currentHash.toString();
|
|
391
358
|
}
|
|
392
359
|
|
|
393
360
|
export { createStore };
|