@griddo/cx 11.9.7-rc.2 → 11.9.8-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -193
- 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 +38 -0
- package/build/commands/prepare-domains-render.js.map +7 -0
- package/build/commands/reset-render.js +31 -0
- package/build/commands/reset-render.js.map +7 -0
- package/build/commands/start-embeddings.js +31 -0
- package/build/commands/start-embeddings.js.map +7 -0
- package/build/commands/start-render.js +66 -0
- package/build/commands/start-render.js.map +7 -0
- package/build/commands/upload-search-content.js +31 -0
- package/build/commands/upload-search-content.js.map +7 -0
- package/build/core/GriddoLog.d.ts +16 -0
- package/build/core/db.d.ts +4 -0
- package/build/core/dist-rollback.d.ts +2 -0
- package/build/{errors/index.d.ts → core/errors.d.ts} +5 -4
- package/build/core/fs.d.ts +69 -0
- package/build/core/logger.d.ts +18 -0
- package/build/index.d.ts +10 -29
- package/build/index.js +406 -73
- package/build/services/auth.d.ts +2 -5
- package/build/services/manage-store.d.ts +48 -0
- package/build/services/render.d.ts +70 -0
- package/build/shared/envs.d.ts +19 -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/{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 +54 -0
- package/build/{types → shared/types}/sites.d.ts +18 -19
- package/cli.mjs +239 -0
- package/exporter/build-esbuild.noop +42 -0
- package/exporter/build.sh +17 -28
- package/exporter/commands/README.md +151 -0
- package/exporter/commands/end-render.ts +65 -86
- package/exporter/commands/prepare-assets-directory.ts +34 -0
- package/exporter/commands/prepare-domains-render.ts +143 -35
- package/exporter/commands/reset-render.ts +12 -7
- package/exporter/commands/single-domain-upload-search-content.noop +206 -0
- package/exporter/commands/start-embeddings.ts +29 -0
- package/exporter/commands/start-render.ts +26 -64
- package/exporter/commands/upload-search-content.ts +201 -26
- package/exporter/core/GriddoLog.ts +45 -0
- package/exporter/core/check-env-health.ts +200 -0
- package/exporter/core/db-class.ts +54 -0
- package/exporter/core/db.ts +33 -0
- package/exporter/core/dist-rollback.ts +40 -0
- package/exporter/core/errors.ts +82 -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 +141 -0
- package/exporter/core/objects.ts +37 -0
- package/exporter/core/print-logos.ts +21 -0
- package/exporter/index.ts +14 -56
- 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 +235 -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 +386 -319
- package/exporter/shared/context.ts +49 -0
- package/exporter/{constants → shared}/endpoints.ts +12 -11
- package/exporter/shared/envs.ts +62 -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 +63 -0
- package/exporter/{types → shared/types}/sites.ts +18 -19
- 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 +114 -0
- package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +16 -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/sync-render.ts +300 -0
- package/exporter/ssg-adapters/gatsby/shared/types.ts +35 -0
- package/exporter/ssg-adapters/gatsby/shared/utils.ts +33 -0
- package/gatsby-browser.tsx +41 -58
- package/gatsby-config.ts +10 -17
- package/gatsby-node.ts +20 -80
- package/gatsby-ssr.tsx +2 -1
- package/package.json +41 -92
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
- package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
- package/react/DynamicScript/index.tsx +33 -0
- package/{exporter/react/Favicon → react/GriddoFavicon}/index.tsx +3 -9
- package/{exporter/react → react}/GriddoIntegrations/index.tsx +17 -23
- package/{exporter/react → react}/GriddoIntegrations/utils.ts +24 -12
- package/react/GriddoOpenGraph/index.tsx +39 -0
- package/src/components/Head.tsx +30 -73
- package/src/components/template.tsx +8 -30
- package/src/gatsby-node-utils.ts +76 -2
- package/src/html.tsx +2 -11
- package/src/types.ts +5 -5
- package/tsconfig.commands.json +36 -0
- package/tsconfig.exporter.json +20 -0
- package/tsconfig.json +5 -3
- package/build/adapters/gatsby/index.d.ts +0 -4
- package/build/adapters/gatsby/utils.d.ts +0 -22
- package/build/artifacts/index.d.ts +0 -6
- package/build/commands/end-render.d.ts +0 -2
- package/build/commands/move-assets.d.ts +0 -1
- package/build/commands/prepare-domains-render.d.ts +0 -1
- package/build/commands/reset-render.d.ts +0 -2
- package/build/commands/start-render.d.ts +0 -2
- package/build/commands/upload-search-content.d.ts +0 -2
- package/build/constants/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/index.js.map +0 -7
- package/build/prepare-domains-render.js +0 -73
- package/build/prepare-domains-render.js.map +0 -7
- package/build/react/Favicon/index.d.ts +0 -5
- package/build/react/Favicon/utils.d.ts +0 -9
- package/build/react/GriddoIntegrations/index.d.ts +0 -20
- package/build/react/GriddoIntegrations/utils.d.ts +0 -26
- package/build/react/index.d.ts +0 -3
- package/build/react/index.js +0 -3
- package/build/registers/api.d.ts +0 -9
- package/build/registers/gatsby.d.ts +0 -9
- package/build/registers/index.d.ts +0 -3
- package/build/reset-render.js +0 -74
- package/build/reset-render.js.map +0 -7
- package/build/services/domains.d.ts +0 -6
- package/build/services/navigation.d.ts +0 -50
- package/build/services/reference-fields.d.ts +0 -20
- package/build/services/register.d.ts +0 -36
- package/build/services/robots.d.ts +0 -19
- package/build/services/settings.d.ts +0 -4
- package/build/services/sites.d.ts +0 -29
- package/build/services/store.d.ts +0 -6
- package/build/start-render.js +0 -100
- package/build/start-render.js.map +0 -7
- package/build/types/templates.d.ts +0 -8
- package/build/upload-search-content.js +0 -74
- package/build/upload-search-content.js.map +0 -7
- package/build/utils/alerts.d.ts +0 -3
- package/build/utils/api.d.ts +0 -23
- package/build/utils/cache.d.ts +0 -35
- package/build/utils/core-utils.d.ts +0 -107
- package/build/utils/create-build-data.d.ts +0 -8
- package/build/utils/domains.d.ts +0 -13
- package/build/utils/folders.d.ts +0 -53
- package/build/utils/health-checks.d.ts +0 -7
- package/build/utils/images.d.ts +0 -16
- package/build/utils/loggin.d.ts +0 -51
- package/build/utils/pages.d.ts +0 -34
- package/build/utils/render.d.ts +0 -13
- package/build/utils/searches.d.ts +0 -15
- package/build/utils/sites.d.ts +0 -31
- package/build/utils/store.d.ts +0 -81
- package/cx.config.d.ts +0 -5
- package/cx.config.js +0 -36
- package/exporter/adapters/gatsby/index.ts +0 -162
- package/exporter/adapters/gatsby/utils.ts +0 -161
- package/exporter/artifacts/README.md +0 -34
- package/exporter/artifacts/index.ts +0 -33
- package/exporter/commands/move-assets.ts +0 -11
- package/exporter/constants/envs.ts +0 -94
- package/exporter/constants/index.ts +0 -129
- package/exporter/errors/index.ts +0 -40
- package/exporter/react/index.tsx +0 -11
- package/exporter/registers/api.ts +0 -14
- package/exporter/registers/gatsby.ts +0 -14
- package/exporter/registers/index.ts +0 -4
- package/exporter/services/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/{utils → core}/instance.d.ts +0 -0
- /package/build/{constants → shared}/endpoints.d.ts +0 -0
- /package/exporter/{types → shared/types}/templates.ts +0 -0
- /package/{exporter/react/Favicon → react/GriddoFavicon}/utils.ts +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fsp from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { withErrorHandler } from "../core/errors";
|
|
5
|
+
import { pathExists } from "../core/fs";
|
|
6
|
+
import { GriddoLog } from "../core/GriddoLog";
|
|
7
|
+
import { getRenderModeFromDB, getRenderPathsHydratedWithDomainFromDB } from "../services/render";
|
|
8
|
+
|
|
9
|
+
async function prepareAssetsDir() {
|
|
10
|
+
const [domain] = process.argv.slice(2);
|
|
11
|
+
|
|
12
|
+
const { renderMode } = await getRenderModeFromDB(domain);
|
|
13
|
+
|
|
14
|
+
if (renderMode === "IDLE") {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { __exports } = await getRenderPathsHydratedWithDomainFromDB({ domain });
|
|
19
|
+
const assetsDir = path.join(__exports, "assets");
|
|
20
|
+
const domainAssetsDir = path.join(__exports, domain);
|
|
21
|
+
|
|
22
|
+
if (await pathExists(assetsDir)) {
|
|
23
|
+
await fsp.rm(domainAssetsDir, { force: true, recursive: true });
|
|
24
|
+
await fsp.rename(assetsDir, domainAssetsDir);
|
|
25
|
+
} else {
|
|
26
|
+
GriddoLog.warn("Assets directory not found");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function main() {
|
|
31
|
+
await prepareAssetsDir();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
withErrorHandler(main);
|
|
@@ -1,46 +1,154 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { RenderDB } from "../shared/types/render";
|
|
2
|
+
|
|
3
|
+
import fsp from "node:fs/promises";
|
|
2
4
|
import path from "node:path";
|
|
3
5
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { version as griddoVersion } from "../../package.json";
|
|
7
|
+
import { checkEnvironmentHealth } from "../core/check-env-health";
|
|
8
|
+
import { readDB, writeDB } from "../core/db";
|
|
9
|
+
import { withErrorHandler } from "../core/errors";
|
|
10
|
+
import { pathExists, rmDirs } from "../core/fs";
|
|
11
|
+
import { GriddoLog } from "../core/GriddoLog";
|
|
12
|
+
import { resolveComponentsPath } from "../core/instance";
|
|
13
|
+
import { AuthService } from "../services/auth";
|
|
14
|
+
import { getInstanceDomains } from "../services/domains";
|
|
15
|
+
import { getSitesToRender } from "../services/manage-sites";
|
|
16
|
+
import { resolveDomainRenderMode } from "../services/render";
|
|
17
|
+
import { pkgDir } from "../shared/npm-modules/pkg-dir";
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
async function getDomainsWithNumberOfPages(domains: string[]) {
|
|
20
|
+
const results = await Promise.all(
|
|
21
|
+
domains.map(async (domain) => {
|
|
22
|
+
// Get the sites to render for the domain
|
|
23
|
+
const { sitesToPublish, sitesToUnpublish } = await getSitesToRender(domain);
|
|
11
24
|
|
|
12
|
-
|
|
25
|
+
// Only count pages (offlinePending && publishPending) if sitesToPublish
|
|
26
|
+
// is not empty. Otherwise we set the domain has having 0 pages.
|
|
27
|
+
const pages: number[] = [];
|
|
13
28
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
if (sitesToPublish.length > 0) {
|
|
30
|
+
for (const site of sitesToPublish) {
|
|
31
|
+
// el site ya está publicado
|
|
32
|
+
if (site.isPublished && !site.shouldBeUpdated) {
|
|
33
|
+
const { pagesStatus } = site;
|
|
34
|
+
const { offlinePending, uploadPending } = pagesStatus;
|
|
35
|
+
const total = offlinePending.length + uploadPending.length;
|
|
36
|
+
pages.push(total);
|
|
37
|
+
}
|
|
38
|
+
// el site esta pendiente de publicar
|
|
39
|
+
if (site.isPublished && site.shouldBeUpdated) {
|
|
40
|
+
const { pagesStatus } = site;
|
|
41
|
+
const { offlinePending, uploadPending, active } = pagesStatus;
|
|
42
|
+
const total = offlinePending.length + uploadPending.length + active.length;
|
|
43
|
+
pages.push(total);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} else if (sitesToUnpublish.length > 0) {
|
|
47
|
+
// si tiene sites para despublicar marcamos el dominio como que tiene 1 página
|
|
48
|
+
pages.push(1);
|
|
49
|
+
} else {
|
|
50
|
+
// si eldominio no tiene nada ni para publicar ni despublicar lomarcamos como 0
|
|
51
|
+
pages.push(0);
|
|
27
52
|
}
|
|
28
|
-
} else {
|
|
29
|
-
pages.push(0);
|
|
30
|
-
}
|
|
31
53
|
|
|
32
|
-
|
|
33
|
-
domainsInfo.push({ domain, totalPages });
|
|
34
|
-
}
|
|
54
|
+
const totalPages = pages.reduce((a, b) => a + b);
|
|
35
55
|
|
|
36
|
-
|
|
56
|
+
return { domain, totalPages };
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getDomainsSortedByNumberOfPages(domainsInfo: { domain: string; totalPages: number }[]) {
|
|
37
64
|
domainsInfo.sort((a, b) => a.totalPages - b.totalPages);
|
|
38
|
-
const domainSorted = domainsInfo.map(({ domain }) => domain);
|
|
39
65
|
|
|
40
|
-
|
|
66
|
+
return domainsInfo.map(({ domain }) => domain);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function initRender() {
|
|
70
|
+
const root = (await pkgDir({ cwd: path.resolve(__dirname, "../../..") })) || "";
|
|
71
|
+
const cx = root;
|
|
72
|
+
const ssg = path.resolve((await pkgDir({ cwd: __dirname })) || "");
|
|
73
|
+
const cxCache = path.resolve(root, ".griddo/cache");
|
|
74
|
+
const components = resolveComponentsPath();
|
|
75
|
+
const exportsDir = path.join(root, "exports/sites");
|
|
76
|
+
const exportsDirBackup = path.join(root, "exports-backup/sites");
|
|
77
|
+
|
|
78
|
+
const data: RenderDB = {
|
|
79
|
+
griddoVersion,
|
|
80
|
+
buildReportFileName: "build-report.json",
|
|
81
|
+
sortedDomains: [],
|
|
82
|
+
needsRollbackOnError: false,
|
|
83
|
+
domains: {},
|
|
84
|
+
currentRenderingDomain: null,
|
|
85
|
+
paths: {
|
|
86
|
+
components,
|
|
87
|
+
cx,
|
|
88
|
+
cxCache,
|
|
89
|
+
exportsDir,
|
|
90
|
+
root,
|
|
91
|
+
ssg,
|
|
92
|
+
exportsDirBackup,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// create the main cache folder for cx if it doesn't exist.
|
|
97
|
+
if (!(await pathExists(cxCache))) {
|
|
98
|
+
await fsp.mkdir(cxCache, { recursive: true });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
await writeDB(data);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function prepareDomains() {
|
|
105
|
+
await AuthService.login();
|
|
106
|
+
|
|
107
|
+
const db = await readDB();
|
|
108
|
+
|
|
109
|
+
const __ssg = db.paths.ssg;
|
|
110
|
+
const domains = await getInstanceDomains();
|
|
111
|
+
const domainsWithNumberOfPages = await getDomainsWithNumberOfPages(domains);
|
|
112
|
+
const domainSorted = getDomainsSortedByNumberOfPages(domainsWithNumberOfPages);
|
|
113
|
+
|
|
114
|
+
// @deprecated use db.json (only for infra)
|
|
115
|
+
await fsp.writeFile(path.join(__ssg, "domains.json"), JSON.stringify(domainSorted));
|
|
116
|
+
|
|
117
|
+
db.sortedDomains = domainSorted;
|
|
118
|
+
db.domains = {};
|
|
119
|
+
|
|
120
|
+
for (const { domain, totalPages } of domainsWithNumberOfPages) {
|
|
121
|
+
const shouldBeRendered = totalPages > 0;
|
|
122
|
+
const { renderMode, reason } = await resolveDomainRenderMode({
|
|
123
|
+
domain,
|
|
124
|
+
shouldBeRendered,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Log RenderModes/Reason
|
|
128
|
+
GriddoLog.info(
|
|
129
|
+
`(From Initial Render) [${domain}]: Marked as ${renderMode} with the reason: ${reason}`,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
db.domains[domain] = db.domains[domain] || {};
|
|
133
|
+
db.domains[domain].renderMode = renderMode;
|
|
134
|
+
db.domains[domain].shouldBeRendered = shouldBeRendered;
|
|
135
|
+
db.domains[domain].renderModeReason = reason;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
await writeDB(db);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function clean() {
|
|
142
|
+
const db = await readDB();
|
|
143
|
+
const { root } = db.paths;
|
|
144
|
+
await rmDirs([path.join(root, "apiCache")]);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function main() {
|
|
148
|
+
checkEnvironmentHealth();
|
|
149
|
+
await initRender();
|
|
150
|
+
await prepareDomains();
|
|
151
|
+
await clean();
|
|
152
|
+
}
|
|
41
153
|
|
|
42
|
-
|
|
43
|
-
})().catch((err) => {
|
|
44
|
-
console.error(err);
|
|
45
|
-
process.exit(1);
|
|
46
|
-
});
|
|
154
|
+
withErrorHandler(main);
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { GriddoLog } from "../core/GriddoLog";
|
|
2
|
+
import { post } from "../services/api";
|
|
3
3
|
import { AuthService } from "../services/auth";
|
|
4
|
-
import {
|
|
4
|
+
import { RESET_RENDER } from "../shared/endpoints";
|
|
5
|
+
|
|
6
|
+
async function resetRender() {
|
|
7
|
+
await post({
|
|
8
|
+
endpoint: RESET_RENDER,
|
|
9
|
+
useApiCacheDir: false,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
5
12
|
|
|
6
13
|
async function main() {
|
|
7
14
|
await AuthService.login();
|
|
8
15
|
await resetRender();
|
|
16
|
+
GriddoLog.info("The render status has been reset.");
|
|
9
17
|
}
|
|
10
18
|
|
|
11
|
-
main().catch(
|
|
12
|
-
console.error("Error", err?.stdout?.toString() || err);
|
|
13
|
-
process.exit(1);
|
|
14
|
-
});
|
|
19
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { PostSearchInfoResponse } from "../shared/types/api";
|
|
2
|
+
import type { PostSearchInfoProps } from "../shared/types/global";
|
|
3
|
+
import type { GatsbyPageData } from "../ssg-adapters/gatsby/shared/types";
|
|
4
|
+
|
|
5
|
+
import fsp from "node:fs/promises";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
import { throwError, withErrorHandler } from "../core/errors";
|
|
9
|
+
import { pathExists } from "../core/fs";
|
|
10
|
+
import { GriddoLog } from "../core/GriddoLog";
|
|
11
|
+
import { post } from "../services/api";
|
|
12
|
+
import { AuthService } from "../services/auth";
|
|
13
|
+
import { getRenderModeFromDB, getRenderPathsHydratedWithDomainFromDB } from "../services/render";
|
|
14
|
+
import { SEARCH } from "../shared/endpoints";
|
|
15
|
+
import { GRIDDO_SEARCH_FEATURE } from "../shared/envs";
|
|
16
|
+
import { ReadFromStoreError, UploadSearchError } from "../shared/errors";
|
|
17
|
+
import { RENDER_MODE } from "../shared/types/render";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Save in the BBDD the content of a page parsed without HTML tags.
|
|
21
|
+
*
|
|
22
|
+
* @param props Object with parts of the final page object to be saved in the BBDD.
|
|
23
|
+
*/
|
|
24
|
+
async function postSearchInfo(props: PostSearchInfoProps) {
|
|
25
|
+
const { title, description, image, pageId, languageId, siteId, url, content, template } = props;
|
|
26
|
+
|
|
27
|
+
const response = await post<PostSearchInfoResponse>({
|
|
28
|
+
endpoint: SEARCH,
|
|
29
|
+
body: {
|
|
30
|
+
title,
|
|
31
|
+
description,
|
|
32
|
+
image,
|
|
33
|
+
pageId,
|
|
34
|
+
languageId,
|
|
35
|
+
siteId,
|
|
36
|
+
url,
|
|
37
|
+
template,
|
|
38
|
+
content,
|
|
39
|
+
},
|
|
40
|
+
useApiCacheDir: false,
|
|
41
|
+
logToFile: false,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function prepareHTMLContentForSearch(content: string): string {
|
|
48
|
+
// 1. Remove script, style, and other unwanted block tags and their content.
|
|
49
|
+
// The regex looks for <tag...>...</tag> where tag is one of the specified ones.
|
|
50
|
+
const tagsToRemove = ["meta", "link", "style", "script", "noscript", "nav", "header", "footer"];
|
|
51
|
+
const removeTagsRegex = new RegExp(`<(${tagsToRemove.join("|")})\\b[^>]*>.*?<\\/\\1>`, "gis");
|
|
52
|
+
let processedContent = content.replace(removeTagsRegex, "");
|
|
53
|
+
|
|
54
|
+
// 2. Strip all remaining HTML tags.
|
|
55
|
+
processedContent = processedContent.replace(/<[^>]+>/g, " ");
|
|
56
|
+
|
|
57
|
+
// 3. Normalize whitespace: replace multiple spaces/newlines with a single space and trim.
|
|
58
|
+
processedContent = processedContent.replace(/\s+/g, " ").trim();
|
|
59
|
+
|
|
60
|
+
return processedContent;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function getContentDirectories(domain: string) {
|
|
64
|
+
const { __exports } = await getRenderPathsHydratedWithDomainFromDB({ domain });
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
htmlContentDir: path.join(__exports, "dist"),
|
|
68
|
+
jsonContentDir: path.join(__exports, "dist", "page-data"),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Walk recursively in a basePath and return an array of pages with json
|
|
74
|
+
* extension with the full absolute path and the path includes "page-data".
|
|
75
|
+
*
|
|
76
|
+
* @param basePath The path to walk recursively.
|
|
77
|
+
* @returns An array of pages with json extension with the full absolute path
|
|
78
|
+
* and the path includes "page-data".
|
|
79
|
+
*/
|
|
80
|
+
async function* walkRecursively(basePath: string): AsyncGenerator<string> {
|
|
81
|
+
const filesHandle = await fsp.opendir(basePath);
|
|
82
|
+
|
|
83
|
+
for await (const fileDirent of filesHandle) {
|
|
84
|
+
if (fileDirent.isDirectory()) {
|
|
85
|
+
yield* walkRecursively(path.join(basePath, fileDirent.name));
|
|
86
|
+
} else if (
|
|
87
|
+
fileDirent.isFile() &&
|
|
88
|
+
path.extname(fileDirent.name) === ".json" &&
|
|
89
|
+
fileDirent.name.includes("page-data")
|
|
90
|
+
) {
|
|
91
|
+
yield path.join(basePath, fileDirent.name);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Walk recursively in a basePath and return an array of pages with json
|
|
98
|
+
* extension with the full absolute path and the path includes "page-data".
|
|
99
|
+
*
|
|
100
|
+
* @param basePath The path to walk recursively.
|
|
101
|
+
* @returns An array of pages with json extension with the full absolute path
|
|
102
|
+
* and the path includes "page-data".
|
|
103
|
+
*/
|
|
104
|
+
async function* getPageDataPagesFromExports<PageType extends GatsbyPageData>(
|
|
105
|
+
basePath: string,
|
|
106
|
+
): AsyncGenerator<PageType> {
|
|
107
|
+
const jsonFiles = walkRecursively(basePath);
|
|
108
|
+
|
|
109
|
+
for await (const filePath of jsonFiles) {
|
|
110
|
+
try {
|
|
111
|
+
const fileContent = await fsp.readFile(filePath, "utf8");
|
|
112
|
+
const page = JSON.parse(fileContent) as PageType;
|
|
113
|
+
|
|
114
|
+
if (page.path) {
|
|
115
|
+
yield page;
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throwError(ReadFromStoreError, error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Function that search in the `/public` dir the content info of the pages and
|
|
125
|
+
* send it to the search table in the ddbb using the API.
|
|
126
|
+
* @todo Utilizar la carpeta page-data en lugar de la carpeta store puesto que
|
|
127
|
+
* esta ya no es persistente.
|
|
128
|
+
*/
|
|
129
|
+
async function uploadRenderedSearchContentToAPI(options: {
|
|
130
|
+
htmlContentDir: string;
|
|
131
|
+
jsonContentDir: string;
|
|
132
|
+
}) {
|
|
133
|
+
const { htmlContentDir, jsonContentDir } = options;
|
|
134
|
+
|
|
135
|
+
if (!(await pathExists(jsonContentDir)) || !(await pathExists(htmlContentDir))) {
|
|
136
|
+
GriddoLog.info(
|
|
137
|
+
`(From Current Render) Skipping uploading content to the search endpoint because it has not exported sites.`,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Get pages from gatsby page-data dir
|
|
144
|
+
const gatsbyPageDataPages = getPageDataPagesFromExports(jsonContentDir);
|
|
145
|
+
|
|
146
|
+
for await (const pageData of gatsbyPageDataPages) {
|
|
147
|
+
const { result } = pageData;
|
|
148
|
+
const { pageContext } = result;
|
|
149
|
+
const { page, openGraph, pageMetadata } = pageContext;
|
|
150
|
+
|
|
151
|
+
const { compose } = page.fullPath;
|
|
152
|
+
|
|
153
|
+
const htmlPath = path.resolve(`${htmlContentDir}/${compose}/index.html`);
|
|
154
|
+
const htmlContent = await fsp.readFile(htmlPath, "utf-8");
|
|
155
|
+
|
|
156
|
+
const pageObject: PostSearchInfoProps = {
|
|
157
|
+
siteId: page.site,
|
|
158
|
+
pageId: page.id,
|
|
159
|
+
// `pageMetadata.title` has already a fallback `metatitle ||
|
|
160
|
+
// pageTitle` so probably `title` never will be take the
|
|
161
|
+
// `openGraph?.title` value. Only when the `metatitle` and
|
|
162
|
+
// `pageTitle` are empty.
|
|
163
|
+
title: pageMetadata?.title || openGraph?.title,
|
|
164
|
+
languageId: page.language,
|
|
165
|
+
url: page.fullUrl,
|
|
166
|
+
template: page.template.templateType || page.templateId,
|
|
167
|
+
description: pageMetadata?.description || openGraph?.description,
|
|
168
|
+
image: openGraph.image,
|
|
169
|
+
// _content: prepareHTMLContentForSearch(htmlContent),
|
|
170
|
+
content: prepareHTMLContentForSearch(htmlContent),
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
await postSearchInfo(pageObject);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
throwError(UploadSearchError, error);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function uploadSearchContent() {
|
|
182
|
+
const [domain] = process.argv.slice(2);
|
|
183
|
+
const { renderMode, reason } = await getRenderModeFromDB(domain);
|
|
184
|
+
|
|
185
|
+
if (renderMode === RENDER_MODE.IDLE) {
|
|
186
|
+
GriddoLog.info(
|
|
187
|
+
`(From Current Render) [${domain}]: Skipping upload-search-content as it is marked as IDLE with the reason ${reason}.`,
|
|
188
|
+
);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const { htmlContentDir, jsonContentDir } = await getContentDirectories(domain);
|
|
193
|
+
await uploadRenderedSearchContentToAPI({
|
|
194
|
+
htmlContentDir,
|
|
195
|
+
jsonContentDir,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function main() {
|
|
200
|
+
if (GRIDDO_SEARCH_FEATURE) {
|
|
201
|
+
await AuthService.login();
|
|
202
|
+
await uploadSearchContent();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
withErrorHandler(main);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//
|
|
2
|
+
//
|
|
3
|
+
// NOTA: Este proceso es para toda la instancia, no discrimina por dominio
|
|
4
|
+
//
|
|
5
|
+
//
|
|
6
|
+
|
|
7
|
+
import type { AIEmbeddingsResponse } from "../shared/types/global";
|
|
8
|
+
|
|
9
|
+
import { withErrorHandler } from "../core/errors";
|
|
10
|
+
import { post } from "../services/api";
|
|
11
|
+
import { AuthService } from "../services/auth";
|
|
12
|
+
import { AI_EMBEDDINGS } from "../shared/endpoints";
|
|
13
|
+
import { GRIDDO_AI_EMBEDDINGS, GRIDDO_SEARCH_FEATURE } from "../shared/envs";
|
|
14
|
+
|
|
15
|
+
async function triggerAIEmbeddings() {
|
|
16
|
+
await post<AIEmbeddingsResponse>({
|
|
17
|
+
endpoint: AI_EMBEDDINGS,
|
|
18
|
+
useApiCacheDir: false,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
if (GRIDDO_SEARCH_FEATURE && GRIDDO_AI_EMBEDDINGS) {
|
|
24
|
+
await AuthService.login();
|
|
25
|
+
await triggerAIEmbeddings();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
withErrorHandler(main);
|
|
@@ -1,68 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
console.log("USANDO EL .ENV");
|
|
17
|
-
showExporterVersion();
|
|
18
|
-
for (const domain of GRIDDO_RENDER_DOMAINS.split(",")) {
|
|
19
|
-
await renderDomainsWithGatsbyAdapter(domain);
|
|
20
|
-
}
|
|
21
|
-
await sendGriddoDefaultAlerts();
|
|
22
|
-
process.exit(0);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// This will render every domain opposed to the new logic of render each
|
|
26
|
-
// domain separately.
|
|
27
|
-
if (RENDER_BY_DOMAIN) {
|
|
28
|
-
const domain = process.argv.splice(2)[0];
|
|
29
|
-
|
|
30
|
-
if (!domain) {
|
|
31
|
-
console.log("Needs the domain name argument");
|
|
32
|
-
throw new RenderError();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
showExporterVersion();
|
|
36
|
-
await renderDomainsWithGatsbyAdapter(domain);
|
|
37
|
-
await sendGriddoDefaultAlerts();
|
|
38
|
-
|
|
39
|
-
process.exit(0);
|
|
40
|
-
} else {
|
|
41
|
-
showExporterVersion();
|
|
42
|
-
|
|
43
|
-
console.log("( Legacy Render Mode )\n");
|
|
44
|
-
|
|
45
|
-
const domains = await getInstanceDomains();
|
|
1
|
+
import { withErrorHandler } from "../core/errors";
|
|
2
|
+
import { GriddoLog } from "../core/GriddoLog";
|
|
3
|
+
import { showExporterVersion } from "../core/print-logos";
|
|
4
|
+
import { AuthService } from "../services/auth";
|
|
5
|
+
import { getInstanceDomains } from "../services/domains";
|
|
6
|
+
import { GRIDDO_RENDER_BY_DOMAINS } from "../shared/envs";
|
|
7
|
+
import { gatsbyRenderDomain } from "../ssg-adapters/gatsby";
|
|
8
|
+
|
|
9
|
+
async function legacyRender() {
|
|
10
|
+
GriddoLog.warn("Legacy Render Mode");
|
|
11
|
+
const domains = await getInstanceDomains();
|
|
12
|
+
for (const domain of domains) {
|
|
13
|
+
await gatsbyRenderDomain(domain);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
46
16
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
process.exit(0);
|
|
52
|
-
}
|
|
53
|
-
} catch (error) {
|
|
54
|
-
if (error instanceof RenderError) {
|
|
55
|
-
errorLabelLog("GRIDDO_ERROR InternalCXError");
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
17
|
+
async function render() {
|
|
18
|
+
const [domain] = process.argv.slice(2);
|
|
19
|
+
await gatsbyRenderDomain(domain);
|
|
20
|
+
}
|
|
58
21
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
22
|
+
async function main() {
|
|
23
|
+
await showExporterVersion();
|
|
24
|
+
await AuthService.login();
|
|
25
|
+
GRIDDO_RENDER_BY_DOMAINS // This is a legacy flag, we should remove it in the future
|
|
26
|
+
? await render()
|
|
27
|
+
: await legacyRender();
|
|
63
28
|
}
|
|
64
29
|
|
|
65
|
-
|
|
66
|
-
console.error("Error", err?.stdout?.toString() || err);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
});
|
|
30
|
+
withErrorHandler(main);
|