@griddo/cx 11.1.3 → 11.1.5

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.
@@ -1,5 +1,5 @@
1
1
  import type { APIResponses } from "../types/api";
2
- import type { CXConfig, LifeCyclesNames } from "../types/global";
2
+ import type { CXConfig, LifeCyclesNames, LifeCycleSteps } from "../types/global";
3
3
  declare const instanceRootDir: string;
4
4
  /**
5
5
  * Returns the configuration file content.
@@ -91,7 +91,7 @@ declare function pause(title: string): Promise<void> | undefined;
91
91
  * @returns - A promise that resolves when the life cycle process is completed.
92
92
  */
93
93
  declare function doLifeCycle(name: LifeCyclesNames, options: {
94
- steps: Array<(...args: Array<unknown>) => unknown | Promise<unknown>>;
94
+ steps: LifeCycleSteps;
95
95
  delay?: number;
96
96
  bypass?: boolean;
97
97
  }): Promise<void>;
@@ -104,5 +104,10 @@ declare function doLifeCycle(name: LifeCyclesNames, options: {
104
104
  */
105
105
  declare function createRenderMetadata(domain: string): Promise<void>;
106
106
  declare function removeAllSiteDirsFromStore(): void;
107
+ /**
108
+ * Save render information to a file to use as debug log.
109
+ *
110
+ * This information will **not** be sent to any API.
111
+ */
107
112
  declare function saveBuildEndLogs(): void;
108
113
  export { createRenderMetadata, delay, doLifeCycle, getConfig, getSafeSiteId, instanceRootDir, isTruthy, measureExecutionTime, msToSec, pause, removeAllSiteDirsFromStore, removeProperties, sanitizeAPICacheDir, saveBuildEndLogs, walk, walkStore, };
@@ -21,13 +21,11 @@ declare function unpublishSites(sites: Array<Site>): Promise<void>;
21
21
  */
22
22
  declare function getSiteData(siteID: number): Promise<SiteData>;
23
23
  /**
24
- * Save a file with the end of build process
24
+ * Save a file with the end of build process to use as `build-end` signal.
25
25
  */
26
26
  declare function generateBuildReport(): Promise<void>;
27
27
  /**
28
28
  * Generate sitemaps and save them into file system.
29
- *
30
- * @param sites An array of sites
31
29
  */
32
30
  declare function generateSitemaps(): Promise<void>;
33
31
  export { checkSites, generateBuildReport, generateSitemaps, getSiteData, unpublishSites, };
@@ -1,4 +1,8 @@
1
- import type { Artifacts } from "../../types/global";
1
+ import type {
2
+ Artifacts,
3
+ LifeCyclesNames,
4
+ LifeCycleSteps,
5
+ } from "../../types/global";
2
6
 
3
7
  import path from "node:path";
4
8
 
@@ -68,6 +72,11 @@ export async function renderDomainsWithGatsbyAdapter() {
68
72
  initials: [],
69
73
  archivables: [],
70
74
  };
75
+ // Compose artifacts
76
+ const disposableArtifacts = [
77
+ ...cxArtifacts.disposables,
78
+ ...gatsbyArtifacts.disposables,
79
+ ];
71
80
 
72
81
  // These variables are involved in the build for create the dist directory
73
82
  // from public and pass to the gatsby-build command via spawnSync.
@@ -76,77 +85,82 @@ export async function renderDomainsWithGatsbyAdapter() {
76
85
 
77
86
  // LifeCycles
78
87
 
79
- await doLifeCycle("Clean", {
80
- steps: [
81
- () =>
82
- removeArtifacts([
83
- ...cxArtifacts.disposables,
84
- ...gatsbyArtifacts.disposables,
85
- ]),
86
- ],
87
- });
88
-
89
- await doLifeCycle("Prepare", {
90
- steps: [() => createArtifacts(cxArtifacts.initials)],
91
- });
92
-
93
- await doLifeCycle("Restore", {
94
- steps: [
95
- () => copyArtifacts(__components, __ssg, ["static"]),
96
- () => copyArtifacts(__exports, __cx, cxArtifacts.archivables),
97
- () =>
98
- renameArtifact(path.join(__cx, "dist"), path.join(__ssg, "public")),
99
- () => moveArtifacts(__cache, __cx, cxArtifacts.cacheables),
100
- () => moveArtifacts(__cache, __ssg, gatsbyArtifacts.cacheables),
101
- ],
102
- });
103
-
104
- await doLifeCycle("Data", {
105
- steps: [() => createBuildData(domain)],
106
- });
107
-
108
- await doLifeCycle("SSG", {
109
- steps: [() => runGatsbyBuildCommand(assetPrefix)],
110
- });
111
-
112
- await doLifeCycle("Relocation", {
113
- steps: [() => createDistFromGatsbyPublic(domain, needsAssetPrefix)],
114
- });
115
-
116
- await doLifeCycle("Meta", {
117
- steps: [
118
- //
119
- () => createRenderMetadata(domain),
120
- () => saveBuildEndLogs(),
121
- ],
122
- });
123
-
124
- await doLifeCycle("Archive", {
125
- steps: [
126
- () => removeVirtualPagesFromStore(),
127
- () => clearEmptyDirs(path.join(__cx, "dist")),
128
- () =>
129
- moveArtifacts(__cx, __exports, cxArtifacts.archivables, {
130
- withBackup: true,
131
- }),
132
- () => moveArtifacts(__cx, __cache, cxArtifacts.cacheables),
133
- () => moveArtifacts(__ssg, __cache, gatsbyArtifacts.cacheables),
134
- ],
135
- });
136
-
137
- await doLifeCycle("Close", {
138
- steps: [
139
- () =>
140
- removeArtifacts([
141
- ...cxArtifacts.disposables,
142
- ...gatsbyArtifacts.disposables,
143
- ]),
144
- ],
145
- });
146
-
147
- await doLifeCycle("HealthCheck", {
148
- steps: [() => isValidRenderProcessOrThrow()],
149
- });
88
+ const allLifeCycles: Array<{
89
+ name: LifeCyclesNames;
90
+ steps: LifeCycleSteps;
91
+ }> = [
92
+ {
93
+ name: "Clean",
94
+ steps: [() => removeArtifacts(disposableArtifacts)],
95
+ },
96
+
97
+ {
98
+ name: "Prepare",
99
+ steps: [() => createArtifacts(cxArtifacts.initials)],
100
+ },
101
+
102
+ {
103
+ name: "Restore",
104
+ steps: [
105
+ () => copyArtifacts(__components, __ssg, ["static"]),
106
+ () => copyArtifacts(__exports, __cx, cxArtifacts.archivables),
107
+ () =>
108
+ renameArtifact(path.join(__cx, "dist"), path.join(__ssg, "public")),
109
+ () => moveArtifacts(__cache, __cx, cxArtifacts.cacheables),
110
+ () => moveArtifacts(__cache, __ssg, gatsbyArtifacts.cacheables),
111
+ ],
112
+ },
113
+
114
+ {
115
+ name: "Data",
116
+ steps: [() => createBuildData(domain)],
117
+ },
118
+
119
+ {
120
+ name: "SSG",
121
+ steps: [() => runGatsbyBuildCommand(assetPrefix)],
122
+ },
123
+
124
+ {
125
+ name: "Relocation",
126
+ steps: [() => createDistFromGatsbyPublic(domain, needsAssetPrefix)],
127
+ },
128
+
129
+ {
130
+ name: "Meta",
131
+ steps: [() => createRenderMetadata(domain), () => saveBuildEndLogs()],
132
+ },
133
+
134
+ {
135
+ name: "Archive",
136
+ steps: [
137
+ () => removeVirtualPagesFromStore(),
138
+ () => clearEmptyDirs(path.join(__cx, "dist")),
139
+ () =>
140
+ moveArtifacts(__cx, __exports, cxArtifacts.archivables, {
141
+ withBackup: true,
142
+ }),
143
+ () => moveArtifacts(__cx, __cache, cxArtifacts.cacheables),
144
+ () => moveArtifacts(__ssg, __cache, gatsbyArtifacts.cacheables),
145
+ ],
146
+ },
147
+
148
+ {
149
+ name: "Close",
150
+ steps: [() => removeArtifacts(disposableArtifacts)],
151
+ },
152
+
153
+ {
154
+ name: "HealthCheck",
155
+ steps: [() => isValidRenderProcessOrThrow()],
156
+ },
157
+ ];
158
+
159
+ for (const { name, steps } of allLifeCycles) {
160
+ await doLifeCycle(name, {
161
+ steps: steps,
162
+ });
163
+ }
150
164
 
151
165
  deleteSentinelRenderFile();
152
166
  }
@@ -7,7 +7,10 @@ import { get } from "../utils/api";
7
7
  * Get an array of available domain.
8
8
  */
9
9
  async function getAllDomains() {
10
- return await get<Domains>({ endpoint: endpoints.DOMAINS });
10
+ return await get<Domains>({
11
+ endpoint: endpoints.DOMAINS,
12
+ useApiCacheDir: false,
13
+ });
11
14
  }
12
15
 
13
16
  export { getAllDomains };
@@ -41,7 +41,7 @@ class RobotsService {
41
41
  }
42
42
 
43
43
  /**
44
- * Write robots.txt files for the current rendering domain.
44
+ * Write robots.txt files for the domain.
45
45
  */
46
46
  async writeFiles(domain: string) {
47
47
  const { __cx } = config.paths(domain);
@@ -8,7 +8,10 @@ async function getAllSettings() {
8
8
  }
9
9
 
10
10
  async function resetRender() {
11
- await post({ endpoint: endpoints.RESET_RENDER });
11
+ await post({
12
+ endpoint: endpoints.RESET_RENDER,
13
+ useApiCacheDir: false,
14
+ });
12
15
  }
13
16
 
14
17
  export { getAllSettings, resetRender };
@@ -71,6 +71,7 @@ async function endSiteRender(id: number, body: EndSiteRenderBody) {
71
71
  return await post<EndPageInfoResponse>({
72
72
  endpoint: `${prefix}${id}${suffix}`,
73
73
  body,
74
+ useApiCacheDir: false,
74
75
  });
75
76
  }
76
77
 
@@ -124,6 +124,8 @@ export interface APIRequest {
124
124
  * @todo type this correctly from axios types
125
125
  */
126
126
  headers?: any; // Record<string, unknown>;
127
+ /* Save results in apiCache folder */
128
+ useApiCacheDir?: boolean;
127
129
  }
128
130
 
129
131
  /** Type with the POST request properties. */
@@ -68,6 +68,10 @@ interface RenderInfo {
68
68
  sitesToPublish: Array<Site>;
69
69
  }
70
70
 
71
+ type LifeCycleSteps = Array<
72
+ (...args: Array<unknown>) => unknown | Promise<unknown>
73
+ >;
74
+
71
75
  type LifeCyclesNames =
72
76
  | "Prepare"
73
77
  | "Restore"
@@ -126,4 +130,5 @@ export type {
126
130
  Robot,
127
131
  Robots,
128
132
  Settings,
133
+ LifeCycleSteps,
129
134
  };
@@ -44,11 +44,18 @@ async function requestAPI<T extends APIResponses>(
44
44
  method: Method,
45
45
  appendToLog = "",
46
46
  ): Promise<T> {
47
- const { endpoint, body, cacheKey = "", attempt = 1, headers } = props;
47
+ const {
48
+ endpoint,
49
+ body,
50
+ cacheKey = "",
51
+ attempt = 1,
52
+ headers,
53
+ useApiCacheDir = true,
54
+ } = props;
48
55
  const cacheOptions = { endpoint, body, headers, cacheKey };
49
56
 
50
57
  // Cache
51
- if (cacheKey) {
58
+ if (cacheKey && useApiCacheDir) {
52
59
  const start = new Date();
53
60
  const cacheData = searchCacheData<T>(cacheOptions);
54
61
 
@@ -83,7 +90,9 @@ async function requestAPI<T extends APIResponses>(
83
90
  `${method} (fetch) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`,
84
91
  );
85
92
 
86
- saveCache(cacheOptions, data);
93
+ if (useApiCacheDir) {
94
+ saveCache(cacheOptions, data);
95
+ }
87
96
 
88
97
  // Only save registers if alerts are enabled
89
98
  if (envs.GRIDDO_ALERT_FEATURE) {
@@ -1,5 +1,9 @@
1
1
  import type { APIResponses } from "../types/api";
2
- import type { CXConfig, LifeCyclesNames } from "../types/global";
2
+ import type {
3
+ CXConfig,
4
+ LifeCyclesNames,
5
+ LifeCycleSteps,
6
+ } from "../types/global";
3
7
  import type { APIPageObject } from "../types/pages";
4
8
 
5
9
  import fs from "node:fs";
@@ -312,7 +316,7 @@ function pause(title: string) {
312
316
  async function doLifeCycle(
313
317
  name: LifeCyclesNames,
314
318
  options: {
315
- steps: Array<(...args: Array<unknown>) => unknown | Promise<unknown>>;
319
+ steps: LifeCycleSteps;
316
320
  delay?: number;
317
321
  bypass?: boolean;
318
322
  },
@@ -411,6 +415,11 @@ function getFormattedDateTime() {
411
415
  return `${date}_${time}`;
412
416
  }
413
417
 
418
+ /**
419
+ * Save render information to a file to use as debug log.
420
+ *
421
+ * This information will **not** be sent to any API.
422
+ */
414
423
  function saveBuildEndLogs() {
415
424
  const { __cx } = config.paths();
416
425
  const { sitesToPublish, createdPages, buildProcessData } = fsx.readJSONSync(
@@ -43,6 +43,7 @@ async function postSearchInfo(props: PostSearchInfoProps) {
43
43
  template,
44
44
  content: prepareHTMLContentForSearch(content),
45
45
  },
46
+ useApiCacheDir: false,
46
47
  });
47
48
 
48
49
  return response;
@@ -165,6 +166,7 @@ async function startAIEmbeddings() {
165
166
  try {
166
167
  await post<AIEmbeddingsResponse>({
167
168
  endpoint: endpoints.AI_EMBEDDINGS,
169
+ useApiCacheDir: false,
168
170
  });
169
171
  } catch (error) {
170
172
  console.warn(
@@ -153,7 +153,7 @@ async function getSiteData(siteID: number) {
153
153
  }
154
154
 
155
155
  /**
156
- * Save a file with the end of build process
156
+ * Save a file with the end of build process to use as `build-end` signal.
157
157
  */
158
158
  async function generateBuildReport() {
159
159
  const { __cx } = config.paths();
@@ -184,8 +184,6 @@ async function generateBuildReport() {
184
184
 
185
185
  /**
186
186
  * Generate sitemaps and save them into file system.
187
- *
188
- * @param sites An array of sites
189
187
  */
190
188
  async function generateSitemaps() {
191
189
  const { sitesToPublish } = await getBuildMetadata();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/cx",
3
3
  "description": "Griddo SSG based on Gatsby",
4
- "version": "11.1.3",
4
+ "version": "11.1.5",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -60,7 +60,7 @@
60
60
  "@babel/preset-env": "7.26.0",
61
61
  "@babel/preset-react": "7.26.3",
62
62
  "@babel/preset-typescript": "7.26.0",
63
- "@griddo/core": "11.1.3",
63
+ "@griddo/core": "11.1.5",
64
64
  "@svgr/webpack": "5.5.0",
65
65
  "axios": "1.7.9",
66
66
  "babel-loader": "9.2.1",
@@ -126,5 +126,5 @@
126
126
  "publishConfig": {
127
127
  "access": "public"
128
128
  },
129
- "gitHead": "5b505e1cd245ac9c2d566bd6efa533f9f910c423"
129
+ "gitHead": "3d7508419bdedbaa6dc6eae55fe73c10cb5bcdb8"
130
130
  }