@griddo/cx 11.9.8-rc.1 → 11.9.8-rc.2
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 +193 -78
- package/build/adapters/gatsby/index.d.ts +4 -0
- package/build/adapters/gatsby/utils.d.ts +22 -0
- package/build/artifacts/index.d.ts +6 -0
- package/build/commands/end-render.d.ts +2 -0
- package/build/commands/move-assets.d.ts +1 -0
- package/build/commands/prepare-domains-render.d.ts +1 -0
- package/build/commands/reset-render.d.ts +2 -0
- package/build/commands/start-render.d.ts +2 -0
- package/build/commands/upload-search-content.d.ts +2 -0
- package/build/constants/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/{core/errors.d.ts → errors/index.d.ts} +4 -5
- 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/Favicon/utils.d.ts +9 -0
- package/build/react/GriddoIntegrations/index.d.ts +20 -0
- package/build/react/GriddoIntegrations/utils.d.ts +26 -0
- package/build/react/index.d.ts +3 -0
- package/build/react/index.js +3 -0
- package/build/registers/api.d.ts +9 -0
- package/build/registers/gatsby.d.ts +9 -0
- package/build/registers/index.d.ts +3 -0
- package/build/reset-render.js +74 -0
- package/build/reset-render.js.map +7 -0
- package/build/services/auth.d.ts +5 -2
- package/build/services/domains.d.ts +6 -0
- package/build/services/navigation.d.ts +50 -0
- package/build/services/reference-fields.d.ts +20 -0
- package/build/services/register.d.ts +36 -0
- package/build/services/robots.d.ts +19 -0
- package/build/services/settings.d.ts +4 -0
- package/build/services/sites.d.ts +29 -0
- package/build/services/store.d.ts +6 -0
- package/build/start-render.js +100 -0
- package/build/start-render.js.map +7 -0
- package/build/{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/types/templates.d.ts +8 -0
- package/build/upload-search-content.js +74 -0
- package/build/upload-search-content.js.map +7 -0
- package/build/utils/alerts.d.ts +3 -0
- package/build/utils/api.d.ts +23 -0
- package/build/utils/cache.d.ts +35 -0
- package/build/utils/core-utils.d.ts +107 -0
- package/build/utils/create-build-data.d.ts +8 -0
- package/build/utils/domains.d.ts +13 -0
- package/build/utils/folders.d.ts +53 -0
- package/build/utils/health-checks.d.ts +7 -0
- package/build/utils/images.d.ts +16 -0
- package/build/utils/loggin.d.ts +51 -0
- package/build/utils/pages.d.ts +34 -0
- package/build/utils/render.d.ts +13 -0
- package/build/utils/searches.d.ts +15 -0
- package/build/utils/sites.d.ts +31 -0
- package/build/utils/store.d.ts +81 -0
- package/cx.config.d.ts +5 -0
- package/cx.config.js +36 -0
- package/exporter/adapters/gatsby/index.ts +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 +28 -17
- package/exporter/commands/end-render.ts +86 -65
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +35 -143
- package/exporter/commands/reset-render.ts +7 -12
- 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/{react/GriddoFavicon → exporter/react/Favicon}/index.tsx +9 -3
- package/{react → exporter/react}/GriddoIntegrations/index.tsx +23 -17
- package/{react → exporter/react}/GriddoIntegrations/utils.ts +12 -24
- package/exporter/react/index.tsx +11 -0
- package/exporter/registers/api.ts +14 -0
- package/exporter/registers/gatsby.ts +14 -0
- package/exporter/registers/index.ts +4 -0
- package/exporter/services/auth.ts +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 +319 -386
- 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 +80 -20
- package/gatsby-ssr.tsx +1 -2
- package/package.json +92 -41
- package/src/README.md +7 -0
- package/src/components/Head.tsx +73 -30
- package/src/components/template.tsx +30 -8
- package/src/gatsby-node-utils.ts +2 -76
- package/src/html.tsx +11 -2
- package/src/types.ts +5 -5
- package/start-render.js +7 -0
- package/tsconfig.json +3 -5
- package/build/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/start-embeddings.js +0 -31
- package/build/commands/start-embeddings.js.map +0 -7
- 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.d.ts +0 -4
- package/build/core/dist-rollback.d.ts +0 -2
- package/build/core/fs.d.ts +0 -69
- package/build/core/logger.d.ts +0 -18
- package/build/services/manage-store.d.ts +0 -48
- package/build/services/render.d.ts +0 -70
- 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/types/render.d.ts +0 -54
- package/cli.mjs +0 -239
- 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.noop +0 -206
- package/exporter/commands/start-embeddings.ts +0 -29
- package/exporter/core/GriddoLog.ts +0 -45
- package/exporter/core/check-env-health.ts +0 -200
- package/exporter/core/db-class.ts +0 -54
- package/exporter/core/db.ts +0 -33
- package/exporter/core/dist-rollback.ts +0 -40
- package/exporter/core/errors.ts +0 -82
- 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/services/api.ts +0 -306
- package/exporter/services/manage-sites.ts +0 -116
- package/exporter/services/manage-store.ts +0 -235
- 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/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 -16
- 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/sync-render.ts +0 -300
- package/exporter/ssg-adapters/gatsby/shared/types.ts +0 -35
- package/exporter/ssg-adapters/gatsby/shared/utils.ts +0 -33
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- package/react/DynamicScript/index.tsx +0 -33
- package/react/GriddoOpenGraph/index.tsx +0 -39
- package/tsconfig.commands.json +0 -36
- package/tsconfig.exporter.json +0 -20
- /package/build/{shared → constants}/endpoints.d.ts +0 -0
- /package/build/{core → utils}/instance.d.ts +0 -0
- /package/{react/GriddoFavicon → exporter/react/Favicon}/utils.ts +0 -0
- /package/exporter/{shared/types → types}/templates.ts +0 -0
|
@@ -1,191 +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 {
|
|
29
|
-
getZombiePagesInStore,
|
|
30
|
-
removeOrphanSites,
|
|
31
|
-
removeSitePagesFromStore,
|
|
32
|
-
saveRenderInfoInStore,
|
|
33
|
-
saveSitePagesInStore,
|
|
34
|
-
} from "./manage-store";
|
|
15
|
+
import { envs } from "../constants";
|
|
35
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";
|
|
36
23
|
import {
|
|
37
24
|
createGriddoListPages,
|
|
38
25
|
createGriddoMultiPages,
|
|
39
26
|
createGriddoSinglePage,
|
|
40
27
|
getMultiPageElements,
|
|
41
28
|
getPaginatedPages,
|
|
42
|
-
} from "
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function listSitesLog(title: string, sites: Site[]) {
|
|
54
|
-
const maxline = Math.max(
|
|
55
|
-
...sites.map((s) => s.name.length + (s.shouldBeUpdated ? 1 : 0) + s.id.toString().length),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const sitesStr = sites.map((s) => {
|
|
59
|
-
const shouldBeUpdated = s.shouldBeUpdated ? "*" : "";
|
|
60
|
-
const lineLen = s.name.length + shouldBeUpdated.length + s.id.toString().length;
|
|
61
|
-
const padding = " ".repeat(maxline - lineLen);
|
|
62
|
-
return `${brush.bold(s.name)} ${brush.dim(`(${s.id})`)} ${shouldBeUpdated} ${padding}${brush.dim("-")} ${brush.dim(s.slug)}`;
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const sitesOutput = sitesStr.length > 0 ? `\n\n${sitesStr.join("\n")}` : brush.dim("--none--\n");
|
|
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";
|
|
66
39
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
40
|
+
const renderId = new Date().valueOf().toString();
|
|
41
|
+
const { griddoVersion, paths } = getConfig();
|
|
42
|
+
const { __cx } = paths();
|
|
43
|
+
const storeDir = path.join(__cx, "store");
|
|
70
44
|
|
|
71
45
|
/**
|
|
72
46
|
* Fetch, process and save object pages and sites data into the file system to
|
|
73
47
|
* be consumed by other services (Griddo itself, Adapters, etc.)
|
|
74
48
|
*/
|
|
75
|
-
async function createStore(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
griddoVersion: string;
|
|
79
|
-
basePath: string;
|
|
80
|
-
}) {
|
|
81
|
-
console.info(`API calls with ${GRIDDO_API_CONCURRENCY_COUNT} threads`);
|
|
82
|
-
console.info(`API URL ${GRIDDO_API_URL as string}`);
|
|
83
|
-
|
|
84
|
-
const { renderMode, domain, griddoVersion, basePath } = options;
|
|
85
|
-
const renderFromScratch = renderMode === RENDER_MODE.FROM_SCRATCH;
|
|
86
|
-
const storeDir = path.join(basePath, "store");
|
|
87
|
-
|
|
88
|
-
// Vars to save later in the report file
|
|
89
|
-
const createdPages: number[] = [];
|
|
90
|
-
const buildProcessData: BuildProcessData = {};
|
|
91
|
-
|
|
92
|
-
// Get sites objects to publish and unpublish from this domain
|
|
93
|
-
const { sitesToPublish, sitesToUnpublish } = await getSitesToRender(domain);
|
|
94
|
-
|
|
95
|
-
listSitesLog("Sites to publish:", sitesToPublish);
|
|
96
|
-
listSitesLog("Sites to unpublish:", sitesToUnpublish);
|
|
97
|
-
|
|
98
|
-
// Send unpublished sites to API.
|
|
99
|
-
await unpublishSites(sitesToUnpublish);
|
|
100
|
-
|
|
101
|
-
// Eliminamos posibles sites que estén en el store pero que no deberían
|
|
102
|
-
// porque han sido cambiados de dominio. Si han sido despublicados ya se
|
|
103
|
-
// despublican bien porque entran en `sitesToUnpublish`
|
|
104
|
-
await removeOrphanSites(sitesToPublish, domain);
|
|
105
|
-
|
|
106
|
-
const allPagesToRemoveFromBuild: number[] = [];
|
|
107
|
-
// let numberOfFinalActivePages: number[] = [];
|
|
108
|
-
|
|
109
|
-
for (const site of sitesToUnpublish) {
|
|
110
|
-
const { pagesStatus } = site;
|
|
111
|
-
|
|
112
|
-
// Añadimos a allPagesToRemoveFromBuild todas las páginas de un site
|
|
113
|
-
// para despublicar.
|
|
114
|
-
allPagesToRemoveFromBuild.push(
|
|
115
|
-
...pagesStatus.active,
|
|
116
|
-
...pagesStatus.offlinePending,
|
|
117
|
-
...pagesStatus.uploadPending,
|
|
118
|
-
...pagesStatus.deleted,
|
|
119
|
-
...pagesStatus.offline,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
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}`);
|
|
122
52
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const siteMetadata = {
|
|
172
|
-
siteUrl: siteInfo.slug,
|
|
173
|
-
title: siteInfo.name,
|
|
174
|
-
favicon,
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const additionalInfo = {
|
|
178
|
-
baseUrl: GRIDDO_API_URL,
|
|
179
|
-
publicBaseUrl: GRIDDO_PUBLIC_API_URL,
|
|
180
|
-
instance: GRIDDO_REACT_APP_INSTANCE,
|
|
181
|
-
siteSlug,
|
|
182
|
-
theme,
|
|
183
|
-
siteMetadata,
|
|
184
|
-
socials,
|
|
185
|
-
siteLangs,
|
|
186
|
-
cloudinaryName,
|
|
187
|
-
griddoVersion,
|
|
188
|
-
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,
|
|
189
100
|
useMetaTitle,
|
|
190
101
|
useMetaKeywords,
|
|
191
102
|
showBasicMetaRobots,
|
|
@@ -193,235 +104,257 @@ async function createStore(options: {
|
|
|
193
104
|
avoidSelfReferenceCanonicals,
|
|
194
105
|
avoidHrefLangXDefault,
|
|
195
106
|
avoidDebugMetas,
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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,
|
|
244
159
|
});
|
|
245
160
|
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
// in
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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);
|
|
337
303
|
|
|
338
|
-
// Create pages to the store. First requesting from API,
|
|
339
|
-
// transform, etc., and then writing them to disk.
|
|
340
|
-
const limit = pLimit(GRIDDO_API_CONCURRENCY_COUNT);
|
|
341
|
-
const pagesToStore = pagesToFetchFromAPI.map((id: number) =>
|
|
342
|
-
limit(() => fetchSitePageAndSaveInStore(siteDirName, id)),
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
await Promise.all(pagesToStore);
|
|
346
|
-
|
|
347
|
-
// @ts-expect-error Mutate pagesStatus for reading pourposes.
|
|
348
|
-
pagesStatus.zombie = await getZombiePagesInStore(siteDirName, [
|
|
349
|
-
...pagesStatus.active,
|
|
350
|
-
...pagesStatus.uploadPending,
|
|
351
|
-
]);
|
|
352
|
-
|
|
353
|
-
// Delete pages from the store removing them from disk.
|
|
354
|
-
await removeSitePagesFromStore(siteDirName, [
|
|
355
|
-
pagesStatus.deleted,
|
|
356
|
-
pagesStatus.offline,
|
|
357
|
-
pagesStatus.offlinePending,
|
|
358
304
|
// @ts-expect-error Mutate pagesStatus for reading pourposes.
|
|
359
|
-
pagesStatus.zombie,
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
createdPages,
|
|
374
|
-
sitesToPublish,
|
|
375
|
-
},
|
|
376
|
-
domain,
|
|
377
|
-
);
|
|
378
|
-
|
|
379
|
-
return {
|
|
380
|
-
pagesToCreate: createdPages,
|
|
381
|
-
pagesToDelete: allPagesToRemoveFromBuild,
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Get site hashes from the file as an object
|
|
387
|
-
*/
|
|
388
|
-
async function getHashSites(): Promise<HashSites> {
|
|
389
|
-
const { __root } = await getRenderPathsHydratedWithDomainFromDB();
|
|
390
|
-
const apiCacheDir = path.join(__root, "apiCache");
|
|
391
|
-
const siteHasFilename = `${apiCacheDir}/siteHash.json`;
|
|
392
|
-
|
|
393
|
-
try {
|
|
394
|
-
const fileContent = await fsp.readFile(siteHasFilename, "utf8");
|
|
395
|
-
const jsonData = JSON.parse(fileContent);
|
|
396
|
-
return jsonData || {};
|
|
397
|
-
} catch {
|
|
398
|
-
return {};
|
|
399
|
-
}
|
|
400
|
-
}
|
|
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
|
+
]);
|
|
318
|
+
}
|
|
401
319
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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);
|
|
422
357
|
}
|
|
423
|
-
|
|
424
|
-
return currentHash.toString();
|
|
425
358
|
}
|
|
426
359
|
|
|
427
360
|
export { createStore };
|