@griddo/cx 11.9.12-rc.0 → 11.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +240 -13
- package/build/adapters/gatsby/index.d.ts +4 -0
- package/build/adapters/gatsby/utils.d.ts +26 -0
- package/build/artifacts/index.d.ts +6 -0
- package/build/commands/end-render.d.ts +1 -0
- package/build/commands/reset-render.d.ts +1 -0
- package/build/commands/start-render.d.ts +1 -0
- package/build/commands/upload-search-content.d.ts +1 -0
- package/build/constants/envs.d.ts +37 -0
- package/build/constants/index.d.ts +57 -0
- package/build/end-render.js +74 -0
- package/build/end-render.js.map +7 -0
- package/build/{shared/errors.d.ts → errors/errors-data.d.ts} +3 -5
- package/build/errors/index.d.ts +15 -0
- package/build/index.d.ts +29 -10
- package/build/index.js +73 -406
- package/build/index.js.map +7 -0
- package/build/prepare-domains-render.js +73 -0
- package/build/prepare-domains-render.js.map +7 -0
- package/build/react/Favicon/index.d.ts +5 -0
- package/build/react/GriddoIntegrations/index.d.ts +4 -3
- package/build/react/GriddoIntegrations/utils.d.ts +6 -7
- package/build/react/index.d.ts +2 -3
- package/build/react/index.js +3 -1
- package/build/registers/api.d.ts +9 -0
- package/build/registers/gatsby.d.ts +9 -0
- package/build/registers/index.d.ts +3 -0
- package/build/reset-render.js +74 -0
- package/build/reset-render.js.map +7 -0
- package/build/services/auth.d.ts +5 -2
- package/build/services/domains.d.ts +4 -3
- package/build/services/navigation.d.ts +16 -16
- package/build/services/reference-fields.d.ts +3 -3
- package/build/services/register.d.ts +36 -0
- package/build/services/robots.d.ts +19 -2
- package/build/services/settings.d.ts +4 -0
- package/build/services/sites.d.ts +5 -8
- package/build/services/store.d.ts +1 -10
- package/build/start-render.js +100 -0
- package/build/start-render.js.map +7 -0
- package/build/{shared/types → types}/api.d.ts +18 -18
- package/build/{shared/types → types}/global.d.ts +16 -15
- package/build/{shared/types → types}/navigation.d.ts +5 -5
- package/build/{shared/types → types}/pages.d.ts +9 -9
- package/build/{shared/types → types}/sites.d.ts +19 -18
- package/build/upload-search-content.js +74 -0
- package/build/upload-search-content.js.map +7 -0
- package/build/utils/alerts.d.ts +3 -0
- package/build/{services → utils}/api.d.ts +1 -1
- package/build/utils/cache.d.ts +35 -0
- package/build/utils/core-utils.d.ts +107 -0
- package/build/utils/create-build-data.d.ts +8 -0
- package/build/utils/domains.d.ts +13 -0
- package/build/utils/folders.d.ts +53 -0
- package/build/{core/check-env-health.d.ts → utils/health-checks.d.ts} +2 -4
- package/build/utils/loggin.d.ts +51 -0
- package/build/{services → utils}/pages.d.ts +3 -3
- package/build/utils/render.d.ts +13 -0
- package/build/utils/searches.d.ts +15 -0
- package/build/utils/sites.d.ts +31 -0
- package/build/utils/store.d.ts +81 -0
- package/cx.config.d.ts +5 -0
- package/cx.config.js +36 -0
- package/exporter/adapters/gatsby/index.ts +182 -0
- package/exporter/adapters/gatsby/utils.ts +186 -0
- package/exporter/artifacts/README.md +34 -0
- package/exporter/artifacts/index.ts +33 -0
- package/exporter/build.sh +24 -16
- package/exporter/commands/end-render.ts +86 -65
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +35 -132
- package/exporter/commands/reset-render.ts +8 -13
- package/exporter/commands/start-render.ts +64 -26
- package/exporter/commands/upload-search-content.ts +26 -204
- package/exporter/{shared → constants}/endpoints.ts +11 -12
- package/exporter/constants/envs.ts +94 -0
- package/exporter/constants/index.ts +129 -0
- package/exporter/{shared/errors.ts → errors/errors-data.ts} +14 -24
- package/exporter/errors/index.ts +40 -0
- package/exporter/index.ts +56 -14
- package/exporter/react/{GriddoFavicon → Favicon}/index.tsx +9 -3
- package/exporter/react/GriddoIntegrations/index.tsx +23 -17
- package/exporter/react/GriddoIntegrations/utils.ts +12 -24
- package/exporter/react/index.tsx +9 -3
- package/exporter/registers/api.ts +14 -0
- package/exporter/registers/gatsby.ts +14 -0
- package/exporter/registers/index.ts +4 -0
- package/exporter/services/auth.ts +10 -8
- package/exporter/services/domains.ts +8 -23
- package/exporter/services/navigation.ts +18 -12
- package/exporter/services/reference-fields.ts +32 -14
- package/exporter/services/register.ts +113 -0
- package/exporter/services/robots.ts +61 -33
- package/exporter/services/settings.ts +17 -0
- package/exporter/services/sites.ts +28 -40
- package/exporter/services/store.ts +321 -354
- package/exporter/{shared/types → types}/api.ts +41 -40
- package/exporter/{shared/types → types}/global.ts +21 -17
- package/exporter/{shared/types → types}/navigation.ts +3 -3
- package/exporter/{shared/types → types}/pages.ts +11 -10
- package/exporter/{shared/types → types}/sites.ts +19 -18
- package/exporter/utils/alerts.ts +29 -0
- package/exporter/utils/api.ts +243 -0
- package/exporter/utils/cache.ts +142 -0
- package/exporter/utils/core-utils.ts +458 -0
- package/exporter/utils/create-build-data.ts +17 -0
- package/exporter/utils/domains.ts +39 -0
- package/exporter/utils/folders.ts +320 -0
- package/exporter/utils/health-checks.ts +64 -0
- package/exporter/{core → utils}/images.ts +6 -1
- package/exporter/{core → utils}/instance.ts +13 -9
- package/exporter/utils/loggin.ts +184 -0
- package/exporter/{services → utils}/pages.ts +92 -27
- package/exporter/utils/render.ts +71 -0
- package/exporter/utils/searches.ts +156 -0
- package/exporter/utils/sites.ts +312 -0
- package/exporter/utils/store.ts +314 -0
- package/gatsby-browser.tsx +58 -41
- package/gatsby-config.ts +17 -10
- package/gatsby-node.ts +79 -20
- package/gatsby-ssr.tsx +1 -2
- package/package.json +80 -41
- package/src/README.md +7 -0
- package/src/components/Head.tsx +73 -28
- package/src/components/template.tsx +29 -6
- package/src/gatsby-node-utils.ts +2 -76
- package/src/html.tsx +11 -2
- package/src/types.ts +3 -3
- package/start-render.js +7 -0
- package/tsconfig.json +3 -5
- package/build/commands/end-render.js +0 -31
- package/build/commands/end-render.js.map +0 -7
- package/build/commands/prepare-assets-directory.js +0 -9
- package/build/commands/prepare-assets-directory.js.map +0 -7
- package/build/commands/prepare-domains-render.js +0 -38
- package/build/commands/prepare-domains-render.js.map +0 -7
- package/build/commands/reset-render.js +0 -31
- package/build/commands/reset-render.js.map +0 -7
- package/build/commands/single-domain-upload-search-content.d.ts +0 -1
- package/build/commands/start-render.js +0 -66
- package/build/commands/start-render.js.map +0 -7
- package/build/commands/upload-search-content.js +0 -32
- package/build/commands/upload-search-content.js.map +0 -7
- package/build/core/GriddoLog.d.ts +0 -16
- package/build/core/db-class.d.ts +0 -11
- package/build/core/db.d.ts +0 -4
- package/build/core/dist-rollback.d.ts +0 -11
- package/build/core/errors.d.ts +0 -26
- package/build/core/fs.d.ts +0 -69
- package/build/core/life-cycle.d.ts +0 -26
- package/build/core/logger.d.ts +0 -18
- package/build/core/objects.d.ts +0 -11
- package/build/core/print-logos.d.ts +0 -5
- package/build/react/DynamicScript/index.d.ts +0 -4
- package/build/react/GriddoFavicon/index.d.ts +0 -4
- package/build/react/GriddoOpenGraph/index.d.ts +0 -10
- package/build/services/manage-sites.d.ts +0 -22
- package/build/services/manage-store.d.ts +0 -32
- package/build/services/render-artifacts.d.ts +0 -6
- package/build/services/render.d.ts +0 -70
- package/build/services/sitemaps.d.ts +0 -5
- package/build/shared/context.d.ts +0 -36
- package/build/shared/envs.d.ts +0 -19
- package/build/shared/npm-modules/brush.d.ts +0 -18
- package/build/shared/npm-modules/find-up-simple.d.ts +0 -34
- package/build/shared/npm-modules/pkg-dir.d.ts +0 -7
- package/build/shared/npm-modules/xml-parser.d.ts +0 -4
- package/build/shared/types/render.d.ts +0 -54
- package/build/shared/types.d.ts +0 -15
- package/build/ssg-adapters/gatsby/actions/clean.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/close.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/data.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/init.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/logs.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/meta.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/prepare.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/relocation.d.ts +0 -2
- package/build/ssg-adapters/gatsby/actions/restore.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/ssg.d.ts +0 -3
- package/build/ssg-adapters/gatsby/actions/sync.d.ts +0 -3
- package/build/ssg-adapters/gatsby/index.d.ts +0 -9
- package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +0 -4
- package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +0 -15
- package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +0 -7
- package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +0 -7
- package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +0 -18
- package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +0 -26
- package/build/ssg-adapters/gatsby/shared/types.d.ts +0 -34
- package/cli.mjs +0 -231
- package/exporter/build-esbuild.noop +0 -42
- package/exporter/commands/README.md +0 -151
- package/exporter/commands/prepare-assets-directory.ts +0 -35
- package/exporter/commands/single-domain-upload-search-content.ts +0 -206
- package/exporter/core/GriddoLog.ts +0 -45
- package/exporter/core/check-env-health.ts +0 -204
- package/exporter/core/db-class.ts +0 -54
- package/exporter/core/db.ts +0 -33
- package/exporter/core/dist-rollback.ts +0 -49
- package/exporter/core/errors.ts +0 -93
- package/exporter/core/fs.ts +0 -385
- package/exporter/core/life-cycle.ts +0 -73
- package/exporter/core/logger.ts +0 -141
- package/exporter/core/objects.ts +0 -37
- package/exporter/core/print-logos.ts +0 -21
- package/exporter/react/DynamicScript/index.tsx +0 -33
- package/exporter/react/GriddoOpenGraph/index.tsx +0 -39
- package/exporter/services/api.ts +0 -306
- package/exporter/services/manage-sites.ts +0 -116
- package/exporter/services/manage-store.ts +0 -173
- package/exporter/services/render-artifacts.ts +0 -44
- package/exporter/services/render.ts +0 -229
- package/exporter/services/sitemaps.ts +0 -129
- package/exporter/shared/context.ts +0 -49
- package/exporter/shared/envs.ts +0 -62
- package/exporter/shared/npm-modules/README.md +0 -36
- package/exporter/shared/npm-modules/brush.ts +0 -34
- package/exporter/shared/npm-modules/find-up-simple.ts +0 -100
- package/exporter/shared/npm-modules/pkg-dir.ts +0 -17
- package/exporter/shared/npm-modules/xml-parser.ts +0 -57
- package/exporter/shared/types/render.ts +0 -63
- package/exporter/shared/types.ts +0 -15
- package/exporter/ssg-adapters/gatsby/actions/clean.ts +0 -26
- package/exporter/ssg-adapters/gatsby/actions/close.ts +0 -17
- package/exporter/ssg-adapters/gatsby/actions/data.ts +0 -22
- package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +0 -10
- package/exporter/ssg-adapters/gatsby/actions/init.ts +0 -12
- package/exporter/ssg-adapters/gatsby/actions/logs.ts +0 -10
- package/exporter/ssg-adapters/gatsby/actions/meta.ts +0 -13
- package/exporter/ssg-adapters/gatsby/actions/prepare.ts +0 -9
- package/exporter/ssg-adapters/gatsby/actions/relocation.ts +0 -15
- package/exporter/ssg-adapters/gatsby/actions/restore.ts +0 -21
- package/exporter/ssg-adapters/gatsby/actions/ssg.ts +0 -12
- package/exporter/ssg-adapters/gatsby/actions/sync.ts +0 -65
- package/exporter/ssg-adapters/gatsby/index.ts +0 -114
- package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +0 -17
- package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +0 -128
- package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +0 -75
- package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +0 -58
- package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +0 -33
- package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +0 -298
- package/exporter/ssg-adapters/gatsby/shared/types.ts +0 -35
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- package/tsconfig.commands.json +0 -36
- package/tsconfig.exporter.json +0 -21
- /package/build/commands/{prepare-assets-directory.d.ts → move-assets.d.ts} +0 -0
- /package/build/{shared → constants}/endpoints.d.ts +0 -0
- /package/build/react/{GriddoFavicon → Favicon}/utils.d.ts +0 -0
- /package/build/{shared/types → types}/templates.d.ts +0 -0
- /package/build/{core → utils}/images.d.ts +0 -0
- /package/build/{core → utils}/instance.d.ts +0 -0
- /package/exporter/react/{GriddoFavicon → Favicon}/utils.ts +0 -0
- /package/exporter/{shared/types → types}/templates.ts +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Footer, Header } from "../
|
|
2
|
-
import type { APIPageObject } from "../
|
|
1
|
+
import type { Footer, Header } from "../types/navigation";
|
|
2
|
+
import type { APIPageObject } from "../types/pages";
|
|
3
3
|
|
|
4
4
|
class NavigationService {
|
|
5
5
|
private _defaultHeaders: Record<string, Header>;
|
|
6
6
|
private _defaultFooters: Record<string, Footer>;
|
|
7
7
|
private _navigations: {
|
|
8
|
-
headers: Header
|
|
9
|
-
footers: Footer
|
|
8
|
+
headers: Array<Header>;
|
|
9
|
+
footers: Array<Footer>;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
constructor() {
|
|
@@ -53,11 +53,11 @@ class NavigationService {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
getRightLanguage(
|
|
56
|
-
list: {
|
|
56
|
+
list: Array<{
|
|
57
57
|
language: number;
|
|
58
|
-
navigationLanguages: { navigationId: number }
|
|
58
|
+
navigationLanguages: Array<{ navigationId: number }>;
|
|
59
59
|
id: number;
|
|
60
|
-
}
|
|
60
|
+
}>,
|
|
61
61
|
id: number,
|
|
62
62
|
language: number,
|
|
63
63
|
) {
|
|
@@ -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,15 +87,19 @@ 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 ...
|
|
94
100
|
// - The one defined for that template or ...
|
|
95
101
|
// - The one you have defined for that data package
|
|
96
|
-
const getValidNavigation = (values:
|
|
102
|
+
const getValidNavigation = (values: Array<number | unknown>) => {
|
|
97
103
|
const fineNavigation = values.find((item) => typeof item === "number");
|
|
98
104
|
|
|
99
105
|
return typeof fineNavigation === "number" ? fineNavigation : null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { FetchDataProps } from "../types/global";
|
|
2
|
+
import type { APIPageObject } from "../types/pages";
|
|
1
3
|
import type { Core, Fields } from "@griddo/core";
|
|
2
|
-
import type { FetchDataProps } from "../shared/types/global";
|
|
3
|
-
import type { APIPageObject } from "../shared/types/pages";
|
|
4
4
|
|
|
5
|
-
import { GriddoLog } from "../core/GriddoLog";
|
|
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
|
-
|
|
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,13 +71,17 @@ 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) {
|
|
77
|
-
|
|
82
|
+
boxLog(
|
|
78
83
|
`Error: Page ${page.id} has \`hasDistributorData: true\` or \`getStaticData: true\` but it doesn't have a \`data\` property.`,
|
|
84
|
+
"No `data` in `ReferenceField`",
|
|
79
85
|
);
|
|
80
86
|
|
|
81
87
|
return [];
|
|
@@ -83,8 +89,9 @@ async function fetchContentTypeData(props: FetchDataProps) {
|
|
|
83
89
|
|
|
84
90
|
// Avoid fetch ReferenceField with empty `data.sources`
|
|
85
91
|
if (Array.isArray(data.sources) && data.sources.length < 1) {
|
|
86
|
-
|
|
92
|
+
boxLog(
|
|
87
93
|
`Warning: Page with id: ${page.id} has a ReferenceField with empty \`data.sources\``,
|
|
94
|
+
"Empty data.sources in ReferenceField",
|
|
88
95
|
);
|
|
89
96
|
|
|
90
97
|
return [];
|
|
@@ -94,14 +101,21 @@ async function fetchContentTypeData(props: FetchDataProps) {
|
|
|
94
101
|
|
|
95
102
|
// Inform that the ReferenceField has not `data.sources`
|
|
96
103
|
if (!data.sources && data.mode === "auto") {
|
|
97
|
-
|
|
104
|
+
boxLog(
|
|
98
105
|
`Warning: Page with id: ${page.id} has a ReferenceField with \`undefined\` \`data.sources\``,
|
|
106
|
+
"undefined data.sources in ReferenceField",
|
|
99
107
|
);
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
const body = getBody(data, page);
|
|
103
111
|
|
|
104
|
-
const response = await getReferenceFieldSiteData(
|
|
112
|
+
const response = await getReferenceFieldSiteData(
|
|
113
|
+
page,
|
|
114
|
+
body,
|
|
115
|
+
cacheKey,
|
|
116
|
+
site,
|
|
117
|
+
lang,
|
|
118
|
+
);
|
|
105
119
|
|
|
106
120
|
return response;
|
|
107
121
|
}
|
|
@@ -151,7 +165,10 @@ async function getReferenceFieldData({
|
|
|
151
165
|
continue;
|
|
152
166
|
}
|
|
153
167
|
|
|
154
|
-
const _key = key as
|
|
168
|
+
const _key = key as
|
|
169
|
+
| "hasDistributorData"
|
|
170
|
+
| "queriedItems"
|
|
171
|
+
| "getStaticData";
|
|
155
172
|
const component = templateChunk[_key] as unknown as {
|
|
156
173
|
data: Fields.Reference<unknown>;
|
|
157
174
|
queriedItems: Fields.QueriedData<unknown>;
|
|
@@ -164,7 +181,8 @@ async function getReferenceFieldData({
|
|
|
164
181
|
continue;
|
|
165
182
|
}
|
|
166
183
|
|
|
167
|
-
const componentHasRequestForData =
|
|
184
|
+
const componentHasRequestForData =
|
|
185
|
+
component.hasDistributorData || component.getStaticData;
|
|
168
186
|
|
|
169
187
|
if (componentHasRequestForData) {
|
|
170
188
|
component.queriedItems = await fetchContentTypeData({
|
|
@@ -190,9 +208,9 @@ async function getReferenceFieldData({
|
|
|
190
208
|
|
|
191
209
|
return response;
|
|
192
210
|
} catch (err) {
|
|
193
|
-
|
|
211
|
+
console.error(`Error in getReferenceFieldData ${err}`);
|
|
194
212
|
|
|
195
|
-
|
|
213
|
+
process.exit(1);
|
|
196
214
|
}
|
|
197
215
|
}
|
|
198
216
|
|
|
@@ -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,43 +1,71 @@
|
|
|
1
|
-
import type { Robots } from "../
|
|
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 {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
async function fetchRobots() {
|
|
13
|
-
const apiRobots = await get<Robots>({ endpoint: ROBOTS });
|
|
14
|
-
return (
|
|
15
|
-
apiRobots
|
|
16
|
-
?.filter((r) => !!r.path)
|
|
17
|
-
.map(({ path, content }) => ({
|
|
18
|
-
path,
|
|
19
|
-
content: content || "User-agent: *\n\r\n\rAllow: /",
|
|
20
|
-
})) || []
|
|
21
|
-
);
|
|
22
|
-
}
|
|
6
|
+
import { endpoints } from "../constants";
|
|
7
|
+
import { get } from "../utils/api";
|
|
8
|
+
import { getConfig } from "../utils/core-utils";
|
|
9
|
+
import { verboseLog } from "../utils/loggin";
|
|
10
|
+
|
|
11
|
+
const config = getConfig();
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
/**
|
|
14
|
+
* TODO: JSDoc
|
|
15
|
+
*/
|
|
16
|
+
class RobotsService {
|
|
17
|
+
robots: Robots;
|
|
18
|
+
settings: Record<string, unknown>;
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
constructor() {
|
|
21
|
+
this.robots = [];
|
|
22
|
+
this.settings = {};
|
|
32
23
|
}
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
/**
|
|
26
|
+
* TODO: JSDoc
|
|
27
|
+
*/
|
|
28
|
+
private async getRobots() {
|
|
29
|
+
try {
|
|
30
|
+
const apiRobots = await get<Robots>({ endpoint: endpoints.ROBOTS });
|
|
31
|
+
this.robots =
|
|
32
|
+
apiRobots
|
|
33
|
+
?.filter((r) => !!r.path)
|
|
34
|
+
.map(({ path, content }) => ({
|
|
35
|
+
path,
|
|
36
|
+
content: content || "User-agent: *\n\r\n\rAllow: /",
|
|
37
|
+
})) || [];
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.warn(`${this.constructor.name}: ${(e as Error).message}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Write robots.txt files for the domain.
|
|
45
|
+
*/
|
|
46
|
+
async writeFiles(domain: string) {
|
|
47
|
+
const { __cx } = config.paths(domain);
|
|
48
|
+
const distDirectory = path.join(__cx, "dist");
|
|
49
|
+
|
|
50
|
+
await this.getRobots();
|
|
51
|
+
|
|
52
|
+
const robot = this.robots.find(({ path }) => path === `/${domain}`);
|
|
53
|
+
|
|
54
|
+
if (!robot) {
|
|
55
|
+
console.log(`Robots not found for ${domain}`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (fs.existsSync(distDirectory)) {
|
|
60
|
+
const fileLocation = path.join(distDirectory, "robots.txt");
|
|
61
|
+
fs.writeFileSync(fileLocation, robot?.content);
|
|
62
|
+
verboseLog(`wrote robots.txt to ${fileLocation}`);
|
|
63
|
+
} else {
|
|
64
|
+
console.log(`${distDirectory} not found`);
|
|
65
|
+
}
|
|
40
66
|
}
|
|
41
67
|
}
|
|
42
68
|
|
|
43
|
-
|
|
69
|
+
const robotsService = new RobotsService();
|
|
70
|
+
|
|
71
|
+
export { robotsService as RobotsService };
|
|
@@ -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,
|
|
@@ -10,28 +9,19 @@ import type {
|
|
|
10
9
|
SitemapAPIResponse,
|
|
11
10
|
SocialsResponse,
|
|
12
11
|
StartPageRenderResponse,
|
|
13
|
-
} from "../
|
|
14
|
-
import type { Site } from "../
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
GET_ALL,
|
|
20
|
-
GET_PAGE,
|
|
21
|
-
GET_REFERENCE_FIELD_DATA,
|
|
22
|
-
GET_SITEMAP,
|
|
23
|
-
INFO,
|
|
24
|
-
LANGUAGES,
|
|
25
|
-
SOCIALS,
|
|
26
|
-
} from "../shared/endpoints";
|
|
27
|
-
import { get, post } from "./api";
|
|
12
|
+
} from "../types/api";
|
|
13
|
+
import type { Site } from "../types/sites";
|
|
14
|
+
import type { Core } from "@griddo/core";
|
|
15
|
+
|
|
16
|
+
import { endpoints } from "../constants";
|
|
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,13 +93,12 @@ 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
|
-
await post<EndPageInfoResponse>({
|
|
98
|
+
return await post<EndPageInfoResponse>({
|
|
108
99
|
endpoint: `${prefix}${id}${suffix}`,
|
|
109
100
|
body,
|
|
110
101
|
useApiCacheDir: false,
|
|
111
|
-
logToFile: false,
|
|
112
102
|
});
|
|
113
103
|
}
|
|
114
104
|
|
|
@@ -119,11 +109,11 @@ async function getReferenceFieldSiteData(
|
|
|
119
109
|
dataSiteId?: number,
|
|
120
110
|
dataLangID?: number,
|
|
121
111
|
) {
|
|
122
|
-
const [prefix, suffix] = GET_REFERENCE_FIELD_DATA;
|
|
112
|
+
const [prefix, suffix] = endpoints.GET_REFERENCE_FIELD_DATA;
|
|
123
113
|
const site = dataSiteId || page.site;
|
|
124
114
|
const lang = dataLangID || page.language;
|
|
125
115
|
|
|
126
|
-
return post<ReferenceFieldResponse>({
|
|
116
|
+
return await post<ReferenceFieldResponse>({
|
|
127
117
|
endpoint: `${prefix}${site}${suffix}`,
|
|
128
118
|
body,
|
|
129
119
|
headers: { lang },
|
|
@@ -131,20 +121,18 @@ async function getReferenceFieldSiteData(
|
|
|
131
121
|
});
|
|
132
122
|
}
|
|
133
123
|
|
|
134
|
-
async function getSitemap(
|
|
135
|
-
const
|
|
136
|
-
const [prefix, suffix] = GET_SITEMAP;
|
|
124
|
+
async function getSitemap(id: number) {
|
|
125
|
+
const [prefix, suffix] = endpoints.GET_SITEMAP;
|
|
137
126
|
|
|
138
127
|
return get<SitemapAPIResponse>({
|
|
139
|
-
endpoint: `${prefix}${
|
|
140
|
-
headers,
|
|
128
|
+
endpoint: `${prefix}${id}${suffix}`,
|
|
141
129
|
});
|
|
142
130
|
}
|
|
143
131
|
|
|
144
132
|
async function getSiteSocials(id: number, cacheKey = "") {
|
|
145
|
-
const [prefix, suffix] = SOCIALS;
|
|
133
|
+
const [prefix, suffix] = endpoints.SOCIALS;
|
|
146
134
|
|
|
147
|
-
return get<SocialsResponse>({
|
|
135
|
+
return await get<SocialsResponse>({
|
|
148
136
|
endpoint: `${prefix}${id}${suffix}`,
|
|
149
137
|
cacheKey,
|
|
150
138
|
});
|