@griddo/cx 11.9.17 → 11.10.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 +13 -240
- package/build/commands/end-render.d.ts +0 -1
- package/build/commands/end-render.js +31 -0
- package/build/commands/end-render.js.map +7 -0
- package/build/commands/prepare-assets-directory.js +9 -0
- package/build/commands/prepare-assets-directory.js.map +7 -0
- package/build/commands/prepare-domains-render.js +40 -0
- package/build/commands/prepare-domains-render.js.map +7 -0
- package/build/commands/reset-render.d.ts +0 -1
- package/build/commands/reset-render.js +31 -0
- package/build/commands/reset-render.js.map +7 -0
- package/build/commands/single-domain-upload-search-content.d.ts +1 -0
- package/build/commands/start-render.d.ts +0 -1
- package/build/commands/start-render.js +66 -0
- package/build/commands/start-render.js.map +7 -0
- package/build/commands/upload-search-content.d.ts +0 -1
- package/build/commands/upload-search-content.js +32 -0
- package/build/commands/upload-search-content.js.map +7 -0
- package/build/core/GriddoLog.d.ts +16 -0
- package/build/{utils/health-checks.d.ts → core/check-env-health.d.ts} +4 -2
- package/build/core/db-class.d.ts +11 -0
- package/build/core/db.d.ts +4 -0
- package/build/core/dist-rollback.d.ts +11 -0
- package/build/core/errors.d.ts +26 -0
- package/build/core/fs.d.ts +69 -0
- package/build/core/life-cycle.d.ts +26 -0
- package/build/core/logger.d.ts +18 -0
- package/build/core/objects.d.ts +11 -0
- package/build/core/print-logos.d.ts +5 -0
- package/build/index.d.ts +10 -29
- package/build/index.js +404 -73
- package/build/react/DynamicScript/index.d.ts +4 -0
- package/build/react/GriddoFavicon/index.d.ts +4 -0
- package/build/react/GriddoIntegrations/index.d.ts +3 -4
- package/build/react/GriddoIntegrations/utils.d.ts +7 -6
- package/build/react/GriddoOpenGraph/index.d.ts +10 -0
- package/build/react/index.d.ts +3 -2
- package/build/react/index.js +1 -3
- package/build/{utils → services}/api.d.ts +1 -1
- package/build/services/auth.d.ts +2 -5
- package/build/services/domains.d.ts +3 -4
- package/build/services/manage-sites.d.ts +22 -0
- package/build/services/manage-store.d.ts +32 -0
- package/build/services/navigation.d.ts +16 -16
- package/build/{utils → services}/pages.d.ts +3 -3
- package/build/services/reference-fields.d.ts +3 -3
- package/build/services/render-artifacts.d.ts +6 -0
- package/build/services/render.d.ts +70 -0
- package/build/services/robots.d.ts +2 -19
- package/build/services/sitemaps.d.ts +5 -0
- package/build/services/sites.d.ts +8 -5
- package/build/services/store.d.ts +10 -1
- package/build/shared/context.d.ts +36 -0
- package/build/shared/envs.d.ts +17 -0
- package/build/{errors/errors-data.d.ts → shared/errors.d.ts} +5 -3
- package/build/shared/npm-modules/brush.d.ts +18 -0
- package/build/shared/npm-modules/find-up-simple.d.ts +34 -0
- package/build/shared/npm-modules/pkg-dir.d.ts +7 -0
- package/build/shared/npm-modules/xml-parser.d.ts +4 -0
- package/build/{types → shared/types}/api.d.ts +18 -18
- package/build/{types → shared/types}/global.d.ts +15 -16
- package/build/{types → shared/types}/navigation.d.ts +5 -5
- package/build/{types → shared/types}/pages.d.ts +9 -9
- package/build/shared/types/render.d.ts +56 -0
- package/build/{types → shared/types}/sites.d.ts +18 -19
- package/build/shared/types.d.ts +15 -0
- package/build/ssg-adapters/gatsby/actions/clean.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/close.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/data.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/init.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/logs.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/meta.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/prepare.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/relocation.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/restore.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/ssg.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/sync.d.ts +3 -0
- package/build/ssg-adapters/gatsby/index.d.ts +9 -0
- package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +4 -0
- package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +15 -0
- package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +7 -0
- package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +7 -0
- package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +18 -0
- package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +26 -0
- package/build/ssg-adapters/gatsby/shared/types.d.ts +34 -0
- package/cli.mjs +231 -0
- package/exporter/build-esbuild.noop +42 -0
- package/exporter/build.sh +16 -24
- package/exporter/commands/README.md +142 -0
- package/exporter/commands/end-render.ts +53 -87
- package/exporter/commands/prepare-assets-directory.ts +35 -0
- package/exporter/commands/prepare-domains-render.ts +150 -33
- package/exporter/commands/reset-render.ts +13 -8
- package/exporter/commands/single-domain-upload-search-content.ts +206 -0
- package/exporter/commands/start-render.ts +14 -65
- package/exporter/commands/upload-search-content.ts +204 -26
- package/exporter/core/GriddoLog.ts +45 -0
- package/exporter/core/check-env-health.ts +203 -0
- package/exporter/core/db-class.ts +54 -0
- package/exporter/core/db.ts +33 -0
- package/exporter/core/dist-rollback.ts +49 -0
- package/exporter/core/errors.ts +93 -0
- package/exporter/core/fs.ts +385 -0
- package/exporter/{utils → core}/images.ts +1 -6
- package/exporter/{utils → core}/instance.ts +9 -13
- package/exporter/core/life-cycle.ts +73 -0
- package/exporter/core/logger.ts +137 -0
- package/exporter/core/objects.ts +37 -0
- package/exporter/core/print-logos.ts +21 -0
- package/exporter/index.ts +14 -56
- package/exporter/react/DynamicScript/index.tsx +33 -0
- package/exporter/react/{Favicon → GriddoFavicon}/index.tsx +3 -9
- package/exporter/react/GriddoIntegrations/index.tsx +17 -23
- package/exporter/react/GriddoIntegrations/utils.ts +24 -12
- package/exporter/react/GriddoOpenGraph/index.tsx +39 -0
- package/exporter/react/index.tsx +3 -9
- package/exporter/services/api.ts +306 -0
- package/exporter/services/auth.ts +8 -10
- package/exporter/services/domains.ts +23 -8
- package/exporter/services/manage-sites.ts +116 -0
- package/exporter/services/manage-store.ts +173 -0
- package/exporter/services/navigation.ts +12 -18
- package/exporter/{utils → services}/pages.ts +27 -92
- package/exporter/services/reference-fields.ts +14 -32
- package/exporter/services/render-artifacts.ts +44 -0
- package/exporter/services/render.ts +229 -0
- package/exporter/services/robots.ts +33 -61
- package/exporter/services/sitemaps.ts +129 -0
- package/exporter/services/sites.ts +40 -28
- package/exporter/services/store.ts +354 -321
- package/exporter/shared/context.ts +49 -0
- package/exporter/{constants → shared}/endpoints.ts +12 -11
- package/exporter/shared/envs.ts +58 -0
- package/exporter/{errors/errors-data.ts → shared/errors.ts} +24 -14
- package/exporter/shared/npm-modules/README.md +36 -0
- package/exporter/shared/npm-modules/brush.ts +34 -0
- package/exporter/shared/npm-modules/find-up-simple.ts +100 -0
- package/exporter/shared/npm-modules/pkg-dir.ts +17 -0
- package/exporter/shared/npm-modules/xml-parser.ts +57 -0
- package/exporter/{types → shared/types}/api.ts +40 -41
- package/exporter/{types → shared/types}/global.ts +17 -21
- package/exporter/{types → shared/types}/navigation.ts +3 -3
- package/exporter/{types → shared/types}/pages.ts +10 -11
- package/exporter/shared/types/render.ts +65 -0
- package/exporter/{types → shared/types}/sites.ts +18 -19
- package/exporter/shared/types.ts +15 -0
- package/exporter/ssg-adapters/gatsby/actions/clean.ts +26 -0
- package/exporter/ssg-adapters/gatsby/actions/close.ts +17 -0
- package/exporter/ssg-adapters/gatsby/actions/data.ts +22 -0
- package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +10 -0
- package/exporter/ssg-adapters/gatsby/actions/init.ts +12 -0
- package/exporter/ssg-adapters/gatsby/actions/logs.ts +10 -0
- package/exporter/ssg-adapters/gatsby/actions/meta.ts +13 -0
- package/exporter/ssg-adapters/gatsby/actions/prepare.ts +9 -0
- package/exporter/ssg-adapters/gatsby/actions/relocation.ts +15 -0
- package/exporter/ssg-adapters/gatsby/actions/restore.ts +21 -0
- package/exporter/ssg-adapters/gatsby/actions/ssg.ts +12 -0
- package/exporter/ssg-adapters/gatsby/actions/sync.ts +65 -0
- package/exporter/ssg-adapters/gatsby/index.ts +117 -0
- package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +17 -0
- package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +128 -0
- package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +75 -0
- package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +58 -0
- package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +33 -0
- package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +298 -0
- package/exporter/ssg-adapters/gatsby/shared/types.ts +35 -0
- package/gatsby-browser.tsx +41 -58
- package/gatsby-config.ts +10 -17
- package/gatsby-node.ts +20 -79
- package/gatsby-ssr.tsx +2 -1
- package/package.json +41 -78
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
- package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
- package/src/components/Head.tsx +28 -73
- package/src/components/template.tsx +6 -29
- package/src/gatsby-node-utils.ts +81 -2
- package/src/html.tsx +2 -11
- package/src/types.ts +3 -3
- package/tsconfig.commands.json +36 -0
- package/tsconfig.exporter.json +21 -0
- package/tsconfig.json +5 -3
- package/build/adapters/gatsby/index.d.ts +0 -4
- package/build/adapters/gatsby/utils.d.ts +0 -26
- package/build/artifacts/index.d.ts +0 -6
- 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/index.d.ts +0 -15
- 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/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/register.d.ts +0 -36
- package/build/services/settings.d.ts +0 -4
- package/build/start-render.js +0 -100
- package/build/start-render.js.map +0 -7
- 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/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/loggin.d.ts +0 -51
- 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/index.ts +0 -182
- package/exporter/adapters/gatsby/utils.ts +0 -186
- 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/envs.ts +0 -94
- package/exporter/constants/index.ts +0 -129
- package/exporter/errors/index.ts +0 -40
- package/exporter/registers/api.ts +0 -14
- package/exporter/registers/gatsby.ts +0 -14
- package/exporter/registers/index.ts +0 -4
- package/exporter/services/register.ts +0 -113
- package/exporter/services/settings.ts +0 -17
- package/exporter/utils/alerts.ts +0 -29
- package/exporter/utils/api.ts +0 -243
- package/exporter/utils/cache.ts +0 -142
- package/exporter/utils/core-utils.ts +0 -458
- package/exporter/utils/create-build-data.ts +0 -17
- package/exporter/utils/domains.ts +0 -39
- package/exporter/utils/folders.ts +0 -320
- package/exporter/utils/health-checks.ts +0 -64
- package/exporter/utils/loggin.ts +0 -184
- package/exporter/utils/render.ts +0 -71
- package/exporter/utils/searches.ts +0 -156
- package/exporter/utils/sites.ts +0 -312
- package/exporter/utils/store.ts +0 -314
- package/src/README.md +0 -7
- package/start-render.js +0 -7
- /package/build/commands/{move-assets.d.ts → prepare-assets-directory.d.ts} +0 -0
- /package/build/{utils → core}/images.d.ts +0 -0
- /package/build/{utils → core}/instance.d.ts +0 -0
- /package/build/react/{Favicon → GriddoFavicon}/utils.d.ts +0 -0
- /package/build/{constants → shared}/endpoints.d.ts +0 -0
- /package/build/{types → shared/types}/templates.d.ts +0 -0
- /package/exporter/react/{Favicon → GriddoFavicon}/utils.ts +0 -0
- /package/exporter/{types → shared/types}/templates.ts +0 -0
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import type { PostSearchInfoResponse } from "../types/api";
|
|
2
|
-
import type {
|
|
3
|
-
AIEmbeddingsResponse,
|
|
4
|
-
PostSearchInfoProps,
|
|
5
|
-
} from "../types/global";
|
|
6
|
-
|
|
7
|
-
import fs from "node:fs";
|
|
8
|
-
import path from "node:path";
|
|
9
|
-
|
|
10
|
-
import { post } from "./api";
|
|
11
|
-
import { getConfig } from "./core-utils";
|
|
12
|
-
import { getBuildPagesFromCachedStore } from "./store";
|
|
13
|
-
import { endpoints } from "../constants";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Save in the BBDD the content of a page parsed without HTML tags.
|
|
17
|
-
*
|
|
18
|
-
* @param props Object with parts of the final page object to be saved in the BBDD.
|
|
19
|
-
*/
|
|
20
|
-
async function postSearchInfo(props: PostSearchInfoProps) {
|
|
21
|
-
const {
|
|
22
|
-
title,
|
|
23
|
-
description,
|
|
24
|
-
image,
|
|
25
|
-
pageId,
|
|
26
|
-
languageId,
|
|
27
|
-
siteId,
|
|
28
|
-
url,
|
|
29
|
-
content,
|
|
30
|
-
template,
|
|
31
|
-
} = props;
|
|
32
|
-
|
|
33
|
-
const response = await post<PostSearchInfoResponse>({
|
|
34
|
-
endpoint: endpoints.SEARCH,
|
|
35
|
-
body: {
|
|
36
|
-
title,
|
|
37
|
-
description,
|
|
38
|
-
image,
|
|
39
|
-
pageId,
|
|
40
|
-
languageId,
|
|
41
|
-
siteId,
|
|
42
|
-
url,
|
|
43
|
-
template,
|
|
44
|
-
content,
|
|
45
|
-
},
|
|
46
|
-
useApiCacheDir: false,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return response;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Remove the every cntent inside some HTML tags including them.
|
|
54
|
-
*
|
|
55
|
-
* @param content A string with the content.
|
|
56
|
-
*/
|
|
57
|
-
function prepareHTMLContentForSearch(content: string): string {
|
|
58
|
-
// 1. Remove script, style, and other unwanted block tags and their content.
|
|
59
|
-
// The regex looks for <tag...>...</tag> where tag is one of the specified ones.
|
|
60
|
-
const tagsToRemove = [
|
|
61
|
-
"meta",
|
|
62
|
-
"link",
|
|
63
|
-
"style",
|
|
64
|
-
"script",
|
|
65
|
-
"noscript",
|
|
66
|
-
"nav",
|
|
67
|
-
"header",
|
|
68
|
-
"footer",
|
|
69
|
-
];
|
|
70
|
-
const removeTagsRegex = new RegExp(
|
|
71
|
-
`<(${tagsToRemove.join("|")})\\b[^>]*>.*?<\\/\\1>`,
|
|
72
|
-
"gis",
|
|
73
|
-
);
|
|
74
|
-
let processedContent = content.replace(removeTagsRegex, "");
|
|
75
|
-
|
|
76
|
-
// 2. Strip all remaining HTML tags.
|
|
77
|
-
processedContent = processedContent.replace(/<[^>]+>/g, " ");
|
|
78
|
-
|
|
79
|
-
// 3. Normalize whitespace: replace multiple spaces/newlines with a single space and trim.
|
|
80
|
-
processedContent = processedContent.replace(/\s+/g, " ").trim();
|
|
81
|
-
|
|
82
|
-
return processedContent;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Function that search in the `/public` dir the content info of the pages and
|
|
87
|
-
* send it to the search table in the ddbb using the API.
|
|
88
|
-
*/
|
|
89
|
-
async function uploadRenderedSearchContentToAPI(
|
|
90
|
-
distDomainPath: string,
|
|
91
|
-
domain: string,
|
|
92
|
-
) {
|
|
93
|
-
const config = getConfig();
|
|
94
|
-
const { __cache } = config.paths(domain);
|
|
95
|
-
|
|
96
|
-
// Extraemos el path de la carpeta store dentro de un dominio
|
|
97
|
-
const storeFolder = path.join(__cache, "store");
|
|
98
|
-
|
|
99
|
-
// Este caso sería que el dominio existe en la instancia pero no hay sites
|
|
100
|
-
// renderizardos bajo el mismo. Por lo que `store` no existe.
|
|
101
|
-
if (!fs.existsSync(storeFolder)) {
|
|
102
|
-
console.log(
|
|
103
|
-
`Skipping uploading content to the search endpoint for the domain ${domain}, it has not exported sites.`,
|
|
104
|
-
);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Obtenemos las páginas del store cacheado de un dominio
|
|
109
|
-
const storePages = getBuildPagesFromCachedStore(domain);
|
|
110
|
-
|
|
111
|
-
for await (const store of storePages) {
|
|
112
|
-
const {
|
|
113
|
-
context: { page, openGraph, pageMetadata },
|
|
114
|
-
} = store;
|
|
115
|
-
|
|
116
|
-
const { compose } = page.fullPath;
|
|
117
|
-
|
|
118
|
-
const contextPath = path.resolve(`${distDomainPath}/${compose}/index.html`);
|
|
119
|
-
|
|
120
|
-
const content = fs.readFileSync(contextPath).toString();
|
|
121
|
-
|
|
122
|
-
const pageObject: PostSearchInfoProps = {
|
|
123
|
-
siteId: page.site,
|
|
124
|
-
pageId: page.id,
|
|
125
|
-
// `pageMetadata.title` has already a fallback `metatitle ||
|
|
126
|
-
// pageTitle` so probably `title` never will be take the
|
|
127
|
-
// `openGraph?.title` value. Only when the `metatitle` and
|
|
128
|
-
// `pageTitle` are empty.
|
|
129
|
-
title: pageMetadata?.title || openGraph?.title,
|
|
130
|
-
languageId: page.language,
|
|
131
|
-
url: page.fullUrl,
|
|
132
|
-
template: page.template.templateType || page.templateId,
|
|
133
|
-
description: pageMetadata?.description || openGraph?.description,
|
|
134
|
-
image: openGraph.image,
|
|
135
|
-
content: prepareHTMLContentForSearch(content),
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
await postSearchInfo(pageObject);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async function startAIEmbeddings() {
|
|
143
|
-
try {
|
|
144
|
-
await post<AIEmbeddingsResponse>({
|
|
145
|
-
endpoint: endpoints.AI_EMBEDDINGS,
|
|
146
|
-
useApiCacheDir: false,
|
|
147
|
-
});
|
|
148
|
-
} catch (error) {
|
|
149
|
-
console.warn(
|
|
150
|
-
"There was an error with the ai embeddings",
|
|
151
|
-
(error as Error).message,
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export { postSearchInfo, startAIEmbeddings, uploadRenderedSearchContentToAPI };
|
package/exporter/utils/sites.ts
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import type { Site, SiteData } from "../types/sites";
|
|
2
|
-
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
import fs from "fs-extra";
|
|
6
|
-
import { parse } from "js2xmlparser";
|
|
7
|
-
|
|
8
|
-
import { envs } from "../constants";
|
|
9
|
-
import { getConfig } from "./core-utils";
|
|
10
|
-
import { buildLog, verboseLog } from "./loggin";
|
|
11
|
-
import { getBuildMetadata } from "./store";
|
|
12
|
-
import { AuthService } from "../services/auth";
|
|
13
|
-
import {
|
|
14
|
-
endSiteRender,
|
|
15
|
-
getAllSites,
|
|
16
|
-
getSiteInfo,
|
|
17
|
-
getSiteLanguages,
|
|
18
|
-
getSitemap,
|
|
19
|
-
getSiteSocials,
|
|
20
|
-
startSiteRender,
|
|
21
|
-
} from "../services/sites";
|
|
22
|
-
|
|
23
|
-
const config = getConfig();
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Check the instance sites and returns site prepared to be published and unpublished.
|
|
27
|
-
*/
|
|
28
|
-
async function getSitesToRender(domain: string) {
|
|
29
|
-
console.info(`API URL ${envs.GRIDDO_API_URL as string}`);
|
|
30
|
-
|
|
31
|
-
// Login to API
|
|
32
|
-
await AuthService.login();
|
|
33
|
-
|
|
34
|
-
// Get all sites. An array of Site
|
|
35
|
-
const allSites = await getAllSites(domain);
|
|
36
|
-
|
|
37
|
-
// Filter the array of sites to get only the ones to build/render
|
|
38
|
-
const validSites = envs.GRIDDO_RENDER_ALL_SITES
|
|
39
|
-
? allSites.filter(
|
|
40
|
-
(site) =>
|
|
41
|
-
!envs.GRIDDO_RENDER_SITE || site.id === envs.GRIDDO_RENDER_SITE,
|
|
42
|
-
)
|
|
43
|
-
: allSites.filter((site) =>
|
|
44
|
-
envs.GRIDDO_RENDER_SITE
|
|
45
|
-
? site.id === envs.GRIDDO_RENDER_SITE
|
|
46
|
-
: !!site.shouldBeUpdated,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
// If there are valid sites...
|
|
50
|
-
// En este paso se añade al objeto `Site` la información de los dominios
|
|
51
|
-
// utilizando los idiomas.
|
|
52
|
-
if (validSites.length) {
|
|
53
|
-
for (const site of validSites) {
|
|
54
|
-
const { items } = await getSiteLanguages(site.id);
|
|
55
|
-
|
|
56
|
-
// Añadimos la prop domains con el dominio "cocinado" con los
|
|
57
|
-
// idiomas y teniendo en cuenta solo el dominio actual.
|
|
58
|
-
site.domains = items
|
|
59
|
-
.filter(
|
|
60
|
-
(item) =>
|
|
61
|
-
item.domain &&
|
|
62
|
-
(item.domain.slug === domain || item.domain.slug === `/${domain}`),
|
|
63
|
-
)
|
|
64
|
-
.map((item) => ({ [item.id]: `${item.domain.slug}${item.path}` }));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Save sites object to publish
|
|
69
|
-
const sitesToPublish = validSites.filter((site) =>
|
|
70
|
-
envs.GRIDDO_RENDER_SITE
|
|
71
|
-
? site.id === envs.GRIDDO_RENDER_SITE
|
|
72
|
-
: !!site.isPublished,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// Save sites object to unpublish
|
|
76
|
-
const sitesToUnpublish = validSites.filter(
|
|
77
|
-
(site) => !site.isPublished && site.shouldBeUpdated,
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
sitesToPublish,
|
|
82
|
-
sitesToUnpublish,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Unpublish an array of sites sending the information to the API.
|
|
88
|
-
*
|
|
89
|
-
* @param sites An array of sites
|
|
90
|
-
* @see https://griddoio.notion.site/Sites-d7bb0b7cb8d24894a5337e1139fc3d09#2019d3255bda4d219c7e19cf28d0c4fe
|
|
91
|
-
*/
|
|
92
|
-
async function unpublishSites(sites: Array<Site>) {
|
|
93
|
-
const { __cx } = config.paths();
|
|
94
|
-
|
|
95
|
-
for (const site of sites) {
|
|
96
|
-
// API
|
|
97
|
-
const buildInfo = await startSiteRender(site.id);
|
|
98
|
-
const { siteHash } = buildInfo;
|
|
99
|
-
const body = {
|
|
100
|
-
siteHash,
|
|
101
|
-
publishHashes: [],
|
|
102
|
-
unpublishHashes: [],
|
|
103
|
-
publishPagesIds: [],
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
await endSiteRender(site.id, body);
|
|
107
|
-
|
|
108
|
-
// STORE
|
|
109
|
-
// Remove site directory from the Store
|
|
110
|
-
fs.rmSync(path.join(__cx, "store", site.id.toString()), {
|
|
111
|
-
force: true,
|
|
112
|
-
recursive: true,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Return a single site generic data.
|
|
119
|
-
*
|
|
120
|
-
* @param siteID The site id.
|
|
121
|
-
* @see SiteData
|
|
122
|
-
*/
|
|
123
|
-
async function getSiteData(siteID: number) {
|
|
124
|
-
const buildData = await startSiteRender(siteID);
|
|
125
|
-
const siteInfo = await getSiteInfo(siteID);
|
|
126
|
-
const siteLangs = await getSiteLanguages(siteID);
|
|
127
|
-
const socials = await getSiteSocials(siteID);
|
|
128
|
-
const siteLangsInfo = siteLangs.items;
|
|
129
|
-
const defaultLang = siteLangsInfo.find((lang) => lang.isDefault);
|
|
130
|
-
|
|
131
|
-
const { siteHash, unpublishHashes, publishIds } = buildData;
|
|
132
|
-
const { headers, footers } = siteInfo;
|
|
133
|
-
const validPagesIds = envs.GRIDDO_RENDER_PAGES.length
|
|
134
|
-
? envs.GRIDDO_RENDER_PAGES.filter((item) => publishIds.includes(item))
|
|
135
|
-
: publishIds;
|
|
136
|
-
|
|
137
|
-
const siteData: SiteData = {
|
|
138
|
-
siteInfo,
|
|
139
|
-
validPagesIds,
|
|
140
|
-
siteHash,
|
|
141
|
-
unpublishHashes,
|
|
142
|
-
siteLangs: siteLangsInfo,
|
|
143
|
-
defaultLang,
|
|
144
|
-
headers,
|
|
145
|
-
footers,
|
|
146
|
-
socials,
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
return siteData;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Save a file with the end of build process to use as `build-end` signal.
|
|
154
|
-
*/
|
|
155
|
-
async function generateBuildReport() {
|
|
156
|
-
const { __cx } = config.paths();
|
|
157
|
-
const { buildReportFileName } = config;
|
|
158
|
-
|
|
159
|
-
const { buildProcessData } = await getBuildMetadata();
|
|
160
|
-
|
|
161
|
-
// Get the token
|
|
162
|
-
const authControl = await AuthService.login();
|
|
163
|
-
|
|
164
|
-
const buildSitesInfo = Object.keys(buildProcessData).map((siteID) => ({
|
|
165
|
-
...buildProcessData[siteID],
|
|
166
|
-
siteId: Number.parseInt(siteID),
|
|
167
|
-
}));
|
|
168
|
-
|
|
169
|
-
const report = {
|
|
170
|
-
authControl,
|
|
171
|
-
sites: buildSitesInfo,
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const reportFilePath = path.join(__cx, "dist", buildReportFileName);
|
|
175
|
-
fs.writeFileSync(reportFilePath, JSON.stringify(report));
|
|
176
|
-
|
|
177
|
-
verboseLog(`build report saved in ${reportFilePath}`);
|
|
178
|
-
|
|
179
|
-
buildLog(`Build report saved for ${buildSitesInfo.length} site(s)`);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Generate sitemaps and save them into file system.
|
|
184
|
-
*/
|
|
185
|
-
async function generateSitemaps() {
|
|
186
|
-
const { sitesToPublish } = await getBuildMetadata();
|
|
187
|
-
const { __cx } = config.paths();
|
|
188
|
-
const distDir = path.join(__cx, "dist");
|
|
189
|
-
|
|
190
|
-
const templateSitemapPrefix = "sitemap-";
|
|
191
|
-
|
|
192
|
-
const isGriddoSitemapFile = (file: string) =>
|
|
193
|
-
file === "sitemap.xml" ||
|
|
194
|
-
(file.startsWith(templateSitemapPrefix) && file.endsWith(".xml"));
|
|
195
|
-
|
|
196
|
-
for (const site of sitesToPublish) {
|
|
197
|
-
const { id, languages } = site;
|
|
198
|
-
|
|
199
|
-
for (const lang of languages) {
|
|
200
|
-
if (AuthService.headers) {
|
|
201
|
-
AuthService.headers.lang = lang.id.toString();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const response = await getSitemap(id);
|
|
205
|
-
|
|
206
|
-
if (!response) continue;
|
|
207
|
-
|
|
208
|
-
const {
|
|
209
|
-
items: sitemapPagesGroup,
|
|
210
|
-
url: { home, domain },
|
|
211
|
-
} = response;
|
|
212
|
-
|
|
213
|
-
if (!home) continue;
|
|
214
|
-
|
|
215
|
-
const domainLanguage = site.domains.find(
|
|
216
|
-
(domain) => Object.keys(domain)[0] === lang.id.toString(),
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
if (!domainLanguage) continue;
|
|
220
|
-
|
|
221
|
-
const slug = Object.values(domainLanguage)[0];
|
|
222
|
-
const sitemaps: Array<string> = [];
|
|
223
|
-
const sitemapPageGroupKeys = Object.keys(sitemapPagesGroup);
|
|
224
|
-
const sitemapBasePath = path.join(distDir, slug.replace(domain, ""));
|
|
225
|
-
|
|
226
|
-
/** delete every griddo sitemap file before create the new ones */
|
|
227
|
-
if (fs.existsSync(sitemapBasePath)) {
|
|
228
|
-
try {
|
|
229
|
-
const files = fs.readdirSync(sitemapBasePath);
|
|
230
|
-
for (const file of files) {
|
|
231
|
-
if (isGriddoSitemapFile(file)) {
|
|
232
|
-
const filePath = path.join(sitemapBasePath, file);
|
|
233
|
-
try {
|
|
234
|
-
fs.unlinkSync(filePath);
|
|
235
|
-
} catch (err) {
|
|
236
|
-
console.error(`Error removing ${filePath}:`, err);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
} catch (err) {
|
|
241
|
-
console.error(`Error reading ${sitemapBasePath}:`, err);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
for (const templateId of sitemapPageGroupKeys) {
|
|
246
|
-
const sitemapPages = sitemapPagesGroup[templateId];
|
|
247
|
-
|
|
248
|
-
if (!sitemapPages.length) continue;
|
|
249
|
-
|
|
250
|
-
const siteMap = parse("urlset", {
|
|
251
|
-
"@": {
|
|
252
|
-
xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9",
|
|
253
|
-
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
|
|
254
|
-
"xsi:schemaLocation":
|
|
255
|
-
"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd",
|
|
256
|
-
},
|
|
257
|
-
url: sitemapPages,
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
const sitemapName = `/${templateSitemapPrefix}${templateId.toLowerCase()}.xml`;
|
|
261
|
-
const exactPath = path.join(sitemapBasePath, sitemapName);
|
|
262
|
-
|
|
263
|
-
saveFile(exactPath, siteMap);
|
|
264
|
-
|
|
265
|
-
sitemaps.push(
|
|
266
|
-
`${home.endsWith("/") ? home.slice(0, -1) : home}${sitemapName}`,
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (!sitemaps.length) {
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const siteMap = parse("sitemapindex", {
|
|
275
|
-
"@": { xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" },
|
|
276
|
-
sitemap: sitemaps.map((loc) => ({ loc })),
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
const exactPath = path.join(sitemapBasePath, "sitemap.xml");
|
|
280
|
-
|
|
281
|
-
saveFile(exactPath, siteMap);
|
|
282
|
-
verboseLog(`sitemap generated in ${exactPath}`);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Saves the content to a file specified by its path. If the file exists, it will be overwritten.
|
|
289
|
-
*
|
|
290
|
-
* @param filePath The path of the file to save the content to.
|
|
291
|
-
* @param content The content to save to the file.
|
|
292
|
-
*/
|
|
293
|
-
function saveFile(filePath: string, content: string) {
|
|
294
|
-
try {
|
|
295
|
-
const pathName = path.dirname(filePath);
|
|
296
|
-
if (!fs.existsSync(pathName)) {
|
|
297
|
-
fs.mkdirSync(pathName, { recursive: true });
|
|
298
|
-
}
|
|
299
|
-
fs.writeFileSync(filePath, content);
|
|
300
|
-
} catch (error) {
|
|
301
|
-
console.log(error);
|
|
302
|
-
throw new Error(`Error saving a file`);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
export {
|
|
307
|
-
generateBuildReport,
|
|
308
|
-
generateSitemaps,
|
|
309
|
-
getSiteData,
|
|
310
|
-
getSitesToRender,
|
|
311
|
-
unpublishSites,
|
|
312
|
-
};
|