@griddo/cx 10.6.4 → 10.6.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 +0 -2
- package/build/adapters/gatsby/index.d.ts +1 -1
- package/build/artifacts/cx.d.ts +6 -0
- package/build/artifacts/gatsby.d.ts +6 -0
- package/build/artifacts/index.d.ts +15 -0
- package/build/build-complete.js +74 -34
- package/build/constants/endpoints.d.ts +18 -0
- package/build/constants/envs.d.ts +33 -0
- package/build/constants/index.d.ts +53 -0
- package/build/index.d.ts +4 -3
- package/build/index.js +90 -49
- package/build/reset-render.js +74 -34
- package/build/run-start-render.js +90 -49
- package/build/services/navigation.d.ts +0 -27
- package/build/services/robots.d.ts +2 -21
- package/build/services/settings.d.ts +3 -22
- package/build/services/sites.d.ts +20 -37
- package/build/start-render.js +90 -49
- package/build/types/global.d.ts +10 -14
- package/build/upload-search-content.js +70 -30
- package/build/utils/core-utils.d.ts +18 -60
- package/build/utils/domains.d.ts +5 -1
- package/build/utils/folders.d.ts +38 -13
- package/build/utils/loggin.d.ts +49 -0
- package/build/utils/render.d.ts +11 -0
- package/build/utils/store.d.ts +0 -1
- package/cx.config.d.ts +0 -15
- package/cx.config.js +3 -16
- package/exporter/adapters/gatsby/index.ts +94 -253
- package/exporter/adapters/gatsby/utils.ts +11 -10
- package/exporter/artifacts/README.md +28 -0
- package/exporter/artifacts/cx.ts +26 -0
- package/exporter/artifacts/gatsby.ts +28 -0
- package/exporter/artifacts/index.ts +30 -0
- package/exporter/browser/index.ts +4 -4
- package/exporter/constants/endpoints.ts +42 -0
- package/exporter/constants/envs.ts +86 -0
- package/exporter/constants/index.ts +120 -0
- package/exporter/errors/index.ts +2 -2
- package/exporter/index.ts +11 -10
- package/exporter/react/GriddoIntegrations/index.tsx +3 -3
- package/exporter/{build-complete.ts → scripts/build-complete.ts} +4 -4
- package/exporter/{reset-render.ts → scripts/reset-render.ts} +3 -3
- package/exporter/scripts/start-render.ts +26 -0
- package/exporter/{upload-search-content.ts → scripts/upload-search-content.ts} +3 -3
- package/exporter/services/auth.ts +7 -5
- package/exporter/services/distributors.ts +12 -18
- package/exporter/services/domains.ts +2 -12
- package/exporter/services/navigation.ts +10 -35
- package/exporter/services/robots.ts +35 -58
- package/exporter/services/settings.ts +7 -44
- package/exporter/services/sites.ts +101 -160
- package/exporter/services/store.ts +24 -29
- package/exporter/types/api.ts +1 -2
- package/exporter/types/global.ts +14 -22
- package/exporter/types/pages.ts +0 -9
- package/exporter/types/sites.ts +0 -3
- package/exporter/utils/api.ts +11 -10
- package/exporter/utils/core-utils.ts +66 -181
- package/exporter/utils/domains.ts +21 -3
- package/exporter/utils/folders.ts +163 -50
- package/exporter/utils/health-checks.ts +4 -4
- package/exporter/utils/instance.ts +3 -3
- package/exporter/utils/integrations.ts +12 -12
- package/exporter/utils/loggin.ts +159 -0
- package/exporter/utils/pages.ts +15 -15
- package/exporter/utils/render.ts +49 -0
- package/exporter/utils/searches.ts +5 -5
- package/exporter/utils/sites.ts +42 -48
- package/exporter/utils/store.ts +9 -10
- package/gatsby-browser.tsx +46 -48
- package/gatsby-config.ts +5 -5
- package/gatsby-node.ts +7 -7
- package/package.json +23 -28
- package/src/components/Head.tsx +1 -1
- package/src/gatsby-node-utils.ts +1 -1
- package/src/types.ts +0 -1
- package/src/utils.ts +1 -1
- package/exporter/start-render.ts +0 -18
- /package/build/{build-complete.d.ts → scripts/build-complete.d.ts} +0 -0
- /package/build/{move-assets.d.ts → scripts/move-assets.d.ts} +0 -0
- /package/build/{reset-render.d.ts → scripts/reset-render.d.ts} +0 -0
- /package/build/{run-start-render.d.ts → scripts/run-start-render.d.ts} +0 -0
- /package/build/{start-render.d.ts → scripts/start-render.d.ts} +0 -0
- /package/build/{upload-search-content.d.ts → scripts/upload-search-content.d.ts} +0 -0
- /package/exporter/{move-assets.ts → scripts/move-assets.ts} +0 -0
- /package/exporter/{run-start-render.ts → scripts/run-start-render.ts} +0 -0
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import fsx, { MakeDirectoryOptions } from "fs-extra";
|
|
5
5
|
|
|
6
6
|
import { getConfig } from "./core-utils";
|
|
7
|
+
import { verboseLog } from "./loggin";
|
|
7
8
|
import { getPageInStoreDir, removePagesFromStore } from "./store";
|
|
8
9
|
|
|
9
10
|
const config = getConfig();
|
|
@@ -90,7 +91,7 @@ function copyDirsSync(
|
|
|
90
91
|
dirs: Array<string>,
|
|
91
92
|
options = {
|
|
92
93
|
withBackup: false,
|
|
93
|
-
}
|
|
94
|
+
},
|
|
94
95
|
) {
|
|
95
96
|
const { withBackup } = options;
|
|
96
97
|
for (const dir of dirs) {
|
|
@@ -132,53 +133,6 @@ function copyDirsSync(
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
/**
|
|
136
|
-
* Move artifacts between CX valid directories.
|
|
137
|
-
*
|
|
138
|
-
* @param src - Source directory.
|
|
139
|
-
* @param dst - Destination directory.
|
|
140
|
-
* @param dirs - Directories to move.
|
|
141
|
-
* @param options - Options.
|
|
142
|
-
*/
|
|
143
|
-
function moveDirsSync(
|
|
144
|
-
src: string,
|
|
145
|
-
dst: string,
|
|
146
|
-
dirs: Array<string>,
|
|
147
|
-
options?: { withBackup?: boolean; override?: boolean }
|
|
148
|
-
) {
|
|
149
|
-
const { override, withBackup } = options || {};
|
|
150
|
-
|
|
151
|
-
for (const dir of dirs) {
|
|
152
|
-
const srcCompose = path.join(src, dir);
|
|
153
|
-
const dstCompose = path.join(dst, dir);
|
|
154
|
-
|
|
155
|
-
if (!fsx.existsSync(srcCompose)) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (withBackup) {
|
|
160
|
-
createBackup(dstCompose);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
// Clean destination
|
|
165
|
-
if (override && fsx.existsSync(dstCompose)) {
|
|
166
|
-
fs.rmSync(dstCompose, { recursive: true, force: true });
|
|
167
|
-
}
|
|
168
|
-
fs.renameSync(srcCompose, dstCompose);
|
|
169
|
-
if (withBackup) {
|
|
170
|
-
deleteBackup(dstCompose);
|
|
171
|
-
}
|
|
172
|
-
} catch (e) {
|
|
173
|
-
console.log("Move failed!");
|
|
174
|
-
if (withBackup) {
|
|
175
|
-
restoreBackup(dstCompose);
|
|
176
|
-
console.log("Backup has been restored.");
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
136
|
/**
|
|
183
137
|
* Remove directories from `basePath` directory.
|
|
184
138
|
*
|
|
@@ -255,7 +209,7 @@ async function removeVirtualPagesFromStore() {
|
|
|
255
209
|
removePagesFromStore(multiPageFiles);
|
|
256
210
|
} catch (e) {
|
|
257
211
|
console.info(
|
|
258
|
-
"`store` folder does not exist. Skipping multipage or static list template cleaning."
|
|
212
|
+
"`store` folder does not exist. Skipping multipage or static list template cleaning.",
|
|
259
213
|
);
|
|
260
214
|
}
|
|
261
215
|
}
|
|
@@ -293,12 +247,171 @@ function clearSitemapsFromDirs(initialFolder: string) {
|
|
|
293
247
|
removeXmlFiles(initialFolder);
|
|
294
248
|
}
|
|
295
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Removes multiple artifact directories.
|
|
252
|
+
*
|
|
253
|
+
* @param artifacts - An array of artifact directory paths.
|
|
254
|
+
*/
|
|
255
|
+
function removeArtifacts(artifacts: Array<string>) {
|
|
256
|
+
for (const dir of artifacts) {
|
|
257
|
+
if (!dir) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (fsx.existsSync(dir)) {
|
|
262
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
263
|
+
verboseLog(`removed directory: ${dir}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Creates multiple directories.
|
|
270
|
+
*
|
|
271
|
+
* @param dirs - An array of directory paths.
|
|
272
|
+
* @param options - Same option as `fs.mkdirSync()`
|
|
273
|
+
*/
|
|
274
|
+
function createArtifacts(dirs: Array<string>, options?: MakeDirectoryOptions) {
|
|
275
|
+
for (const dir of dirs) {
|
|
276
|
+
if (!fs.existsSync(dir)) {
|
|
277
|
+
fs.mkdirSync(dir, { recursive: true, ...options });
|
|
278
|
+
verboseLog(`create directory: ${dir}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Copy multiple directories with backup option.
|
|
285
|
+
*
|
|
286
|
+
* @param src - Source directory.
|
|
287
|
+
* @param dst - Destination directory.
|
|
288
|
+
* @param dirs - Directories to copy.
|
|
289
|
+
* @param options.withBackup - Create a previous backup before copy.
|
|
290
|
+
*/
|
|
291
|
+
function copyArtifacts(
|
|
292
|
+
src: string,
|
|
293
|
+
dst: string,
|
|
294
|
+
dirs: Array<string>,
|
|
295
|
+
options = {
|
|
296
|
+
withBackup: false,
|
|
297
|
+
},
|
|
298
|
+
) {
|
|
299
|
+
const { withBackup } = options;
|
|
300
|
+
for (const dir of dirs) {
|
|
301
|
+
const srcCompose = path.join(src, dir);
|
|
302
|
+
const dstCompose = path.join(dst, dir);
|
|
303
|
+
|
|
304
|
+
// The dir we want to copy, doesn't exist.
|
|
305
|
+
if (!fsx.existsSync(srcCompose)) {
|
|
306
|
+
console.log(
|
|
307
|
+
`(Maybe first render) Source directory does not exist: ${srcCompose}`,
|
|
308
|
+
);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Create the backup
|
|
313
|
+
if (withBackup) {
|
|
314
|
+
createBackup(dstCompose);
|
|
315
|
+
verboseLog(`create backup: ${dstCompose}`);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Copy directory
|
|
319
|
+
try {
|
|
320
|
+
// First clean destination
|
|
321
|
+
if (fsx.existsSync(dstCompose)) {
|
|
322
|
+
fs.rmSync(dstCompose, { recursive: true, force: true });
|
|
323
|
+
verboseLog(`clean destination: ${dstCompose}`);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Then copy src to dst
|
|
327
|
+
fs.cpSync(srcCompose, dstCompose, {
|
|
328
|
+
recursive: true,
|
|
329
|
+
preserveTimestamps: true,
|
|
330
|
+
});
|
|
331
|
+
verboseLog(`copy: ${srcCompose} to ${dstCompose}`);
|
|
332
|
+
|
|
333
|
+
if (withBackup) {
|
|
334
|
+
deleteBackup(dstCompose);
|
|
335
|
+
verboseLog(`delete backup: ${dstCompose}`);
|
|
336
|
+
}
|
|
337
|
+
} catch (e) {
|
|
338
|
+
console.log("copy failed!");
|
|
339
|
+
if (withBackup) {
|
|
340
|
+
restoreBackup(dstCompose);
|
|
341
|
+
console.log("Backup has been restored.");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function renameArtifact(src: string, dst: string) {
|
|
348
|
+
if (fs.existsSync(src)) {
|
|
349
|
+
fs.renameSync(src, dst);
|
|
350
|
+
verboseLog(`rename ${src} to ${dst}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Move artifacts between cx-paths
|
|
356
|
+
*
|
|
357
|
+
* @param src - Source directory.
|
|
358
|
+
* @param dst - Destination directory.
|
|
359
|
+
* @param dirs - Directories to move.
|
|
360
|
+
* @param options - Options.
|
|
361
|
+
*/
|
|
362
|
+
function moveArtifacts(
|
|
363
|
+
src: string,
|
|
364
|
+
dst: string,
|
|
365
|
+
dirs: Array<string>,
|
|
366
|
+
options?: { withBackup?: boolean; override?: boolean },
|
|
367
|
+
) {
|
|
368
|
+
const { override, withBackup } = options || {};
|
|
369
|
+
|
|
370
|
+
for (const dir of dirs) {
|
|
371
|
+
const srcCompose = path.join(src, dir);
|
|
372
|
+
const dstCompose = path.join(dst, dir);
|
|
373
|
+
|
|
374
|
+
if (!fsx.existsSync(srcCompose)) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (withBackup) {
|
|
379
|
+
createBackup(dstCompose);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
try {
|
|
383
|
+
// Clean destination
|
|
384
|
+
if (override && fsx.existsSync(dstCompose)) {
|
|
385
|
+
fs.rmSync(dstCompose, { recursive: true, force: true });
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
fs.renameSync(srcCompose, dstCompose);
|
|
389
|
+
verboseLog(`moved: ${srcCompose} to ${dstCompose}`);
|
|
390
|
+
|
|
391
|
+
if (withBackup) {
|
|
392
|
+
deleteBackup(dstCompose);
|
|
393
|
+
}
|
|
394
|
+
} catch (e) {
|
|
395
|
+
if (withBackup) {
|
|
396
|
+
restoreBackup(dstCompose);
|
|
397
|
+
console.log("Backup has been restored.");
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
throw new Error(JSON.stringify(e));
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
296
405
|
export {
|
|
297
406
|
clearEmptyDirs,
|
|
298
407
|
clearSitemapsFromDirs,
|
|
408
|
+
copyArtifacts,
|
|
299
409
|
copyDirsSync,
|
|
410
|
+
createArtifacts,
|
|
300
411
|
createDirsSync,
|
|
301
|
-
|
|
412
|
+
moveArtifacts,
|
|
413
|
+
removeArtifacts,
|
|
302
414
|
removeDirsSync,
|
|
303
415
|
removeVirtualPagesFromStore,
|
|
416
|
+
renameArtifact,
|
|
304
417
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { boxLog } from "./loggin";
|
|
2
2
|
|
|
3
3
|
const GRIDDO_SKIP_BUILD_CHECKS = process.env.GRIDDO_SKIP_BUILD_CHECKS;
|
|
4
4
|
const GRIDDO_ENVS_VARS: ReadonlyArray<string> = [];
|
|
@@ -30,9 +30,9 @@ function checkRenderHealthOrExit() {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// Error
|
|
33
|
-
|
|
33
|
+
boxLog(
|
|
34
34
|
`Error. The environment is not suitable for a build.`,
|
|
35
|
-
"Not valid environment"
|
|
35
|
+
"Not valid environment",
|
|
36
36
|
);
|
|
37
37
|
process.exit(1);
|
|
38
38
|
}
|
|
@@ -52,7 +52,7 @@ function checkEnvsVars(envs: ReadonlyArray<string>) {
|
|
|
52
52
|
if (missingEnvs.length) {
|
|
53
53
|
const missingEnvsMsg = missingEnvs.join("\n");
|
|
54
54
|
console.error(
|
|
55
|
-
`Env check failed. These envs vars are missing: \n\n${missingEnvsMsg}
|
|
55
|
+
`Env check failed. These envs vars are missing: \n\n${missingEnvsMsg}`,
|
|
56
56
|
);
|
|
57
57
|
|
|
58
58
|
return false;
|
|
@@ -18,8 +18,8 @@ function resolveComponentsPath(customPath = "") {
|
|
|
18
18
|
: path.resolve(
|
|
19
19
|
pkgDir.sync(__dirname) as string,
|
|
20
20
|
"../griddo-components",
|
|
21
|
-
customPath
|
|
22
|
-
|
|
21
|
+
customPath,
|
|
22
|
+
);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -65,7 +65,7 @@ function getComponentsLibAliases() {
|
|
|
65
65
|
// Por este motivo se puede hacer `... import from "@griddo-instance" en
|
|
66
66
|
// los packages del monorepo.
|
|
67
67
|
"@griddo-instance": `${resolveComponentsPath()}/src/index.js`,
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -10,7 +10,7 @@ function isObject(value: unknown) {
|
|
|
10
10
|
|
|
11
11
|
function filterBodyIntegrationFromPosition(
|
|
12
12
|
integrations: Array<Core.PageIntegration>,
|
|
13
|
-
position: "start" | "end"
|
|
13
|
+
position: "start" | "end",
|
|
14
14
|
) {
|
|
15
15
|
return (
|
|
16
16
|
integrations
|
|
@@ -18,7 +18,7 @@ function filterBodyIntegrationFromPosition(
|
|
|
18
18
|
(integration) =>
|
|
19
19
|
integration.contentBody !== null &&
|
|
20
20
|
integration.contentBody !== "" &&
|
|
21
|
-
integration.contentBodyPosition === position
|
|
21
|
+
integration.contentBodyPosition === position,
|
|
22
22
|
)
|
|
23
23
|
.map((integration) => {
|
|
24
24
|
return { content: integration.contentBody!, type: integration.type };
|
|
@@ -32,11 +32,11 @@ function filterHeadIntegrations(integrations: Array<Core.PageIntegration>) {
|
|
|
32
32
|
return integrations
|
|
33
33
|
?.filter(
|
|
34
34
|
(integration) =>
|
|
35
|
-
(integration.type===
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
||
|
|
39
|
-
|
|
35
|
+
(integration.type === "addon" &&
|
|
36
|
+
integration.contentHead !== null &&
|
|
37
|
+
integration.contentHead !== "") ||
|
|
38
|
+
integration.type === "analytics" ||
|
|
39
|
+
integration.type === "datalayer",
|
|
40
40
|
)
|
|
41
41
|
.map((integration) => {
|
|
42
42
|
return {
|
|
@@ -48,7 +48,7 @@ function filterHeadIntegrations(integrations: Array<Core.PageIntegration>) {
|
|
|
48
48
|
|
|
49
49
|
export const filterPositionIntegrations = (
|
|
50
50
|
integrations: Array<Core.PageIntegration>,
|
|
51
|
-
position: "head" | "start" | "end"
|
|
51
|
+
position: "head" | "start" | "end",
|
|
52
52
|
) => {
|
|
53
53
|
switch (position) {
|
|
54
54
|
case "head":
|
|
@@ -70,7 +70,7 @@ export function composeAnalytics(
|
|
|
70
70
|
};
|
|
71
71
|
},
|
|
72
72
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
73
|
-
generateAutomaticDimensions = (page: Record<string, unknown>) => null
|
|
73
|
+
generateAutomaticDimensions = (page: Record<string, unknown>) => null,
|
|
74
74
|
) {
|
|
75
75
|
const analyticsScript = siteScriptRaw ? siteScriptRaw.trim() : "";
|
|
76
76
|
|
|
@@ -96,10 +96,10 @@ export function composeAnalytics(
|
|
|
96
96
|
dimensionValue?.startsWith(dynamicValuePrefix)
|
|
97
97
|
? `${dimensionValue.slice(
|
|
98
98
|
dynamicValuePrefix.length,
|
|
99
|
-
dimensionValue.endsWith(";") ? -1 : dimensionValue.length
|
|
100
|
-
|
|
99
|
+
dimensionValue.endsWith(";") ? -1 : dimensionValue.length,
|
|
100
|
+
)}`
|
|
101
101
|
: `"${dimensionValue}"`
|
|
102
|
-
}
|
|
102
|
+
}`,
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { Adapters } from "../adapters";
|
|
2
|
+
|
|
3
|
+
import kleur from "kleur";
|
|
4
|
+
import { version as reactVersion } from "react";
|
|
5
|
+
|
|
6
|
+
import { getConfig } from "./core-utils";
|
|
7
|
+
import { envs } from "../constants";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Custom basic logging function controlled by a environment variable.
|
|
11
|
+
*
|
|
12
|
+
* @param str The string to be logged.
|
|
13
|
+
*/
|
|
14
|
+
function verboseLog(str: string) {
|
|
15
|
+
if (envs.GRIDDO_VERBOSE_LOGS) {
|
|
16
|
+
console.log(
|
|
17
|
+
kleur.yellow("verbose"),
|
|
18
|
+
kleur.dim(str.replace(/(\s)\s+/g, "$1").trim()),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Custom log inside a line-box.
|
|
25
|
+
*
|
|
26
|
+
* @param stringValue The string to be logged.
|
|
27
|
+
* @param paddingInline The number of white spaces inside the box at left and right.
|
|
28
|
+
* @param paddingBlock The number of white spaces inside the box at top and bottom.
|
|
29
|
+
*/
|
|
30
|
+
function boxLog(
|
|
31
|
+
stringValue: string,
|
|
32
|
+
title = "",
|
|
33
|
+
paddingInline = 1,
|
|
34
|
+
paddingBlock = 1,
|
|
35
|
+
) {
|
|
36
|
+
const lines = stringValue
|
|
37
|
+
.split("\n") // lines
|
|
38
|
+
.map((line) => line.trim()); // remove extra spaces
|
|
39
|
+
const windowTitle = title ? ` ${title} ` : "";
|
|
40
|
+
const windowTitleLength = title ? windowTitle.length : 0;
|
|
41
|
+
const longerContent =
|
|
42
|
+
Math.max(...lines.map((l) => l.length)) + paddingInline * 2;
|
|
43
|
+
const longerLine = Math.max(longerContent, windowTitleLength);
|
|
44
|
+
const paddingBlockString = `│${" ".repeat(longerLine)}│\n`.repeat(
|
|
45
|
+
paddingBlock,
|
|
46
|
+
);
|
|
47
|
+
const minWidth = longerLine;
|
|
48
|
+
const borderTop = `╭${windowTitle}${"─".repeat(
|
|
49
|
+
minWidth - windowTitleLength,
|
|
50
|
+
)}╮\n`;
|
|
51
|
+
const borderBottom = `╰${"─".repeat(minWidth)}╯`;
|
|
52
|
+
const content = lines
|
|
53
|
+
.map((l) => {
|
|
54
|
+
const mr = " ".repeat(longerLine - l.length - paddingInline);
|
|
55
|
+
return `│${" ".repeat(paddingInline)}${l}${mr}│\n`;
|
|
56
|
+
})
|
|
57
|
+
.join("");
|
|
58
|
+
|
|
59
|
+
console.log(
|
|
60
|
+
`${borderTop}${paddingBlockString}${content}${paddingBlockString}${borderBottom}`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Custom basic logging function controlled by a environment variable.
|
|
66
|
+
* Strip double spaces.
|
|
67
|
+
*
|
|
68
|
+
* @param str The string to be logged.
|
|
69
|
+
*/
|
|
70
|
+
function buildLog(str: string) {
|
|
71
|
+
if (envs.GRIDDO_BUILD_LOGS) {
|
|
72
|
+
console.info(str.replace(/(\s)\s+/g, "$1").trim());
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Console log with a blue color in the info prefix.
|
|
78
|
+
* @param str The string to be logged.
|
|
79
|
+
*/
|
|
80
|
+
function infoLog(str: string) {
|
|
81
|
+
console.info(`${kleur.blue("info")} ${str}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Console log with a green color in the success prefix.
|
|
86
|
+
* @param str The string to be logged.
|
|
87
|
+
*/
|
|
88
|
+
function successLog(str: string) {
|
|
89
|
+
console.info(`${kleur.green("success")} ${str}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Internal log
|
|
94
|
+
* @param values The values to be logged.
|
|
95
|
+
*/
|
|
96
|
+
function debugLog(...values: Array<unknown>) {
|
|
97
|
+
if (!envs.GRIDDO_DEBUG_LOGS) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
console.log(...values);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Return a scale size colors with a number and a measure string (KB by default).
|
|
105
|
+
*
|
|
106
|
+
* @param size The page size in KB.
|
|
107
|
+
* @param measure The measure string to be added in the log.
|
|
108
|
+
*/
|
|
109
|
+
function pageSizeLog(size: number, measure = "KB") {
|
|
110
|
+
const sizeScale = {
|
|
111
|
+
low: 50,
|
|
112
|
+
mid: 80,
|
|
113
|
+
large: 130,
|
|
114
|
+
extraLarge: 210,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Ternary pawa!
|
|
118
|
+
const color =
|
|
119
|
+
size > sizeScale.large
|
|
120
|
+
? "red"
|
|
121
|
+
: size > sizeScale.mid
|
|
122
|
+
? "magenta"
|
|
123
|
+
: size > sizeScale.low
|
|
124
|
+
? "blue"
|
|
125
|
+
: "green";
|
|
126
|
+
|
|
127
|
+
return kleur[color](kleur.bold(`${size}${measure}`));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Print Griddo, adapter and Node version.
|
|
132
|
+
*/
|
|
133
|
+
function printExporterLogo(adapter: Adapters) {
|
|
134
|
+
const config = getConfig();
|
|
135
|
+
const nodeVersion = process.version;
|
|
136
|
+
const { griddoVersion } = config;
|
|
137
|
+
const logo = `
|
|
138
|
+
··
|
|
139
|
+
·· Griddo ${griddoVersion}
|
|
140
|
+
··
|
|
141
|
+
·· Adapter: ${adapter}
|
|
142
|
+
·· Node: ${nodeVersion}
|
|
143
|
+
·· React: ${reactVersion}
|
|
144
|
+
··
|
|
145
|
+
`;
|
|
146
|
+
|
|
147
|
+
console.log(logo);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
boxLog,
|
|
152
|
+
buildLog,
|
|
153
|
+
debugLog,
|
|
154
|
+
infoLog,
|
|
155
|
+
pageSizeLog,
|
|
156
|
+
printExporterLogo,
|
|
157
|
+
successLog,
|
|
158
|
+
verboseLog,
|
|
159
|
+
};
|
package/exporter/utils/pages.ts
CHANGED
|
@@ -78,8 +78,8 @@ function getPageMetaData(params: Core.Page): Core.Page["pageMetaData"] {
|
|
|
78
78
|
canonicalURL && canonicalURL.trim() && canonicalURL !== fullUrl
|
|
79
79
|
? canonicalURL.trim()
|
|
80
80
|
: isIndexed
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
? fullUrl
|
|
82
|
+
: undefined,
|
|
83
83
|
locale,
|
|
84
84
|
url,
|
|
85
85
|
index: isIndexed ? "index" : "noindex",
|
|
@@ -105,7 +105,7 @@ function getPageMetaData(params: Core.Page): Core.Page["pageMetaData"] {
|
|
|
105
105
|
*/
|
|
106
106
|
async function createGriddoPageObject(
|
|
107
107
|
page: GriddoSinglePage | GriddoListPage | GriddoMultiPage,
|
|
108
|
-
additionalInfo: PageAdditionalInfo
|
|
108
|
+
additionalInfo: PageAdditionalInfo,
|
|
109
109
|
): Promise<GriddoPageObject> {
|
|
110
110
|
// Extract some props from page
|
|
111
111
|
const {
|
|
@@ -207,7 +207,7 @@ async function createGriddoPageObject(
|
|
|
207
207
|
*/
|
|
208
208
|
async function createGriddoSinglePage(
|
|
209
209
|
page: GriddoSinglePage,
|
|
210
|
-
additionalInfo: PageAdditionalInfo
|
|
210
|
+
additionalInfo: PageAdditionalInfo,
|
|
211
211
|
) {
|
|
212
212
|
return await createGriddoPageObject(page, additionalInfo);
|
|
213
213
|
}
|
|
@@ -224,7 +224,7 @@ async function createGriddoListPages(
|
|
|
224
224
|
template,
|
|
225
225
|
totalQueriedItems,
|
|
226
226
|
}: GriddoListPage,
|
|
227
|
-
additionalInfo: PageAdditionalInfo
|
|
227
|
+
additionalInfo: PageAdditionalInfo,
|
|
228
228
|
) {
|
|
229
229
|
const allPages = pages.map(async (dataInPage, idx) => {
|
|
230
230
|
const isFirstPage = idx === 0;
|
|
@@ -287,12 +287,12 @@ async function createGriddoListPages(
|
|
|
287
287
|
*/
|
|
288
288
|
function createGriddoMultiPages(
|
|
289
289
|
page: GriddoMultiPage,
|
|
290
|
-
additionalInfo: PageAdditionalInfo
|
|
290
|
+
additionalInfo: PageAdditionalInfo,
|
|
291
291
|
) {
|
|
292
292
|
const { multiPageElements: multiPageElementsBulk, ...cleanPage } = page;
|
|
293
293
|
// TODO: Use structuredClone() when node 18 is available.
|
|
294
294
|
const multiPageElements: MultiPageElements = JSON.parse(
|
|
295
|
-
JSON.stringify(multiPageElementsBulk)
|
|
295
|
+
JSON.stringify(multiPageElementsBulk),
|
|
296
296
|
);
|
|
297
297
|
|
|
298
298
|
// Si no hay un elemento sin slug, como mínimo hay que dibujar una página
|
|
@@ -365,7 +365,7 @@ function createGriddoMultiPages(
|
|
|
365
365
|
* @param page The page to get the multipage parts.
|
|
366
366
|
*/
|
|
367
367
|
function getMultiPageElements(
|
|
368
|
-
page: TemplateWithDistributor
|
|
368
|
+
page: TemplateWithDistributor,
|
|
369
369
|
): Promise<MultiPageElements> | null {
|
|
370
370
|
const multiPageElements = new Promise((resolve) => {
|
|
371
371
|
// Recursive
|
|
@@ -373,7 +373,7 @@ function getMultiPageElements(
|
|
|
373
373
|
// No puede ser Core.Page['template'] porque a medida que va bajando en
|
|
374
374
|
// el árbol ya no es la estructura de un template.
|
|
375
375
|
template: Record<string, unknown>,
|
|
376
|
-
level = 0
|
|
376
|
+
level = 0,
|
|
377
377
|
) => {
|
|
378
378
|
// If it doesn't have a "template strcuture"
|
|
379
379
|
if (!template || typeof template !== "object") return;
|
|
@@ -388,7 +388,7 @@ function getMultiPageElements(
|
|
|
388
388
|
const isValidComponent =
|
|
389
389
|
currentComponent || typeof currentComponent === "object";
|
|
390
390
|
const hasGriddoMultiPageProp = JSON.stringify(
|
|
391
|
-
currentComponent
|
|
391
|
+
currentComponent,
|
|
392
392
|
).includes('"hasGriddoMultiPage":true');
|
|
393
393
|
|
|
394
394
|
if (!isValidComponent) continue;
|
|
@@ -434,7 +434,7 @@ function getMultiPageElements(
|
|
|
434
434
|
function getPage(
|
|
435
435
|
itemsPerPage: number,
|
|
436
436
|
items: Array<Fields.QueriedDataItem>,
|
|
437
|
-
page: number
|
|
437
|
+
page: number,
|
|
438
438
|
) {
|
|
439
439
|
return items?.slice(itemsPerPage * (page - 1), itemsPerPage * page);
|
|
440
440
|
}
|
|
@@ -451,13 +451,13 @@ function getPage(
|
|
|
451
451
|
*/
|
|
452
452
|
function getPageCluster(
|
|
453
453
|
itemsPerPage: number,
|
|
454
|
-
items: Array<Fields.QueriedDataItem
|
|
454
|
+
items: Array<Fields.QueriedDataItem>,
|
|
455
455
|
) {
|
|
456
456
|
const totalPagesCount = Math.ceil(items.length / itemsPerPage) || 1;
|
|
457
457
|
const pageNumbers = Array.from({ length: totalPagesCount }, (_, i) => i + 1);
|
|
458
458
|
|
|
459
459
|
return pageNumbers?.map((pageNumber) =>
|
|
460
|
-
getPage(itemsPerPage, items, pageNumber)
|
|
460
|
+
getPage(itemsPerPage, items, pageNumber),
|
|
461
461
|
);
|
|
462
462
|
}
|
|
463
463
|
|
|
@@ -501,7 +501,7 @@ function removeDuplicateTrailing(url: string) {
|
|
|
501
501
|
function addPageNumberToUrl(
|
|
502
502
|
url: string,
|
|
503
503
|
pageNumber: number,
|
|
504
|
-
options?: { addEndingSlash: boolean }
|
|
504
|
+
options?: { addEndingSlash: boolean },
|
|
505
505
|
) {
|
|
506
506
|
const trailingSlash = url.endsWith("/") ? "" : "/";
|
|
507
507
|
const endingSlash = options?.addEndingSlash ? "/" : "";
|
|
@@ -511,7 +511,7 @@ function addPageNumberToUrl(
|
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
return removeDuplicateTrailing(
|
|
514
|
-
`${url}${trailingSlash}${pageNumber}${endingSlash}
|
|
514
|
+
`${url}${trailingSlash}${pageNumber}${endingSlash}`,
|
|
515
515
|
);
|
|
516
516
|
}
|
|
517
517
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { getConfig } from "./core-utils";
|
|
5
|
+
import { throwError } from "../errors";
|
|
6
|
+
import { RenderUUIDError } from "../errors/errors-data";
|
|
7
|
+
|
|
8
|
+
const config = getConfig();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a sentinel file with the current date and time.
|
|
12
|
+
* This file is used to track later if node_modules/@griddo/cx was cleaned by a
|
|
13
|
+
* npm install from a deploy.
|
|
14
|
+
*/
|
|
15
|
+
function createSentinelRenderFile() {
|
|
16
|
+
const { __cx } = config.paths();
|
|
17
|
+
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
18
|
+
fs.writeFileSync(renderSentinelFile, new Date().toISOString());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function deleteSentinelRenderFile() {
|
|
22
|
+
const { __cx } = config.paths();
|
|
23
|
+
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
24
|
+
fs.unlinkSync(renderSentinelFile);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isValidRenderProcessOrThrow() {
|
|
28
|
+
const { __cx } = config.paths();
|
|
29
|
+
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
30
|
+
if (!fs.existsSync(renderSentinelFile)) {
|
|
31
|
+
throwError(RenderUUIDError);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function initRender() {
|
|
36
|
+
createSentinelRenderFile();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function finishRender() {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
finishRender,
|
|
45
|
+
initRender,
|
|
46
|
+
isValidRenderProcessOrThrow,
|
|
47
|
+
createSentinelRenderFile,
|
|
48
|
+
deleteSentinelRenderFile,
|
|
49
|
+
};
|