@griddo/cx 11.2.5 → 11.2.6-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 (64) hide show
  1. package/build/adapters/gatsby/index.d.ts +1 -1
  2. package/build/commands/prepare-domains-render.d.ts +1 -0
  3. package/build/commands/upload-search-content.d.ts +2 -0
  4. package/build/constants/envs.d.ts +2 -1
  5. package/build/end-render.js +25 -25
  6. package/build/end-render.js.map +4 -4
  7. package/build/index.d.ts +1 -2
  8. package/build/index.js +28 -51
  9. package/build/index.js.map +4 -4
  10. package/build/prepare-domains-render.js +73 -0
  11. package/build/prepare-domains-render.js.map +7 -0
  12. package/build/reset-render.js +21 -21
  13. package/build/reset-render.js.map +4 -4
  14. package/build/services/sites.d.ts +5 -1
  15. package/build/start-render.js +41 -38
  16. package/build/start-render.js.map +4 -4
  17. package/build/types/global.d.ts +5 -4
  18. package/build/types/sites.d.ts +7 -0
  19. package/build/upload-search-content.js +18 -18
  20. package/build/upload-search-content.js.map +4 -4
  21. package/build/utils/core-utils.d.ts +4 -8
  22. package/build/utils/create-build-data.d.ts +2 -2
  23. package/build/utils/domains.d.ts +9 -1
  24. package/build/utils/publish.d.ts +7 -0
  25. package/build/utils/render.d.ts +1 -1
  26. package/build/utils/sites.d.ts +2 -2
  27. package/build/utils/store.d.ts +28 -3
  28. package/exporter/adapters/gatsby/index.ts +124 -126
  29. package/exporter/build.sh +5 -5
  30. package/exporter/commands/end-render.ts +107 -0
  31. package/exporter/commands/prepare-domains-render.ts +46 -0
  32. package/exporter/commands/start-render.ts +68 -0
  33. package/exporter/{scripts → commands}/upload-search-content.ts +1 -1
  34. package/exporter/constants/envs.ts +4 -2
  35. package/exporter/constants/index.ts +1 -0
  36. package/exporter/index.ts +0 -2
  37. package/exporter/services/sites.ts +26 -0
  38. package/exporter/services/store.ts +33 -81
  39. package/exporter/types/global.ts +6 -2
  40. package/exporter/types/sites.ts +7 -0
  41. package/exporter/utils/core-utils.ts +5 -21
  42. package/exporter/utils/create-build-data.ts +2 -2
  43. package/exporter/utils/domains.ts +1 -1
  44. package/exporter/utils/folders.ts +2 -1
  45. package/exporter/utils/loggin.ts +7 -4
  46. package/exporter/utils/publish.ts +29 -0
  47. package/exporter/utils/render.ts +2 -1
  48. package/exporter/utils/sites.ts +12 -52
  49. package/exporter/utils/store.ts +88 -42
  50. package/package.json +11 -6
  51. package/start-render.js +1 -1
  52. package/build/run-start-render.js +0 -97
  53. package/build/run-start-render.js.map +0 -7
  54. package/build/scripts/end-render.d.ts +0 -20
  55. package/build/scripts/start-render.d.ts +0 -3
  56. package/exporter/scripts/end-render.ts +0 -102
  57. package/exporter/scripts/run-start-render.ts +0 -5
  58. package/exporter/scripts/start-render.ts +0 -25
  59. /package/build/{scripts/reset-render.d.ts → commands/end-render.d.ts} +0 -0
  60. /package/build/{scripts → commands}/move-assets.d.ts +0 -0
  61. /package/build/{scripts/run-start-render.d.ts → commands/reset-render.d.ts} +0 -0
  62. /package/build/{scripts/upload-search-content.d.ts → commands/start-render.d.ts} +0 -0
  63. /package/exporter/{scripts → commands}/move-assets.ts +0 -0
  64. /package/exporter/{scripts → commands}/reset-render.ts +0 -0
@@ -69,7 +69,7 @@ declare function sanitizeAPICacheDir(): void;
69
69
  * @param functions - Functions to be executed to measure their execution time.
70
70
  * @returns A promise that resolves with the total execution time in seconds.
71
71
  */
72
- declare function measureExecutionTime(functions: Array<(...args: Array<unknown>) => unknown | Promise<unknown>>, delayInMS?: number): Promise<number>;
72
+ declare function measureExecutionTime(functions: Array<(...args: Array<unknown>) => unknown | Promise<unknown>>): Promise<number>;
73
73
  /**
74
74
  * Pause the process until a key is pressed.
75
75
  *
@@ -90,11 +90,7 @@ declare function pause(title: string): Promise<void> | undefined;
90
90
  * @param options.bypass - Skip the step functions.
91
91
  * @returns - A promise that resolves when the life cycle process is completed.
92
92
  */
93
- declare function doLifeCycle(name: LifeCyclesNames, options: {
94
- steps: LifeCycleSteps;
95
- delay?: number;
96
- bypass?: boolean;
97
- }): Promise<void>;
93
+ declare function doLifeCycle(name: LifeCyclesNames, steps: LifeCycleSteps): Promise<void>;
98
94
  /**
99
95
  * Creates additional files after the render: sitemaps, robots and a report of
100
96
  * the finished render.
@@ -102,7 +98,7 @@ declare function doLifeCycle(name: LifeCyclesNames, options: {
102
98
  * @async
103
99
  * @param domain
104
100
  */
105
- declare function createRenderMetadata(domain: string): Promise<void>;
101
+ declare function createDomainMetadata(domain: string): Promise<void>;
106
102
  declare function removeAllSiteDirsFromStore(): void;
107
103
  /**
108
104
  * Save render information to a file to use as debug log.
@@ -110,4 +106,4 @@ declare function removeAllSiteDirsFromStore(): void;
110
106
  * This information will **not** be sent to any API.
111
107
  */
112
108
  declare function saveBuildEndLogs(): void;
113
- export { createRenderMetadata, delay, doLifeCycle, getConfig, getSafeSiteId, instanceRootDir, isTruthy, measureExecutionTime, msToSec, pause, removeAllSiteDirsFromStore, removeProperties, sanitizeAPICacheDir, saveBuildEndLogs, walk, walkStore, };
109
+ export { createDomainMetadata, delay, doLifeCycle, getConfig, getSafeSiteId, instanceRootDir, isTruthy, measureExecutionTime, msToSec, pause, removeAllSiteDirsFromStore, removeProperties, sanitizeAPICacheDir, saveBuildEndLogs, walk, walkStore, };
@@ -4,5 +4,5 @@
4
4
  * `getBuildMetadata()` to get build and sites metadata as objects. Both from
5
5
  * exporter utils sites dir.
6
6
  */
7
- declare function createBuildData(domain: string): Promise<void>;
8
- export { createBuildData };
7
+ declare function createDomainRenderData(domain: string): Promise<void>;
8
+ export { createDomainRenderData };
@@ -1,5 +1,13 @@
1
+ import type { Domains } from "../types/global";
1
2
  /**
2
3
  * Return an array of domains name (string) of the current instance.
3
4
  */
4
5
  declare function getInstanceDomains(): Promise<string[]>;
5
- export { getInstanceDomains };
6
+ /**
7
+ * Return an unique array of domains, filtered without "/".
8
+ *
9
+ * @param domains An array of domains
10
+ * @see Domains
11
+ */
12
+ declare function getDomainSlugs(domains: Domains): string[];
13
+ export { getInstanceDomains, getDomainSlugs };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Spawn a new node process to upload the domain content.
3
+ * @note This proccess can not access to the custom Griddo `process.env` so it
4
+ * needs variables passed to it via the `env` prop
5
+ */
6
+ declare function publishDomain(domain: string): string;
7
+ export { publishDomain };
@@ -12,4 +12,4 @@ declare function finishRender(): undefined;
12
12
  * Send the default registers through Griddo alerts.
13
13
  */
14
14
  declare function sendGriddoDefaultAlerts(): void;
15
- export { createSentinelRenderFile, deleteSentinelRenderFile, finishRender, initRender, isValidRenderProcessOrThrow, sendGriddoDefaultAlerts, };
15
+ export { createSentinelRenderFile, deleteSentinelRenderFile, finishRender, initRender, isValidRenderProcessOrThrow, sendGriddoDefaultAlerts };
@@ -2,7 +2,7 @@ import type { Site, SiteData } from "../types/sites";
2
2
  /**
3
3
  * Check the instance sites and returns site prepared to be published and unpublished.
4
4
  */
5
- declare function checkSites(domain: string): Promise<{
5
+ declare function getSitesToRender(domain: string): Promise<{
6
6
  sitesToPublish: Site[];
7
7
  sitesToUnpublish: Site[];
8
8
  }>;
@@ -28,4 +28,4 @@ declare function generateBuildReport(): Promise<void>;
28
28
  * Generate sitemaps and save them into file system.
29
29
  */
30
30
  declare function generateSitemaps(): Promise<void>;
31
- export { checkSites, generateBuildReport, generateSitemaps, getSiteData, unpublishSites, };
31
+ export { generateBuildReport, generateSitemaps, getSiteData, getSitesToRender, unpublishSites, };
@@ -59,7 +59,7 @@ declare function savePagesInStore(siteFolderName: string, pages: Array<GriddoPag
59
59
  * Remove files from dir.
60
60
  * @param filenames - An array of ids representing file page names.
61
61
  */
62
- declare function removePagesFromStore(siteDirName: string, filenames: Array<number>): void;
62
+ declare function removeSitePagesFromStore(siteDirName: string, filenames: Array<number>): void;
63
63
  /**
64
64
  * Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
65
65
  * @param sitePages - Properties for page retrieval.
@@ -69,7 +69,7 @@ declare function removePagesFromStore(siteDirName: string, filenames: Array<numb
69
69
  * @param props.changedPages - Array of pages that have been modified in the site.
70
70
  * @returns - An object containing the pages to be created and deleted in the site.
71
71
  */
72
- declare function getPagesToCreateOrDelete(sitePages: {
72
+ declare function getSitePagesToCreateOrDelete(sitePages: {
73
73
  sitesToPublish: Array<Site>;
74
74
  validPagesIds: Array<number>;
75
75
  changedPages: Array<number>;
@@ -80,10 +80,35 @@ declare function getPagesToCreateOrDelete(sitePages: {
80
80
  pagesToDeleteFromStore: number[];
81
81
  pagesToWriteToStore: number[];
82
82
  }>;
83
+ /**
84
+ * Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
85
+ * @param sitePages - Properties for page retrieval.
86
+ * @param props.storeDir - Absolute path of the Griddo store.
87
+ * @param props.pages - Exhaustive array of all pages in the site.
88
+ * @param props.validPagesIds - Array of valid pages in the site.
89
+ * @param props.changedPages - Array of pages that have been modified in the site.
90
+ * @returns - An object containing the pages to be created and deleted in the site.
91
+ */
92
+ declare function getSitePagesToCreateOrDeleteCached(sitePages: {
93
+ sitesToPublish: Array<Site>;
94
+ validPagesIds: Array<number>;
95
+ changedPages: Array<number>;
96
+ siteDirName: string;
97
+ domain: string;
98
+ }): Promise<{
99
+ pagesInStore: number[];
100
+ pagesMissingInStore: number[];
101
+ pagesToDeleteFromStore: number[];
102
+ pagesToWriteToStore: number[];
103
+ }>;
104
+ /**
105
+ * Removes sites from store that are not in `sitesToPublish` array.
106
+ */
107
+ declare function deleteZombieSitesFoldersFromStore(sitesToPublish: Array<Site>): void;
83
108
  /**
84
109
  * Removes sites that exist in the store that should no longer be there because
85
110
  * the domain has been changed. This is necessary because those sites will not
86
111
  * be marked as `sitesToUnpublish` so they must be removed manually.
87
112
  */
88
113
  declare function removeOrphanSites(sitesToPublish: Array<Site>, domain: string): void;
89
- export { createStoreDir, getBuildMetadata, getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath, getPageInStoreDir, getPagesToCreateOrDelete, removeOrphanSites, removePagesFromStore, savePagesInStore, saveRenderInfoInStore, };
114
+ export { createStoreDir, deleteZombieSitesFoldersFromStore, getBuildMetadata, getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath, getPageInStoreDir, getSitePagesToCreateOrDelete, getSitePagesToCreateOrDeleteCached, removeOrphanSites, removeSitePagesFromStore, savePagesInStore, saveRenderInfoInStore, };
@@ -12,14 +12,14 @@ import {
12
12
  runGatsbyBuildCommand,
13
13
  } from "./utils";
14
14
  import getCxArtifacts from "../../artifacts";
15
+ import { AuthService } from "../../services/auth";
15
16
  import {
16
- createRenderMetadata,
17
+ createDomainMetadata,
17
18
  doLifeCycle,
18
19
  getConfig,
19
20
  saveBuildEndLogs,
20
21
  } from "../../utils/core-utils";
21
- import { createBuildData } from "../../utils/create-build-data";
22
- import { getInstanceDomains } from "../../utils/domains";
22
+ import { createDomainRenderData } from "../../utils/create-build-data";
23
23
  import {
24
24
  clearEmptyDirs,
25
25
  copyArtifacts,
@@ -36,132 +36,130 @@ import {
36
36
  isValidRenderProcessOrThrow,
37
37
  } from "../../utils/render";
38
38
 
39
- const config = getConfig();
40
-
41
39
  /**
42
40
  * Render every instance domain with the Gatsby adapter.
43
41
  */
44
- export async function renderDomainsWithGatsbyAdapter() {
45
- const domains = await getInstanceDomains();
46
-
47
- for (const domain of domains) {
48
- infoLog(`Initializing render for the domain ${domain}`);
49
-
50
- createSentinelRenderFile();
51
-
52
- const {
53
- //
54
- __ssg,
55
- __exports,
56
- __cache,
57
- __cx,
58
- __components,
59
- } = config.paths(domain);
60
-
61
- // Griddo artifacts
62
- const cxArtifacts = getCxArtifacts(domain);
63
-
64
- // Gatsby artifacts
65
- const gatsbyArtifacts: Artifacts = {
66
- disposables: [
67
- path.join(__ssg, "public"),
68
- path.join(__ssg, "static"),
69
- path.join(__ssg, ".cache"),
42
+ export async function renderDomainsWithGatsbyAdapter(domain: string) {
43
+ await AuthService.login();
44
+ const config = getConfig();
45
+
46
+ infoLog(`Initializing render for the domain ${domain}\n`);
47
+
48
+ const {
49
+ //
50
+ __ssg,
51
+ __exports,
52
+ __cache,
53
+ __cx,
54
+ __components,
55
+ } = config.paths(domain);
56
+
57
+ // Griddo artifacts
58
+ const cxArtifacts = getCxArtifacts(domain);
59
+
60
+ // Gatsby artifacts
61
+ const gatsbyArtifacts: Pick<Artifacts, "disposables" | "cacheables"> = {
62
+ disposables: [
63
+ path.join(__ssg, "public"),
64
+ path.join(__ssg, "static"),
65
+ path.join(__ssg, ".cache"),
66
+ ],
67
+ cacheables: [".cache"],
68
+ };
69
+
70
+ // These variables are involved in the build for create the dist directory
71
+ // from public and pass to the gatsby-build command via spawnSync.
72
+ const assetPrefix = getGatsbyAssetPrefixWithDomain(domain);
73
+ const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
74
+
75
+ // Compose artifacts
76
+ const disposableArtifacts = [
77
+ ...cxArtifacts.disposables,
78
+ ...gatsbyArtifacts.disposables,
79
+ ];
80
+
81
+ // LifeCycles
82
+
83
+ const allLifeCycles: Array<{
84
+ name: LifeCyclesNames;
85
+ steps: LifeCycleSteps;
86
+ }> = [
87
+ {
88
+ name: "Init",
89
+ steps: [() => createSentinelRenderFile()],
90
+ },
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: [() => createDomainRenderData(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: [() => createDomainMetadata(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),
70
145
  ],
71
- cacheables: [".cache"],
72
- initials: [],
73
- archivables: [],
74
- };
75
- // Compose artifacts
76
- const disposableArtifacts = [
77
- ...cxArtifacts.disposables,
78
- ...gatsbyArtifacts.disposables,
79
- ];
80
-
81
- // These variables are involved in the build for create the dist directory
82
- // from public and pass to the gatsby-build command via spawnSync.
83
- const assetPrefix = getGatsbyAssetPrefixWithDomain(domain);
84
- const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
85
-
86
- // LifeCycles
87
-
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
- }
164
-
165
- deleteSentinelRenderFile();
146
+ },
147
+
148
+ {
149
+ name: "Clean",
150
+ steps: [() => removeArtifacts(disposableArtifacts)],
151
+ },
152
+
153
+ {
154
+ name: "HealthCheck",
155
+ steps: [
156
+ () => isValidRenderProcessOrThrow(),
157
+ () => deleteSentinelRenderFile(),
158
+ ],
159
+ },
160
+ ];
161
+
162
+ for (const { name, steps } of allLifeCycles) {
163
+ await doLifeCycle(name, steps);
166
164
  }
167
165
  }
package/exporter/build.sh CHANGED
@@ -29,11 +29,11 @@ esbuild ${log} ./exporter/index.ts ${bundle_node_opts} --outfile=./build/index.j
29
29
  esbuild ${log} ./exporter/react/index.tsx ${react_opts} --outfile=./build/react/index.js
30
30
 
31
31
  # scripts
32
- esbuild ${log} ./exporter/scripts/run-start-render.ts ${bundle_node_opts} --outfile=./build/run-start-render.js
33
- esbuild ${log} ./exporter/scripts/end-render.ts ${bundle_node_opts} --outfile=./build/end-render.js
34
- esbuild ${log} ./exporter/scripts/upload-search-content.ts ${bundle_node_opts} --outfile=./build/upload-search-content.js
35
- esbuild ${log} ./exporter/scripts/reset-render.ts ${bundle_node_opts} --outfile=./build/reset-render.js
36
- esbuild ${log} ./exporter/scripts/start-render.ts ${bundle_node_opts} --outfile=./build/start-render.js
32
+ esbuild ${log} ./exporter/commands/end-render.ts ${bundle_node_opts} --outfile=./build/end-render.js
33
+ esbuild ${log} ./exporter/commands/upload-search-content.ts ${bundle_node_opts} --outfile=./build/upload-search-content.js
34
+ esbuild ${log} ./exporter/commands/reset-render.ts ${bundle_node_opts} --outfile=./build/reset-render.js
35
+ esbuild ${log} ./exporter/commands/start-render.ts ${bundle_node_opts} --outfile=./build/start-render.js
36
+ esbuild ${log} ./exporter/commands/prepare-domains-render.ts ${bundle_node_opts} --outfile=./build/prepare-domains-render.js
37
37
 
38
38
  # types
39
39
  tsc --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+
6
+ import pkgDir from "pkg-dir";
7
+
8
+ import { AuthService } from "../services/auth";
9
+ import { endSiteRender } from "../services/sites";
10
+ import { getConfig } from "../utils/core-utils";
11
+ import { getInstanceDomains } from "../utils/domains";
12
+ import { infoLog } from "../utils/loggin";
13
+
14
+ const RENDER_BY_DOMAIN = process.env.GRIDDO_RENDER_BY_DOMAINS || "";
15
+
16
+ // Where we are going to find export dirs
17
+ const execBasePath = pkgDir.sync(path.resolve(__dirname, "../.."))!;
18
+
19
+ // Where we are going to find archived exports
20
+ const exportArchiveBasePath = path.resolve(execBasePath, "exports/sites");
21
+
22
+ type Report = {
23
+ authControl:
24
+ | {
25
+ Authorization: string;
26
+ "Cache-Control": string;
27
+ lang?: string | undefined;
28
+ }
29
+ | undefined;
30
+ sites: Array<{
31
+ siteId: number;
32
+ publishHashes: Array<string>;
33
+ siteHash: string | null;
34
+ unpublishHashes: Array<string>;
35
+ publishPagesIds: Array<number>;
36
+ }>;
37
+ };
38
+
39
+ // function getExportedDomains() {
40
+ // const domains = fs
41
+ // .readdirSync(exportArchiveBasePath)
42
+ // // Avoid empty files, usually .DS_Store from local renders.
43
+ // .filter((file) => !file.startsWith("."));
44
+
45
+ // return domains;
46
+ // }
47
+
48
+ function getDomainRenderReport(domain: string) {
49
+ const reports: Array<Report> = [];
50
+ const { buildReportFileName } = getConfig();
51
+
52
+ const buildReportFile = path.resolve(
53
+ exportArchiveBasePath,
54
+ domain,
55
+ "dist",
56
+ buildReportFileName,
57
+ );
58
+
59
+ if (!fs.existsSync(buildReportFile)) {
60
+ console.info(`Build report file "${buildReportFile}" not found.`);
61
+ }
62
+
63
+ const buildReport = JSON.parse(fs.readFileSync(buildReportFile, "utf-8"));
64
+
65
+ reports.push(buildReport);
66
+
67
+ return reports;
68
+ }
69
+
70
+ (async () => {
71
+ const sendEndSiteRender = async (reports: Array<Report>) => {
72
+ for (const report of reports) {
73
+ const sites = report.sites;
74
+
75
+ for (const site of sites) {
76
+ const { siteId, ...body } = site;
77
+
78
+ console.info(`Site (${siteId})`);
79
+
80
+ await endSiteRender(siteId, body);
81
+ }
82
+ }
83
+ };
84
+
85
+ if (RENDER_BY_DOMAIN) {
86
+ await AuthService.login();
87
+ const domain = process.argv.splice(2)[0];
88
+ const reports = getDomainRenderReport(domain);
89
+
90
+ infoLog(`Sending ending call to ${domain} sites`);
91
+
92
+ sendEndSiteRender(reports);
93
+ } else {
94
+ // Legacy render
95
+ const domains = await getInstanceDomains();
96
+ for (const domain of domains) {
97
+ const reports = getDomainRenderReport(domain);
98
+
99
+ infoLog(`Sending ending call to ${domain} sites`);
100
+
101
+ sendEndSiteRender(reports);
102
+ }
103
+ }
104
+ })().catch((err) => {
105
+ console.error("Error", err?.stdout?.toString() || err);
106
+ process.exit(1);
107
+ });
@@ -0,0 +1,46 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import { getConfig } from "../utils/core-utils";
5
+ import { getInstanceDomains } from "../utils/domains";
6
+ import { infoLog, successLog } from "../utils/loggin";
7
+ import { getSitesToRender } from "../utils/sites";
8
+
9
+ (async () => {
10
+ infoLog("Checking domains size");
11
+
12
+ const { __cx } = getConfig().paths();
13
+
14
+ const domains = await getInstanceDomains();
15
+ const domainsInfo = [];
16
+ const domainsFilePath = path.join(__cx, "domains.json");
17
+
18
+ for (const domain of domains) {
19
+ const { sitesToPublish } = await getSitesToRender(domain);
20
+
21
+ // Only count pages (changedPages) if sitesToPublish is not empty.
22
+ // Otherwise we set the domain has having 0 pages.
23
+ const pages = [];
24
+ if (sitesToPublish.length > 0) {
25
+ for (const site of sitesToPublish) {
26
+ pages.push(site.changedPages.length);
27
+ }
28
+ } else {
29
+ pages.push(0);
30
+ }
31
+
32
+ const totalPages = pages.reduce((a, b) => a + b);
33
+ domainsInfo.push({ domain, totalPages });
34
+ }
35
+
36
+ // sort domains, smaller first
37
+ domainsInfo.sort((a, b) => a.totalPages - b.totalPages);
38
+ const domainSorted = domainsInfo.map(({ domain }) => domain);
39
+
40
+ fs.writeFileSync(domainsFilePath, JSON.stringify(domainSorted));
41
+
42
+ successLog(`Checking domains size`);
43
+ })().catch((err) => {
44
+ console.error(err);
45
+ process.exit(1);
46
+ });
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ import { renderDomainsWithGatsbyAdapter } from "../adapters/gatsby";
3
+ import { RenderError } from "../errors";
4
+ import { getInstanceDomains } from "../utils/domains";
5
+ import { errorLabelLog, showExporterVersion } from "../utils/loggin";
6
+ import { sendGriddoDefaultAlerts } from "../utils/render";
7
+
8
+ const GRIDDO_RENDER_DOMAINS = process.env.GRIDDO_RENDER_DOMAINS || "";
9
+ const RENDER_BY_DOMAIN = process.env.GRIDDO_RENDER_BY_DOMAINS || "";
10
+
11
+ async function startRender() {
12
+ try {
13
+ // DOMAINS
14
+ // This block is just for the local instance renders.
15
+ if (GRIDDO_RENDER_DOMAINS) {
16
+ console.log("USANDO EL .ENV");
17
+ showExporterVersion();
18
+ for (const domain of GRIDDO_RENDER_DOMAINS.split(",")) {
19
+ await renderDomainsWithGatsbyAdapter(domain);
20
+ }
21
+ sendGriddoDefaultAlerts();
22
+ process.exit(0);
23
+ }
24
+
25
+ // This will render every domain opposed to the new logic of render each
26
+ // domain separately.
27
+ if (RENDER_BY_DOMAIN) {
28
+ const domain = process.argv.splice(2)[0];
29
+
30
+ if (!domain) {
31
+ console.log("Needs the domain name argument");
32
+ throw new RenderError();
33
+ }
34
+
35
+ showExporterVersion();
36
+ await renderDomainsWithGatsbyAdapter(domain);
37
+ sendGriddoDefaultAlerts();
38
+
39
+ process.exit(0);
40
+ } else {
41
+ showExporterVersion();
42
+
43
+ console.log("( Legacy Render Mode )\n");
44
+
45
+ const domains = await getInstanceDomains();
46
+
47
+ for (const domain of domains) {
48
+ await renderDomainsWithGatsbyAdapter(domain);
49
+ sendGriddoDefaultAlerts();
50
+ }
51
+ process.exit(0);
52
+ }
53
+ } catch (error) {
54
+ if (error instanceof RenderError) {
55
+ errorLabelLog("GRIDDO_ERROR InternalCXError");
56
+ process.exit(1);
57
+ }
58
+
59
+ errorLabelLog("GRIDDO_ERROR UnknownError");
60
+ console.error(error);
61
+ process.exit(1);
62
+ }
63
+ }
64
+
65
+ startRender().catch((err) => {
66
+ console.error("Error", err?.stdout?.toString() || err);
67
+ process.exit(1);
68
+ });
@@ -17,7 +17,6 @@ async function main() {
17
17
 
18
18
  const domains = await getInstanceDomains();
19
19
  const config = getConfig();
20
-
21
20
  for (const domain of domains) {
22
21
  const { __exports_dist } = config.paths(domain);
23
22
 
@@ -28,6 +27,7 @@ async function main() {
28
27
  }
29
28
  }
30
29
 
30
+ // Solo una vez en cada render de todos los dominios...
31
31
  if (envs.GRIDDO_AI_EMBEDDINGS) {
32
32
  await startAIEmbeddings();
33
33
  }