@griddo/cx 10.3.13 → 10.3.15
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 +53 -30
- package/build/build-complete.js +24 -20
- package/build/download-data.js +53 -0
- package/build/index.js +35 -47
- package/build/reset-render.js +25 -21
- package/exporter/adapters/astro/index.ts +37 -0
- package/exporter/adapters/astro/utils.ts +29 -0
- package/exporter/adapters/gatsby/index.ts +86 -0
- package/exporter/adapters/gatsby/utils.ts +352 -0
- package/exporter/adapters/index.ts +5 -0
- package/{scripts → exporter}/build-complete.ts +16 -14
- package/exporter/download-data.ts +6 -0
- package/exporter/index-width-adapter.ts +25 -0
- package/exporter/index.ts +14 -0
- package/exporter/reset-render.ts +12 -0
- package/{src → exporter}/services/auth.ts +0 -2
- package/{src → exporter}/services/distributors.ts +10 -1
- package/{src → exporter}/services/robots.ts +9 -6
- package/exporter/services/store.ts +351 -0
- package/{src → exporter}/types/api.ts +6 -0
- package/{src → exporter}/types/pages.ts +18 -17
- package/{src → exporter}/types/sites.ts +1 -1
- package/{src → exporter}/utils/api.ts +10 -7
- package/{src → exporter}/utils/cache.ts +14 -8
- package/{src → exporter}/utils/domains.ts +3 -3
- package/exporter/utils/download-build-data.ts +22 -0
- package/exporter/utils/folders.ts +49 -0
- package/{src → exporter}/utils/health-checks.ts +8 -7
- package/{src → exporter}/utils/instance.ts +1 -1
- package/{src/utils/integrations.tsx → exporter/utils/integrations.ts} +6 -4
- package/{src → exporter}/utils/pages.ts +21 -24
- package/exporter/utils/runners.ts +53 -0
- package/{src → exporter}/utils/shared.ts +31 -29
- package/{src → exporter}/utils/sites.ts +7 -7
- package/exporter/utils/store.ts +56 -0
- package/gatsby-config.ts +1 -1
- package/gatsby-node.ts +38 -72
- package/index.js +4 -1
- package/package.json +13 -10
- package/src/README.md +7 -0
- package/src/components/Head.tsx +3 -3
- package/src/components/template.tsx +3 -4
- package/src/gatsby-node-utils.ts +154 -0
- package/src/html.tsx +1 -1
- package/src/types.ts +98 -0
- package/src/{components/utils.ts → utils.ts} +6 -8
- package/static/robots.txt +1 -0
- package/scripts/griddo-exporter.ts +0 -431
- package/scripts/reset-render.ts +0 -9
- package/src/components/types.ts +0 -40
- package/src/services/store.ts +0 -423
- package/src/utils/folders.ts +0 -125
- package/src/utils/gatsby.ts +0 -47
- /package/{src → exporter}/services/domains.ts +0 -0
- /package/{src → exporter}/services/navigation.ts +0 -0
- /package/{src → exporter}/services/settings.ts +0 -0
- /package/{src → exporter}/services/sites.ts +0 -0
- /package/{src → exporter}/types/global.ts +0 -0
- /package/{src → exporter}/types/navigation.ts +0 -0
- /package/{src → exporter}/types/templates.ts +0 -0
- /package/{src → exporter}/utils/searches.ts +0 -0
package/src/components/Head.tsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { CustomHeadProps } from "
|
|
1
|
+
import type { CustomHeadProps } from "../types";
|
|
2
2
|
|
|
3
3
|
// @ts-expect-error components is unknown
|
|
4
4
|
import { generateAutomaticDimensions } from "components";
|
|
5
5
|
import parse from "html-react-parser";
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { filterHeadIntegrations } from "../../exporter/utils/integrations";
|
|
9
|
+
import { cleanCommaSeparated, composeAnalytics, formatImage } from "../utils";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Gatsby Head API
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { TemplateProps } from "
|
|
2
|
-
import type { Core } from "@griddo/core";
|
|
1
|
+
import type { TemplateProps } from "../types";
|
|
3
2
|
|
|
4
|
-
import { Page as RenderGriddoPage } from "@griddo/core";
|
|
3
|
+
import { Core, Page as RenderGriddoPage } from "@griddo/core";
|
|
5
4
|
// @ts-expect-error components is unknown
|
|
6
5
|
import { components, SiteProvider, templates } from "components";
|
|
7
6
|
import { Link, navigate } from "gatsby";
|
|
@@ -9,7 +8,7 @@ import parse from "html-react-parser";
|
|
|
9
8
|
import * as React from "react";
|
|
10
9
|
import { Helmet } from "react-helmet";
|
|
11
10
|
|
|
12
|
-
import { filterPositionIntegrations } from "
|
|
11
|
+
import { filterPositionIntegrations } from "../../exporter/utils/integrations";
|
|
13
12
|
|
|
14
13
|
// Gatsby Head
|
|
15
14
|
export { Head } from "./Head";
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { GatsbyNode } from "gatsby";
|
|
2
|
+
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
IS_COMPONENT_LIBRARY,
|
|
9
|
+
PROJECT_ALIASES,
|
|
10
|
+
resolveComponentsPath,
|
|
11
|
+
} from "../exporter/utils/instance";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copy the instance's `/static` folder into the Gatsby's to include it in the render assets.
|
|
15
|
+
*/
|
|
16
|
+
function prepareStaticFolder() {
|
|
17
|
+
const src = resolveComponentsPath("static");
|
|
18
|
+
const dest = "./static";
|
|
19
|
+
|
|
20
|
+
const files = fs.readdirSync(src);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
files.map(async (file) => {
|
|
24
|
+
const fileSrc = `${src}/${file}`;
|
|
25
|
+
const fileDest = `${dest}/${file}`;
|
|
26
|
+
fs.copySync(fileSrc, fileDest);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.info("Components static folder copied");
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error(err);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Update the Griddo's `/dist` folder with the contents from `/public` only with files of type:
|
|
37
|
+
* - js
|
|
38
|
+
* - json
|
|
39
|
+
* - css
|
|
40
|
+
*/
|
|
41
|
+
async function updateDist() {
|
|
42
|
+
const src = "./public";
|
|
43
|
+
const dest = "./dist";
|
|
44
|
+
|
|
45
|
+
const domainDestPath = `${dest}/${process.env.DOMAIN}`;
|
|
46
|
+
|
|
47
|
+
const files = fs
|
|
48
|
+
.readdirSync(src)
|
|
49
|
+
.filter(
|
|
50
|
+
(file) =>
|
|
51
|
+
path.extname(file) === ".js" ||
|
|
52
|
+
path.extname(file) === ".json" ||
|
|
53
|
+
path.extname(file) === ".css"
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const assetsDest = "./assets";
|
|
57
|
+
|
|
58
|
+
const pageDataSrc = `${src}/page-data`;
|
|
59
|
+
const pageDataDest = `${assetsDest}/page-data`;
|
|
60
|
+
|
|
61
|
+
const projectStaticSrc = "./static";
|
|
62
|
+
const projectStaticDest = assetsDest;
|
|
63
|
+
|
|
64
|
+
const gatsbyStaticSrc = `${dest}/static`;
|
|
65
|
+
const gatsbyStaticDest = `${assetsDest}/static`;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
fs.mkdirSync(assetsDest, { recursive: true });
|
|
69
|
+
fs.copySync(src, dest);
|
|
70
|
+
|
|
71
|
+
if (process.env.NEEDS_ASSET_DOMAIN_PREFIX) {
|
|
72
|
+
fs.copySync(pageDataSrc, pageDataDest);
|
|
73
|
+
fs.copySync(projectStaticSrc, projectStaticDest, { overwrite: false });
|
|
74
|
+
fs.copySync(gatsbyStaticSrc, gatsbyStaticDest, { overwrite: false });
|
|
75
|
+
fs.copySync(projectStaticSrc, domainDestPath, { overwrite: false });
|
|
76
|
+
|
|
77
|
+
files.map(async (file) => {
|
|
78
|
+
const fileSrc = `${src}/${file}`;
|
|
79
|
+
const fileDest = `${assetsDest}/${file}`;
|
|
80
|
+
fs.copySync(fileSrc, fileDest);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
console.error(err);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const onCreateWebpackConfig: GatsbyNode["onCreateWebpackConfig"] = ({
|
|
89
|
+
actions,
|
|
90
|
+
plugins,
|
|
91
|
+
loaders,
|
|
92
|
+
getConfig,
|
|
93
|
+
stage,
|
|
94
|
+
}) => {
|
|
95
|
+
if (IS_COMPONENT_LIBRARY) {
|
|
96
|
+
const config = getConfig();
|
|
97
|
+
config.module.rules = [
|
|
98
|
+
// Omit the default rule where test === '\.jsx?$'
|
|
99
|
+
...config.module.rules.filter(
|
|
100
|
+
(rule: { test: string }) => String(rule.test) !== String(/\.jsx?$/)
|
|
101
|
+
),
|
|
102
|
+
// Recreate it with custom exclude filter
|
|
103
|
+
{
|
|
104
|
+
...loaders.js(),
|
|
105
|
+
test: /\.jsx?$/,
|
|
106
|
+
// Exclude all node_modules from transpilation, except for '@griddo/cx'
|
|
107
|
+
exclude: (modulePath: string) =>
|
|
108
|
+
/node_modules/.test(modulePath) && !/@griddo\/cx/.test(modulePath),
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
actions.replaceWebpackConfig(config);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Add component-system aliases to Webpack's Resolve:
|
|
115
|
+
actions.setWebpackConfig({
|
|
116
|
+
resolve: {
|
|
117
|
+
fallback: { path: false },
|
|
118
|
+
alias: PROJECT_ALIASES,
|
|
119
|
+
},
|
|
120
|
+
plugins: [plugins.provide({ process: "process/browser", React: "react" })],
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// No sourcemaps on builds
|
|
124
|
+
if (stage === "build-javascript") {
|
|
125
|
+
actions.setWebpackConfig({ devtool: false });
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
function getGatsbyAssetPrefixSlug(domain: string) {
|
|
130
|
+
const assetPrefix =
|
|
131
|
+
process.env.GRIDDO_ASSET_PREFIX || process.env.ASSET_PREFIX;
|
|
132
|
+
|
|
133
|
+
if (!assetPrefix || !domain) return "";
|
|
134
|
+
if (!domain.startsWith("pro-")) return "";
|
|
135
|
+
|
|
136
|
+
return `${assetPrefix}/${domain}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getMatchPath(domain: string, compose: string) {
|
|
140
|
+
const domainWithNoSlashes = domain.replace("/", "");
|
|
141
|
+
const assetPrefix = getGatsbyAssetPrefixSlug(domainWithNoSlashes);
|
|
142
|
+
const needsAssetDomainPrefix = assetPrefix && assetPrefix !== "";
|
|
143
|
+
const matchPath = needsAssetDomainPrefix ? compose : "";
|
|
144
|
+
|
|
145
|
+
return matchPath;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export {
|
|
149
|
+
getMatchPath,
|
|
150
|
+
onCreateWebpackConfig,
|
|
151
|
+
prepareStaticFolder,
|
|
152
|
+
updateDist,
|
|
153
|
+
getGatsbyAssetPrefixSlug,
|
|
154
|
+
};
|
package/src/html.tsx
CHANGED
package/src/types.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { SocialsResponse } from "../exporter/types/api";
|
|
2
|
+
import type {
|
|
3
|
+
AdditionalInfo,
|
|
4
|
+
GriddoListPage,
|
|
5
|
+
GriddoMultiPage,
|
|
6
|
+
GriddoPageObject,
|
|
7
|
+
GriddoSinglePage,
|
|
8
|
+
} from "../exporter/types/pages";
|
|
9
|
+
import type { Site } from "../exporter/types/sites";
|
|
10
|
+
import type { Core } from "@griddo/core";
|
|
11
|
+
import type { HeadProps } from "gatsby";
|
|
12
|
+
|
|
13
|
+
export interface CustomHeadProps extends HeadProps {
|
|
14
|
+
pageContext: GriddoPageObject["context"] & {
|
|
15
|
+
page: Core.Page & {
|
|
16
|
+
defaultLang: { id: number };
|
|
17
|
+
dimensions: Dimensions;
|
|
18
|
+
disableHrefLangs: Array<number>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TemplateProps extends Omit<GriddoPageObject, "context"> {
|
|
24
|
+
pageContext: GriddoPageObject["context"] & {
|
|
25
|
+
page: Core.Page;
|
|
26
|
+
};
|
|
27
|
+
location: {
|
|
28
|
+
pathname: string;
|
|
29
|
+
search: string;
|
|
30
|
+
hash: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface HtmlProps {
|
|
35
|
+
body: string;
|
|
36
|
+
bodyAttributes: React.HtmlHTMLAttributes<HTMLBodyElement>;
|
|
37
|
+
headComponents: React.ReactNode;
|
|
38
|
+
htmlAttributes: React.HtmlHTMLAttributes<HTMLHtmlElement>;
|
|
39
|
+
postBodyComponents: React.ReactNode;
|
|
40
|
+
preBodyComponents: React.ReactNode;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface Dimensions {
|
|
44
|
+
values: Record<string, string> | null;
|
|
45
|
+
contentSelect?: "group" | "individual" | null;
|
|
46
|
+
groupSelect?: string;
|
|
47
|
+
dimensionsSelect?: Array<string>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// TODO: JSDoc
|
|
51
|
+
export type GatsbyPageObject = {
|
|
52
|
+
matchPath?: string;
|
|
53
|
+
path: string;
|
|
54
|
+
component: string;
|
|
55
|
+
/** Page size in bytes */
|
|
56
|
+
size?: number;
|
|
57
|
+
context: {
|
|
58
|
+
// Page
|
|
59
|
+
BUILD_MODE?: string;
|
|
60
|
+
cloudinaryName?: string;
|
|
61
|
+
footer: Record<string, unknown> | null;
|
|
62
|
+
fullPath: Core.Page["fullPath"];
|
|
63
|
+
griddoVersion: string;
|
|
64
|
+
renderDate: string;
|
|
65
|
+
header: Record<string, unknown> | null;
|
|
66
|
+
id?: number;
|
|
67
|
+
languageId: number;
|
|
68
|
+
locale?: string;
|
|
69
|
+
openGraph: {
|
|
70
|
+
description?: string;
|
|
71
|
+
image?: string | null;
|
|
72
|
+
title?: string;
|
|
73
|
+
twitterImage?: string | null;
|
|
74
|
+
type: "website";
|
|
75
|
+
};
|
|
76
|
+
pageMetadata: {
|
|
77
|
+
canonical?: string | undefined;
|
|
78
|
+
description?: string;
|
|
79
|
+
follow?: "follow" | "nofollow";
|
|
80
|
+
index: "index" | "noindex";
|
|
81
|
+
locale?: string;
|
|
82
|
+
metaKeywords?: string;
|
|
83
|
+
metasAdvanced?: string;
|
|
84
|
+
pageLanguages?: Core.Page["pageLanguages"];
|
|
85
|
+
title?: string;
|
|
86
|
+
translate?: "notranslate" | "";
|
|
87
|
+
url?: string;
|
|
88
|
+
};
|
|
89
|
+
siteMetadata: Site["siteMetadata"];
|
|
90
|
+
theme: string;
|
|
91
|
+
title: string;
|
|
92
|
+
siteLangs: Array<Core.SiteLanguage>;
|
|
93
|
+
siteOptions: AdditionalInfo["siteOptions"];
|
|
94
|
+
siteScript: string;
|
|
95
|
+
socials: SocialsResponse;
|
|
96
|
+
page: GriddoSinglePage | GriddoListPage | GriddoMultiPage;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// Only browser environment code
|
|
1
|
+
// Only browser environment code, not node.
|
|
2
2
|
//
|
|
3
|
-
// Don't write node code (fs, path, etc..) in this
|
|
4
|
-
// `template.tsx` in a browser environment and node doesn't
|
|
5
|
-
// If
|
|
3
|
+
// Don't write node code (fs, path, etc..) in this file because is imported by
|
|
4
|
+
// `template.tsx` in a browser environment and node doesn't exist there.
|
|
5
|
+
// If you need to write utils, for example for `gatsby-node.ts` that uses node
|
|
6
|
+
// packages write them in `gatsby-node-utils.ts`.
|
|
6
7
|
//
|
|
7
|
-
// Browserify doesn't work with the mixture of typescript + webpack 5 + SSR
|
|
8
|
+
// NOTE: Browserify doesn't work with the mixture of typescript + webpack 5 + SSR
|
|
8
9
|
|
|
9
10
|
import type { Dimensions } from "./types";
|
|
10
11
|
import type { Fields } from "@griddo/core";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
14
|
* Sanitize a string separated by commas.
|
|
15
15
|
*/
|
|
16
16
|
export function cleanCommaSeparated(str: string) {
|
|
@@ -136,8 +136,6 @@ export function composeAnalytics(
|
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
138
|
* Return true if the argument is an object (not null)
|
|
139
|
-
*
|
|
140
|
-
* @param any value
|
|
141
139
|
*/
|
|
142
140
|
export function isObject(value: unknown) {
|
|
143
141
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
package/static/robots.txt
CHANGED