@griddo/cx 10.4.8 → 10.4.9
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/build/create-build-data.js +18 -18
- package/build/index.js +42 -40
- package/exporter/adapters/gatsby/index.ts +67 -15
- package/exporter/adapters/gatsby/utils.ts +1 -5
- package/exporter/adapters/index.ts +2 -3
- package/exporter/services/robots.ts +12 -9
- package/exporter/services/store.ts +1 -1
- package/exporter/types/global.ts +7 -1
- package/exporter/utils/folders.ts +18 -46
- package/exporter/utils/instance.ts +5 -2
- package/exporter/utils/shared.ts +1 -1
- package/exporter/utils/sites.ts +21 -15
- package/exporter/utils/store.ts +7 -2
- package/exporter/utils/temp-utils.ts +74 -1
- package/gatsby-browser.tsx +1 -2
- package/gatsby-config.ts +2 -1
- package/gatsby-node.ts +18 -47
- package/gatsby-ssr.tsx +1 -2
- package/package.json +2 -2
- package/src/components/Head.tsx +1 -2
- package/src/components/template.tsx +1 -2
- package/src/gatsby-node-utils.ts +1 -57
- package/exporter/adapters/astro/index.ts +0 -36
- package/exporter/adapters/astro/utils.ts +0 -30
- package/exporter/index-width-adapter.ts +0 -25
- package/static/.gitkeep +0 -0
- package/static/README.md +0 -3
- package/static/fonts/dm-sans/dm-sans-v14-latin-500.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-500italic.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-600.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-600italic.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-700.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-700italic.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-800.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-800italic.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-900.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-900italic.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-italic.woff2 +0 -0
- package/static/fonts/dm-sans/dm-sans-v14-latin-regular.woff2 +0 -0
- package/static/fonts/dm-serif-display/dm-serif-display-v15-latin-italic.woff2 +0 -0
- package/static/fonts/dm-serif-display/dm-serif-display-v15-latin-regular.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-Black.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-BlackItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-Bold.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-BoldItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-ExtraBold.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-ExtraBoldItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-Heavy.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-HeavyItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-Light.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-LightItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-Medium.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-MediumItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-Regular.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-RegularItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-SemiBold.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-SemiBoldItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-Thin.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-ThinItalic.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-UltraLight.woff2 +0 -0
- package/static/fonts/gilroy/Gilroy-UltraLightItalic.woff2 +0 -0
- package/static/fonts/work-sans/work-sans-v17-latin-700.woff +0 -0
- package/static/fonts/work-sans/work-sans-v17-latin-700.woff2 +0 -0
- package/static/fonts/work-sans/work-sans-v17-latin-regular.woff +0 -0
- package/static/fonts/work-sans/work-sans-v17-latin-regular.woff2 +0 -0
- package/static/grisso.css +0 -1
- package/static/robots.txt +0 -3
- package/static/webfonts.css +0 -115
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
import { attempts, getGatsbyDomainRunner } from "./utils";
|
|
2
|
+
import { getGatsbyAssetPrefixSlug } from "../../../src/gatsby-node-utils";
|
|
3
|
+
import { RobotsService } from "../../services/robots";
|
|
2
4
|
import { getInstanceDomains } from "../../utils/domains";
|
|
3
5
|
import { createBuildData } from "../../utils/download-build-data";
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
clearEmptyDirs,
|
|
8
|
+
copyArtifacts,
|
|
9
|
+
removeArtifacts,
|
|
10
|
+
removeMultiPagesFromStore,
|
|
11
|
+
} from "../../utils/folders";
|
|
5
12
|
import { uploadSearchContentToAPI } from "../../utils/searches";
|
|
6
13
|
import { doLifeCycle, pause, printExporterLogo } from "../../utils/shared";
|
|
14
|
+
import { generateBuildReport, generateSitemaps } from "../../utils/sites";
|
|
15
|
+
import {
|
|
16
|
+
getConfig,
|
|
17
|
+
legacy__createDistFromGatsbyPublic,
|
|
18
|
+
} from "../../utils/temp-utils";
|
|
7
19
|
|
|
8
20
|
async function runGatsbyAdapter() {
|
|
9
21
|
printExporterLogo("gatsby");
|
|
10
22
|
|
|
11
23
|
const domains = await getInstanceDomains();
|
|
24
|
+
const config = await getConfig();
|
|
12
25
|
|
|
13
26
|
for (const domain of domains) {
|
|
14
27
|
const runner = getGatsbyDomainRunner(domain);
|
|
28
|
+
const { __components, __cx } = config.dirs(domain);
|
|
29
|
+
const assetPrefix = getGatsbyAssetPrefixSlug(domain);
|
|
30
|
+
const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Prepare
|
|
34
|
+
*/
|
|
35
|
+
await doLifeCycle({
|
|
36
|
+
name: "Prepare",
|
|
37
|
+
steps: [
|
|
38
|
+
() =>
|
|
39
|
+
copyArtifacts({
|
|
40
|
+
artifacts: ["static"],
|
|
41
|
+
from: __components,
|
|
42
|
+
to: __cx,
|
|
43
|
+
}),
|
|
44
|
+
runner.init,
|
|
45
|
+
() => pause("Prepared LifeCycle"),
|
|
46
|
+
],
|
|
47
|
+
attempts: attempts.prepare,
|
|
48
|
+
});
|
|
15
49
|
|
|
16
50
|
/**
|
|
17
51
|
* Restore
|
|
@@ -22,12 +56,9 @@ async function runGatsbyAdapter() {
|
|
|
22
56
|
name: "Restore",
|
|
23
57
|
attempts: attempts.restore,
|
|
24
58
|
steps: [
|
|
25
|
-
runner.init,
|
|
26
|
-
() => pause("init done!"),
|
|
27
59
|
runner.restoreArtifacts,
|
|
28
|
-
() => pause("Restore `dist` and `assets` dirs done!"),
|
|
29
60
|
runner.restoreCacheArtifacts,
|
|
30
|
-
() => pause("Restore
|
|
61
|
+
() => pause("Restore LifeCycle"),
|
|
31
62
|
],
|
|
32
63
|
});
|
|
33
64
|
|
|
@@ -40,10 +71,7 @@ async function runGatsbyAdapter() {
|
|
|
40
71
|
await doLifeCycle({
|
|
41
72
|
name: "Data",
|
|
42
73
|
attempts: attempts.data,
|
|
43
|
-
steps: [
|
|
44
|
-
() => createBuildData(domain),
|
|
45
|
-
() => pause("Download data from API to `store` done!"),
|
|
46
|
-
],
|
|
74
|
+
steps: [() => createBuildData(domain), () => pause("Data LifeCycle")],
|
|
47
75
|
});
|
|
48
76
|
|
|
49
77
|
/**
|
|
@@ -56,7 +84,18 @@ async function runGatsbyAdapter() {
|
|
|
56
84
|
await doLifeCycle({
|
|
57
85
|
name: "SSG",
|
|
58
86
|
attempts: attempts.ssg,
|
|
59
|
-
steps: [runner.runGatsbyBuild, () => pause("
|
|
87
|
+
steps: [runner.runGatsbyBuild, () => pause("SSG LifeCycle")],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Relocation
|
|
92
|
+
*/
|
|
93
|
+
await doLifeCycle({
|
|
94
|
+
name: "Relocation",
|
|
95
|
+
steps: [
|
|
96
|
+
() => legacy__createDistFromGatsbyPublic(domain, needsAssetPrefix),
|
|
97
|
+
() => pause("Relocation LifeCycle"),
|
|
98
|
+
],
|
|
60
99
|
});
|
|
61
100
|
|
|
62
101
|
/**
|
|
@@ -72,7 +111,11 @@ async function runGatsbyAdapter() {
|
|
|
72
111
|
name: "Meta",
|
|
73
112
|
attempts: attempts.meta,
|
|
74
113
|
steps: [
|
|
114
|
+
() => generateBuildReport(),
|
|
115
|
+
() => RobotsService.writeFiles(domain),
|
|
116
|
+
() => generateSitemaps(),
|
|
75
117
|
() => (shouldUploadSearchData ? uploadSearchContentToAPI() : undefined),
|
|
118
|
+
() => pause("Meta LifeCycle"),
|
|
76
119
|
],
|
|
77
120
|
});
|
|
78
121
|
|
|
@@ -90,16 +133,25 @@ async function runGatsbyAdapter() {
|
|
|
90
133
|
// aseguramos que se vuelven a crear por Gatsby siempre
|
|
91
134
|
// actualizadas.
|
|
92
135
|
removeMultiPagesFromStore,
|
|
93
|
-
() => pause("MultiPages removed from `store`"),
|
|
94
136
|
() => clearEmptyDirs(),
|
|
95
|
-
() => pause("Clean empty dirs done!"),
|
|
96
137
|
runner.removeDisposableArtifacts,
|
|
97
|
-
() => pause("Clean `public` done!"),
|
|
98
138
|
runner.archiveArtifacts,
|
|
99
|
-
() => pause("Archive `dist` and `assets` done!"),
|
|
100
139
|
runner.archiveCacheArtifacts,
|
|
101
|
-
() => pause("Archive
|
|
140
|
+
() => pause("Archive LifeCycle"),
|
|
141
|
+
],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await doLifeCycle({
|
|
145
|
+
name: "Clean",
|
|
146
|
+
steps: [
|
|
147
|
+
() =>
|
|
148
|
+
removeArtifacts({
|
|
149
|
+
from: __cx,
|
|
150
|
+
artifacts: ["static", "apiCache"],
|
|
151
|
+
}),
|
|
152
|
+
() => pause("Clean LifeCycle"),
|
|
102
153
|
],
|
|
154
|
+
attempts: attempts.clean,
|
|
103
155
|
});
|
|
104
156
|
}
|
|
105
157
|
}
|
|
@@ -24,7 +24,6 @@ const attempts = {
|
|
|
24
24
|
clean: JSON.parse(process.env.GRIDDO_CLEAN_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
|
|
28
27
|
/**
|
|
29
28
|
* Return a runner, a serie of functions to manage the Gatsby render artifacts.
|
|
30
29
|
*/
|
|
@@ -58,10 +57,8 @@ function getGatsbyDomainRunner(domain: string) {
|
|
|
58
57
|
const assetPrefix = getGatsbyAssetPrefixSlug(domain);
|
|
59
58
|
|
|
60
59
|
const run = getEnvRunner({
|
|
61
|
-
DOMAIN: domain,
|
|
62
60
|
GRIDDO_ASSET_PREFIX: assetPrefix,
|
|
63
|
-
|
|
64
|
-
GRIDDO_RENDERID: new Date().valueOf(),
|
|
61
|
+
FOO: "true-and-false",
|
|
65
62
|
});
|
|
66
63
|
|
|
67
64
|
/**
|
|
@@ -378,4 +375,3 @@ function getGatsbyAssetPrefixSlug(domain: string) {
|
|
|
378
375
|
}
|
|
379
376
|
|
|
380
377
|
export { attempts, getGatsbyDomainRunner };
|
|
381
|
-
|
|
@@ -8,6 +8,7 @@ dotenv.config();
|
|
|
8
8
|
import dotenv from "dotenv";
|
|
9
9
|
|
|
10
10
|
import { get } from "../utils/api";
|
|
11
|
+
import { getConfig } from "../utils/temp-utils";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* TODO: JSDoc
|
|
@@ -48,27 +49,29 @@ class RobotsService {
|
|
|
48
49
|
/**
|
|
49
50
|
* Write robots.txt files for the current rendering domain.
|
|
50
51
|
*/
|
|
51
|
-
async writeFiles(
|
|
52
|
+
async writeFiles(domain: string) {
|
|
53
|
+
const config = await getConfig();
|
|
54
|
+
const dirs = config.dirs(domain);
|
|
55
|
+
const distDirectory = path.join(dirs.__cx, "dist");
|
|
56
|
+
|
|
52
57
|
await this.getRobots();
|
|
53
58
|
|
|
54
|
-
const robot = this.robots.find(
|
|
55
|
-
({ path }) => path === `/${process.env.DOMAIN}`
|
|
56
|
-
);
|
|
59
|
+
const robot = this.robots.find(({ path }) => path === `/${domain}`);
|
|
57
60
|
|
|
58
61
|
if (!robot) {
|
|
59
|
-
console.log(`Robots not found for ${
|
|
62
|
+
console.log(`Robots not found for ${domain}`);
|
|
60
63
|
return;
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
if (fs.existsSync(
|
|
66
|
+
if (fs.existsSync(distDirectory)) {
|
|
64
67
|
const fileLocation = JSON.parse(
|
|
65
68
|
process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
|
|
66
69
|
)
|
|
67
|
-
? path.join(
|
|
68
|
-
: path.join(
|
|
70
|
+
? path.join(distDirectory, "robots.txt")
|
|
71
|
+
: path.join(distDirectory, robot.path, "robots.txt");
|
|
69
72
|
fs.writeFileSync(fileLocation, robot?.content);
|
|
70
73
|
} else {
|
|
71
|
-
console.log(`${
|
|
74
|
+
console.log(`${distDirectory} not found`);
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
}
|
|
@@ -39,7 +39,7 @@ dotenv.config();
|
|
|
39
39
|
/* prettier-ignore */ const REACT_APP_INSTANCE = process.env.GRIDDO_REACT_APP_INSTANCE || process.env.REACT_APP_INSTANCE;
|
|
40
40
|
/* prettier-ignore */ const API_CONCURRENCY_COUNT = parseInt(process.env.GRIDDO_API_CONCURRENCY_COUNT || "10");
|
|
41
41
|
/* prettier-ignore */ const PUBLIC_API_URL = process.env.PUBLIC_API_URL as string;
|
|
42
|
-
/* prettier-ignore */ const RENDER_ID =
|
|
42
|
+
/* prettier-ignore */ const RENDER_ID = new Date().valueOf().toString();
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Fetch, process and save object pages and sites data into the file system to
|
package/exporter/types/global.ts
CHANGED
|
@@ -86,7 +86,13 @@ type LifeCyclesNames =
|
|
|
86
86
|
| "Archive"
|
|
87
87
|
| "Clean";
|
|
88
88
|
|
|
89
|
-
type CXDir =
|
|
89
|
+
type CXDir =
|
|
90
|
+
| "__exports"
|
|
91
|
+
| "__cache"
|
|
92
|
+
| "__cx"
|
|
93
|
+
| "__ssg"
|
|
94
|
+
| "__components"
|
|
95
|
+
| "__root";
|
|
90
96
|
|
|
91
97
|
interface CXConfig {
|
|
92
98
|
proDomain: string;
|
|
@@ -121,27 +121,22 @@ const clearEmptyDirs = (baseDir?: string) => {
|
|
|
121
121
|
/**
|
|
122
122
|
* Copy artifacts between CX valid directories.
|
|
123
123
|
*
|
|
124
|
-
* @param args.domain - The render domain
|
|
125
124
|
* @param args.from - Source dir
|
|
126
125
|
* @param args.to - Destination dir
|
|
127
126
|
* @param args.artifacts - Artifact names
|
|
128
127
|
* @param args.withBackup - Create a previous backup
|
|
129
128
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
to: CXDir;
|
|
129
|
+
function copyArtifacts(args: {
|
|
130
|
+
from: string;
|
|
131
|
+
to: string;
|
|
134
132
|
artifacts: Array<string>;
|
|
135
133
|
withBackup?: boolean;
|
|
136
134
|
}) {
|
|
137
|
-
const { artifacts,
|
|
138
|
-
|
|
139
|
-
const config = await getConfig();
|
|
140
|
-
const dirs = config.dirs(domain);
|
|
135
|
+
const { artifacts, from, to, withBackup } = args;
|
|
141
136
|
|
|
142
137
|
for (const artifact of artifacts) {
|
|
143
|
-
const src = path.join(
|
|
144
|
-
const dest = path.join(
|
|
138
|
+
const src = path.join(from, artifact);
|
|
139
|
+
const dest = path.join(to, artifact);
|
|
145
140
|
|
|
146
141
|
// The dir we want to copy, doesn't exist.
|
|
147
142
|
if (!fsx.existsSync(src)) {
|
|
@@ -177,42 +172,27 @@ async function copyArtifacts(args: {
|
|
|
177
172
|
/**
|
|
178
173
|
* Move artifacts between CX valid directories.
|
|
179
174
|
*
|
|
180
|
-
* @param domain - The render domain
|
|
181
175
|
* @param from - Source dir
|
|
182
176
|
* @param to - Destination dir
|
|
183
177
|
* @param artifacts - Artifact names
|
|
184
178
|
*
|
|
185
179
|
* @example
|
|
186
180
|
* // normal
|
|
187
|
-
* moveArtifacts({
|
|
188
|
-
* // renaming
|
|
189
|
-
* moveArtifacts({
|
|
190
|
-
*
|
|
191
|
-
* domain: domain,
|
|
192
|
-
* from: "__cx",
|
|
193
|
-
* to: "__ssg",
|
|
194
|
-
* ["foo", "taz", "bar"],
|
|
195
|
-
* ["foo", "taz", "bar-renamed"]
|
|
196
|
-
*
|
|
197
|
-
* })
|
|
181
|
+
* moveArtifacts({from: __cx, to: __ssg, ["dist"]})
|
|
198
182
|
* // with backup
|
|
199
|
-
* moveArtifacts({
|
|
183
|
+
* moveArtifacts({from: __cx, to: __ssg, ["dist"]})
|
|
200
184
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
to: CXDir;
|
|
185
|
+
function moveArtifacts(args: {
|
|
186
|
+
from: string;
|
|
187
|
+
to: string;
|
|
205
188
|
artifacts: Array<string>;
|
|
206
189
|
withBackup?: boolean;
|
|
207
190
|
}) {
|
|
208
|
-
const { artifacts,
|
|
209
|
-
|
|
210
|
-
const config = await getConfig();
|
|
211
|
-
const dirs = config.dirs(domain);
|
|
191
|
+
const { artifacts, from, to, withBackup } = args;
|
|
212
192
|
|
|
213
193
|
for (const artifact of artifacts) {
|
|
214
|
-
const src = path.join(
|
|
215
|
-
const dest = path.join(
|
|
194
|
+
const src = path.join(from, artifact);
|
|
195
|
+
const dest = path.join(to, artifact);
|
|
216
196
|
|
|
217
197
|
// The dir we want to move, doesn't exist.
|
|
218
198
|
if (!fsx.existsSync(src)) {
|
|
@@ -246,27 +226,19 @@ async function moveArtifacts(args: {
|
|
|
246
226
|
/**
|
|
247
227
|
* Remove artifacts from CX valid directories.
|
|
248
228
|
*
|
|
249
|
-
* @param domain - The render domain
|
|
250
229
|
* @param from - Source dir
|
|
251
230
|
* @param to - Destination dir
|
|
252
231
|
* @param artifacts - Artifact names
|
|
253
232
|
*
|
|
254
233
|
* @example
|
|
255
|
-
* removeArtifacts(
|
|
234
|
+
* removeArtifacts({from: __cx, to: __ssg, ["dist", "public"]})
|
|
256
235
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
from: CXDir;
|
|
260
|
-
artifacts: Array<string>;
|
|
261
|
-
}) {
|
|
262
|
-
const { artifacts, domain, from } = args;
|
|
263
|
-
|
|
264
|
-
const config = await getConfig();
|
|
265
|
-
const dirs = config.dirs(domain);
|
|
236
|
+
function removeArtifacts(args: { from: string; artifacts: Array<string> }) {
|
|
237
|
+
const { artifacts, from } = args;
|
|
266
238
|
|
|
267
239
|
for (const artifact of artifacts) {
|
|
268
240
|
if (artifact) {
|
|
269
|
-
const src = path.join(
|
|
241
|
+
const src = path.join(from, artifact);
|
|
270
242
|
if (fsx.existsSync(src)) {
|
|
271
243
|
spawnSync("rm", ["-rf", src]);
|
|
272
244
|
}
|
|
@@ -62,15 +62,18 @@ function getComponentsLibAliases() {
|
|
|
62
62
|
};
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
|
+
// Por este motivo se puede hacer `... import from "@components" en
|
|
66
|
+
// los packages del monorepo.
|
|
67
|
+
"@components": `${resolveComponentsPath()}/src/index.js`,
|
|
65
68
|
components: `${resolveComponentsPath()}/src/index.js`,
|
|
66
69
|
}
|
|
67
70
|
);
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
export {
|
|
71
|
-
getComponentsJSConfig,
|
|
72
|
-
getComponentsLibAliases,
|
|
73
74
|
IS_COMPONENT_LIBRARY,
|
|
74
75
|
PROJECT_ALIASES,
|
|
76
|
+
getComponentsJSConfig,
|
|
77
|
+
getComponentsLibAliases,
|
|
75
78
|
resolveComponentsPath,
|
|
76
79
|
};
|
package/exporter/utils/shared.ts
CHANGED
package/exporter/utils/sites.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { BuildProcessData } from "../types/global";
|
|
2
1
|
import type { Site, SiteData } from "../types/sites";
|
|
3
2
|
|
|
4
3
|
import path from "node:path";
|
|
@@ -7,6 +6,8 @@ import fs from "fs-extra";
|
|
|
7
6
|
import { parse } from "js2xmlparser";
|
|
8
7
|
|
|
9
8
|
import { logInfo } from "./shared";
|
|
9
|
+
import { getBuildMetadata } from "./store";
|
|
10
|
+
import { getConfig } from "./temp-utils";
|
|
10
11
|
import { AuthService } from "../services/auth";
|
|
11
12
|
import { SitesService } from "../services/sites";
|
|
12
13
|
|
|
@@ -148,14 +149,16 @@ async function getSiteData(siteID: number) {
|
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* Save a file with the end of build process
|
|
151
|
-
*
|
|
152
|
-
* @param filePathName The pathname for the file report
|
|
153
|
-
* @param buildProcessData The whole build process data.
|
|
154
152
|
*/
|
|
155
|
-
async function generateBuildReport(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
153
|
+
async function generateBuildReport() {
|
|
154
|
+
const config = await getConfig();
|
|
155
|
+
const dirs = config.dirs();
|
|
156
|
+
|
|
157
|
+
const DIST_FOLDER = path.join(dirs.__cx, "dist");
|
|
158
|
+
|
|
159
|
+
const { buildProcessData } = await getBuildMetadata();
|
|
160
|
+
const filePathName = path.join(DIST_FOLDER, "__build-report__.json");
|
|
161
|
+
|
|
159
162
|
// Get the token
|
|
160
163
|
const authControl = await AuthService.login();
|
|
161
164
|
|
|
@@ -179,8 +182,13 @@ async function generateBuildReport(
|
|
|
179
182
|
*
|
|
180
183
|
* @param sites An array of sites
|
|
181
184
|
*/
|
|
182
|
-
async function generateSitemaps(
|
|
183
|
-
const
|
|
185
|
+
async function generateSitemaps() {
|
|
186
|
+
const { sitesToPublish } = await getBuildMetadata();
|
|
187
|
+
const config = await getConfig();
|
|
188
|
+
const dirs = config.dirs();
|
|
189
|
+
const basePath = path.resolve(dirs.__cx, "dist");
|
|
190
|
+
|
|
191
|
+
const promisesOfSites = sitesToPublish.map(async (site) => {
|
|
184
192
|
const { id: siteID, languages } = site;
|
|
185
193
|
|
|
186
194
|
const promisesOfLanguages = languages.map(async (lang) => {
|
|
@@ -207,11 +215,9 @@ async function generateSitemaps(sites: Array<Site>) {
|
|
|
207
215
|
const sitemaps: Array<string> = [];
|
|
208
216
|
const sitemapPageGroupKeys = Object.keys(sitemapPagesGroup);
|
|
209
217
|
|
|
210
|
-
const sitemapBasePath = path.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
STRIP_DOMAIN_FROM_PATH ? slug.replace(domain, "") : slug
|
|
214
|
-
}`
|
|
218
|
+
const sitemapBasePath = path.join(
|
|
219
|
+
basePath,
|
|
220
|
+
`${STRIP_DOMAIN_FROM_PATH ? slug.replace(domain, "") : slug}`
|
|
215
221
|
);
|
|
216
222
|
|
|
217
223
|
for (const templateId of sitemapPageGroupKeys) {
|
package/exporter/utils/store.ts
CHANGED
|
@@ -9,6 +9,7 @@ import path from "node:path";
|
|
|
9
9
|
import fsx from "fs-extra";
|
|
10
10
|
|
|
11
11
|
import { removeProperties, walk } from "./shared";
|
|
12
|
+
import { getConfig } from "./temp-utils";
|
|
12
13
|
import { Site } from "../types/sites";
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -44,9 +45,13 @@ async function* getBuildPages<PageType extends GriddoPageObject>(
|
|
|
44
45
|
* Get the build metadata from the Store.
|
|
45
46
|
* TODO: Refactorizar para leer un solo archivo: __metadata__.json
|
|
46
47
|
*/
|
|
47
|
-
function getBuildMetadata(
|
|
48
|
+
async function getBuildMetadata(): Promise<BuildMetaData> {
|
|
49
|
+
const config = await getConfig();
|
|
50
|
+
const dirs = config.dirs();
|
|
51
|
+
const storePath = path.join(dirs.__cx, "store");
|
|
52
|
+
|
|
48
53
|
const { sitesToPublish, createdPages, buildProcessData } = fsx.readJSONSync(
|
|
49
|
-
path.resolve(
|
|
54
|
+
path.resolve(storePath, "metadata", "render-info.json")
|
|
50
55
|
);
|
|
51
56
|
return {
|
|
52
57
|
buildProcessData,
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import fsx from "fs-extra";
|
|
4
|
+
|
|
5
|
+
function getConfigSync() {
|
|
6
|
+
try {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-missing-require, node/no-unpublished-require
|
|
8
|
+
const configModule = require("../../cx.config");
|
|
9
|
+
const config = configModule.default;
|
|
10
|
+
|
|
11
|
+
return config;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
async function getConfig() {
|
|
2
18
|
try {
|
|
3
19
|
// eslint-disable-next-line node/no-unpublished-import
|
|
@@ -10,4 +26,61 @@ async function getConfig() {
|
|
|
10
26
|
}
|
|
11
27
|
}
|
|
12
28
|
|
|
13
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Update the Griddo's `/dist` dir with the contents from `public` dir only
|
|
31
|
+
* with files of type: js, json and css.
|
|
32
|
+
*/
|
|
33
|
+
async function legacy__createDistFromGatsbyPublic(
|
|
34
|
+
domain: string,
|
|
35
|
+
needsAssetPrefix: boolean
|
|
36
|
+
) {
|
|
37
|
+
const config = await getConfig();
|
|
38
|
+
const dirs = config.dirs(domain);
|
|
39
|
+
|
|
40
|
+
const cxDistDir = path.resolve(dirs.__cx, "dist");
|
|
41
|
+
const cxAssetsDir = path.resolve(dirs.__cx, "assets");
|
|
42
|
+
const cxDistDirWithDomain = path.join(dirs.__cx, "dist", domain);
|
|
43
|
+
const publicDir = path.resolve(dirs.__ssg, "public");
|
|
44
|
+
|
|
45
|
+
const validFiles = fsx
|
|
46
|
+
.readdirSync(publicDir)
|
|
47
|
+
.filter(
|
|
48
|
+
(file) =>
|
|
49
|
+
path.extname(file) === ".js" ||
|
|
50
|
+
path.extname(file) === ".json" ||
|
|
51
|
+
path.extname(file) === ".css"
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const pageDataSrc = `${publicDir}/page-data`;
|
|
55
|
+
const pageDataDest = `${cxAssetsDir}/page-data`;
|
|
56
|
+
|
|
57
|
+
const projectStaticSrc = path.resolve(dirs.__cx, "./static");
|
|
58
|
+
const projectStaticDest = cxAssetsDir;
|
|
59
|
+
|
|
60
|
+
const gatsbyStaticSrc = `${cxDistDir}/static`;
|
|
61
|
+
const gatsbyStaticDest = `${cxAssetsDir}/static`;
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
fsx.mkdirSync(cxAssetsDir, { recursive: true });
|
|
65
|
+
fsx.copySync(publicDir, cxDistDir);
|
|
66
|
+
|
|
67
|
+
if (needsAssetPrefix) {
|
|
68
|
+
fsx.copySync(pageDataSrc, pageDataDest);
|
|
69
|
+
fsx.copySync(projectStaticSrc, projectStaticDest, { overwrite: false });
|
|
70
|
+
fsx.copySync(gatsbyStaticSrc, gatsbyStaticDest, { overwrite: false });
|
|
71
|
+
fsx.copySync(projectStaticSrc, cxDistDirWithDomain, {
|
|
72
|
+
overwrite: false,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
validFiles.map(async (file) => {
|
|
76
|
+
const fileSrc = `${publicDir}/${file}`;
|
|
77
|
+
const fileDest = `${cxAssetsDir}/${file}`;
|
|
78
|
+
fsx.copySync(fileSrc, fileDest);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(err);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { legacy__createDistFromGatsbyPublic, getConfig, getConfigSync };
|
package/gatsby-browser.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { GatsbyBrowser } from "gatsby";
|
|
2
2
|
|
|
3
|
+
import { browser } from "@components";
|
|
3
4
|
import { SessionProvider } from "@griddo/core";
|
|
4
|
-
// @ts-expect-error components is unknown
|
|
5
|
-
import { browser } from "components";
|
|
6
5
|
import * as React from "react";
|
|
7
6
|
|
|
8
7
|
export const disableCorePrefetching = () => {
|
package/gatsby-config.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { resolveComponentsPath } from "./exporter/utils/instance";
|
|
|
6
6
|
|
|
7
7
|
dotenv.config();
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// Este process.env.GRIDDO_ASSET_PREFIX se lee porque se ha introducido en
|
|
10
|
+
// `getEnvRunner()`.
|
|
10
11
|
const GRIDDO_ASSET_PREFIX = process.env.GRIDDO_ASSET_PREFIX || undefined;
|
|
11
12
|
|
|
12
13
|
// Gatsby configuration file from client
|
package/gatsby-node.ts
CHANGED
|
@@ -2,67 +2,38 @@ import type { GatsbyNode } from "gatsby";
|
|
|
2
2
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
import { RobotsService } from "./exporter/services/robots";
|
|
6
5
|
import { logInfo, logPageSize } from "./exporter/utils/shared";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
getMatchPath,
|
|
11
|
-
prepareStaticDir,
|
|
12
|
-
updateDist,
|
|
13
|
-
} from "./src/gatsby-node-utils";
|
|
6
|
+
import { getBuildPages } from "./exporter/utils/store";
|
|
7
|
+
import { getConfigSync } from "./exporter/utils/temp-utils";
|
|
8
|
+
import { getMatchPath } from "./src/gatsby-node-utils";
|
|
14
9
|
import { GatsbyPageObject } from "./src/types";
|
|
15
10
|
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const gatsbyTemplateFile = path.resolve(
|
|
20
|
-
__dirname,
|
|
21
|
-
"./src/components/template.tsx"
|
|
22
|
-
);
|
|
11
|
+
const dirs = getConfigSync().dirs();
|
|
12
|
+
const storeDir = path.join(dirs.__cx, "store");
|
|
13
|
+
const templateFile = path.join(dirs.__ssg, "src/components/template.tsx");
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
prepareStaticDir();
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// createPages
|
|
30
|
-
const createPages: GatsbyNode["createPages"] = async ({
|
|
31
|
-
actions: { createPage },
|
|
32
|
-
}) => {
|
|
33
|
-
const pages = getBuildPages<GatsbyPageObject>(storeDirPath);
|
|
15
|
+
const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
|
|
16
|
+
const pages = getBuildPages<GatsbyPageObject>(storeDir);
|
|
34
17
|
|
|
35
18
|
for await (const page of pages) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
19
|
+
if (!page) return;
|
|
20
|
+
|
|
40
21
|
const { domain, compose } = page.context.fullPath;
|
|
41
22
|
const matchPath = getMatchPath(domain, compose);
|
|
42
23
|
|
|
43
|
-
page.component =
|
|
24
|
+
page.component = templateFile;
|
|
44
25
|
page.matchPath = matchPath;
|
|
45
26
|
|
|
46
|
-
createPage(page);
|
|
27
|
+
actions.createPage(page);
|
|
47
28
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
)}`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// onPostBuild
|
|
57
|
-
const onPostBuild = async () => {
|
|
58
|
-
const { buildProcessData, sitesToPublish } = getBuildMetadata(storeDirPath);
|
|
29
|
+
const path = page.path;
|
|
30
|
+
const id = page.context.id;
|
|
31
|
+
const size = logPageSize(Math.round(page.size || 0));
|
|
59
32
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
await generateSitemaps(sitesToPublish);
|
|
63
|
-
await updateDist();
|
|
33
|
+
logInfo(`Creating page ${path} - ${id} - ${size}`);
|
|
34
|
+
}
|
|
64
35
|
};
|
|
65
36
|
|
|
66
37
|
// onCreateWebpackConfig
|
|
67
38
|
export { onCreateWebpackConfig } from "./src/gatsby-node-utils";
|
|
68
|
-
export { createPages
|
|
39
|
+
export { createPages };
|