@griddo/cx 11.9.11-rc.9 → 11.9.12-rc.0

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 (254) hide show
  1. package/README.md +13 -240
  2. package/build/commands/end-render.d.ts +0 -1
  3. package/build/commands/end-render.js +31 -0
  4. package/build/commands/end-render.js.map +7 -0
  5. package/build/commands/prepare-assets-directory.js +9 -0
  6. package/build/commands/prepare-assets-directory.js.map +7 -0
  7. package/build/commands/prepare-domains-render.js +38 -0
  8. package/build/commands/prepare-domains-render.js.map +7 -0
  9. package/build/commands/reset-render.d.ts +0 -1
  10. package/build/commands/reset-render.js +31 -0
  11. package/build/commands/reset-render.js.map +7 -0
  12. package/build/commands/single-domain-upload-search-content.d.ts +1 -0
  13. package/build/commands/start-render.d.ts +0 -1
  14. package/build/commands/start-render.js +66 -0
  15. package/build/commands/start-render.js.map +7 -0
  16. package/build/commands/upload-search-content.d.ts +0 -1
  17. package/build/commands/upload-search-content.js +32 -0
  18. package/build/commands/upload-search-content.js.map +7 -0
  19. package/build/core/GriddoLog.d.ts +16 -0
  20. package/build/{utils/health-checks.d.ts → core/check-env-health.d.ts} +4 -2
  21. package/build/core/db-class.d.ts +11 -0
  22. package/build/core/db.d.ts +4 -0
  23. package/build/core/dist-rollback.d.ts +11 -0
  24. package/build/core/errors.d.ts +26 -0
  25. package/build/core/fs.d.ts +69 -0
  26. package/build/core/life-cycle.d.ts +26 -0
  27. package/build/core/logger.d.ts +18 -0
  28. package/build/core/objects.d.ts +11 -0
  29. package/build/core/print-logos.d.ts +5 -0
  30. package/build/index.d.ts +10 -29
  31. package/build/index.js +406 -73
  32. package/build/react/DynamicScript/index.d.ts +4 -0
  33. package/build/react/GriddoFavicon/index.d.ts +4 -0
  34. package/build/react/GriddoIntegrations/index.d.ts +3 -4
  35. package/build/react/GriddoIntegrations/utils.d.ts +7 -6
  36. package/build/react/GriddoOpenGraph/index.d.ts +10 -0
  37. package/build/react/index.d.ts +3 -2
  38. package/build/react/index.js +1 -3
  39. package/build/{utils → services}/api.d.ts +1 -1
  40. package/build/services/auth.d.ts +2 -5
  41. package/build/services/domains.d.ts +3 -4
  42. package/build/services/manage-sites.d.ts +22 -0
  43. package/build/services/manage-store.d.ts +32 -0
  44. package/build/services/navigation.d.ts +16 -16
  45. package/build/{utils → services}/pages.d.ts +3 -3
  46. package/build/services/reference-fields.d.ts +3 -3
  47. package/build/services/render-artifacts.d.ts +6 -0
  48. package/build/services/render.d.ts +70 -0
  49. package/build/services/robots.d.ts +2 -19
  50. package/build/services/sitemaps.d.ts +5 -0
  51. package/build/services/sites.d.ts +8 -5
  52. package/build/services/store.d.ts +10 -1
  53. package/build/shared/context.d.ts +36 -0
  54. package/build/shared/envs.d.ts +19 -0
  55. package/build/{errors/errors-data.d.ts → shared/errors.d.ts} +5 -3
  56. package/build/shared/npm-modules/brush.d.ts +18 -0
  57. package/build/shared/npm-modules/find-up-simple.d.ts +34 -0
  58. package/build/shared/npm-modules/pkg-dir.d.ts +7 -0
  59. package/build/shared/npm-modules/xml-parser.d.ts +4 -0
  60. package/build/{types → shared/types}/api.d.ts +18 -18
  61. package/build/{types → shared/types}/global.d.ts +15 -16
  62. package/build/{types → shared/types}/navigation.d.ts +5 -5
  63. package/build/{types → shared/types}/pages.d.ts +9 -9
  64. package/build/shared/types/render.d.ts +54 -0
  65. package/build/{types → shared/types}/sites.d.ts +18 -19
  66. package/build/shared/types.d.ts +15 -0
  67. package/build/ssg-adapters/gatsby/actions/clean.d.ts +3 -0
  68. package/build/ssg-adapters/gatsby/actions/close.d.ts +3 -0
  69. package/build/ssg-adapters/gatsby/actions/data.d.ts +2 -0
  70. package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +2 -0
  71. package/build/ssg-adapters/gatsby/actions/init.d.ts +2 -0
  72. package/build/ssg-adapters/gatsby/actions/logs.d.ts +3 -0
  73. package/build/ssg-adapters/gatsby/actions/meta.d.ts +2 -0
  74. package/build/ssg-adapters/gatsby/actions/prepare.d.ts +2 -0
  75. package/build/ssg-adapters/gatsby/actions/relocation.d.ts +2 -0
  76. package/build/ssg-adapters/gatsby/actions/restore.d.ts +3 -0
  77. package/build/ssg-adapters/gatsby/actions/ssg.d.ts +3 -0
  78. package/build/ssg-adapters/gatsby/actions/sync.d.ts +3 -0
  79. package/build/ssg-adapters/gatsby/index.d.ts +9 -0
  80. package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +4 -0
  81. package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +15 -0
  82. package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +7 -0
  83. package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +7 -0
  84. package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +18 -0
  85. package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +26 -0
  86. package/build/ssg-adapters/gatsby/shared/types.d.ts +34 -0
  87. package/cli.mjs +231 -0
  88. package/exporter/build-esbuild.noop +42 -0
  89. package/exporter/build.sh +16 -24
  90. package/exporter/commands/README.md +151 -0
  91. package/exporter/commands/end-render.ts +65 -86
  92. package/exporter/commands/prepare-assets-directory.ts +35 -0
  93. package/exporter/commands/prepare-domains-render.ts +132 -35
  94. package/exporter/commands/reset-render.ts +13 -8
  95. package/exporter/commands/single-domain-upload-search-content.ts +206 -0
  96. package/exporter/commands/start-render.ts +26 -64
  97. package/exporter/commands/upload-search-content.ts +204 -26
  98. package/exporter/core/GriddoLog.ts +45 -0
  99. package/exporter/core/check-env-health.ts +204 -0
  100. package/exporter/core/db-class.ts +54 -0
  101. package/exporter/core/db.ts +33 -0
  102. package/exporter/core/dist-rollback.ts +49 -0
  103. package/exporter/core/errors.ts +93 -0
  104. package/exporter/core/fs.ts +385 -0
  105. package/exporter/{utils → core}/images.ts +1 -6
  106. package/exporter/{utils → core}/instance.ts +9 -13
  107. package/exporter/core/life-cycle.ts +73 -0
  108. package/exporter/core/logger.ts +141 -0
  109. package/exporter/core/objects.ts +37 -0
  110. package/exporter/core/print-logos.ts +21 -0
  111. package/exporter/index.ts +14 -56
  112. package/exporter/react/DynamicScript/index.tsx +33 -0
  113. package/exporter/react/{Favicon → GriddoFavicon}/index.tsx +3 -9
  114. package/exporter/react/GriddoIntegrations/index.tsx +17 -23
  115. package/exporter/react/GriddoIntegrations/utils.ts +24 -12
  116. package/exporter/react/GriddoOpenGraph/index.tsx +39 -0
  117. package/exporter/react/index.tsx +3 -9
  118. package/exporter/services/api.ts +306 -0
  119. package/exporter/services/auth.ts +8 -10
  120. package/exporter/services/domains.ts +23 -8
  121. package/exporter/services/manage-sites.ts +116 -0
  122. package/exporter/services/manage-store.ts +173 -0
  123. package/exporter/services/navigation.ts +12 -18
  124. package/exporter/{utils → services}/pages.ts +27 -92
  125. package/exporter/services/reference-fields.ts +14 -32
  126. package/exporter/services/render-artifacts.ts +44 -0
  127. package/exporter/services/render.ts +229 -0
  128. package/exporter/services/robots.ts +33 -61
  129. package/exporter/services/sitemaps.ts +129 -0
  130. package/exporter/services/sites.ts +40 -28
  131. package/exporter/services/store.ts +354 -321
  132. package/exporter/shared/context.ts +49 -0
  133. package/exporter/{constants → shared}/endpoints.ts +12 -11
  134. package/exporter/shared/envs.ts +62 -0
  135. package/exporter/{errors/errors-data.ts → shared/errors.ts} +24 -14
  136. package/exporter/shared/npm-modules/README.md +36 -0
  137. package/exporter/shared/npm-modules/brush.ts +34 -0
  138. package/exporter/shared/npm-modules/find-up-simple.ts +100 -0
  139. package/exporter/shared/npm-modules/pkg-dir.ts +17 -0
  140. package/exporter/shared/npm-modules/xml-parser.ts +57 -0
  141. package/exporter/{types → shared/types}/api.ts +40 -41
  142. package/exporter/{types → shared/types}/global.ts +17 -21
  143. package/exporter/{types → shared/types}/navigation.ts +3 -3
  144. package/exporter/{types → shared/types}/pages.ts +10 -11
  145. package/exporter/shared/types/render.ts +63 -0
  146. package/exporter/{types → shared/types}/sites.ts +18 -19
  147. package/exporter/shared/types.ts +15 -0
  148. package/exporter/ssg-adapters/gatsby/actions/clean.ts +26 -0
  149. package/exporter/ssg-adapters/gatsby/actions/close.ts +17 -0
  150. package/exporter/ssg-adapters/gatsby/actions/data.ts +22 -0
  151. package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +10 -0
  152. package/exporter/ssg-adapters/gatsby/actions/init.ts +12 -0
  153. package/exporter/ssg-adapters/gatsby/actions/logs.ts +10 -0
  154. package/exporter/ssg-adapters/gatsby/actions/meta.ts +13 -0
  155. package/exporter/ssg-adapters/gatsby/actions/prepare.ts +9 -0
  156. package/exporter/ssg-adapters/gatsby/actions/relocation.ts +15 -0
  157. package/exporter/ssg-adapters/gatsby/actions/restore.ts +21 -0
  158. package/exporter/ssg-adapters/gatsby/actions/ssg.ts +12 -0
  159. package/exporter/ssg-adapters/gatsby/actions/sync.ts +65 -0
  160. package/exporter/ssg-adapters/gatsby/index.ts +114 -0
  161. package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +17 -0
  162. package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +128 -0
  163. package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +75 -0
  164. package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +58 -0
  165. package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +33 -0
  166. package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +298 -0
  167. package/exporter/ssg-adapters/gatsby/shared/types.ts +35 -0
  168. package/gatsby-browser.tsx +41 -58
  169. package/gatsby-config.ts +10 -17
  170. package/gatsby-node.ts +20 -79
  171. package/gatsby-ssr.tsx +2 -1
  172. package/package.json +41 -80
  173. package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
  174. package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
  175. package/src/components/Head.tsx +28 -73
  176. package/src/components/template.tsx +6 -29
  177. package/src/gatsby-node-utils.ts +76 -2
  178. package/src/html.tsx +2 -11
  179. package/src/types.ts +3 -3
  180. package/tsconfig.commands.json +36 -0
  181. package/tsconfig.exporter.json +21 -0
  182. package/tsconfig.json +5 -3
  183. package/build/adapters/gatsby/index.d.ts +0 -4
  184. package/build/adapters/gatsby/utils.d.ts +0 -22
  185. package/build/artifacts/index.d.ts +0 -6
  186. package/build/constants/envs.d.ts +0 -37
  187. package/build/constants/index.d.ts +0 -57
  188. package/build/end-render.js +0 -74
  189. package/build/end-render.js.map +0 -7
  190. package/build/errors/index.d.ts +0 -15
  191. package/build/index.js.map +0 -7
  192. package/build/prepare-domains-render.js +0 -73
  193. package/build/prepare-domains-render.js.map +0 -7
  194. package/build/react/Favicon/index.d.ts +0 -5
  195. package/build/registers/api.d.ts +0 -9
  196. package/build/registers/gatsby.d.ts +0 -9
  197. package/build/registers/index.d.ts +0 -3
  198. package/build/reset-render.js +0 -74
  199. package/build/reset-render.js.map +0 -7
  200. package/build/services/register.d.ts +0 -36
  201. package/build/services/settings.d.ts +0 -4
  202. package/build/start-render.js +0 -100
  203. package/build/start-render.js.map +0 -7
  204. package/build/upload-search-content.js +0 -74
  205. package/build/upload-search-content.js.map +0 -7
  206. package/build/utils/alerts.d.ts +0 -3
  207. package/build/utils/cache.d.ts +0 -35
  208. package/build/utils/core-utils.d.ts +0 -107
  209. package/build/utils/create-build-data.d.ts +0 -8
  210. package/build/utils/domains.d.ts +0 -13
  211. package/build/utils/folders.d.ts +0 -53
  212. package/build/utils/loggin.d.ts +0 -51
  213. package/build/utils/render.d.ts +0 -13
  214. package/build/utils/searches.d.ts +0 -15
  215. package/build/utils/sites.d.ts +0 -31
  216. package/build/utils/store.d.ts +0 -81
  217. package/cx.config.d.ts +0 -5
  218. package/cx.config.js +0 -36
  219. package/exporter/adapters/gatsby/index.ts +0 -162
  220. package/exporter/adapters/gatsby/utils.ts +0 -161
  221. package/exporter/artifacts/README.md +0 -34
  222. package/exporter/artifacts/index.ts +0 -33
  223. package/exporter/commands/move-assets.ts +0 -11
  224. package/exporter/constants/envs.ts +0 -94
  225. package/exporter/constants/index.ts +0 -129
  226. package/exporter/errors/index.ts +0 -40
  227. package/exporter/registers/api.ts +0 -14
  228. package/exporter/registers/gatsby.ts +0 -14
  229. package/exporter/registers/index.ts +0 -4
  230. package/exporter/services/register.ts +0 -113
  231. package/exporter/services/settings.ts +0 -17
  232. package/exporter/utils/alerts.ts +0 -29
  233. package/exporter/utils/api.ts +0 -243
  234. package/exporter/utils/cache.ts +0 -142
  235. package/exporter/utils/core-utils.ts +0 -458
  236. package/exporter/utils/create-build-data.ts +0 -17
  237. package/exporter/utils/domains.ts +0 -39
  238. package/exporter/utils/folders.ts +0 -320
  239. package/exporter/utils/health-checks.ts +0 -64
  240. package/exporter/utils/loggin.ts +0 -184
  241. package/exporter/utils/render.ts +0 -71
  242. package/exporter/utils/searches.ts +0 -156
  243. package/exporter/utils/sites.ts +0 -312
  244. package/exporter/utils/store.ts +0 -314
  245. package/src/README.md +0 -7
  246. package/start-render.js +0 -7
  247. /package/build/commands/{move-assets.d.ts → prepare-assets-directory.d.ts} +0 -0
  248. /package/build/{utils → core}/images.d.ts +0 -0
  249. /package/build/{utils → core}/instance.d.ts +0 -0
  250. /package/build/react/{Favicon → GriddoFavicon}/utils.d.ts +0 -0
  251. /package/build/{constants → shared}/endpoints.d.ts +0 -0
  252. /package/build/{types → shared/types}/templates.d.ts +0 -0
  253. /package/exporter/react/{Favicon → GriddoFavicon}/utils.ts +0 -0
  254. /package/exporter/{types → shared/types}/templates.ts +0 -0
@@ -1,458 +0,0 @@
1
- import type { APIResponses } from "../types/api";
2
- import type {
3
- CXConfig,
4
- LifeCyclesNames,
5
- LifeCycleSteps,
6
- } from "../types/global";
7
- import type { APIPageObject } from "../types/pages";
8
-
9
- import fs from "node:fs";
10
- import path from "node:path";
11
-
12
- import fsx from "fs-extra";
13
- import kleur from "kleur";
14
- import { bgRed, black } from "kleur/colors";
15
- import pkgDir from "pkg-dir";
16
-
17
- import { envs } from "../constants";
18
- import { throwError } from "../errors";
19
- import { prependFileSync } from "./folders";
20
- import { boxLog, infoLog, successLog } from "./loggin";
21
- import { generateBuildReport, generateSitemaps } from "./sites";
22
- import { LifecycleExecutionError } from "../errors/errors-data";
23
- import { RobotsService } from "../services/robots";
24
-
25
- const config = getConfig();
26
-
27
- const instanceRootDir = pkgDir.sync()!; // instance root dir
28
-
29
- /**
30
- * Returns the configuration file content.
31
- *
32
- * @example
33
- * const config = getConfig()
34
- * const { __cx } = config.paths()
35
- * const { griddoVersion, proDomain } = config
36
- */
37
- function getConfig(): CXConfig {
38
- try {
39
- const configModule = require("../../cx.config.js");
40
- const config = configModule.default;
41
-
42
- return config;
43
- } catch (error) {
44
- console.log(error);
45
- throw new Error("Error while reading configuration file");
46
- }
47
- }
48
-
49
- /**
50
- * Returns true for "true", "on", true and positive numbers.
51
- * Returns false for "false", "off", false, 0, negative integers and anything else.
52
- */
53
- function isTruthy(value: any): boolean {
54
- // Return if Boolean
55
- if (typeof value === "boolean") {
56
- return value;
57
- }
58
-
59
- // Return false if null or undefined
60
- if (value === undefined || value === null) {
61
- return false;
62
- }
63
-
64
- // If the String is true or false
65
- if (value.toLowerCase() === "true") {
66
- return true;
67
- }
68
- if (value.toLowerCase() === "false") {
69
- return false;
70
- }
71
-
72
- // "on" | "off", We love them in Griddo ^^.
73
- if (value.toLowerCase() === "on") {
74
- return true;
75
- }
76
- if (value.toLowerCase() === "off") {
77
- return false;
78
- }
79
-
80
- // Now check if it's a number
81
- const number = Number.parseInt(value, 10);
82
- if (Number.isNaN(number)) {
83
- return false;
84
- }
85
- if (number > 0) {
86
- return true;
87
- }
88
-
89
- // Default to false
90
- return false;
91
- }
92
-
93
- /**
94
- * Walk a directory and returns the file pathts.
95
- *
96
- * @param dir A directory path.
97
- */
98
- function walk(dir: string) {
99
- const results: Array<string> = [];
100
- const list = fs.readdirSync(dir);
101
- for (const file of list) {
102
- results.push(path.join(dir, file));
103
- }
104
-
105
- return results;
106
- }
107
-
108
- /**
109
- * Walk a directory and returns the JSON file absolute paths with one level of depth.
110
- * Bypass the `metadata` folder.
111
- * /abs/.../sotre/<siteId>/jsonfile.json
112
- * /abs/.../sotre/<siteId>/jsonfile.json
113
- * /abs/.../sotre/<siteId>/jsonfile.json
114
- * /abs/.../sotre/<siteId>/jsonfile.json
115
- */
116
- function walkStore(dir: string): Array<string> {
117
- const results: Array<string> = [];
118
-
119
- // Listamos todas las subcarpetas y evitamos entrar en 'metadata'
120
- const subdirs = fs.readdirSync(dir).filter((file) => {
121
- const fullPath = path.join(dir, file);
122
- return fs.statSync(fullPath).isDirectory() && file !== "metadata";
123
- });
124
-
125
- // Iteramos sobre las subcarpetas
126
- for (const subdir of subdirs) {
127
- const subdirPath = path.join(dir, subdir);
128
-
129
- // Listamos los archivos en cada subcarpeta y filtramos los .json
130
- const files = fs
131
- .readdirSync(subdirPath)
132
- .filter((file) => file.endsWith(".json"));
133
-
134
- for (const file of files) {
135
- results.push(path.join(subdirPath, file));
136
- }
137
- }
138
-
139
- return results;
140
- }
141
-
142
- /**
143
- * Custom delay using the "promise hack",
144
- *
145
- * @param ms Amount of miliseconds to be delayed
146
- */
147
- function delay(ms: number) {
148
- return new Promise((res) => setTimeout(res, ms));
149
- }
150
-
151
- /**
152
- * Converts milliseconds to seconds with a fixed number of decimals.
153
- *
154
- * @param ms The number in milliseconds.
155
- * @param fixed The amount of fixed decimals.
156
- * @returns The converted number in seconds with the fixed number of decimals.
157
- */
158
- function msToSec(ms: number, decimals = 3) {
159
- return (ms / 1000).toFixed(decimals);
160
- }
161
-
162
- /**
163
- * Return a siteID from a response object if exist
164
- * @param response A response object
165
- */
166
- function getSafeSiteId(response: APIResponses) {
167
- if (typeof response === "string") {
168
- return undefined;
169
- }
170
-
171
- return "site" in response && response.site ? response?.site : undefined;
172
- }
173
-
174
- /**
175
- * Remove props from an object
176
- *
177
- * @param obj The object
178
- * @param props An array of props to be removed
179
- */
180
- function removeProperties(obj: Record<string, unknown>, props: Array<string>) {
181
- for (const key in obj) {
182
- if (props.includes(key)) {
183
- delete obj[key];
184
- } else if (typeof obj[key] === "object") {
185
- removeProperties(obj[key] as Record<string, unknown>, props);
186
- }
187
- }
188
- }
189
-
190
- /**
191
- * Remove unused files (old) inside the `apiCache` dir
192
- *
193
- * @todo remove other file types: sites, socials, etc..
194
- */
195
- function sanitizeAPICacheDir() {
196
- const { __cx } = config.paths();
197
- const dirPath = path.join(__cx, "apiCache");
198
- const allCachedFiles = fs.readdirSync(dirPath);
199
-
200
- // Object to store the the more rencent file names
201
- // Record<string, string> = { "234856872634", "3268746238747238.json"};
202
- const filesByIdMap: Record<string, string> = {};
203
- // ^id ^path
204
-
205
- // Page files.
206
- // We only need files that describes a page object.
207
- const pageFilePaths = allCachedFiles.filter((fileName) => {
208
- const filePath = `${dirPath}/${fileName}`;
209
- const fileObject = fsx.readJSONSync(filePath, "utf-8") as APIPageObject;
210
- const { id, entity, fullUrl } = fileObject;
211
-
212
- // Is a page file if has id, entity and fullUrl
213
- return !!(id && entity && fullUrl);
214
- });
215
-
216
- // Fill the filesById object
217
- for (const fileName of pageFilePaths) {
218
- const filePath = `${dirPath}/${fileName}`;
219
- const fileObject = fsx.readJSONSync(filePath, "utf-8") as APIPageObject;
220
- const fileCreationDate = fs.statSync(filePath).mtimeMs;
221
-
222
- const { id } = fileObject;
223
-
224
- // Is a valid page if doesn't exists in the store object or is newer
225
- // that the stored one.
226
- const validPageFile =
227
- !filesByIdMap[id] ||
228
- fileCreationDate > fs.statSync(`${dirPath}/${filesByIdMap[id]}`).mtimeMs;
229
-
230
- if (validPageFile) {
231
- filesByIdMap[id] = fileName;
232
- }
233
- }
234
-
235
- let counter = 0;
236
-
237
- // Delete files using the store object filesById as reference map.
238
- for (const fileName of pageFilePaths) {
239
- const filePath = `${dirPath}/${fileName}`;
240
- const fileObject = fsx.readJSONSync(filePath, "utf-8") as APIPageObject;
241
-
242
- const { id } = fileObject;
243
-
244
- // If the filename is not present in the map, remove it!
245
- if (fileName !== filesByIdMap[id]) {
246
- fs.unlinkSync(filePath);
247
- counter++;
248
- }
249
- }
250
-
251
- console.log(`Sanitize apiCache dir for ${counter} files`);
252
- }
253
-
254
- /**
255
- * Measures the execution time of a series of sync or async functions.
256
- *
257
- * @async
258
- * @param functions - Functions to be executed to measure their execution time.
259
- * @returns A promise that resolves with the total execution time in seconds.
260
- */
261
- async function measureExecutionTime(
262
- functions: Array<(...args: Array<unknown>) => unknown | Promise<unknown>>,
263
- ) {
264
- const start = process.hrtime();
265
-
266
- for (const func of functions) {
267
- await func();
268
- }
269
-
270
- const [seconds, miliseconds] = process.hrtime(start);
271
- const timeInSeconds = seconds + miliseconds / 1e9;
272
-
273
- return +timeInSeconds.toFixed(3);
274
- }
275
-
276
- /**
277
- * Pause the process until a key is pressed.
278
- *
279
- * @param title
280
- * @returns
281
- */
282
- function pause(title: string) {
283
- const isPauseEnabled = !!envs.GRIDDO_RENDER_BREAKPOINTS_FEATURE;
284
-
285
- if (!isPauseEnabled) {
286
- return;
287
- }
288
-
289
- return new Promise<void>((resolve) => {
290
- console.log("\n");
291
- boxLog(`⌛️ ${title}`, "", 1, 0);
292
- process.stdin.once("data", () => {
293
- resolve();
294
- });
295
- });
296
- }
297
-
298
- /**
299
- * Executes a life cycle process, which involves executing an array of
300
- * functions, printing to the console, and handling errors with optional
301
- * retries.
302
- *
303
- * @async
304
- * @param name - The name of the life cycle.
305
- * @param options - The arguments object.
306
- * @param options.steps - An array of functions to execute.
307
- * @returns - A promise that resolves when the life cycle process is completed.
308
- */
309
- async function doLifeCycle(name: LifeCyclesNames, steps: LifeCycleSteps) {
310
- const attemptsByLifeCycleName: Record<LifeCyclesNames, number> = {
311
- Init: envs.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS,
312
- Archive: envs.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS,
313
- Data: envs.GRIDDO_DATA_LIFECYCLE_MAX_ATTEMPTS,
314
- Meta: envs.GRIDDO_META_LIFECYCLE_MAX_ATTEMPTS,
315
- Relocation: envs.GRIDDO_RELOCATION_LIFECYCLE_MAX_ATTEMPTS,
316
- Clean: envs.GRIDDO_CLEAN_LIFECYCLE_MAX_ATTEMPTS,
317
- Restore: envs.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS,
318
- Prepare: envs.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS,
319
- Close: envs.GRIDDO_CLOSE_LIFECYCLE_MAX_ATTEMPTS,
320
- SSG: envs.GRIDDO_SSG_LIFECYCLE_MAX_ATTEMPTS,
321
- HealthCheck: 1,
322
- __DEBUG__: 1,
323
- };
324
-
325
- let trysCount = 0;
326
- const maxTrysAccepted = attemptsByLifeCycleName[name] || 1;
327
-
328
- while (trysCount < maxTrysAccepted) {
329
- try {
330
- infoLog(`start ${name} life-cycle`);
331
- const exeTime = await measureExecutionTime(steps);
332
- successLog(`${name} - ${exeTime}s\n`);
333
- // if no errors, print and go out
334
- await pause(`${name} LifeCycle`);
335
- break;
336
- } catch (error) {
337
- const errorString = bgRed(black(` Error in ${name} LifeCycle `));
338
- const attemptsString = kleur.yellow(`Attempt (${trysCount + 1})`);
339
- console.log(`\n${errorString} ${attemptsString}\n`);
340
- console.log(error);
341
- console.log();
342
-
343
- trysCount++;
344
- }
345
- }
346
-
347
- if (trysCount === maxTrysAccepted) {
348
- throwError(LifecycleExecutionError(maxTrysAccepted, name));
349
- }
350
- }
351
-
352
- /**
353
- * Creates additional files after the render: sitemaps, robots and a report of
354
- * the finished render.
355
- *
356
- * @async
357
- * @param domain
358
- */
359
- async function createDomainMetadata(domain: string) {
360
- await generateBuildReport();
361
- await generateSitemaps();
362
- await RobotsService.writeFiles(domain);
363
- }
364
-
365
- function removeAllSiteDirsFromStore() {
366
- const { __cx } = config.paths();
367
- const storeDir = path.join(__cx, "store");
368
- const allDirs = fs.readdirSync(storeDir);
369
-
370
- const allSiteDirs = allDirs.filter((dirname) => dirname !== "metadata");
371
-
372
- const allSiteDirsFullPath = allSiteDirs.map((name) =>
373
- path.join(storeDir, name),
374
- );
375
-
376
- // Remove all site directories except "metadata" directory.
377
- for (const site of allSiteDirsFullPath) {
378
- fs.rmSync(site, { recursive: true, force: true });
379
- }
380
- }
381
-
382
- function getFormattedDateTime() {
383
- const now = new Date();
384
- const date = [
385
- String(now.getDate()).padStart(2, "0"),
386
- String(now.getMonth() + 1).padStart(2, "0"),
387
- now.getFullYear(),
388
- ].join("-");
389
-
390
- const time = [
391
- String(now.getHours()).padStart(2, "0"),
392
- String(now.getMinutes()).padStart(2, "0"),
393
- String(now.getSeconds()).padStart(2, "0"),
394
- ].join(":");
395
-
396
- return `${date}_${time}`;
397
- }
398
-
399
- /**
400
- * Save render information to a file to use as debug log.
401
- *
402
- * This information will **not** be sent to any API.
403
- */
404
- function saveBuildEndLogs() {
405
- const { __cx } = config.paths();
406
- const { sitesToPublish, createdPages, buildProcessData } = fsx.readJSONSync(
407
- path.join(__cx, "render-metadata.json"),
408
- );
409
-
410
- const dateString = getFormattedDateTime();
411
- const buildEndLogsDir = path.join(__cx, "debug", "build-end");
412
-
413
- if (!fs.existsSync(buildEndLogsDir)) {
414
- fs.mkdirSync(buildEndLogsDir, { recursive: true });
415
- }
416
-
417
- // Log
418
- fs.writeFileSync(
419
- path.join(buildEndLogsDir, `${dateString}.json`),
420
- JSON.stringify(
421
- {
422
- date: new Date().toLocaleString(),
423
- log: {
424
- sitesToPublish,
425
- createdPages,
426
- buildProcessData,
427
- },
428
- },
429
- null,
430
- 2,
431
- ),
432
- );
433
-
434
- // Update index
435
- prependFileSync(
436
- path.join(buildEndLogsDir, "index.html"),
437
- `<pre><a href="${dateString}.json">${dateString}</a></pre>\n`,
438
- );
439
- }
440
-
441
- export {
442
- createDomainMetadata,
443
- delay,
444
- doLifeCycle,
445
- getConfig,
446
- getSafeSiteId,
447
- instanceRootDir,
448
- isTruthy,
449
- measureExecutionTime,
450
- msToSec,
451
- pause,
452
- removeAllSiteDirsFromStore,
453
- removeProperties,
454
- sanitizeAPICacheDir,
455
- saveBuildEndLogs,
456
- walk,
457
- walkStore,
458
- };
@@ -1,17 +0,0 @@
1
- import { createAPICacheDir } from "./cache";
2
- import { sanitizeAPICacheDir } from "./core-utils";
3
- import { createStore } from "../services/store";
4
-
5
- /**
6
- * Download all data: sites, pages etc.. from the instance private Griddo API.
7
- * Then you can use the generator funcion `getBuildPagesFromStore()` to get the pages and
8
- * `getBuildMetadata()` to get build and sites metadata as objects. Both from
9
- * exporter utils sites dir.
10
- */
11
- async function createDomainRenderData(domain: string) {
12
- createAPICacheDir();
13
- await createStore(domain);
14
- sanitizeAPICacheDir();
15
- }
16
-
17
- export { createDomainRenderData };
@@ -1,39 +0,0 @@
1
- import type { Domains } from "../types/global";
2
-
3
- import { verboseLog } from "./loggin";
4
- import { throwError } from "../errors";
5
- import { NoDomainsFoundError } from "../errors/errors-data";
6
- import { AuthService } from "../services/auth";
7
- import { getAllDomains } from "../services/domains";
8
-
9
- /**
10
- * Return an array of domains name (string) of the current instance.
11
- */
12
- async function getInstanceDomains() {
13
- await AuthService.login();
14
- const domains = await getAllDomains();
15
-
16
- if (!domains.length) {
17
- throwError(NoDomainsFoundError);
18
- }
19
-
20
- verboseLog(`getting domains names (${domains.length})`);
21
-
22
- return getDomainSlugs(domains);
23
- }
24
-
25
- /**
26
- * Return an unique array of domains, filtered without "/".
27
- *
28
- * @param domains An array of domains
29
- * @see Domains
30
- */
31
- function getDomainSlugs(domains: Domains) {
32
- const filteredDomains = domains
33
- .filter(({ slug }) => !!slug)
34
- .map(({ slug }) => slug.replace("/", ""));
35
-
36
- return [...new Set(filteredDomains)];
37
- }
38
-
39
- export { getInstanceDomains, getDomainSlugs };