@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
@@ -0,0 +1,37 @@
1
+ import { getInstanceDomains } from "@exporter/utils/domains";
2
+ import { downloadBuildData } from "@exporter/utils/download-build-data";
3
+ import { printExporterLogo } from "@exporter/utils/shared";
4
+
5
+ import { getAstroDomainRunner } from "./utils";
6
+
7
+ /**
8
+ * Astro adapter for Griddo.
9
+ */
10
+ async function runAstroAdapter() {
11
+ printExporterLogo("astro");
12
+
13
+ const domains = await getInstanceDomains();
14
+
15
+ for (const domain of domains) {
16
+ const runner = getAstroDomainRunner(domain);
17
+ // ---------------------------------------------------------------------- //
18
+ // Init the render, restore Gatsby /.cache and /public folders //
19
+ // ---------------------------------------------------------------------- //
20
+ runner.init();
21
+ // runner.whatEverAction();
22
+ // runner.otherAstroRelatedFunction();
23
+
24
+ // ---------------------------------------------------------------------- //
25
+ // Download domain build data (sites, pages, etc) and generator a folder //
26
+ // called `store` where all the domain render data is saved. //
27
+ // ---------------------------------------------------------------------- //
28
+ await downloadBuildData();
29
+
30
+ // ---------------------------------------------------------------------- //
31
+ // Call the `astro build` command. //
32
+ // ---------------------------------------------------------------------- //
33
+ runner.runAstroBuild();
34
+ }
35
+ }
36
+
37
+ export { runAstroAdapter };
@@ -0,0 +1,29 @@
1
+ import { getEnvRunner } from "@exporter/utils/runners";
2
+ import dotenv from "dotenv";
3
+
4
+ dotenv.config();
5
+
6
+ /**
7
+ * Return a runner, a serie of functions to manage the Astro render artifacts.
8
+ */
9
+ function getAstroDomainRunner(domain: string) {
10
+ const run = getEnvRunner({
11
+ DOMAIN: domain,
12
+ GRIDDO_RENDERID: new Date().valueOf(),
13
+ });
14
+
15
+ const init = () => {
16
+ console.info(`Initializing exporter for the domain ${domain}`);
17
+ };
18
+
19
+ const runAstroBuild = () => {
20
+ run("yarn astro-build");
21
+ };
22
+
23
+ return {
24
+ init,
25
+ runAstroBuild,
26
+ };
27
+ }
28
+
29
+ export { getAstroDomainRunner };
@@ -0,0 +1,86 @@
1
+ import { getInstanceDomains } from "@exporter/utils/domains";
2
+ import { downloadBuildData } from "@exporter/utils/download-build-data";
3
+ import {
4
+ measureExecutionTime,
5
+ printExporterLogo,
6
+ } from "@exporter/utils/shared";
7
+
8
+ import { getGatsbyDomainRunner } from "./utils";
9
+
10
+ /**
11
+ * Gatsby adapter for Griddo.
12
+ */
13
+ async function runGatsbyAdapter() {
14
+ printExporterLogo("gatsby");
15
+
16
+ let exeTime = 0;
17
+ const domains = await getInstanceDomains();
18
+
19
+ for (const domain of domains) {
20
+ const runner = getGatsbyDomainRunner(domain);
21
+
22
+ /*
23
+ * Init the render, restore Gatsby `.cache` and `public` folders.
24
+ */
25
+ exeTime = await measureExecutionTime(
26
+ runner.init,
27
+ runner.restoreArtifacts,
28
+ runner.restoreCacheArtifacts
29
+ ).catch((err) => {
30
+ console.error(
31
+ "Error in init() || restoreArtifacts() || restoreCacheArtifacts() :",
32
+ err?.stdout?.toString() || err
33
+ );
34
+ process.exit(1);
35
+ });
36
+
37
+ console.info(`success restore ${domain} - ${exeTime}s`);
38
+
39
+ /*
40
+ * Download domain build data (sites, pages, etc) and generator a folder
41
+ * called `store` where all the domain render data is saved.
42
+ */
43
+ exeTime = await measureExecutionTime(downloadBuildData).catch((err) => {
44
+ console.error(
45
+ "Error in downloadBuildData() :",
46
+ err?.stdout?.toString() || err
47
+ );
48
+ process.exit(1);
49
+ });
50
+ console.info(`success download ${domain} - ${exeTime}s`);
51
+
52
+ /*
53
+ * Call the `gatsby build` command.
54
+ * Gatsby will use the downloaded data and create the static build.
55
+ * `gatsby-node.ts` is the main file where the stati generation happens.
56
+ */
57
+ exeTime = await measureExecutionTime(runner.runGatsbyBuild).catch((err) => {
58
+ console.error(
59
+ "Error in runGatsbyBuild() :",
60
+ err?.stdout?.toString() || err
61
+ );
62
+ process.exit(1);
63
+ });
64
+
65
+ console.info(`success gatsby build command - ${exeTime}s`);
66
+
67
+ /*
68
+ * When Gatsby ends, remove disposable artifacts and save .cache and
69
+ * public foler to use in the next render.
70
+ */
71
+ exeTime = await measureExecutionTime(
72
+ runner.removeDisposableArtifacts,
73
+ runner.archiveArtifacts,
74
+ runner.archiveCacheArtifacts
75
+ ).catch((err) => {
76
+ console.error(
77
+ "Error in removeDisposableArtifacts() || archiveArtifacts()|| archiveCacheArtifacts() :",
78
+ err?.stdout?.toString() || err
79
+ );
80
+ process.exit(1);
81
+ });
82
+ console.info(`success archive ${domain} - ${exeTime}s`);
83
+ }
84
+ }
85
+
86
+ export { runGatsbyAdapter };
@@ -0,0 +1,352 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import { getEnvRunner } from "@exporter/utils/runners";
5
+ import { CXRootFolder, instanceRootFolder } from "@exporter/utils/shared";
6
+ import chalk from "chalk";
7
+ import dotenv from "dotenv";
8
+
9
+ dotenv.config();
10
+
11
+ /**
12
+ * Return a runner, a serie of functions to manage the Gatsby render artifacts.
13
+ */
14
+ function getGatsbyDomainRunner(domain: string) {
15
+ // Artifacts to preserve between CX installs
16
+ const artifactsArchivable = ["dist", "assets"];
17
+
18
+ // Artifacts to remove after export
19
+ // if STRIP_DOMAIN_FROM_PATH is false `.cache` will be added.
20
+ const artifactsDisposable = ["public", "store"];
21
+
22
+ // Artifacts to make exports faster
23
+ // if STRIP_DOMAIN_FROM_PATH is true `.cache` will be added.
24
+ const artifactsCache = ["apiCache" /* , ".cache" */];
25
+
26
+ // TODO: Remove STRIP_DOMAIN_FROM_PATH behaviour when all instances are over 1.75.219
27
+ const STRIP_DOMAIN_FROM_PATH = JSON.parse(
28
+ process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
29
+ );
30
+
31
+ if (STRIP_DOMAIN_FROM_PATH) {
32
+ artifactsCache.push(".cache");
33
+ } else {
34
+ artifactsDisposable.push(".cache");
35
+ }
36
+
37
+ // Where we are going to find archived exports
38
+ const exportArchiveBasePath = path.resolve(
39
+ instanceRootFolder,
40
+ "exports/sites"
41
+ );
42
+ const exportCachesArchivePath = path.resolve(__dirname, "../caches");
43
+
44
+ const assetPrefix = getGatsbyAssetPrefixSlug(domain);
45
+
46
+ const run = getEnvRunner({
47
+ DOMAIN: domain,
48
+ GRIDDO_ASSET_PREFIX: assetPrefix,
49
+ NEEDS_ASSET_DOMAIN_PREFIX: assetPrefix && assetPrefix !== "",
50
+ GRIDDO_RENDERID: new Date().valueOf(),
51
+ });
52
+
53
+ /**
54
+ * Initialize exporter clearing artifacts data from a unsuccessful build and
55
+ * creating necesary folders to store a new build.
56
+ */
57
+ const init = () => {
58
+ console.info(`Initializing exporter for the domain ${domain}`);
59
+ cleanDirtyArtifactPaths();
60
+ createBaseExportPaths();
61
+ };
62
+
63
+ /**
64
+ * Restore Gatsby artifacts from a previous render to improve performance.
65
+ */
66
+ const restoreArtifacts = () => {
67
+ for (const artifact of artifactsArchivable) {
68
+ const { currentExportArchivePath, currentExportWorkingPath } =
69
+ getArtifactPaths(artifact);
70
+
71
+ if (fs.existsSync(currentExportArchivePath)) {
72
+ console.log(`️Restoring ${chalk.gray(currentExportArchivePath)}`);
73
+ run(`cp -R ${currentExportArchivePath} ${currentExportWorkingPath}`);
74
+ }
75
+ }
76
+
77
+ moveDistToPublic();
78
+ };
79
+
80
+ const getArtifactPaths = (artifact = "") => {
81
+ if (artifact === "/")
82
+ throw new Error(`Artifact path cannot be root: ${artifact}`);
83
+
84
+ // Archives
85
+ const domainExportArchiveBasePath = path.resolve(
86
+ exportArchiveBasePath,
87
+ domain
88
+ );
89
+ const currentExportArchivePath = path.resolve(
90
+ domainExportArchiveBasePath,
91
+ artifact
92
+ );
93
+ const currentExportArchivePathInDomain = path.resolve(
94
+ currentExportArchivePath,
95
+ domain
96
+ );
97
+
98
+ // Cachés
99
+ const domainCacheArchiveBasePath = path.resolve(
100
+ exportCachesArchivePath,
101
+ domain
102
+ );
103
+ const currentExportArchiveCachePath = path.resolve(
104
+ domainCacheArchiveBasePath,
105
+ artifact
106
+ );
107
+ const currentExportArchiveCachePathInDomain = path.resolve(
108
+ currentExportArchiveCachePath,
109
+ domain
110
+ );
111
+
112
+ const currentExportBackupPath = `${currentExportArchivePath}-BACKUP`;
113
+ const currentExportWorkingPath = path.resolve(CXRootFolder, artifact);
114
+
115
+ return {
116
+ domainExportArchiveBasePath,
117
+ currentExportArchivePath,
118
+ currentExportBackupPath,
119
+ currentExportWorkingPath,
120
+ currentExportArchivePathInDomain,
121
+ domainCacheArchiveBasePath,
122
+ currentExportArchiveCachePath,
123
+ currentExportArchiveCachePathInDomain,
124
+ };
125
+ };
126
+
127
+ /**
128
+ * Remove artifacts probably from a unsuccessful build.
129
+ */
130
+ const cleanDirtyArtifactPaths = () => {
131
+ for (const artifact of [
132
+ ...artifactsArchivable,
133
+ ...artifactsDisposable,
134
+ ...artifactsCache,
135
+ ]) {
136
+ const { currentExportWorkingPath } = getArtifactPaths(artifact);
137
+
138
+ if (fs.existsSync(currentExportWorkingPath)) {
139
+ console.log(`Cleanup dirty ${chalk.gray(currentExportWorkingPath)}`);
140
+ run(`rm -rf ${currentExportWorkingPath}`);
141
+ }
142
+ }
143
+ };
144
+
145
+ /**
146
+ * Creates necesary folders.
147
+ */
148
+ const createBaseExportPaths = () => {
149
+ const { domainExportArchiveBasePath, domainCacheArchiveBasePath } =
150
+ getArtifactPaths();
151
+
152
+ for (const _path of [
153
+ domainExportArchiveBasePath,
154
+ domainCacheArchiveBasePath,
155
+ ]) {
156
+ if (!fs.existsSync(_path)) {
157
+ console.info(`Creating ${_path}`);
158
+ run(`mkdir -p ${_path}`);
159
+ }
160
+ }
161
+ };
162
+
163
+ const archiveExportArtifact = (artifact: string) => {
164
+ const { currentExportArchivePath, currentExportWorkingPath } =
165
+ getArtifactPaths(artifact);
166
+
167
+ console.info(
168
+ `Moving files from ${chalk.gray(
169
+ currentExportWorkingPath
170
+ )} to ${chalk.gray(currentExportArchivePath)}`
171
+ );
172
+ run(`mv ${currentExportWorkingPath} ${currentExportArchivePath}`);
173
+ };
174
+
175
+ /** Archive archivable artifacts to reuse them in the next render */
176
+ const archiveArtifacts = () => {
177
+ for (const artifact of artifactsArchivable) {
178
+ const { currentExportWorkingPath, currentExportArchivePath } =
179
+ getArtifactPaths(artifact);
180
+
181
+ if (!fs.existsSync(currentExportWorkingPath)) {
182
+ console.log(
183
+ "Source directory has not been created:",
184
+ currentExportWorkingPath
185
+ );
186
+ continue;
187
+ }
188
+
189
+ try {
190
+ createArtifactBackup(artifact);
191
+ archiveExportArtifact(artifact);
192
+ deleteArtifactBackup(artifact);
193
+ } catch (error) {
194
+ console.log(
195
+ `Error moving files to ${currentExportArchivePath}`,
196
+ (error as Error).message
197
+ );
198
+ restoreArtifactBackup(artifact);
199
+ continue;
200
+ }
201
+ }
202
+ };
203
+
204
+ const createArtifactBackup = (artifact: string) => {
205
+ const { currentExportArchivePath, currentExportBackupPath } =
206
+ getArtifactPaths(artifact);
207
+
208
+ if (fs.existsSync(currentExportArchivePath)) {
209
+ console.info(
210
+ `Creating backup of ${chalk.gray(currentExportArchivePath)}`
211
+ );
212
+ run(`mv ${currentExportArchivePath} ${currentExportBackupPath}`);
213
+ }
214
+ };
215
+
216
+ const restoreArtifactBackup = (artifact: string) => {
217
+ const { currentExportArchivePath, currentExportBackupPath } =
218
+ getArtifactPaths(artifact);
219
+
220
+ if (fs.existsSync(currentExportBackupPath)) {
221
+ console.log(`️Restoring backup ${chalk.gray(currentExportArchivePath)}`);
222
+ run(`mv ${currentExportBackupPath} ${currentExportArchivePath}`);
223
+ }
224
+ };
225
+
226
+ const deleteArtifactBackup = (artifact: string) => {
227
+ const { currentExportArchivePath, currentExportBackupPath } =
228
+ getArtifactPaths(artifact);
229
+
230
+ console.log(`️Removing backup ${chalk.gray(currentExportArchivePath)}`);
231
+ run(`rm -rf ${currentExportBackupPath}`);
232
+ };
233
+
234
+ /** Archive archivable cache artifacts to reuse them in the next render */
235
+ const archiveCacheArtifacts = () => {
236
+ for (const artifact of artifactsCache) {
237
+ const { currentExportArchiveCachePath, currentExportWorkingPath } =
238
+ getArtifactPaths(artifact);
239
+
240
+ if (fs.existsSync(currentExportWorkingPath)) {
241
+ console.info(
242
+ `Moving files from ${chalk.gray(
243
+ currentExportWorkingPath
244
+ )} to ${chalk.gray(currentExportArchiveCachePath)}`
245
+ );
246
+ run(`mv ${currentExportWorkingPath} ${currentExportArchiveCachePath}`);
247
+ } else {
248
+ throw new Error(
249
+ `Error moving files from ${currentExportWorkingPath}: Path does not exist.`
250
+ );
251
+ }
252
+ }
253
+ };
254
+
255
+ /**
256
+ * Restore Gatsby cache artifacts from a previous render to improve
257
+ * performance.
258
+ */
259
+ const restoreCacheArtifacts = () => {
260
+ for (const artifact of artifactsCache) {
261
+ const { currentExportArchiveCachePath, currentExportWorkingPath } =
262
+ getArtifactPaths(artifact);
263
+
264
+ if (fs.existsSync(currentExportArchiveCachePath)) {
265
+ console.log(`️Restoring ${chalk.gray(currentExportArchiveCachePath)}`);
266
+ run(`mv ${currentExportArchiveCachePath} ${currentExportWorkingPath}`);
267
+ }
268
+ }
269
+ };
270
+
271
+ /**
272
+ * Call the gatsby build command.
273
+ * This start the `yarn gatsby-build` command that will use the data downloaded.
274
+ */
275
+ const runGatsbyBuild = () => {
276
+ run("yarn gatsby-build");
277
+ };
278
+
279
+ // TODO: Hacer que infra tire de `public` en vez de `dist` y quitar esto
280
+ const moveDistToPublic = () => {
281
+ const { currentExportWorkingPath: distPath } = getArtifactPaths("dist");
282
+ const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
283
+
284
+ if (fs.existsSync(distPath)) {
285
+ console.log(
286
+ `Moving ${chalk.gray(distPath)} to ${chalk.gray(publicPath)}`
287
+ );
288
+ run(`mv ${distPath} ${publicPath}`);
289
+ }
290
+ };
291
+
292
+ // TODO: Esto no debería hacerse desde infra
293
+ // const movePublicToDist = () => {
294
+ // const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
295
+ // const { currentExportWorkingPath: distPath } = getArtifactPaths("dist");
296
+
297
+ // if (fs.existsSync(publicPath)) {
298
+ // console.log(`Moving ${publicPath} to ${distPath}`);
299
+ // run(`mv ${publicPath} ${distPath}`);
300
+ // }
301
+ // };
302
+
303
+ /**
304
+ * Delete disposable artifacts between renders.
305
+ */
306
+ const removeDisposableArtifacts = () => {
307
+ for (const artifact of artifactsDisposable) {
308
+ const { currentExportWorkingPath: artifactPath } =
309
+ getArtifactPaths(artifact);
310
+
311
+ if (fs.existsSync(artifactPath)) {
312
+ console.log(`️Removing ${chalk.gray(artifactPath)}`);
313
+ run(`rm -rf ${artifactPath}`);
314
+ }
315
+ }
316
+ };
317
+
318
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
319
+ const cleanAfterFail = () => {
320
+ cleanDirtyArtifactPaths();
321
+ };
322
+
323
+ return {
324
+ init,
325
+ getArtifactPaths,
326
+ archiveExportArtifact,
327
+ archiveArtifacts,
328
+ restoreArtifacts,
329
+ createArtifactBackup,
330
+ restoreArtifactBackup,
331
+ deleteArtifactBackup,
332
+ archiveCacheArtifacts,
333
+ restoreCacheArtifacts,
334
+ runGatsbyBuild,
335
+ removeDisposableArtifacts,
336
+ };
337
+ }
338
+
339
+ /**
340
+ * Return the assetPrefix url `assetPrefix/domain`
341
+ */
342
+ function getGatsbyAssetPrefixSlug(domain: string) {
343
+ const assetPrefix =
344
+ process.env.GRIDDO_ASSET_PREFIX || process.env.ASSET_PREFIX;
345
+
346
+ if (!assetPrefix || !domain) return "";
347
+ if (!domain.startsWith("pro-")) return "";
348
+
349
+ return `${assetPrefix}/${domain}`;
350
+ }
351
+
352
+ export { getGatsbyDomainRunner };
@@ -0,0 +1,5 @@
1
+ import { runAstroAdapter } from "./astro";
2
+ import { runGatsbyAdapter } from "./gatsby";
3
+
4
+ export type Adapters = "gatsby" | "astro";
5
+ export { runAstroAdapter, runGatsbyAdapter };
@@ -1,11 +1,10 @@
1
- import fs from "fs";
2
- import path from "path";
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
3
 
4
4
  import pkgDir from "pkg-dir";
5
5
 
6
- import { AuthService } from "../src/services/auth";
7
- import { SitesService } from "../src/services/sites";
8
- import { logInfo } from "../src/utils/shared";
6
+ import { AuthService } from "./services/auth";
7
+ import { SitesService } from "./services/sites";
9
8
 
10
9
  // Where we are going to find export folders
11
10
  const execBasePath = pkgDir.sync(path.resolve(__dirname, "../.."))!;
@@ -21,12 +20,12 @@ type Report = {
21
20
  lang?: string | undefined;
22
21
  }
23
22
  | undefined;
24
- sites: {
23
+ sites: Array<{
25
24
  siteId: number;
26
- publishHashes: string[];
25
+ publishHashes: Array<string>;
27
26
  siteHash: string | null;
28
- unpublishHashes: string[];
29
- }[];
27
+ unpublishHashes: Array<string>;
28
+ }>;
30
29
  };
31
30
 
32
31
  export async function buildComplete(report: Report) {
@@ -35,14 +34,14 @@ export async function buildComplete(report: Report) {
35
34
  const promises = report.sites.map((site) => {
36
35
  const { siteId, ...body } = site;
37
36
 
38
- logInfo(`Deploying ending call to site ${siteId}:`);
37
+ console.info(`Deploying ending call to site ${siteId}:`);
39
38
 
40
39
  return SitesService.endSiteRender(siteId, body);
41
40
  });
42
41
 
43
42
  await Promise.all(promises);
44
43
 
45
- logInfo(`Build end signal sent for ${report.sites.length} site(s)`);
44
+ console.info(`Build end's signal sent for ${report.sites.length} site(s)`);
46
45
  }
47
46
 
48
47
  function getExportedDomains() {
@@ -51,7 +50,7 @@ function getExportedDomains() {
51
50
  return domains;
52
51
  }
53
52
 
54
- function getBuildReports(domains: string[]) {
53
+ function getBuildReports(domains: Array<string>) {
55
54
  const reports = [];
56
55
 
57
56
  for (const domain of domains) {
@@ -63,7 +62,7 @@ function getBuildReports(domains: string[]) {
63
62
  );
64
63
 
65
64
  if (!fs.existsSync(buildReportFile)) {
66
- console.log(`Build report "${buildReportFile}" not found.`);
65
+ console.info(`Build report file "${buildReportFile}" not found.`);
67
66
  continue;
68
67
  }
69
68
 
@@ -84,4 +83,7 @@ async function main() {
84
83
  }
85
84
  }
86
85
 
87
- main();
86
+ main().catch((err) => {
87
+ console.error("Error", err?.stdout?.toString() || err);
88
+ process.exit(1);
89
+ });
@@ -0,0 +1,6 @@
1
+ import { downloadBuildData } from "./utils/download-build-data";
2
+
3
+ downloadBuildData().catch((err) => {
4
+ console.error("Error", err?.stdout?.toString() || err);
5
+ process.exit(1);
6
+ });
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable node/shebang */
3
+ import { Adapters, runGatsbyAdapter } from "./adapters";
4
+
5
+ const adapter = process.env.GRIDDO_CX_ADAPTER as Adapters;
6
+
7
+ async function main(adapter: Adapters) {
8
+ if (adapter === "gatsby") {
9
+ await runGatsbyAdapter();
10
+ process.exit(0);
11
+ }
12
+
13
+ // if (adapter === "astro") {
14
+ // await runAstroAdapter();
15
+ // process.exit(0);
16
+ // }
17
+
18
+ throw new Error("Adapter not configured correctly");
19
+ }
20
+
21
+ // Go render, go!
22
+ main(adapter).catch((err) => {
23
+ console.error("Error in main():", err?.stdout?.toString() || err);
24
+ process.exit(1);
25
+ });
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable node/shebang */
3
+
4
+ import { runGatsbyAdapter } from "./adapters";
5
+
6
+ async function main() {
7
+ await runGatsbyAdapter();
8
+ }
9
+
10
+ // Go render, go!
11
+ main().catch((err) => {
12
+ console.error("Error in main():", err?.stdout?.toString() || err);
13
+ process.exit(1);
14
+ });
@@ -0,0 +1,12 @@
1
+ import { AuthService } from "./services/auth";
2
+ import { SettingsService } from "./services/settings";
3
+
4
+ async function main() {
5
+ await AuthService.login();
6
+ await SettingsService.resetRender();
7
+ }
8
+
9
+ main().catch((err) => {
10
+ console.error("Error", err?.stdout?.toString() || err);
11
+ process.exit(1);
12
+ });
@@ -43,8 +43,6 @@ class AuthService {
43
43
  }
44
44
 
45
45
  return this.headers;
46
-
47
- console.log("👋 Login\n");
48
46
  } catch (e) {
49
47
  console.error(
50
48
  chalk.red(`
@@ -64,7 +64,7 @@ class DistributorService {
64
64
  }
65
65
 
66
66
  console.log(
67
- `ERROR: Distribuidor mode: ${mode} is not recognized on page ${page?.id}.`
67
+ `Error: Distribuidor mode: ${mode} is not recognized on page ${page?.id}.`
68
68
  );
69
69
 
70
70
  return data;
@@ -95,6 +95,15 @@ class DistributorService {
95
95
  return [];
96
96
  }
97
97
 
98
+ // Avoid fetch distributors with empty `data.sources`
99
+ if (Array.isArray(data.sources) && data.sources.length < 1) {
100
+ logBox(
101
+ `Warning: Page with id: ${page.id} has a ReferenceField with empty \`data.sources\``
102
+ );
103
+
104
+ return [];
105
+ }
106
+
98
107
  const { site, lang } = data;
99
108
  const body = this.getBody(data, page);
100
109
  const response = await SitesService.getDistributorData(