@griddo/cx 11.7.6-rc.1 → 11.7.6
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 +228 -25
- 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/move-assets.d.ts +1 -0
- package/build/commands/prepare-domains-render.d.ts +1 -0
- package/build/{exporter/constants → constants}/envs.d.ts +7 -1
- 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/{exporter/constants/errors.d.ts → errors/errors-data.d.ts} +3 -5
- package/build/{exporter/utils/errors.d.ts → errors/index.d.ts} +3 -3
- package/build/index.d.ts +29 -0
- package/build/index.js +73 -0
- 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/{react/index.tsx → build/react/index.d.ts} +0 -1
- 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/{exporter/services → services}/auth.d.ts +1 -1
- package/build/services/domains.d.ts +6 -0
- package/build/services/register.d.ts +36 -0
- package/build/{exporter/services → services}/robots.d.ts +6 -0
- package/build/services/settings.d.ts +4 -0
- package/build/{exporter/services → services}/sites.d.ts +2 -5
- 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/{exporter/types → types}/api.d.ts +4 -3
- package/build/{exporter/types → types}/global.d.ts +6 -6
- package/build/{exporter/types → types}/navigation.d.ts +1 -1
- package/build/{exporter/types → types}/sites.d.ts +2 -1
- 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/{exporter/utils → utils}/cache.d.ts +12 -7
- package/build/utils/core-utils.d.ts +107 -0
- package/build/utils/create-build-data.d.ts +8 -0
- package/build/{exporter/utils → utils}/domains.d.ts +1 -1
- package/build/utils/folders.d.ts +53 -0
- package/build/{exporter/utils/check-health.d.ts → utils/health-checks.d.ts} +2 -2
- package/build/{exporter/utils → utils}/loggin.d.ts +16 -2
- package/build/{exporter/utils → utils}/pages.d.ts +2 -2
- package/build/utils/render.d.ts +13 -0
- package/build/utils/searches.d.ts +15 -0
- package/build/{exporter/utils → utils}/sites.d.ts +3 -3
- package/build/{exporter/utils → utils}/store.d.ts +38 -10
- package/cx.config.d.ts +5 -0
- package/cx.config.js +36 -0
- package/exporter/adapters/gatsby/index.ts +146 -60
- package/exporter/adapters/gatsby/utils.ts +161 -0
- package/exporter/artifacts/README.md +34 -0
- package/exporter/{utils/artifacts.ts → artifacts/index.ts} +8 -9
- package/exporter/build.sh +38 -5
- package/exporter/commands/end-render.ts +81 -56
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +31 -149
- package/exporter/commands/reset-render.ts +3 -12
- package/exporter/commands/start-render.ts +47 -18
- package/exporter/commands/upload-search-content.ts +21 -206
- package/exporter/constants/envs.ts +51 -59
- package/exporter/constants/index.ts +129 -0
- package/exporter/{constants/errors.ts → errors/errors-data.ts} +15 -24
- package/exporter/{utils/errors.ts → errors/index.ts} +9 -10
- package/exporter/index.ts +82 -0
- package/{react → exporter/react}/Favicon/index.tsx +7 -1
- package/{react → exporter/react}/GriddoIntegrations/index.tsx +14 -6
- package/{react → exporter/react}/GriddoIntegrations/utils.ts +9 -4
- 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 +6 -7
- package/exporter/services/domains.ts +16 -0
- package/exporter/services/navigation.ts +10 -4
- package/exporter/services/reference-fields.ts +23 -8
- package/exporter/services/register.ts +113 -0
- package/exporter/services/robots.ts +15 -8
- package/exporter/services/settings.ts +17 -0
- package/exporter/services/sites.ts +24 -35
- package/exporter/services/store.ts +76 -118
- package/exporter/types/api.ts +27 -24
- package/exporter/types/global.ts +10 -8
- package/exporter/types/navigation.ts +1 -1
- package/exporter/types/pages.ts +3 -2
- package/exporter/types/sites.ts +2 -1
- package/exporter/utils/alerts.ts +29 -0
- package/exporter/utils/api.ts +82 -46
- package/exporter/utils/cache.ts +59 -34
- package/exporter/utils/core-utils.ts +247 -86
- package/exporter/utils/create-build-data.ts +17 -0
- package/exporter/utils/domains.ts +7 -10
- package/exporter/utils/folders.ts +92 -161
- package/exporter/utils/health-checks.ts +64 -0
- package/exporter/utils/images.ts +6 -1
- package/exporter/utils/instance.ts +12 -9
- package/exporter/utils/loggin.ts +89 -24
- package/exporter/utils/pages.ts +88 -23
- package/exporter/utils/render.ts +48 -147
- package/exporter/utils/searches.ts +156 -0
- package/exporter/utils/sites.ts +77 -67
- package/exporter/utils/store.ts +178 -85
- package/gatsby-browser.tsx +58 -41
- package/gatsby-config.ts +12 -6
- package/gatsby-node.ts +77 -15
- package/gatsby-ssr.tsx +1 -2
- package/package.json +74 -33
- package/src/README.md +7 -0
- package/src/components/Head.tsx +46 -13
- package/src/components/template.tsx +30 -8
- package/src/gatsby-node-utils.ts +2 -91
- package/src/html.tsx +11 -2
- package/src/types.ts +5 -5
- package/start-render.js +3 -1
- package/tsconfig.json +2 -3
- package/build/adapters/gatsby/actions/clean.js +0 -10
- package/build/adapters/gatsby/actions/clean.js.map +0 -1
- package/build/adapters/gatsby/actions/close.js +0 -12
- package/build/adapters/gatsby/actions/close.js.map +0 -1
- package/build/adapters/gatsby/actions/data.js +0 -18
- package/build/adapters/gatsby/actions/data.js.map +0 -1
- package/build/adapters/gatsby/actions/healthCheck.js +0 -10
- package/build/adapters/gatsby/actions/healthCheck.js.map +0 -1
- package/build/adapters/gatsby/actions/init.js +0 -9
- package/build/adapters/gatsby/actions/init.js.map +0 -1
- package/build/adapters/gatsby/actions/meta.js +0 -14
- package/build/adapters/gatsby/actions/meta.js.map +0 -1
- package/build/adapters/gatsby/actions/prepare.js +0 -9
- package/build/adapters/gatsby/actions/prepare.js.map +0 -1
- package/build/adapters/gatsby/actions/relocation.js +0 -15
- package/build/adapters/gatsby/actions/relocation.js.map +0 -1
- package/build/adapters/gatsby/actions/restore.js +0 -26
- package/build/adapters/gatsby/actions/restore.js.map +0 -1
- package/build/adapters/gatsby/actions/ssg.js +0 -9
- package/build/adapters/gatsby/actions/ssg.js.map +0 -1
- package/build/adapters/gatsby/actions/sync.js +0 -50
- package/build/adapters/gatsby/actions/sync.js.map +0 -1
- package/build/adapters/gatsby/index.js +0 -74
- package/build/adapters/gatsby/index.js.map +0 -1
- package/build/adapters/gatsby/shared/context.js +0 -25
- package/build/adapters/gatsby/shared/context.js.map +0 -1
- package/build/adapters/gatsby/shared/extract-assets.js +0 -58
- package/build/adapters/gatsby/shared/extract-assets.js.map +0 -1
- package/build/adapters/gatsby/shared/gatsby-build.js +0 -49
- package/build/adapters/gatsby/shared/gatsby-build.js.map +0 -1
- package/build/adapters/gatsby/shared/sync-render.js +0 -208
- package/build/adapters/gatsby/shared/sync-render.js.map +0 -1
- package/build/adapters/gatsby/shared/types.js +0 -3
- package/build/adapters/gatsby/shared/types.js.map +0 -1
- package/build/commands/end-render.js +0 -63
- package/build/commands/end-render.js.map +0 -1
- package/build/commands/prepare-assets-directory.js +0 -32
- package/build/commands/prepare-assets-directory.js.map +0 -1
- package/build/commands/prepare-domains-render.js +0 -138
- package/build/commands/prepare-domains-render.js.map +0 -1
- package/build/commands/reset-render.js +0 -22
- package/build/commands/reset-render.js.map +0 -1
- package/build/commands/start-render.js +0 -35
- package/build/commands/start-render.js.map +0 -1
- package/build/commands/upload-search-content.js +0 -189
- package/build/commands/upload-search-content.js.map +0 -1
- package/build/constants/endpoints.js +0 -42
- package/build/constants/endpoints.js.map +0 -1
- package/build/constants/envs.js +0 -73
- package/build/constants/envs.js.map +0 -1
- package/build/constants/errors.js +0 -89
- package/build/constants/errors.js.map +0 -1
- package/build/exporter/adapters/gatsby/actions/clean.d.ts +0 -3
- package/build/exporter/adapters/gatsby/actions/close.d.ts +0 -3
- package/build/exporter/adapters/gatsby/actions/data.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/healthCheck.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/init.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/meta.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/prepare.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/relocation.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/restore.d.ts +0 -3
- package/build/exporter/adapters/gatsby/actions/ssg.d.ts +0 -3
- package/build/exporter/adapters/gatsby/actions/sync.d.ts +0 -3
- package/build/exporter/adapters/gatsby/index.d.ts +0 -9
- package/build/exporter/adapters/gatsby/shared/context.d.ts +0 -38
- package/build/exporter/adapters/gatsby/shared/extract-assets.d.ts +0 -7
- package/build/exporter/adapters/gatsby/shared/gatsby-build.d.ts +0 -7
- package/build/exporter/adapters/gatsby/shared/sync-render.d.ts +0 -36
- package/build/exporter/adapters/gatsby/shared/types.d.ts +0 -34
- package/build/exporter/commands/prepare-assets-directory.d.ts +0 -2
- package/build/exporter/commands/prepare-domains-render.d.ts +0 -2
- package/build/exporter/services/db.d.ts +0 -4
- package/build/exporter/services/store.d.ts +0 -15
- package/build/exporter/types/render.d.ts +0 -50
- package/build/exporter/utils/artifacts.d.ts +0 -6
- package/build/exporter/utils/brush.d.ts +0 -18
- package/build/exporter/utils/core-utils.d.ts +0 -77
- package/build/exporter/utils/folders.d.ts +0 -66
- package/build/exporter/utils/render.d.ts +0 -49
- package/build/services/auth.js +0 -39
- package/build/services/auth.js.map +0 -1
- package/build/services/db.js +0 -34
- package/build/services/db.js.map +0 -1
- package/build/services/navigation.js +0 -93
- package/build/services/navigation.js.map +0 -1
- package/build/services/reference-fields.js +0 -131
- package/build/services/reference-fields.js.map +0 -1
- package/build/services/robots.js +0 -58
- package/build/services/robots.js.map +0 -1
- package/build/services/sites.js +0 -109
- package/build/services/sites.js.map +0 -1
- package/build/services/store.js +0 -282
- package/build/services/store.js.map +0 -1
- package/build/types/api.js +0 -3
- package/build/types/api.js.map +0 -1
- package/build/types/global.js +0 -3
- package/build/types/global.js.map +0 -1
- package/build/types/navigation.js +0 -3
- package/build/types/navigation.js.map +0 -1
- package/build/types/pages.js +0 -3
- package/build/types/pages.js.map +0 -1
- package/build/types/render.js +0 -10
- package/build/types/render.js.map +0 -1
- package/build/types/sites.js +0 -3
- package/build/types/sites.js.map +0 -1
- package/build/types/templates.js +0 -3
- package/build/types/templates.js.map +0 -1
- package/build/utils/api.js +0 -161
- package/build/utils/api.js.map +0 -1
- package/build/utils/artifacts.js +0 -34
- package/build/utils/artifacts.js.map +0 -1
- package/build/utils/brush.js +0 -30
- package/build/utils/brush.js.map +0 -1
- package/build/utils/cache.js +0 -106
- package/build/utils/cache.js.map +0 -1
- package/build/utils/check-health.js +0 -68
- package/build/utils/check-health.js.map +0 -1
- package/build/utils/core-utils.js +0 -251
- package/build/utils/core-utils.js.map +0 -1
- package/build/utils/domains.js +0 -37
- package/build/utils/domains.js.map +0 -1
- package/build/utils/errors.js +0 -30
- package/build/utils/errors.js.map +0 -1
- package/build/utils/folders.js +0 -339
- package/build/utils/folders.js.map +0 -1
- package/build/utils/images.js +0 -45
- package/build/utils/images.js.map +0 -1
- package/build/utils/instance.js +0 -66
- package/build/utils/instance.js.map +0 -1
- package/build/utils/loggin.js +0 -102
- package/build/utils/loggin.js.map +0 -1
- package/build/utils/pages.js +0 -359
- package/build/utils/pages.js.map +0 -1
- package/build/utils/render.js +0 -144
- package/build/utils/render.js.map +0 -1
- package/build/utils/sites.js +0 -239
- package/build/utils/sites.js.map +0 -1
- package/build/utils/store.js +0 -193
- package/build/utils/store.js.map +0 -1
- package/exporter/adapters/gatsby/actions/clean.ts +0 -14
- package/exporter/adapters/gatsby/actions/close.ts +0 -17
- package/exporter/adapters/gatsby/actions/data.ts +0 -25
- package/exporter/adapters/gatsby/actions/healthCheck.ts +0 -10
- package/exporter/adapters/gatsby/actions/init.ts +0 -12
- package/exporter/adapters/gatsby/actions/meta.ts +0 -18
- package/exporter/adapters/gatsby/actions/prepare.ts +0 -9
- package/exporter/adapters/gatsby/actions/relocation.ts +0 -15
- package/exporter/adapters/gatsby/actions/restore.ts +0 -36
- package/exporter/adapters/gatsby/actions/ssg.ts +0 -12
- package/exporter/adapters/gatsby/actions/sync.ts +0 -70
- package/exporter/adapters/gatsby/shared/context.ts +0 -50
- package/exporter/adapters/gatsby/shared/extract-assets.ts +0 -61
- package/exporter/adapters/gatsby/shared/gatsby-build.ts +0 -54
- package/exporter/adapters/gatsby/shared/sync-render.ts +0 -294
- package/exporter/adapters/gatsby/shared/types.ts +0 -35
- package/exporter/build-esbuild.noop +0 -42
- package/exporter/commands/prepare-assets-directory.ts +0 -33
- package/exporter/services/db.ts +0 -32
- package/exporter/types/render.ts +0 -59
- package/exporter/utils/brush.ts +0 -34
- package/exporter/utils/check-health.ts +0 -79
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- package/build/{exporter/commands → commands}/end-render.d.ts +0 -0
- package/build/{exporter/commands → commands}/reset-render.d.ts +0 -0
- package/build/{exporter/commands → commands}/start-render.d.ts +0 -0
- package/build/{exporter/commands → commands}/upload-search-content.d.ts +0 -0
- package/build/{exporter/constants → constants}/endpoints.d.ts +0 -0
- package/build/{exporter/services → services}/navigation.d.ts +0 -0
- package/build/{exporter/services → services}/reference-fields.d.ts +0 -0
- package/build/{exporter/types → types}/pages.d.ts +1 -1
- /package/build/{exporter/types → types}/templates.d.ts +0 -0
- /package/build/{exporter/utils → utils}/api.d.ts +0 -0
- /package/build/{exporter/utils → utils}/images.d.ts +0 -0
- /package/build/{exporter/utils → utils}/instance.d.ts +0 -0
- /package/{react → exporter/react}/Favicon/utils.ts +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Domains } from "../types/global";
|
|
2
|
+
|
|
3
|
+
import { endpoints } from "../constants";
|
|
4
|
+
import { get } from "../utils/api";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get an array of available domain.
|
|
8
|
+
*/
|
|
9
|
+
async function getAllDomains() {
|
|
10
|
+
return get<Domains>({
|
|
11
|
+
endpoint: endpoints.DOMAINS,
|
|
12
|
+
useApiCacheDir: false,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getAllDomains };
|
|
@@ -68,7 +68,9 @@ class NavigationService {
|
|
|
68
68
|
const rightLanguageItem = list.find(
|
|
69
69
|
(item) =>
|
|
70
70
|
item.language === language &&
|
|
71
|
-
item.navigationLanguages?.find(
|
|
71
|
+
item.navigationLanguages?.find(
|
|
72
|
+
(version) => version.navigationId === id,
|
|
73
|
+
),
|
|
72
74
|
);
|
|
73
75
|
|
|
74
76
|
const result = rightLanguageItem || list.find((item) => item.id === id);
|
|
@@ -85,9 +87,13 @@ class NavigationService {
|
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
getPageNavigations(page: APIPageObject) {
|
|
88
|
-
const {
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
const {
|
|
91
|
+
header: pageHeader,
|
|
92
|
+
footer: pageFooter,
|
|
93
|
+
language,
|
|
94
|
+
template: { templateType },
|
|
95
|
+
templateConfig: { defaultHeader, defaultFooter, templates },
|
|
96
|
+
} = page;
|
|
91
97
|
|
|
92
98
|
// The navigations would be:
|
|
93
99
|
// - The one with the page or ...
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Core, Fields } from "@griddo/core";
|
|
2
1
|
import type { FetchDataProps } from "../types/global";
|
|
3
2
|
import type { APIPageObject } from "../types/pages";
|
|
3
|
+
import type { Core, Fields } from "@griddo/core";
|
|
4
4
|
|
|
5
|
-
import { boxLog } from "../utils/loggin";
|
|
6
5
|
import { getReferenceFieldSiteData } from "./sites";
|
|
6
|
+
import { boxLog } from "../utils/loggin";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Get the body data from a ReferenceField.
|
|
@@ -54,7 +54,9 @@ function getBody(data: Fields.Reference<unknown>, page: Core.Page) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
console.log(
|
|
57
|
+
console.log(
|
|
58
|
+
`Error: ReferenceField mode: ${mode} is not recognized on page ${page?.id}.`,
|
|
59
|
+
);
|
|
58
60
|
|
|
59
61
|
return data;
|
|
60
62
|
}
|
|
@@ -69,8 +71,11 @@ function getBody(data: Fields.Reference<unknown>, page: Core.Page) {
|
|
|
69
71
|
* @returns The ContentType data.
|
|
70
72
|
*/
|
|
71
73
|
async function fetchContentTypeData(props: FetchDataProps) {
|
|
72
|
-
const {
|
|
73
|
-
|
|
74
|
+
const {
|
|
75
|
+
page,
|
|
76
|
+
component: { data },
|
|
77
|
+
cacheKey,
|
|
78
|
+
} = props;
|
|
74
79
|
|
|
75
80
|
// Distrubutor with `hasDistributorData: true` / `getStaticData: true` but without `data` prop
|
|
76
81
|
if (!data) {
|
|
@@ -104,7 +109,13 @@ async function fetchContentTypeData(props: FetchDataProps) {
|
|
|
104
109
|
|
|
105
110
|
const body = getBody(data, page);
|
|
106
111
|
|
|
107
|
-
const response = await getReferenceFieldSiteData(
|
|
112
|
+
const response = await getReferenceFieldSiteData(
|
|
113
|
+
page,
|
|
114
|
+
body,
|
|
115
|
+
cacheKey,
|
|
116
|
+
site,
|
|
117
|
+
lang,
|
|
118
|
+
);
|
|
108
119
|
|
|
109
120
|
return response;
|
|
110
121
|
}
|
|
@@ -154,7 +165,10 @@ async function getReferenceFieldData({
|
|
|
154
165
|
continue;
|
|
155
166
|
}
|
|
156
167
|
|
|
157
|
-
const _key = key as
|
|
168
|
+
const _key = key as
|
|
169
|
+
| "hasDistributorData"
|
|
170
|
+
| "queriedItems"
|
|
171
|
+
| "getStaticData";
|
|
158
172
|
const component = templateChunk[_key] as unknown as {
|
|
159
173
|
data: Fields.Reference<unknown>;
|
|
160
174
|
queriedItems: Fields.QueriedData<unknown>;
|
|
@@ -167,7 +181,8 @@ async function getReferenceFieldData({
|
|
|
167
181
|
continue;
|
|
168
182
|
}
|
|
169
183
|
|
|
170
|
-
const componentHasRequestForData =
|
|
184
|
+
const componentHasRequestForData =
|
|
185
|
+
component.hasDistributorData || component.getStaticData;
|
|
171
186
|
|
|
172
187
|
if (componentHasRequestForData) {
|
|
173
188
|
component.queriedItems = await fetchContentTypeData({
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import fsx from "fs-extra";
|
|
2
|
+
|
|
3
|
+
type Entry = Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
type EntryData = {
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
entries: Array<Entry>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type Entries = Record<string, EntryData>;
|
|
12
|
+
|
|
13
|
+
interface RegisterBase<T extends Entries> {
|
|
14
|
+
insert(name: keyof T, entry: Entry): void;
|
|
15
|
+
get(name: keyof T): EntryData;
|
|
16
|
+
getAll(): T;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class MemoryRegister<T extends Entries> implements RegisterBase<T> {
|
|
20
|
+
entries: T;
|
|
21
|
+
|
|
22
|
+
constructor(entries: T) {
|
|
23
|
+
this.entries = entries;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
insert(name: keyof T, entry: Entry) {
|
|
27
|
+
this.entries[name].entries.push(entry);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get(name: keyof T) {
|
|
31
|
+
return this.entries[name];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getAll() {
|
|
35
|
+
return this.entries;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class FileRegister<T extends Entries> implements RegisterBase<T> {
|
|
40
|
+
private readonly filePath: string;
|
|
41
|
+
entries: T;
|
|
42
|
+
|
|
43
|
+
constructor(filePath: string, entries: T) {
|
|
44
|
+
this.entries = entries;
|
|
45
|
+
this.filePath = filePath;
|
|
46
|
+
try {
|
|
47
|
+
fsx.writeJSONSync(this.filePath, this.entries);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error(`Error writing ${this.filePath}`, e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private getCurrentEntries(): T {
|
|
54
|
+
return fsx.readJSONSync(this.filePath, "utf8") as T;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
insert(name: keyof T, entry: Entry) {
|
|
58
|
+
try {
|
|
59
|
+
const currentEntries = this.getCurrentEntries();
|
|
60
|
+
currentEntries[name].entries.push(entry);
|
|
61
|
+
fsx.writeJSONSync(this.filePath, currentEntries);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get(name: keyof T) {
|
|
68
|
+
try {
|
|
69
|
+
return fsx.readJSONSync(this.filePath, "utf8")[name] as EntryData;
|
|
70
|
+
} catch (e) {
|
|
71
|
+
console.error(e);
|
|
72
|
+
throw new Error(`Error reading ${this.filePath}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getAll() {
|
|
77
|
+
try {
|
|
78
|
+
return fsx.readJSONSync(this.filePath, "utf8") as T;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.error(e);
|
|
81
|
+
throw new Error(`Error reading ${this.filePath}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
class Register<T extends Entries> {
|
|
87
|
+
private strategy: RegisterBase<T>;
|
|
88
|
+
|
|
89
|
+
constructor(strategy: RegisterBase<T>) {
|
|
90
|
+
this.strategy = strategy;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
insert<K extends keyof T>(name: K, entry: Entry) {
|
|
94
|
+
this.strategy.insert(name, entry);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get<K extends keyof T>(name: K) {
|
|
98
|
+
return this.strategy.get(name);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getAll() {
|
|
102
|
+
return this.strategy.getAll();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
FileRegister,
|
|
108
|
+
MemoryRegister,
|
|
109
|
+
Register,
|
|
110
|
+
type Entries,
|
|
111
|
+
type Entry,
|
|
112
|
+
type EntryData,
|
|
113
|
+
};
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { Robots } from "../types/global";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { endpoints } from "../constants";
|
|
7
7
|
import { get } from "../utils/api";
|
|
8
|
-
import {
|
|
8
|
+
import { getConfig } from "../utils/core-utils";
|
|
9
9
|
import { verboseLog } from "../utils/loggin";
|
|
10
|
-
import { getRenderPathsFromDB } from "../utils/render";
|
|
11
10
|
|
|
11
|
+
const config = getConfig();
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* TODO: JSDoc
|
|
15
|
+
*/
|
|
12
16
|
class RobotsService {
|
|
13
17
|
robots: Robots;
|
|
14
18
|
settings: Record<string, unknown>;
|
|
@@ -18,9 +22,12 @@ class RobotsService {
|
|
|
18
22
|
this.settings = {};
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
/**
|
|
26
|
+
* TODO: JSDoc
|
|
27
|
+
*/
|
|
21
28
|
private async getRobots() {
|
|
22
29
|
try {
|
|
23
|
-
const apiRobots = await get<Robots>({ endpoint: ROBOTS });
|
|
30
|
+
const apiRobots = await get<Robots>({ endpoint: endpoints.ROBOTS });
|
|
24
31
|
this.robots =
|
|
25
32
|
apiRobots
|
|
26
33
|
?.filter((r) => !!r.path)
|
|
@@ -37,7 +44,7 @@ class RobotsService {
|
|
|
37
44
|
* Write robots.txt files for the domain.
|
|
38
45
|
*/
|
|
39
46
|
async writeFiles(domain: string) {
|
|
40
|
-
const { __cx } =
|
|
47
|
+
const { __cx } = config.paths(domain);
|
|
41
48
|
const distDirectory = path.join(__cx, "dist");
|
|
42
49
|
|
|
43
50
|
await this.getRobots();
|
|
@@ -49,9 +56,9 @@ class RobotsService {
|
|
|
49
56
|
return;
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
if (
|
|
59
|
+
if (fs.existsSync(distDirectory)) {
|
|
53
60
|
const fileLocation = path.join(distDirectory, "robots.txt");
|
|
54
|
-
|
|
61
|
+
fs.writeFileSync(fileLocation, robot?.content);
|
|
55
62
|
verboseLog(`wrote robots.txt to ${fileLocation}`);
|
|
56
63
|
} else {
|
|
57
64
|
console.log(`${distDirectory} not found`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Settings } from "../types/global";
|
|
2
|
+
|
|
3
|
+
import { endpoints } from "../constants";
|
|
4
|
+
import { get, post } from "../utils/api";
|
|
5
|
+
|
|
6
|
+
async function getAllSettings() {
|
|
7
|
+
return get<Settings>({ endpoint: endpoints.SETTINGS });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function resetRender() {
|
|
11
|
+
await post({
|
|
12
|
+
endpoint: endpoints.RESET_RENDER,
|
|
13
|
+
useApiCacheDir: false,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { getAllSettings, resetRender };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Core } from "@griddo/core";
|
|
2
1
|
import type {
|
|
3
2
|
AllSitesReponse,
|
|
4
3
|
EndPageInfoResponse,
|
|
@@ -12,26 +11,17 @@ import type {
|
|
|
12
11
|
StartPageRenderResponse,
|
|
13
12
|
} from "../types/api";
|
|
14
13
|
import type { Site } from "../types/sites";
|
|
14
|
+
import type { Core } from "@griddo/core";
|
|
15
15
|
|
|
16
|
-
import {
|
|
17
|
-
BUILD_END,
|
|
18
|
-
BUILD_START,
|
|
19
|
-
GET_ALL,
|
|
20
|
-
GET_PAGE,
|
|
21
|
-
GET_REFERENCE_FIELD_DATA,
|
|
22
|
-
GET_SITEMAP,
|
|
23
|
-
INFO,
|
|
24
|
-
LANGUAGES,
|
|
25
|
-
SOCIALS,
|
|
26
|
-
} from "../constants/endpoints";
|
|
16
|
+
import { endpoints } from "../constants";
|
|
27
17
|
import { get, post } from "../utils/api";
|
|
28
18
|
|
|
29
19
|
/**
|
|
30
20
|
* Get a list of site objects.
|
|
31
21
|
*/
|
|
32
22
|
async function getAllSites(domain: string) {
|
|
33
|
-
return get<AllSitesReponse>({
|
|
34
|
-
endpoint: `${GET_ALL}?domainSlug=${domain}`,
|
|
23
|
+
return await get<AllSitesReponse>({
|
|
24
|
+
endpoint: `${endpoints.GET_ALL}?domainSlug=${domain}`,
|
|
35
25
|
});
|
|
36
26
|
}
|
|
37
27
|
|
|
@@ -39,7 +29,7 @@ async function getAllSites(domain: string) {
|
|
|
39
29
|
* Get a list of site objects from a domain.
|
|
40
30
|
*/
|
|
41
31
|
async function getAllSitesFromDomain(domain: string) {
|
|
42
|
-
const allSites = await get<AllSitesReponse>({ endpoint: GET_ALL });
|
|
32
|
+
const allSites = await get<AllSitesReponse>({ endpoint: endpoints.GET_ALL });
|
|
43
33
|
|
|
44
34
|
if (allSites.length) {
|
|
45
35
|
for (const site of allSites) {
|
|
@@ -50,7 +40,8 @@ async function getAllSitesFromDomain(domain: string) {
|
|
|
50
40
|
site.domains = items
|
|
51
41
|
.filter(
|
|
52
42
|
(item) =>
|
|
53
|
-
item.domain &&
|
|
43
|
+
item.domain &&
|
|
44
|
+
(item.domain.slug === domain || item.domain.slug === `/${domain}`),
|
|
54
45
|
)
|
|
55
46
|
.map((item) => ({ [item.id]: `${item.domain.slug}${item.path}` }));
|
|
56
47
|
}
|
|
@@ -63,8 +54,8 @@ async function getAllSitesFromDomain(domain: string) {
|
|
|
63
54
|
* Fetch a page object from API.
|
|
64
55
|
*/
|
|
65
56
|
async function getPage(id: number, cacheKey: string) {
|
|
66
|
-
return get<PageResponse>({
|
|
67
|
-
endpoint: `${GET_PAGE}/${id}`,
|
|
57
|
+
return await get<PageResponse>({
|
|
58
|
+
endpoint: `${endpoints.GET_PAGE}/${id}`,
|
|
68
59
|
cacheKey,
|
|
69
60
|
});
|
|
70
61
|
}
|
|
@@ -73,27 +64,27 @@ async function getPage(id: number, cacheKey: string) {
|
|
|
73
64
|
* Get site info
|
|
74
65
|
*/
|
|
75
66
|
async function getSiteInfo(id: number, cacheKey = "") {
|
|
76
|
-
const [prefix, suffix] = INFO;
|
|
67
|
+
const [prefix, suffix] = endpoints.INFO;
|
|
77
68
|
|
|
78
|
-
return get<Site>({
|
|
69
|
+
return await get<Site>({
|
|
79
70
|
endpoint: `${prefix}${id}${suffix}`,
|
|
80
71
|
cacheKey,
|
|
81
72
|
});
|
|
82
73
|
}
|
|
83
74
|
|
|
84
75
|
async function getSiteLanguages(id: number, cacheKey = "") {
|
|
85
|
-
const [prefix, suffix] = LANGUAGES;
|
|
76
|
+
const [prefix, suffix] = endpoints.LANGUAGES;
|
|
86
77
|
|
|
87
|
-
return get<LanguagesResponse>({
|
|
78
|
+
return await get<LanguagesResponse>({
|
|
88
79
|
endpoint: `${prefix}${id}${suffix}`,
|
|
89
80
|
cacheKey,
|
|
90
81
|
});
|
|
91
82
|
}
|
|
92
83
|
|
|
93
84
|
async function startSiteRender(id: number) {
|
|
94
|
-
const [prefix, suffix] = BUILD_START;
|
|
85
|
+
const [prefix, suffix] = endpoints.BUILD_START;
|
|
95
86
|
|
|
96
|
-
return get<StartPageRenderResponse>({
|
|
87
|
+
return await get<StartPageRenderResponse>({
|
|
97
88
|
endpoint: `${prefix}${id}${suffix}`,
|
|
98
89
|
});
|
|
99
90
|
}
|
|
@@ -102,9 +93,9 @@ async function startSiteRender(id: number) {
|
|
|
102
93
|
* Send the end signal to API for a render site.
|
|
103
94
|
*/
|
|
104
95
|
async function endSiteRender(id: number, body: EndSiteRenderBody) {
|
|
105
|
-
const [prefix, suffix] = BUILD_END;
|
|
96
|
+
const [prefix, suffix] = endpoints.BUILD_END;
|
|
106
97
|
|
|
107
|
-
return post<EndPageInfoResponse>({
|
|
98
|
+
return await post<EndPageInfoResponse>({
|
|
108
99
|
endpoint: `${prefix}${id}${suffix}`,
|
|
109
100
|
body,
|
|
110
101
|
useApiCacheDir: false,
|
|
@@ -118,11 +109,11 @@ async function getReferenceFieldSiteData(
|
|
|
118
109
|
dataSiteId?: number,
|
|
119
110
|
dataLangID?: number,
|
|
120
111
|
) {
|
|
121
|
-
const [prefix, suffix] = GET_REFERENCE_FIELD_DATA;
|
|
112
|
+
const [prefix, suffix] = endpoints.GET_REFERENCE_FIELD_DATA;
|
|
122
113
|
const site = dataSiteId || page.site;
|
|
123
114
|
const lang = dataLangID || page.language;
|
|
124
115
|
|
|
125
|
-
return post<ReferenceFieldResponse>({
|
|
116
|
+
return await post<ReferenceFieldResponse>({
|
|
126
117
|
endpoint: `${prefix}${site}${suffix}`,
|
|
127
118
|
body,
|
|
128
119
|
headers: { lang },
|
|
@@ -130,20 +121,18 @@ async function getReferenceFieldSiteData(
|
|
|
130
121
|
});
|
|
131
122
|
}
|
|
132
123
|
|
|
133
|
-
async function getSitemap(
|
|
134
|
-
const
|
|
135
|
-
const [prefix, suffix] = GET_SITEMAP;
|
|
124
|
+
async function getSitemap(id: number) {
|
|
125
|
+
const [prefix, suffix] = endpoints.GET_SITEMAP;
|
|
136
126
|
|
|
137
127
|
return get<SitemapAPIResponse>({
|
|
138
|
-
endpoint: `${prefix}${
|
|
139
|
-
headers,
|
|
128
|
+
endpoint: `${prefix}${id}${suffix}`,
|
|
140
129
|
});
|
|
141
130
|
}
|
|
142
131
|
|
|
143
132
|
async function getSiteSocials(id: number, cacheKey = "") {
|
|
144
|
-
const [prefix, suffix] = SOCIALS;
|
|
133
|
+
const [prefix, suffix] = endpoints.SOCIALS;
|
|
145
134
|
|
|
146
|
-
return get<SocialsResponse>({
|
|
135
|
+
return await get<SocialsResponse>({
|
|
147
136
|
endpoint: `${prefix}${id}${suffix}`,
|
|
148
137
|
cacheKey,
|
|
149
138
|
});
|