@griddo/cx 10.3.26 → 10.4.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.
- package/README.md +1 -1
- package/build/build-complete.js +15 -15
- package/build/create-build-data.js +60 -0
- package/build/index.js +39 -29
- package/build/reset-render.js +18 -18
- package/exporter/adapters/astro/index.ts +4 -5
- package/exporter/adapters/astro/utils.ts +2 -1
- package/exporter/adapters/gatsby/index.ts +133 -63
- package/exporter/adapters/gatsby/utils.ts +18 -4
- package/exporter/build-complete.ts +8 -2
- package/exporter/create-build-data.ts +22 -0
- package/exporter/index.ts +13 -1
- package/exporter/services/distributors.ts +4 -2
- package/exporter/services/store.ts +75 -109
- package/exporter/types/global.ts +38 -8
- package/exporter/types/pages.ts +0 -2
- package/exporter/types/sites.ts +1 -0
- package/exporter/utils/download-build-data.ts +4 -2
- package/exporter/utils/folders.ts +100 -15
- package/exporter/utils/health-checks.ts +4 -1
- package/exporter/utils/instance.ts +5 -1
- package/exporter/utils/messages.ts +31 -0
- package/exporter/utils/pages.ts +1 -4
- package/exporter/utils/shared.ts +92 -18
- package/exporter/utils/sites.ts +1 -6
- package/exporter/utils/store.ts +207 -13
- package/gatsby-node.ts +4 -0
- package/package.json +6 -6
- package/src/components/template.tsx +0 -2
- package/src/types.ts +0 -1
- package/build/download-data.js +0 -53
- package/exporter/download-data.ts +0 -6
|
@@ -1,8 +1,7 @@
|
|
|
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
1
|
import { getAstroDomainRunner } from "./utils";
|
|
2
|
+
import { getInstanceDomains } from "../../utils/domains";
|
|
3
|
+
import { createBuildData } from "../../utils/download-build-data";
|
|
4
|
+
import { printExporterLogo } from "../../utils/shared";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Astro adapter for Griddo.
|
|
@@ -25,7 +24,7 @@ async function runAstroAdapter() {
|
|
|
25
24
|
// Download domain build data (sites, pages, etc) and generator a folder //
|
|
26
25
|
// called `store` where all the domain render data is saved. //
|
|
27
26
|
// ---------------------------------------------------------------------- //
|
|
28
|
-
await
|
|
27
|
+
await createBuildData(domain);
|
|
29
28
|
|
|
30
29
|
// ---------------------------------------------------------------------- //
|
|
31
30
|
// Call the `astro build` command. //
|
|
@@ -1,104 +1,174 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import type { LifeCycles } from "../../types/global";
|
|
2
|
+
|
|
3
|
+
import { getGatsbyDomainRunner } from "./utils";
|
|
4
|
+
import { getInstanceDomains } from "../../utils/domains";
|
|
5
|
+
import { createBuildData } from "../../utils/download-build-data";
|
|
6
|
+
import { clearEmptyDirs } from "../../utils/folders";
|
|
7
|
+
import { printWarningMessage } from "../../utils/messages";
|
|
8
|
+
import { uploadSearchContentToAPI } from "../../utils/searches";
|
|
4
9
|
import {
|
|
5
10
|
measureExecutionTime,
|
|
11
|
+
pause,
|
|
6
12
|
printExporterLogo,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
startLifeCycle,
|
|
14
|
+
successLifeCyle,
|
|
15
|
+
} from "../../utils/shared";
|
|
10
16
|
|
|
11
17
|
/**
|
|
12
18
|
* Gatsby adapter for Griddo.
|
|
13
19
|
*/
|
|
14
|
-
async function runGatsbyAdapter() {
|
|
20
|
+
async function runGatsbyAdapter(lifeCycles: LifeCycles) {
|
|
15
21
|
printExporterLogo("gatsby");
|
|
22
|
+
const { doArchive, doData, doRestore, doMeta, doSSG } = lifeCycles;
|
|
16
23
|
|
|
17
24
|
let exeTime = 0;
|
|
18
25
|
const domains = await getInstanceDomains();
|
|
26
|
+
if (!domains.length) {
|
|
27
|
+
printWarningMessage(
|
|
28
|
+
"We didn't find any domains to render during the adapter phase.",
|
|
29
|
+
"getInstanceDomains",
|
|
30
|
+
"Function getInstanceDomains returned an empty array of domains. Check if the domains are correctly set in the instance's database."
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
19
34
|
|
|
20
35
|
for (const domain of domains) {
|
|
21
36
|
const runner = getGatsbyDomainRunner(domain);
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Phases:
|
|
40
|
+
* - Prepare.
|
|
41
|
+
* - Folders.
|
|
42
|
+
* - Restore.
|
|
43
|
+
*
|
|
24
44
|
* Init the render, restore Gatsby `.cache` and `public` folders.
|
|
25
45
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
runner.restoreArtifacts,
|
|
29
|
-
runner.restoreCacheArtifacts
|
|
30
|
-
).catch((err) => {
|
|
31
|
-
console.error(
|
|
32
|
-
"Error in init() || restoreArtifacts() || restoreCacheArtifacts() :",
|
|
33
|
-
err?.stdout?.toString() || err
|
|
34
|
-
);
|
|
35
|
-
process.exit(1);
|
|
36
|
-
});
|
|
46
|
+
if (doRestore) {
|
|
47
|
+
startLifeCycle(`Restore ${domain}`);
|
|
37
48
|
|
|
38
|
-
|
|
49
|
+
exeTime = await measureExecutionTime(
|
|
50
|
+
runner.init,
|
|
51
|
+
() => pause("init done!"),
|
|
52
|
+
runner.restoreArtifacts,
|
|
53
|
+
() => pause("Restore `dist` and `assets` folders done!"),
|
|
54
|
+
runner.restoreCacheArtifacts,
|
|
55
|
+
() => pause("Restore `apiCache`, `store` and `.cache` restored!")
|
|
56
|
+
// runner.cleanUpSites,
|
|
57
|
+
// () => pause("cleanUpSites done!")
|
|
58
|
+
).catch((err) => {
|
|
59
|
+
console.error(
|
|
60
|
+
"Error in init() || restoreArtifacts() || restoreCacheArtifacts() :",
|
|
61
|
+
err?.stdout?.toString() || err
|
|
62
|
+
);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
});
|
|
39
65
|
|
|
40
|
-
|
|
66
|
+
successLifeCyle(`Restore ${domain} - ${exeTime}s`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Phases:
|
|
71
|
+
* - Data.
|
|
72
|
+
*
|
|
41
73
|
* Download domain build data (sites, pages, etc) and generator a folder
|
|
42
74
|
* called `store` where all the domain render data is saved.
|
|
43
75
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
).catch((err) => {
|
|
47
|
-
console.error(
|
|
48
|
-
"Error in downloadBuildData() :",
|
|
49
|
-
err?.stdout?.toString() || err
|
|
50
|
-
);
|
|
51
|
-
process.exit(1);
|
|
52
|
-
});
|
|
53
|
-
console.info(`success download ${domain} - ${exeTime}s`);
|
|
76
|
+
if (doData) {
|
|
77
|
+
startLifeCycle(`Data ${domain}`);
|
|
54
78
|
|
|
55
|
-
|
|
79
|
+
exeTime = await measureExecutionTime(
|
|
80
|
+
async () => await createBuildData(domain),
|
|
81
|
+
() => pause("Download data from API to store folder done!")
|
|
82
|
+
).catch((err) => {
|
|
83
|
+
console.error(
|
|
84
|
+
"Error in createBuildData() :",
|
|
85
|
+
err?.stdout?.toString() || err
|
|
86
|
+
);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
successLifeCyle(`Data ${domain} - ${exeTime}s`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Phases:
|
|
95
|
+
* - SSG.
|
|
96
|
+
*
|
|
56
97
|
* Call the `gatsby build` command.
|
|
57
98
|
* Gatsby will use the downloaded data and create the static build.
|
|
58
99
|
* `gatsby-node.ts` is the main file where the stati generation happens.
|
|
59
100
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"Error in runGatsbyBuild() :",
|
|
63
|
-
err?.stdout?.toString() || err
|
|
64
|
-
);
|
|
65
|
-
process.exit(1);
|
|
66
|
-
});
|
|
101
|
+
if (doSSG) {
|
|
102
|
+
startLifeCycle(`SSG ${domain}`);
|
|
67
103
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* Gatsby build is done, if the .env GRIDDO_SEARCH_FEATURE is set to true
|
|
72
|
-
* we save the search data in the API.
|
|
73
|
-
*/
|
|
74
|
-
const shouldUploadSearchData = JSON.parse(process.env.GRIDDO_SEARCH_FEATURE || "false");
|
|
75
|
-
if (shouldUploadSearchData) {
|
|
76
|
-
exeTime = await measureExecutionTime(uploadSearchContentToAPI).catch((err) => {
|
|
104
|
+
exeTime = await measureExecutionTime(runner.runGatsbyBuild, () =>
|
|
105
|
+
pause("Gatsby build done!")
|
|
106
|
+
).catch((err) => {
|
|
77
107
|
console.error(
|
|
78
|
-
"Error
|
|
108
|
+
"Error in runGatsbyBuild() :",
|
|
79
109
|
err?.stdout?.toString() || err
|
|
80
110
|
);
|
|
81
111
|
process.exit(1);
|
|
82
112
|
});
|
|
83
|
-
|
|
84
|
-
|
|
113
|
+
|
|
114
|
+
successLifeCyle(`SSG ${domain} - ${exeTime}s`);
|
|
85
115
|
}
|
|
116
|
+
|
|
86
117
|
/*
|
|
118
|
+
* Gatsby build is done, if the .env GRIDDO_SEARCH_FEATURE is set to true
|
|
119
|
+
* we save the search data in the API.
|
|
120
|
+
*/
|
|
121
|
+
if (doMeta) {
|
|
122
|
+
startLifeCycle(`Meta ${domain}`);
|
|
123
|
+
|
|
124
|
+
const shouldUploadSearchData = JSON.parse(
|
|
125
|
+
process.env.GRIDDO_SEARCH_FEATURE || "false"
|
|
126
|
+
);
|
|
127
|
+
if (shouldUploadSearchData) {
|
|
128
|
+
exeTime = await measureExecutionTime(uploadSearchContentToAPI).catch(
|
|
129
|
+
(err) => {
|
|
130
|
+
console.error(
|
|
131
|
+
"Error while uploads search content in DDBB :",
|
|
132
|
+
err?.stdout?.toString() || err
|
|
133
|
+
);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
successLifeCyle(`Meta ${domain} - ${exeTime}s`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Phases:
|
|
144
|
+
* - Clean.
|
|
145
|
+
* - Archive.
|
|
146
|
+
*
|
|
87
147
|
* When Gatsby ends, remove disposable artifacts and save .cache and
|
|
88
148
|
* public foler to use in the next render.
|
|
89
149
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
150
|
+
if (doArchive) {
|
|
151
|
+
startLifeCycle(`Archive ${domain}`);
|
|
152
|
+
|
|
153
|
+
exeTime = await measureExecutionTime(
|
|
154
|
+
() => clearEmptyDirs(),
|
|
155
|
+
() => pause("Clean empty dirs!"),
|
|
156
|
+
runner.removeDisposableArtifacts,
|
|
157
|
+
() => pause("Clean `public` done!"),
|
|
158
|
+
runner.archiveArtifacts,
|
|
159
|
+
() => pause("Archive dist and assets done!"),
|
|
160
|
+
runner.archiveCacheArtifacts,
|
|
161
|
+
() => pause("Archive apiCache, .cache and store done!")
|
|
162
|
+
).catch((err) => {
|
|
163
|
+
console.error(
|
|
164
|
+
"Error in removeDisposableArtifacts() || archiveArtifacts()|| archiveCacheArtifacts() :",
|
|
165
|
+
err?.stdout?.toString() || err
|
|
166
|
+
);
|
|
167
|
+
process.exit(1);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
successLifeCyle(`Archive ${domain} - ${exeTime}s`);
|
|
171
|
+
}
|
|
102
172
|
}
|
|
103
173
|
}
|
|
104
174
|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
-
import { getEnvRunner } from "@exporter/utils/runners";
|
|
5
|
-
import { CXRootFolder, instanceRootFolder } from "@exporter/utils/shared";
|
|
6
4
|
import chalk from "chalk";
|
|
7
5
|
import dotenv from "dotenv";
|
|
8
6
|
|
|
7
|
+
import { deleteSites } from "../../utils/folders";
|
|
8
|
+
import { getEnvRunner } from "../../utils/runners";
|
|
9
|
+
import { CXRootFolder, instanceRootFolder } from "../../utils/shared";
|
|
10
|
+
import { checkSites } from "../../utils/sites";
|
|
11
|
+
|
|
9
12
|
dotenv.config();
|
|
10
13
|
|
|
11
14
|
/**
|
|
@@ -17,11 +20,11 @@ function getGatsbyDomainRunner(domain: string) {
|
|
|
17
20
|
|
|
18
21
|
// Artifacts to remove after export
|
|
19
22
|
// if STRIP_DOMAIN_FROM_PATH is false `.cache` will be added.
|
|
20
|
-
const artifactsDisposable = ["public"
|
|
23
|
+
const artifactsDisposable = ["public"];
|
|
21
24
|
|
|
22
25
|
// Artifacts to make exports faster
|
|
23
26
|
// if STRIP_DOMAIN_FROM_PATH is true `.cache` will be added.
|
|
24
|
-
const artifactsCache = ["apiCache" /* , ".cache" */];
|
|
27
|
+
const artifactsCache = ["apiCache", "store" /* , ".cache" */];
|
|
25
28
|
|
|
26
29
|
// TODO: Remove STRIP_DOMAIN_FROM_PATH behaviour when all instances are over 1.75.219
|
|
27
30
|
const STRIP_DOMAIN_FROM_PATH = JSON.parse(
|
|
@@ -268,6 +271,16 @@ function getGatsbyDomainRunner(domain: string) {
|
|
|
268
271
|
}
|
|
269
272
|
};
|
|
270
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Remove sites folder from restoring phase.
|
|
276
|
+
*/
|
|
277
|
+
const cleanUpSites = async () => {
|
|
278
|
+
const { sitesToPublish, sitesToUnpublish } = await checkSites(domain);
|
|
279
|
+
|
|
280
|
+
await deleteSites(sitesToUnpublish, domain);
|
|
281
|
+
await deleteSites(sitesToPublish, domain);
|
|
282
|
+
};
|
|
283
|
+
|
|
271
284
|
/**
|
|
272
285
|
* Restore Gatsby cache artifacts from a previous render to improve
|
|
273
286
|
* performance.
|
|
@@ -350,6 +363,7 @@ function getGatsbyDomainRunner(domain: string) {
|
|
|
350
363
|
deleteArtifactBackup,
|
|
351
364
|
archiveCacheArtifacts,
|
|
352
365
|
restoreCacheArtifacts,
|
|
366
|
+
cleanUpSites,
|
|
353
367
|
runGatsbyBuild,
|
|
354
368
|
removeDisposableArtifacts,
|
|
355
369
|
};
|
|
@@ -28,6 +28,9 @@ type Report = {
|
|
|
28
28
|
}>;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Informa a la API del estado de publicación de los sites: published y unpublished.
|
|
33
|
+
*/
|
|
31
34
|
export async function buildComplete(report: Report) {
|
|
32
35
|
await AuthService.login();
|
|
33
36
|
|
|
@@ -45,13 +48,16 @@ export async function buildComplete(report: Report) {
|
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
function getExportedDomains() {
|
|
48
|
-
const domains = fs
|
|
51
|
+
const domains = fs
|
|
52
|
+
.readdirSync(exportArchiveBasePath)
|
|
53
|
+
// Avoid empty files, usually .DS_Store from local renders.
|
|
54
|
+
.filter((file) => !file.startsWith("."));
|
|
49
55
|
|
|
50
56
|
return domains;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
function getBuildReports(domains: Array<string>) {
|
|
54
|
-
const reports = [];
|
|
60
|
+
const reports: Array<Report> = [];
|
|
55
61
|
|
|
56
62
|
for (const domain of domains) {
|
|
57
63
|
const buildReportFile = path.resolve(
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getInstanceDomains } from "./utils/domains";
|
|
2
|
+
import { createBuildData } from "./utils/download-build-data";
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const domains = await getInstanceDomains();
|
|
6
|
+
|
|
7
|
+
for (const domain of domains) {
|
|
8
|
+
createBuildData(domain).catch((err) => {
|
|
9
|
+
console.error("Error", err?.stdout?.toString() || err);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
});
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
main().catch((err) => {
|
|
17
|
+
console.error(
|
|
18
|
+
"Error in create-build-data.ts:",
|
|
19
|
+
err?.stdout?.toString() || err
|
|
20
|
+
);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
});
|
package/exporter/index.ts
CHANGED
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
/* eslint-disable node/shebang */
|
|
3
3
|
|
|
4
4
|
import { runGatsbyAdapter } from "./adapters";
|
|
5
|
+
import { logBox, measureExecutionTime } from "./utils/shared";
|
|
5
6
|
|
|
6
7
|
async function main() {
|
|
7
|
-
await
|
|
8
|
+
const exeTime = await measureExecutionTime(() =>
|
|
9
|
+
runGatsbyAdapter({
|
|
10
|
+
doRestore: true,
|
|
11
|
+
doData: true,
|
|
12
|
+
doSSG: true,
|
|
13
|
+
doRelocation: true,
|
|
14
|
+
doMeta: true,
|
|
15
|
+
doArchive: true,
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
logBox(`All domains rendered in ${exeTime}s.`, "", 1, 0);
|
|
19
|
+
process.exit(0);
|
|
8
20
|
}
|
|
9
21
|
|
|
10
22
|
// Go render, go!
|
|
@@ -89,7 +89,8 @@ class DistributorService {
|
|
|
89
89
|
// Distrubutor with `hasDistributorDat: true` but without `data` prop
|
|
90
90
|
if (!data) {
|
|
91
91
|
logBox(
|
|
92
|
-
`Error: Page ${page.id} has \`hasDistributorData: true\` but it doesn't have a \`data\` prop
|
|
92
|
+
`Error: Page ${page.id} has \`hasDistributorData: true\` but it doesn't have a \`data\` prop`,
|
|
93
|
+
"No data in ReferenceField"
|
|
93
94
|
);
|
|
94
95
|
|
|
95
96
|
return [];
|
|
@@ -98,7 +99,8 @@ class DistributorService {
|
|
|
98
99
|
// Avoid fetch distributors with empty `data.sources`
|
|
99
100
|
if (Array.isArray(data.sources) && data.sources.length < 1) {
|
|
100
101
|
logBox(
|
|
101
|
-
`Warning: Page with id: ${page.id} has a ReferenceField with empty \`data.sources
|
|
102
|
+
`Warning: Page with id: ${page.id} has a ReferenceField with empty \`data.sources\``,
|
|
103
|
+
"Empty data.sources in ReferenceField"
|
|
102
104
|
);
|
|
103
105
|
|
|
104
106
|
return [];
|