@griddo/cx 10.3.13 → 10.3.15

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 (61) hide show
  1. package/README.md +53 -30
  2. package/build/build-complete.js +24 -20
  3. package/build/download-data.js +53 -0
  4. package/build/index.js +35 -47
  5. package/build/reset-render.js +25 -21
  6. package/exporter/adapters/astro/index.ts +37 -0
  7. package/exporter/adapters/astro/utils.ts +29 -0
  8. package/exporter/adapters/gatsby/index.ts +86 -0
  9. package/exporter/adapters/gatsby/utils.ts +352 -0
  10. package/exporter/adapters/index.ts +5 -0
  11. package/{scripts → exporter}/build-complete.ts +16 -14
  12. package/exporter/download-data.ts +6 -0
  13. package/exporter/index-width-adapter.ts +25 -0
  14. package/exporter/index.ts +14 -0
  15. package/exporter/reset-render.ts +12 -0
  16. package/{src → exporter}/services/auth.ts +0 -2
  17. package/{src → exporter}/services/distributors.ts +10 -1
  18. package/{src → exporter}/services/robots.ts +9 -6
  19. package/exporter/services/store.ts +351 -0
  20. package/{src → exporter}/types/api.ts +6 -0
  21. package/{src → exporter}/types/pages.ts +18 -17
  22. package/{src → exporter}/types/sites.ts +1 -1
  23. package/{src → exporter}/utils/api.ts +10 -7
  24. package/{src → exporter}/utils/cache.ts +14 -8
  25. package/{src → exporter}/utils/domains.ts +3 -3
  26. package/exporter/utils/download-build-data.ts +22 -0
  27. package/exporter/utils/folders.ts +49 -0
  28. package/{src → exporter}/utils/health-checks.ts +8 -7
  29. package/{src → exporter}/utils/instance.ts +1 -1
  30. package/{src/utils/integrations.tsx → exporter/utils/integrations.ts} +6 -4
  31. package/{src → exporter}/utils/pages.ts +21 -24
  32. package/exporter/utils/runners.ts +53 -0
  33. package/{src → exporter}/utils/shared.ts +31 -29
  34. package/{src → exporter}/utils/sites.ts +7 -7
  35. package/exporter/utils/store.ts +56 -0
  36. package/gatsby-config.ts +1 -1
  37. package/gatsby-node.ts +38 -72
  38. package/index.js +4 -1
  39. package/package.json +13 -10
  40. package/src/README.md +7 -0
  41. package/src/components/Head.tsx +3 -3
  42. package/src/components/template.tsx +3 -4
  43. package/src/gatsby-node-utils.ts +154 -0
  44. package/src/html.tsx +1 -1
  45. package/src/types.ts +98 -0
  46. package/src/{components/utils.ts → utils.ts} +6 -8
  47. package/static/robots.txt +1 -0
  48. package/scripts/griddo-exporter.ts +0 -431
  49. package/scripts/reset-render.ts +0 -9
  50. package/src/components/types.ts +0 -40
  51. package/src/services/store.ts +0 -423
  52. package/src/utils/folders.ts +0 -125
  53. package/src/utils/gatsby.ts +0 -47
  54. /package/{src → exporter}/services/domains.ts +0 -0
  55. /package/{src → exporter}/services/navigation.ts +0 -0
  56. /package/{src → exporter}/services/settings.ts +0 -0
  57. /package/{src → exporter}/services/sites.ts +0 -0
  58. /package/{src → exporter}/types/global.ts +0 -0
  59. /package/{src → exporter}/types/navigation.ts +0 -0
  60. /package/{src → exporter}/types/templates.ts +0 -0
  61. /package/{src → exporter}/utils/searches.ts +0 -0
@@ -1,431 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
4
- /* eslint-disable node/shebang */
5
-
6
- import { spawnSync } from "child_process";
7
- import fs from "fs";
8
- import path from "path";
9
-
10
- import chalk from "chalk";
11
- import dotenv from "dotenv";
12
- import pkgDir from "pkg-dir";
13
-
14
- import { initCache } from "../src/utils/cache";
15
- import { findDomains } from "../src/utils/domains";
16
- import { buildHealthCheck } from "../src/utils/health-checks";
17
- import { exporterLogo as splash, measureFunctions } from "../src/utils/shared";
18
-
19
- dotenv.config();
20
-
21
- // Envs
22
- // Artifacts to preserve between CX installs
23
- const artifactsArchivable = ["dist", "assets"];
24
- // Artifacts to remove after export
25
- const artifactsDisposable = ["public", ".store"];
26
- // Artifacts to make exports faster
27
- const artifactsCache = ["apiCache" /* , ".cache" */];
28
-
29
- // TODO: Remove STRIP_DOMAIN_FROM_PATH behaviour when all instances are over 1.75.219
30
- const STRIP_DOMAIN_FROM_PATH =
31
- !!process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH;
32
-
33
- if (STRIP_DOMAIN_FROM_PATH) {
34
- artifactsCache.push(".cache");
35
- } else {
36
- artifactsDisposable.push(".cache");
37
- }
38
-
39
- // TODO: Remove GRIDDO_INFRA_BUILD_COMPLETES behaviour when all instances are over 1.75.227 and infra calls export:complete
40
- const INFRA_COMPLETES_BUILD = !!process.env.GRIDDO_INFRA_BUILD_COMPLETES;
41
-
42
- // Where we are going to find export folders
43
- const execBasePath = pkgDir.sync()!;
44
-
45
- // Where we are going to find archived exports
46
- const exportArchiveBasePath = path.resolve(execBasePath, "exports/sites");
47
- const exportCachesArchivePath = path.resolve(__dirname, "../caches");
48
-
49
- // Where we are going to run the export command
50
- const workingPath = pkgDir.sync(__dirname)!;
51
-
52
- // Types
53
- type Env = Record<string, unknown>;
54
-
55
- // -----------------------------------------------------------------------------
56
- // Process Runner
57
- // -----------------------------------------------------------------------------
58
- const getEnvRunner = (env: Env) => (command: string) => runner(command, env);
59
-
60
- const runner = (command: string, env: Env) => {
61
- // TODO: Cuando esto falle, ejecutar `cleanAfterFail`
62
-
63
- const [commandName, ...args] = command.split(" ");
64
- const { error, status } = spawnSync(commandName, args, {
65
- cwd: workingPath,
66
- stdio: ["ignore", "inherit", "ignore"],
67
- encoding: "utf8",
68
- shell: true,
69
- env: Object.assign({ GRIDDO_EXPORTER: "true" }, process.env, env),
70
- });
71
-
72
- if (error) {
73
- console.error(error);
74
- process.exit(1);
75
- }
76
-
77
- if (status !== 0) {
78
- console.error(`Command \`${command}\` exited with code ${status}`);
79
- process.exit(1);
80
- }
81
- };
82
-
83
- const getAssetPrefix = (domain: string) => {
84
- // TODO: Usar asset_prefix del dominio
85
- if (!(process.env.GRIDDO_ASSET_PREFIX || process.env.ASSET_PREFIX) || !domain)
86
- return "";
87
-
88
- if (!domain.startsWith("pro-")) return "";
89
-
90
- return `${
91
- process.env.GRIDDO_ASSET_PREFIX || process.env.ASSET_PREFIX
92
- }/${domain}`;
93
- };
94
-
95
- // -----------------------------------------------------------------------------
96
- // Loggers
97
- // -----------------------------------------------------------------------------
98
- const logError = (...message: Array<any>) => console.log(...message);
99
- const logInfo = (...message: Array<any>) => console.log(...message);
100
- const logSuccess = (...message: Array<any>) => console.log(...message);
101
- const logWarning = (...message: Array<any>) => console.log(...message);
102
-
103
- // -----------------------------------------------------------------------------
104
- // Main Stuff
105
- // -----------------------------------------------------------------------------
106
- const domainExport = async (domain: string) => {
107
- const runner = getDomainRunner(domain);
108
- // onPreExporter
109
- const endRestore = measureFunctions(
110
- runner.init,
111
- runner.restoreArtifacts,
112
- runner.restoreCacheArtifacts
113
- );
114
- logInfo(`\n⌛️ Domain ${domain} restored: ${endRestore}s`);
115
-
116
- // Gatsby
117
- runner.runExporter();
118
-
119
- // onPostExporter
120
- const endArchive = measureFunctions(
121
- runner.archiveArtifacts,
122
- runner.archiveCacheArtifacts
123
- );
124
- logInfo(`\n⌛️ Domain ${domain} archived: ${endArchive}s`);
125
- };
126
-
127
- const launchExports = async () => {
128
- splash();
129
- // Check the server-environment throwing an error and exit if the check is not successfully.
130
- buildHealthCheck();
131
- initCache();
132
-
133
- const domains = await findDomains();
134
-
135
- for (const domain of domains) {
136
- logInfo(`️🚢 Exporting domain ${chalk.underline(domain)}`);
137
- await domainExport(domain);
138
- }
139
-
140
- // TODO: Remove when all instances are over 1.75.227 and infra calls export:complete
141
- if (!INFRA_COMPLETES_BUILD) {
142
- const runner = getEnvRunner({ cwd: __dirname });
143
- runner("node ./build/build-complete.js");
144
- }
145
- };
146
-
147
- const getDomainRunner = (domain: string) => {
148
- const assetPrefix = getAssetPrefix(domain);
149
-
150
- const run = getEnvRunner({
151
- DOMAIN: domain,
152
- GRIDDO_ASSET_PREFIX: assetPrefix,
153
- NEEDS_ASSET_DOMAIN_PREFIX: assetPrefix && assetPrefix !== "",
154
- GRIDDO_RENDERID: new Date().valueOf(),
155
- });
156
-
157
- const init = () => {
158
- logInfo(`🚀 Initializing ${chalk.underline(domain)} exporter`);
159
-
160
- cleanDirtyArtifactPaths();
161
- createBaseExportPaths();
162
- };
163
-
164
- const getArtifactPaths = (artifact = "") => {
165
- if (artifact === "/")
166
- throw new Error(`Artifact path cannot be root: ${artifact}`);
167
-
168
- // Archives
169
- const domainExportArchiveBasePath = path.resolve(
170
- exportArchiveBasePath,
171
- domain
172
- );
173
- const currentExportArchivePath = path.resolve(
174
- domainExportArchiveBasePath,
175
- artifact
176
- );
177
- const currentExportArchivePathInDomain = path.resolve(
178
- currentExportArchivePath,
179
- domain
180
- );
181
-
182
- // Cachés
183
- const domainCacheArchiveBasePath = path.resolve(
184
- exportCachesArchivePath,
185
- domain
186
- );
187
- const currentExportArchiveCachePath = path.resolve(
188
- domainCacheArchiveBasePath,
189
- artifact
190
- );
191
- const currentExportArchiveCachePathInDomain = path.resolve(
192
- currentExportArchiveCachePath,
193
- domain
194
- );
195
-
196
- const currentExportBackupPath = `${currentExportArchivePath}-BACKUP`;
197
- const currentExportWorkingPath = path.resolve(workingPath, artifact);
198
-
199
- return {
200
- domainExportArchiveBasePath,
201
- currentExportArchivePath,
202
- currentExportBackupPath,
203
- currentExportWorkingPath,
204
- currentExportArchivePathInDomain,
205
- domainCacheArchiveBasePath,
206
- currentExportArchiveCachePath,
207
- currentExportArchiveCachePathInDomain,
208
- };
209
- };
210
-
211
- const cleanDirtyArtifactPaths = () => {
212
- for (const artifact of [
213
- ...artifactsArchivable,
214
- ...artifactsDisposable,
215
- ...artifactsCache,
216
- ]) {
217
- const { currentExportWorkingPath } = getArtifactPaths(artifact);
218
-
219
- if (fs.existsSync(currentExportWorkingPath)) {
220
- logWarning(`🧹 Cleanup dirty ${chalk.gray(currentExportWorkingPath)}`);
221
- run(`rm -rf ${currentExportWorkingPath}`);
222
- }
223
- }
224
- };
225
-
226
- const createBaseExportPaths = () => {
227
- const { domainExportArchiveBasePath, domainCacheArchiveBasePath } =
228
- getArtifactPaths();
229
-
230
- for (const _path of [
231
- domainExportArchiveBasePath,
232
- domainCacheArchiveBasePath,
233
- ]) {
234
- if (!fs.existsSync(_path)) {
235
- logInfo(`✨ Creating ${_path}`);
236
- run(`mkdir -p ${_path}`);
237
- }
238
- }
239
- };
240
-
241
- const archiveExportArtifact = (artifact: string) => {
242
- const { currentExportArchivePath, currentExportWorkingPath } =
243
- getArtifactPaths(artifact);
244
-
245
- logInfo(
246
- `🚚 Moving files from ${chalk.gray(
247
- currentExportWorkingPath
248
- )} to ${chalk.gray(currentExportArchivePath)}`
249
- );
250
- run(`mv ${currentExportWorkingPath} ${currentExportArchivePath}`);
251
- };
252
-
253
- const archiveArtifacts = () => {
254
- for (const artifact of artifactsArchivable) {
255
- const { currentExportWorkingPath, currentExportArchivePath } =
256
- getArtifactPaths(artifact);
257
-
258
- if (!fs.existsSync(currentExportWorkingPath)) {
259
- logError(
260
- "📁 Source directory has not been created:",
261
- currentExportWorkingPath
262
- );
263
- continue;
264
- }
265
-
266
- try {
267
- createArtifactBackup(artifact);
268
- archiveExportArtifact(artifact);
269
- deleteArtifactBackup(artifact);
270
- } catch (error) {
271
- logError(
272
- `🚚 Error moving files to ${currentExportArchivePath}`,
273
- (error as Error).message
274
- );
275
- restoreArtifactBackup(artifact);
276
- continue;
277
- }
278
- }
279
- };
280
-
281
- const restoreArtifacts = () => {
282
- for (const artifact of artifactsArchivable) {
283
- const { currentExportArchivePath, currentExportWorkingPath } =
284
- getArtifactPaths(artifact);
285
-
286
- if (fs.existsSync(currentExportArchivePath)) {
287
- logWarning(`️♻️ Restoring ${chalk.gray(currentExportArchivePath)}`);
288
- run(`cp -R ${currentExportArchivePath} ${currentExportWorkingPath}`);
289
- }
290
- }
291
-
292
- moveDistToPublic();
293
- };
294
-
295
- const createArtifactBackup = (artifact: string) => {
296
- const { currentExportArchivePath, currentExportBackupPath } =
297
- getArtifactPaths(artifact);
298
-
299
- if (fs.existsSync(currentExportArchivePath)) {
300
- logInfo(`💿 Creating backup of ${chalk.gray(currentExportArchivePath)}`);
301
- run(`mv ${currentExportArchivePath} ${currentExportBackupPath}`);
302
- }
303
- };
304
-
305
- const restoreArtifactBackup = (artifact: string) => {
306
- const { currentExportArchivePath, currentExportBackupPath } =
307
- getArtifactPaths(artifact);
308
-
309
- if (fs.existsSync(currentExportBackupPath)) {
310
- logWarning(
311
- `️♻️ Restoring backup ${chalk.gray(currentExportArchivePath)}`
312
- );
313
- run(`mv ${currentExportBackupPath} ${currentExportArchivePath}`);
314
- }
315
- };
316
-
317
- const deleteArtifactBackup = (artifact: string) => {
318
- const { currentExportArchivePath, currentExportBackupPath } =
319
- getArtifactPaths(artifact);
320
-
321
- logWarning(`️🗑️ Removing backup ${chalk.gray(currentExportArchivePath)}`);
322
- run(`rm -rf ${currentExportBackupPath}`);
323
- };
324
-
325
- const archiveCacheArtifacts = () => {
326
- for (const artifact of artifactsCache) {
327
- const { currentExportArchiveCachePath, currentExportWorkingPath } =
328
- getArtifactPaths(artifact);
329
-
330
- if (fs.existsSync(currentExportWorkingPath)) {
331
- logInfo(
332
- `🚚 Moving files from ${chalk.gray(
333
- currentExportWorkingPath
334
- )} to ${chalk.gray(currentExportArchiveCachePath)}`
335
- );
336
- run(`mv ${currentExportWorkingPath} ${currentExportArchiveCachePath}`);
337
- } else {
338
- throw new Error(
339
- `🚚 Error moving files from ${currentExportWorkingPath}: Path does not exist.`
340
- );
341
- }
342
- }
343
- };
344
- const restoreCacheArtifacts = () => {
345
- for (const artifact of artifactsCache) {
346
- const { currentExportArchiveCachePath, currentExportWorkingPath } =
347
- getArtifactPaths(artifact);
348
-
349
- if (fs.existsSync(currentExportArchiveCachePath)) {
350
- logWarning(
351
- `️♻️ Restoring ${chalk.gray(currentExportArchiveCachePath)}`
352
- );
353
- run(`mv ${currentExportArchiveCachePath} ${currentExportWorkingPath}`);
354
- }
355
- }
356
- };
357
-
358
- const runExporter = () => {
359
- console.log(`\n${chalk.black(chalk.bgGreen(" Gatsby (start) "))}\n`);
360
-
361
- run("yarn export");
362
- // run("cp build-report.json build-report-${domain}.json")
363
- logSuccess("Your sites have been exported correctly");
364
-
365
- console.log(`\n${chalk.black(chalk.bgGreen(" Gatsby (end) "))}\n`);
366
-
367
- removeDisposableArtifacts();
368
- };
369
-
370
- // TODO: Hacer que infra tire de `public` en vez de `dist` y quitar esto
371
- const moveDistToPublic = () => {
372
- const { currentExportWorkingPath: distPath } = getArtifactPaths("dist");
373
- const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
374
-
375
- if (fs.existsSync(distPath)) {
376
- logWarning(
377
- `🚚 Moving ${chalk.gray(distPath)} to ${chalk.gray(publicPath)}`
378
- );
379
- run(`mv ${distPath} ${publicPath}`);
380
- }
381
- };
382
-
383
- // TODO: Esto no debería hacerse desde infra
384
- const movePublicToDist = () => {
385
- const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
386
- const { currentExportWorkingPath: distPath } = getArtifactPaths("dist");
387
-
388
- if (fs.existsSync(publicPath)) {
389
- logWarning(`🚚 Moving ${publicPath} to ${distPath}`);
390
- run(`mv ${publicPath} ${distPath}`);
391
- }
392
- };
393
-
394
- const removeDisposableArtifacts = () => {
395
- for (const artifact of artifactsDisposable) {
396
- const { currentExportWorkingPath: artifactPath } =
397
- getArtifactPaths(artifact);
398
-
399
- if (fs.existsSync(artifactPath)) {
400
- logWarning(`🗑️ Removing ${chalk.gray(artifactPath)}`);
401
- run(`rm -rf ${artifactPath}`);
402
- }
403
- }
404
- };
405
-
406
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
407
- const cleanAfterFail = () => {
408
- cleanDirtyArtifactPaths();
409
- };
410
-
411
- return {
412
- init,
413
- getArtifactPaths,
414
- archiveExportArtifact,
415
- archiveArtifacts,
416
- restoreArtifacts,
417
- createArtifactBackup,
418
- restoreArtifactBackup,
419
- deleteArtifactBackup,
420
- archiveCacheArtifacts,
421
- restoreCacheArtifacts,
422
- runExporter,
423
- };
424
- };
425
-
426
- console.clear();
427
-
428
- launchExports().catch((err) => {
429
- console.error("⛔️ ERROR", err?.stdout?.toString() || err);
430
- process.exit(1);
431
- });
@@ -1,9 +0,0 @@
1
- import { AuthService } from "../src/services/auth";
2
- import { SettingsService } from "../src/services/settings";
3
-
4
- const resetRender = async () => {
5
- await AuthService.login();
6
- await SettingsService.resetRender();
7
- };
8
-
9
- resetRender();
@@ -1,40 +0,0 @@
1
- import type { GatsbyPageObject } from "../types/pages";
2
- import type { Core } from "@griddo/core";
3
- import type { HeadProps } from "gatsby";
4
-
5
- export interface CustomHeadProps extends HeadProps {
6
- pageContext: GatsbyPageObject["context"] & {
7
- page: Core.Page & {
8
- defaultLang: { id: number };
9
- dimensions: Dimensions;
10
- disableHrefLangs: Array<number>;
11
- };
12
- };
13
- }
14
-
15
- export interface TemplateProps extends Omit<GatsbyPageObject, "context"> {
16
- pageContext: GatsbyPageObject["context"] & {
17
- page: Core.Page;
18
- };
19
- location: {
20
- pathname: string;
21
- search: string;
22
- hash: string;
23
- };
24
- }
25
-
26
- export interface HtmlProps {
27
- body: string;
28
- bodyAttributes: React.HtmlHTMLAttributes<HTMLBodyElement>;
29
- headComponents: React.ReactNode;
30
- htmlAttributes: React.HtmlHTMLAttributes<HTMLHtmlElement>;
31
- postBodyComponents: React.ReactNode;
32
- preBodyComponents: React.ReactNode;
33
- }
34
-
35
- export interface Dimensions {
36
- values: Record<string, string> | null;
37
- contentSelect?: "group" | "individual" | null;
38
- groupSelect?: string;
39
- dimensionsSelect?: Array<string>;
40
- }