@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.
Files changed (87) hide show
  1. package/README.md +0 -2
  2. package/build/adapters/gatsby/index.d.ts +1 -1
  3. package/build/artifacts/cx.d.ts +6 -0
  4. package/build/artifacts/gatsby.d.ts +6 -0
  5. package/build/artifacts/index.d.ts +15 -0
  6. package/build/build-complete.js +74 -34
  7. package/build/constants/endpoints.d.ts +18 -0
  8. package/build/constants/envs.d.ts +33 -0
  9. package/build/constants/index.d.ts +53 -0
  10. package/build/index.d.ts +4 -3
  11. package/build/index.js +90 -49
  12. package/build/reset-render.js +74 -34
  13. package/build/run-start-render.js +90 -49
  14. package/build/services/navigation.d.ts +0 -27
  15. package/build/services/robots.d.ts +2 -21
  16. package/build/services/settings.d.ts +3 -22
  17. package/build/services/sites.d.ts +20 -37
  18. package/build/start-render.js +90 -49
  19. package/build/types/global.d.ts +10 -14
  20. package/build/upload-search-content.js +70 -30
  21. package/build/utils/core-utils.d.ts +18 -60
  22. package/build/utils/domains.d.ts +5 -1
  23. package/build/utils/folders.d.ts +38 -13
  24. package/build/utils/loggin.d.ts +49 -0
  25. package/build/utils/render.d.ts +11 -0
  26. package/build/utils/store.d.ts +0 -1
  27. package/cx.config.d.ts +0 -15
  28. package/cx.config.js +3 -16
  29. package/exporter/adapters/gatsby/index.ts +94 -253
  30. package/exporter/adapters/gatsby/utils.ts +11 -10
  31. package/exporter/artifacts/README.md +28 -0
  32. package/exporter/artifacts/cx.ts +26 -0
  33. package/exporter/artifacts/gatsby.ts +28 -0
  34. package/exporter/artifacts/index.ts +30 -0
  35. package/exporter/browser/index.ts +4 -4
  36. package/exporter/constants/endpoints.ts +42 -0
  37. package/exporter/constants/envs.ts +86 -0
  38. package/exporter/constants/index.ts +120 -0
  39. package/exporter/errors/index.ts +2 -2
  40. package/exporter/index.ts +11 -10
  41. package/exporter/react/GriddoIntegrations/index.tsx +3 -3
  42. package/exporter/{build-complete.ts → scripts/build-complete.ts} +4 -4
  43. package/exporter/{reset-render.ts → scripts/reset-render.ts} +3 -3
  44. package/exporter/scripts/start-render.ts +26 -0
  45. package/exporter/{upload-search-content.ts → scripts/upload-search-content.ts} +3 -3
  46. package/exporter/services/auth.ts +7 -5
  47. package/exporter/services/distributors.ts +12 -18
  48. package/exporter/services/domains.ts +2 -12
  49. package/exporter/services/navigation.ts +10 -35
  50. package/exporter/services/robots.ts +35 -58
  51. package/exporter/services/settings.ts +7 -44
  52. package/exporter/services/sites.ts +101 -160
  53. package/exporter/services/store.ts +24 -29
  54. package/exporter/types/api.ts +1 -2
  55. package/exporter/types/global.ts +14 -22
  56. package/exporter/types/pages.ts +0 -9
  57. package/exporter/types/sites.ts +0 -3
  58. package/exporter/utils/api.ts +11 -10
  59. package/exporter/utils/core-utils.ts +66 -181
  60. package/exporter/utils/domains.ts +21 -3
  61. package/exporter/utils/folders.ts +163 -50
  62. package/exporter/utils/health-checks.ts +4 -4
  63. package/exporter/utils/instance.ts +3 -3
  64. package/exporter/utils/integrations.ts +12 -12
  65. package/exporter/utils/loggin.ts +159 -0
  66. package/exporter/utils/pages.ts +15 -15
  67. package/exporter/utils/render.ts +49 -0
  68. package/exporter/utils/searches.ts +5 -5
  69. package/exporter/utils/sites.ts +42 -48
  70. package/exporter/utils/store.ts +9 -10
  71. package/gatsby-browser.tsx +46 -48
  72. package/gatsby-config.ts +5 -5
  73. package/gatsby-node.ts +7 -7
  74. package/package.json +23 -28
  75. package/src/components/Head.tsx +1 -1
  76. package/src/gatsby-node-utils.ts +1 -1
  77. package/src/types.ts +0 -1
  78. package/src/utils.ts +1 -1
  79. package/exporter/start-render.ts +0 -18
  80. /package/build/{build-complete.d.ts → scripts/build-complete.d.ts} +0 -0
  81. /package/build/{move-assets.d.ts → scripts/move-assets.d.ts} +0 -0
  82. /package/build/{reset-render.d.ts → scripts/reset-render.d.ts} +0 -0
  83. /package/build/{run-start-render.d.ts → scripts/run-start-render.d.ts} +0 -0
  84. /package/build/{start-render.d.ts → scripts/start-render.d.ts} +0 -0
  85. /package/build/{upload-search-content.d.ts → scripts/upload-search-content.d.ts} +0 -0
  86. /package/exporter/{move-assets.ts → scripts/move-assets.ts} +0 -0
  87. /package/exporter/{run-start-render.ts → scripts/run-start-render.ts} +0 -0
@@ -3,7 +3,6 @@ import type { Core, Fields } from "@griddo/core";
3
3
 
4
4
  import { Site } from "./sites";
5
5
 
6
- // TODO: JSDoc
7
6
  interface Settings {
8
7
  apiVersion?: string;
9
8
  avoidCanonicalsOnSitemaps?: boolean;
@@ -28,10 +27,8 @@ interface Settings {
28
27
  welcomeText2?: string;
29
28
  }
30
29
 
31
- // TODO: JSDoc
32
30
  type Petition = Record<string, unknown>;
33
31
 
34
- // TODO: JSDoc
35
32
  interface PostSearchInfoProps {
36
33
  title?: string;
37
34
  description: string | null | undefined;
@@ -44,7 +41,6 @@ interface PostSearchInfoProps {
44
41
  url?: string;
45
42
  }
46
43
 
47
- // TODO: JSDoc
48
44
  interface FetchDataProps {
49
45
  page: Core.Page;
50
46
  component: {
@@ -54,7 +50,6 @@ interface FetchDataProps {
54
50
  cacheKey: string;
55
51
  }
56
52
 
57
- // TODO: JSDoc
58
53
  type Domains = Array<{
59
54
  id: number;
60
55
  slug: string;
@@ -64,10 +59,8 @@ type Domains = Array<{
64
59
  /** Describes the type of build process data object. */
65
60
  type BuildProcessData = Record<string, EndSiteRenderBody>;
66
61
 
67
- // TODO: JSDoc
68
62
  type Robot = { path: string; content: string };
69
63
 
70
- // TODO: JSDoc
71
64
  type Robots = Array<Robot>;
72
65
 
73
66
  interface RenderInfo {
@@ -86,9 +79,10 @@ type LifeCyclesNames =
86
79
  | "Archive"
87
80
  | "Clean"
88
81
  | "HealthCheck"
82
+ | "Close"
89
83
  | "__DEBUG__";
90
84
 
91
- type CXDir =
85
+ type PlaceholderPath =
92
86
  | "__exports"
93
87
  | "__caches"
94
88
  | "__cx"
@@ -101,17 +95,7 @@ type CXDir =
101
95
  interface CXConfig {
102
96
  proDomain: string;
103
97
  griddoVersion: string;
104
- CXDir: {
105
- EXPORTS: "__exports";
106
- CACHE: "__caches";
107
- CX: "__cx";
108
- SSG: "__ssg";
109
- COMPONENTS: "__components";
110
- ROOT: "__root";
111
- EXPORTS_DIST: "__exports_dist";
112
- CX_DIST: "__cx_dist";
113
- };
114
- paths: (domain?: string) => Record<CXDir, string>;
98
+ paths: (domain?: string) => Record<PlaceholderPath, string>;
115
99
  }
116
100
 
117
101
  interface AIEmbeddingsResponse {
@@ -119,18 +103,26 @@ interface AIEmbeddingsResponse {
119
103
  message: string;
120
104
  }
121
105
 
122
- export {
106
+ interface Artifacts {
107
+ disposables: Array<string>;
108
+ cacheables: Array<string>;
109
+ initials: Array<string>;
110
+ archivables: Array<string>;
111
+ }
112
+
113
+ export type {
114
+ AIEmbeddingsResponse,
115
+ Artifacts,
123
116
  BuildProcessData,
124
117
  CXConfig,
125
- CXDir,
126
118
  Domains,
127
119
  FetchDataProps,
128
120
  LifeCyclesNames,
129
121
  Petition,
122
+ PlaceholderPath,
130
123
  PostSearchInfoProps,
131
124
  RenderInfo,
132
125
  Robot,
133
126
  Robots,
134
127
  Settings,
135
- type AIEmbeddingsResponse,
136
128
  };
@@ -10,13 +10,11 @@ export type APIPageObject = Core.Page & { id: number } & {
10
10
  footer: number | null;
11
11
  };
12
12
 
13
- // TODO: JSDoc
14
13
  export type CleanPage = Core.Page & {
15
14
  isRoot: boolean;
16
15
  defaultLang?: Core.SiteLanguage | undefined;
17
16
  };
18
17
 
19
- // TODO: JSDoc
20
18
  export type RenderPage = Core.Page & {
21
19
  isRoot?: boolean;
22
20
  multiPageElements: MultiPageElements;
@@ -31,12 +29,10 @@ export type RenderPage = Core.Page & {
31
29
  mode: "list";
32
30
  };
33
31
 
34
- // TODO: JSDoc
35
32
  export type GriddoSinglePage = Core.Page & {
36
33
  defaultLang?: Core.SiteLanguage;
37
34
  };
38
35
 
39
- // TODO: JSDoc
40
36
  export type GriddoListPage = Core.Page & {
41
37
  page: APIPageObject;
42
38
  pages: Array<Array<Fields.QueriedDataItem>>;
@@ -52,7 +48,6 @@ export type GriddoListPage = Core.Page & {
52
48
  totalQueriedItems: Array<Fields.QueriedDataItem>;
53
49
  };
54
50
 
55
- // TODO: JSDoc
56
51
  export type GriddoMultiPage = Core.Page & {
57
52
  header: number | null;
58
53
  footer: number | null;
@@ -61,7 +56,6 @@ export type GriddoMultiPage = Core.Page & {
61
56
  defaultLang?: Core.SiteLanguage | undefined;
62
57
  };
63
58
 
64
- // TODO: JSDoc
65
59
  export interface AdditionalInfo {
66
60
  baseUrl: string;
67
61
  cloudinaryName?: string;
@@ -86,7 +80,6 @@ export interface AdditionalInfo {
86
80
  theme: string;
87
81
  }
88
82
 
89
- // TODO: JSDoc
90
83
  export interface PageAdditionalInfo extends AdditionalInfo {
91
84
  navigations: {
92
85
  header: Record<string, unknown> | null;
@@ -94,7 +87,6 @@ export interface PageAdditionalInfo extends AdditionalInfo {
94
87
  };
95
88
  }
96
89
 
97
- // TODO: JSDoc
98
90
  export type MultiPageElement = {
99
91
  component: string;
100
92
  title: string | Required<Fields.Heading>;
@@ -105,7 +97,6 @@ export type MultiPageElement = {
105
97
  metaDescription: string;
106
98
  };
107
99
 
108
- // TODO: JSDoc
109
100
  export type MultiPageElements = Array<MultiPageElement>;
110
101
 
111
102
  /**
@@ -46,7 +46,6 @@ export interface Site
46
46
  updated: boolean;
47
47
  }
48
48
 
49
- // TODO: JSDoc
50
49
  export interface SiteData {
51
50
  siteInfo: Site;
52
51
  validPagesIds: Array<number>;
@@ -59,8 +58,6 @@ export interface SiteData {
59
58
  socials: SocialsResponse;
60
59
  }
61
60
 
62
- // TODO: JSDoc
63
61
  export type SiteHash = string | null;
64
62
 
65
- // TODO: JSDoc
66
63
  export type HashSites = Record<string, number | string>;
@@ -13,7 +13,8 @@ import chalk from "chalk";
13
13
  import dotenv from "dotenv";
14
14
 
15
15
  import { saveCache, searchCacheData } from "./cache";
16
- import { delay, getSafeSiteId, logInfo, msToSec } from "./core-utils";
16
+ import { delay, getSafeSiteId, msToSec } from "./core-utils";
17
+ import { infoLog } from "./loggin";
17
18
  import { AuthService } from "../services/auth";
18
19
 
19
20
  dotenv.config();
@@ -39,7 +40,7 @@ const {
39
40
  async function requestAPI<T extends APIResponses>(
40
41
  props: APIRequest,
41
42
  method: Method,
42
- appendToLog = ""
43
+ appendToLog = "",
43
44
  ): Promise<T> {
44
45
  const { endpoint, body, cacheKey = "", attempt = 1, headers } = props;
45
46
  const cacheOptions = { endpoint, body, headers, cacheKey };
@@ -53,8 +54,8 @@ async function requestAPI<T extends APIResponses>(
53
54
  const siteId = getSafeSiteId(cacheData);
54
55
  const siteIdMsg = siteId ? `site: ${siteId}` : "";
55
56
  const duration = msToSec(new Date().getTime() - start.getTime());
56
- logInfo(
57
- `${method} (cache) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`
57
+ infoLog(
58
+ `${method} (cache) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`,
58
59
  );
59
60
  return cacheData;
60
61
  }
@@ -73,8 +74,8 @@ async function requestAPI<T extends APIResponses>(
73
74
  const siteId = getSafeSiteId(data);
74
75
  const siteIdMsg = siteId ? `site: ${siteId}` : "";
75
76
  const duration = msToSec(new Date().getTime() - start.getTime());
76
- logInfo(
77
- `${method} (fetch) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`
77
+ infoLog(
78
+ `${method} (fetch) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`,
78
79
  );
79
80
 
80
81
  saveCache(cacheOptions, data);
@@ -123,7 +124,7 @@ Max attempts ${RETRY_ATTEMPTS} reached
123
124
  attempt: attempt + 1,
124
125
  },
125
126
  method,
126
- appendToLog
127
+ appendToLog,
127
128
  );
128
129
  }
129
130
  }
@@ -159,7 +160,7 @@ async function postApi<T extends APIResponses>(props: PostAPI) {
159
160
  const distributorBodyParams =
160
161
  endpoint.endsWith("/distributor") &&
161
162
  `# Distributor body: ${JSON.stringify(body)} lang: ${JSON.stringify(
162
- headers?.lang
163
+ headers?.lang,
163
164
  )}`;
164
165
 
165
166
  return await requestAPI<T>(props, "post", distributorBodyParams || "");
@@ -180,7 +181,7 @@ function showApiError(error: AxiosError, options: ShowApiErrorOptions) {
180
181
  typeof callInfo[item] === "object"
181
182
  ? JSON.stringify(callInfo[item])
182
183
  : callInfo[item]
183
- }`
184
+ }`,
184
185
  );
185
186
  }
186
187
 
@@ -206,7 +207,7 @@ ${apiResponseStr}
206
207
  ${errorDetailsStr}
207
208
 
208
209
  =============
209
- `)
210
+ `),
210
211
  );
211
212
  }
212
213
 
@@ -1,4 +1,3 @@
1
- import type { Adapters } from "../adapters";
2
1
  import type { APIResponses } from "../types/api";
3
2
  import type { CXConfig, LifeCyclesNames } from "../types/global";
4
3
  import type { APIPageObject } from "../types/pages";
@@ -10,33 +9,20 @@ import path from "node:path";
10
9
  import chalk from "chalk";
11
10
  import dotenv from "dotenv";
12
11
  import fsx from "fs-extra";
13
- import gradient from "gradient-string";
14
12
  import pkgDir from "pkg-dir";
15
13
 
16
14
  import { createDirsSync, removeDirsSync } from "./folders";
15
+ import { boxLog, verboseLog } from "./loggin";
16
+ import { generateBuildReport, generateSitemaps } from "./sites";
17
+ import { envs } from "../constants";
18
+ import { writeRobots } from "../services/robots";
17
19
 
18
20
  dotenv.config();
19
21
 
20
22
  const config = getConfig();
21
23
 
22
- const GRIDDO_DEBUG_LOGS = isTruthy(process.env.GRIDDO_DEBUG_LOGS);
23
- const GRIDDO_BUILD_LOGS = isTruthy(process.env.GRIDDO_BUILD_LOGS);
24
-
25
24
  const instanceRootDir = pkgDir.sync()!; // instance root dir
26
25
 
27
- const attempts = {
28
- clean: JSON.parse(process.env.GRIDDO_CLEAN_LIFECYCLE_MAX_ATTEMPTS || "1"),
29
- prepare: JSON.parse(process.env.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS || "1"),
30
- restore: JSON.parse(process.env.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS || "1"),
31
- data: JSON.parse(process.env.GRIDDO_DATA_LIFECYCLE_MAX_ATTEMPTS || "1"),
32
- ssg: JSON.parse(process.env.GRIDDO_SSG_LIFECYCLE_MAX_ATTEMPTS || "2"),
33
- relocation: JSON.parse(
34
- process.env.GRIDDO_RELOCATION_LIFECYCLE_MAX_ATTEMPTS || "1"
35
- ),
36
- meta: JSON.parse(process.env.GRIDDO_META_LIFECYCLE_MAX_ATTEMPTS || "4"),
37
- archive: JSON.parse(process.env.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS || "1"),
38
- };
39
-
40
26
  /**
41
27
  * Returns the configuration file content.
42
28
  *
@@ -67,9 +53,9 @@ async function exporterCreateInitialDirectories(domain: string) {
67
53
  const { __exports, __caches } = config.paths(domain);
68
54
 
69
55
  createDirsSync([__exports]);
70
- verbose("create `exports/sites/<domain>` directory");
56
+ verboseLog("create `exports/sites/<domain>` directory");
71
57
  createDirsSync([__caches]);
72
- verbose("create `caches/<domain>` directory");
58
+ verboseLog("create `caches/<domain>` directory");
73
59
  }
74
60
 
75
61
  /**
@@ -81,21 +67,7 @@ async function exporterCleanDisposableDirectories(domain: string) {
81
67
  const { __cx } = config.paths(domain);
82
68
 
83
69
  removeDirsSync(__cx, ["store", "apiCache", "dist"]);
84
- verbose("clean `store`, `apiCache` and `dist` directories from `__cx`");
85
- }
86
-
87
- /**
88
- * Custom basic logging function controlled by a environment variable.
89
- *
90
- * @param str The string to be logged.
91
- */
92
- function verbose(str: string) {
93
- if (GRIDDO_DEBUG_LOGS) {
94
- console.log(
95
- chalk.hex("#ffff33")("verbose"),
96
- chalk.gray(str.replace(/(\s)\s+/g, "$1").trim())
97
- );
98
- }
70
+ verboseLog("clean `store`, `apiCache` and `dist` directories from `__cx`");
99
71
  }
100
72
 
101
73
  /**
@@ -142,70 +114,6 @@ function walk(dir: string) {
142
114
  return results;
143
115
  }
144
116
 
145
- /**
146
- * Custom log inside a line-box.
147
- *
148
- * @param stringValue The string to be logged.
149
- * @param paddingInline The number of white spaces inside the box at left and right.
150
- * @param paddingBlock The number of white spaces inside the box at top and bottom.
151
- */
152
- function logBox(
153
- stringValue: string,
154
- title = "",
155
- paddingInline = 1,
156
- paddingBlock = 1
157
- ) {
158
- const lines = stringValue
159
- .split("\n") // lines
160
- .map((line) => line.trim()); // remove extra spaces
161
- const windowTitle = title ? ` ${title} ` : "";
162
- const windowTitleLength = title ? windowTitle.length : 0;
163
- const longerContent =
164
- Math.max(...lines.map((l) => l.length)) + paddingInline * 2;
165
- const longerLine = Math.max(longerContent, windowTitleLength);
166
- const paddingBlockString = `│${" ".repeat(longerLine)}│\n`.repeat(
167
- paddingBlock
168
- );
169
- const minWidth = longerLine;
170
- const borderTop = `╭${windowTitle}${"─".repeat(
171
- minWidth - windowTitleLength
172
- )}╮\n`;
173
- const borderBottom = `╰${"─".repeat(minWidth)}╯`;
174
- const content = lines
175
- .map((l) => {
176
- const mr = " ".repeat(longerLine - l.length - paddingInline);
177
- return `│${" ".repeat(paddingInline)}${l}${mr}│\n`;
178
- })
179
- .join("");
180
-
181
- console.log(
182
- `${borderTop}${paddingBlockString}${content}${paddingBlockString}${borderBottom}`
183
- );
184
- }
185
-
186
- /**
187
- * Custom basic logging function controlled by a environment variable.
188
- * Strip double spaces.
189
- *
190
- * @param str The string to be logged.
191
- */
192
- function logInfo(str: string) {
193
- if (GRIDDO_BUILD_LOGS) {
194
- console.info(str.replace(/(\s)\s+/g, "$1").trim());
195
- }
196
- }
197
-
198
- /**
199
- * Internal log
200
- * @param values The values to be logged.
201
- */
202
- function debug(...values: Array<unknown>) {
203
- if (!GRIDDO_DEBUG_LOGS) {
204
- return;
205
- }
206
- console.log(...values);
207
- }
208
-
209
117
  /**
210
118
  * Custom delay using the "promise hack",
211
119
  *
@@ -215,33 +123,6 @@ function delay(ms: number) {
215
123
  return new Promise((res) => setTimeout(res, ms));
216
124
  }
217
125
 
218
- /**
219
- * Return a scale size colors with a number and a measure string (KB by default).
220
- *
221
- * @param size The page size in KB.
222
- * @param measure The measure string to be added in the log.
223
- */
224
- function logPageSize(size: number, measure = "KB") {
225
- const sizeScale = {
226
- low: 50,
227
- mid: 80,
228
- large: 130,
229
- extraLarge: 210,
230
- };
231
-
232
- // Ternary pawa!
233
- const color =
234
- size > sizeScale.large
235
- ? "red"
236
- : size > sizeScale.mid
237
- ? "magenta"
238
- : size > sizeScale.low
239
- ? "blue"
240
- : "green";
241
-
242
- return chalk[color].bold(`${size}${measure}`);
243
- }
244
-
245
126
  /**
246
127
  * Converts milliseconds to seconds with a fixed number of decimals.
247
128
  *
@@ -259,9 +140,9 @@ export function msToSec(ms: number, decimals = 3) {
259
140
  */
260
141
  export function getSafeSiteId(response: APIResponses) {
261
142
  if (typeof response === "string") {
262
- return undefined
143
+ return undefined;
263
144
  }
264
-
145
+
265
146
  return "site" in response && response.site ? response?.site : undefined;
266
147
  }
267
148
 
@@ -290,23 +171,6 @@ function siteList(sites: Array<Site>) {
290
171
  return sites.map(({ name, id }) => `${name} (${id})`).join(", ");
291
172
  }
292
173
 
293
- /**
294
- * Print the great Griddo Exporter logo in ASCII.
295
- */
296
- function printExporterLogo(adapter: Adapters) {
297
- const nodeVersion = process.version;
298
- const { griddoVersion } = config;
299
- const logo = `
300
- ··
301
- ·· Griddo Exporter ${griddoVersion}
302
- ·· Adapter: ${adapter}
303
- ·· Node: ${nodeVersion}
304
- ··
305
- `;
306
-
307
- console.log(gradient.cristal(logo));
308
- }
309
-
310
174
  /**
311
175
  * Remove unused files (old) inside the `apiCache` dir
312
176
  *
@@ -350,7 +214,6 @@ function sanitizeAPICacheDir() {
350
214
  if (validPageFile) filesByIdMap[id] = fileName;
351
215
  }
352
216
 
353
- // TODO: Remove this counter for production
354
217
  let counter = 0;
355
218
 
356
219
  // Delete files using the store object filesById as reference map.
@@ -376,12 +239,16 @@ function sanitizeAPICacheDir() {
376
239
  * @returns A promise that resolves with the total execution time in seconds.
377
240
  */
378
241
  async function measureExecutionTime(
379
- ...functions: Array<(...args: Array<unknown>) => unknown | Promise<any>>
242
+ functions: Array<(...args: Array<unknown>) => unknown | Promise<unknown>>,
243
+ delayInMS = 0,
380
244
  ): Promise<number> {
381
245
  const start = process.hrtime();
382
246
 
383
247
  for (const func of functions) {
384
248
  await func();
249
+ if (delayInMS > 0) {
250
+ await delay(delayInMS);
251
+ }
385
252
  }
386
253
 
387
254
  const [seconds, miliseconds] = process.hrtime(start);
@@ -392,7 +259,7 @@ async function measureExecutionTime(
392
259
 
393
260
  function pause(title: string) {
394
261
  const isPauseEnabled = !!JSON.parse(
395
- process.env.GRIDDO_RENDER_BREAKPOINTS_FEATURE || "false"
262
+ process.env.GRIDDO_RENDER_BREAKPOINTS_FEATURE || "false",
396
263
  );
397
264
 
398
265
  if (!isPauseEnabled) {
@@ -401,51 +268,64 @@ function pause(title: string) {
401
268
 
402
269
  return new Promise<void>((resolve) => {
403
270
  console.log("\n");
404
- logBox(`⌛️ ${title}`, "", 1, 0);
271
+ boxLog(`⌛️ ${title}`, "", 1, 0);
405
272
  process.stdin.once("data", () => {
406
273
  resolve();
407
274
  });
408
275
  });
409
276
  }
410
277
 
411
- function startLifeCycle(lifeCyleName: string) {
412
- console.info(`
413
- ${chalk.blue(`info`)} start ${lifeCyleName} life-cycle`);
414
- }
415
-
416
- function successLifeCyle(value: string) {
417
- console.info(`${chalk.green("success")} ${value}`);
418
- }
419
-
420
278
  /**
421
279
  * Executes a life cycle process, which involves executing an array of
422
280
  * functions, printing to the console, and handling errors with optional
423
281
  * retries.
424
282
  *
425
283
  * @async
426
- * @param args - The arguments object.
427
- * @param args.steps - An array of functions to execute.
428
- * @param args.name - The name of the life cycle.
429
- * @param args.attempts=1 - The number of retry attempts allowed in case of errors.
430
- * @param args.bypass - Skip the step functions.
284
+ * @param name - The name of the life cycle.
285
+ * @param options - The arguments object.
286
+ * @param options.steps - An array of functions to execute.
287
+ * @param options.delay - Delay between steps functions.
288
+ * @param options.bypass - Skip the step functions.
431
289
  * @returns - A promise that resolves when the life cycle process is completed.
432
290
  */
433
- async function doLifeCycle(args: {
434
- steps: Array<(...args: Array<unknown>) => unknown | Promise<any>>;
435
- name: LifeCyclesNames;
436
- attempts?: number;
437
- }) {
438
- const { steps, name, attempts } = args;
291
+ async function doLifeCycle(
292
+ name: LifeCyclesNames,
293
+ options: {
294
+ steps: Array<(...args: Array<unknown>) => unknown | Promise<any>>;
295
+ delay?: number;
296
+ bypass?: boolean;
297
+ },
298
+ ) {
299
+ const { steps, bypass, delay } = options;
300
+
301
+ if (bypass) {
302
+ return;
303
+ }
304
+
305
+ const attemptsByLifeCycleName: Record<LifeCyclesNames, number> = {
306
+ Archive: envs.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS,
307
+ Data: envs.GRIDDO_DATA_LIFECYCLE_MAX_ATTEMPTS,
308
+ Meta: envs.GRIDDO_META_LIFECYCLE_MAX_ATTEMPTS,
309
+ Relocation: envs.GRIDDO_RELOCATION_LIFECYCLE_MAX_ATTEMPTS,
310
+ Clean: envs.GRIDDO_CLEAN_LIFECYCLE_MAX_ATTEMPTS,
311
+ Restore: envs.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS,
312
+ Prepare: envs.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS,
313
+ Close: envs.GRIDDO_CLOSE_LIFECYCLE_MAX_ATTEMPTS,
314
+ SSG: envs.GRIDDO_SSG_LIFECYCLE_MAX_ATTEMPTS,
315
+ HealthCheck: 1,
316
+ __DEBUG__: 1,
317
+ };
439
318
 
440
319
  let trysCount = 0;
441
- const maxTrysAccepted = attempts || 1;
320
+ const maxTrysAccepted = attemptsByLifeCycleName[name] || 1;
442
321
 
443
322
  while (trysCount < maxTrysAccepted) {
444
323
  try {
445
324
  console.info(`\n${chalk.blue(`info`)} start ${name} life-cycle`);
446
- const exeTime = await measureExecutionTime(...steps);
325
+ const exeTime = await measureExecutionTime(steps, delay);
447
326
  console.info(`${chalk.green("success")} ${name} - ${exeTime}s`);
448
327
  // if no errors, go out!! :)
328
+ await pause(`${name} LifeCycle`);
449
329
  break;
450
330
  } catch (error) {
451
331
  const errorString = chalk.bgRed.black(` Error in ${name} LifeCycle `);
@@ -459,7 +339,7 @@ async function doLifeCycle(args: {
459
339
  }
460
340
  if (trysCount === maxTrysAccepted) {
461
341
  throw new Error(
462
- `Exceeded maximum retry attempts (${maxTrysAccepted}) for ${name} LifeCycle`
342
+ `Exceeded maximum retry attempts (${maxTrysAccepted}) for ${name} LifeCycle`,
463
343
  );
464
344
  }
465
345
  }
@@ -483,9 +363,21 @@ function isVersionLowerThan(versionA: string, versionB: string) {
483
363
  return !isVersionGreaterThan(versionA, versionB);
484
364
  }
485
365
 
366
+ /**
367
+ * Creates additional files after the render: sitemaps, robots and a report of
368
+ * the finished render.
369
+ *
370
+ * @async
371
+ * @param domain
372
+ */
373
+ async function createRenderMetadata(domain: string) {
374
+ await generateBuildReport();
375
+ await generateSitemaps();
376
+ await writeRobots(domain);
377
+ }
378
+
486
379
  export {
487
- attempts,
488
- debug,
380
+ createRenderMetadata,
489
381
  delay,
490
382
  doLifeCycle,
491
383
  exporterCleanDisposableDirectories,
@@ -495,17 +387,10 @@ export {
495
387
  isTruthy,
496
388
  isVersionGreaterThan,
497
389
  isVersionLowerThan,
498
- logBox,
499
- logInfo,
500
- logPageSize,
501
390
  measureExecutionTime,
502
391
  pause,
503
- printExporterLogo,
504
392
  removeProperties,
505
393
  sanitizeAPICacheDir,
506
394
  siteList,
507
- startLifeCycle,
508
- successLifeCyle,
509
- verbose,
510
395
  walk,
511
396
  };
@@ -1,9 +1,27 @@
1
1
  import type { Domains } from "../types/global";
2
2
 
3
- import { verbose } from "./core-utils";
3
+ import { verboseLog } from "./loggin";
4
+ import { throwError } from "../errors";
5
+ import { NoDomainsFoundError } from "../errors/errors-data";
4
6
  import { AuthService } from "../services/auth";
5
7
  import { DomainsService } from "../services/domains";
6
8
 
9
+ /**
10
+ * Return an array of domains name (string) of the current instance.
11
+ */
12
+ async function getInstanceDomainsOrThrow() {
13
+ await AuthService.login();
14
+ const domains = await DomainsService.getAll();
15
+
16
+ if (!domains.length) {
17
+ throwError(NoDomainsFoundError);
18
+ }
19
+
20
+ verboseLog(`getting domains names (${domains.length})`);
21
+
22
+ return getDomainSlugs(domains);
23
+ }
24
+
7
25
  /**
8
26
  * Return an array of domains name (string) of the current instance.
9
27
  */
@@ -11,7 +29,7 @@ async function getInstanceDomains() {
11
29
  await AuthService.login();
12
30
  const domains = await DomainsService.getAll();
13
31
 
14
- verbose(`Getting domains slugs (${domains.length})`);
32
+ verboseLog(`Getting domains slugs (${domains.length})`);
15
33
 
16
34
  return getDomainSlugs(domains);
17
35
  }
@@ -30,4 +48,4 @@ function getDomainSlugs(domains: Domains) {
30
48
  return [...new Set(filteredDomains)];
31
49
  }
32
50
 
33
- export { getInstanceDomains };
51
+ export { getInstanceDomains, getInstanceDomainsOrThrow };