@griddo/cx 11.7.6-rc.0 → 11.7.6-rc.2
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 +13 -9
- package/build/adapters/gatsby/actions/clean.js.map +1 -1
- package/build/adapters/gatsby/actions/close.js.map +1 -1
- package/build/adapters/gatsby/actions/data.js +3 -3
- package/build/adapters/gatsby/actions/data.js.map +1 -1
- package/build/adapters/gatsby/actions/healthCheck.js.map +1 -1
- package/build/adapters/gatsby/actions/init.js +2 -2
- package/build/adapters/gatsby/actions/init.js.map +1 -1
- package/build/adapters/gatsby/actions/meta.js +2 -2
- package/build/adapters/gatsby/actions/meta.js.map +1 -1
- package/build/adapters/gatsby/actions/prepare.js.map +1 -1
- package/build/adapters/gatsby/actions/relocation.js +2 -2
- package/build/adapters/gatsby/actions/relocation.js.map +1 -1
- package/build/adapters/gatsby/actions/restore.js +4 -4
- package/build/adapters/gatsby/actions/restore.js.map +1 -1
- package/build/adapters/gatsby/actions/ssg.js.map +1 -1
- package/build/adapters/gatsby/actions/sync.js +10 -9
- package/build/adapters/gatsby/actions/sync.js.map +1 -1
- package/build/adapters/gatsby/index.js +10 -6
- package/build/adapters/gatsby/index.js.map +1 -1
- package/build/adapters/gatsby/shared/context.js +8 -2
- package/build/adapters/gatsby/shared/context.js.map +1 -1
- package/build/adapters/gatsby/shared/diff-assets.js +101 -0
- package/build/adapters/gatsby/shared/diff-assets.js.map +1 -0
- package/build/adapters/gatsby/shared/extract-assets.js +11 -11
- package/build/adapters/gatsby/shared/extract-assets.js.map +1 -1
- package/build/adapters/gatsby/shared/gatsby-build.js.map +1 -1
- package/build/adapters/gatsby/shared/sync-render.js +162 -158
- package/build/adapters/gatsby/shared/sync-render.js.map +1 -1
- package/build/commands/end-render.js +44 -19
- package/build/commands/end-render.js.map +1 -1
- package/build/commands/prepare-assets-directory.js +4 -4
- package/build/commands/prepare-assets-directory.js.map +1 -1
- package/build/commands/prepare-domains-render.js +14 -19
- package/build/commands/prepare-domains-render.js.map +1 -1
- package/build/commands/reset-render.js +4 -4
- package/build/commands/reset-render.js.map +1 -1
- package/build/commands/start-render.js +20 -10
- package/build/commands/start-render.js.map +1 -1
- package/build/commands/upload-search-content.js +8 -17
- package/build/commands/upload-search-content.js.map +1 -1
- package/build/constants/endpoints.js.map +1 -1
- package/build/constants/envs.js +2 -7
- package/build/constants/envs.js.map +1 -1
- package/build/constants/errors.js +7 -9
- package/build/constants/errors.js.map +1 -1
- package/build/services/auth.js +1 -0
- package/build/services/auth.js.map +1 -1
- package/build/services/db-class.js +49 -0
- package/build/services/db-class.js.map +1 -0
- package/build/services/db.js.map +1 -1
- package/build/services/navigation.js +3 -0
- package/build/services/navigation.js.map +1 -1
- package/build/services/reference-fields.js.map +1 -1
- package/build/services/robots.js +4 -2
- package/build/services/robots.js.map +1 -1
- package/build/services/sites.js.map +1 -1
- package/build/services/store.js +2 -2
- package/build/services/store.js.map +1 -1
- package/build/types/render.js.map +1 -1
- package/build/utils/api.js.map +1 -1
- package/build/utils/artifacts.js +11 -11
- package/build/utils/artifacts.js.map +1 -1
- package/build/utils/brush.js +2 -2
- package/build/utils/brush.js.map +1 -1
- package/build/utils/cache.js +6 -6
- package/build/utils/cache.js.map +1 -1
- package/build/utils/check-health.js.map +1 -1
- package/build/utils/core-utils.js +35 -3
- package/build/utils/core-utils.js.map +1 -1
- package/build/utils/domains.js.map +1 -1
- package/build/utils/errors.js.map +1 -1
- package/build/utils/folders.js +30 -7
- package/build/utils/folders.js.map +1 -1
- package/build/utils/images.js.map +1 -1
- package/build/utils/instance.js.map +1 -1
- package/build/utils/loggin.js +9 -3
- package/build/utils/loggin.js.map +1 -1
- package/build/utils/pages.js.map +1 -1
- package/build/utils/render.js +1 -1
- package/build/utils/render.js.map +1 -1
- package/build/utils/sites.js +20 -19
- package/build/utils/sites.js.map +1 -1
- package/build/utils/store.js +8 -8
- package/build/utils/store.js.map +1 -1
- package/exporter/adapters/gatsby/actions/data.ts +3 -3
- package/exporter/adapters/gatsby/actions/init.ts +2 -2
- package/exporter/adapters/gatsby/actions/meta.ts +2 -2
- package/exporter/adapters/gatsby/actions/relocation.ts +2 -2
- package/exporter/adapters/gatsby/actions/restore.ts +4 -4
- package/exporter/adapters/gatsby/actions/sync.ts +10 -9
- package/exporter/adapters/gatsby/index.ts +13 -8
- package/exporter/adapters/gatsby/shared/diff-assets.ts +113 -0
- package/exporter/adapters/gatsby/shared/extract-assets.ts +11 -11
- package/exporter/adapters/gatsby/shared/sync-render.ts +195 -212
- package/exporter/build.sh +2 -3
- package/exporter/commands/end-render.ts +54 -25
- package/exporter/commands/prepare-assets-directory.ts +4 -4
- package/exporter/commands/prepare-domains-render.ts +15 -20
- package/exporter/commands/reset-render.ts +4 -4
- package/exporter/commands/start-render.ts +19 -11
- package/exporter/commands/upload-search-content.ts +9 -20
- package/exporter/constants/envs.ts +0 -6
- package/exporter/constants/errors.ts +12 -4
- package/exporter/services/db-class.ts +54 -0
- package/exporter/services/robots.ts +2 -2
- package/exporter/services/store.ts +2 -2
- package/exporter/types/global.ts +0 -1
- package/exporter/utils/artifacts.ts +11 -11
- package/exporter/utils/cache.ts +6 -6
- package/exporter/utils/core-utils.ts +46 -4
- package/exporter/utils/folders.ts +30 -7
- package/exporter/utils/loggin.ts +9 -3
- package/exporter/utils/render.ts +3 -1
- package/exporter/utils/sites.ts +18 -17
- package/exporter/utils/store.ts +8 -8
- package/gatsby-node.ts +22 -25
- package/package.json +10 -11
- package/src/gatsby-node-utils.ts +2 -2
- package/tsconfig.json +3 -2
- package/build/exporter/adapters/gatsby/actions/clean.d.ts +0 -3
- package/build/exporter/adapters/gatsby/actions/close.d.ts +0 -3
- package/build/exporter/adapters/gatsby/actions/data.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/healthCheck.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/init.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/meta.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/prepare.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/relocation.d.ts +0 -2
- package/build/exporter/adapters/gatsby/actions/restore.d.ts +0 -3
- package/build/exporter/adapters/gatsby/actions/ssg.d.ts +0 -3
- package/build/exporter/adapters/gatsby/actions/sync.d.ts +0 -3
- package/build/exporter/adapters/gatsby/index.d.ts +0 -9
- package/build/exporter/adapters/gatsby/shared/context.d.ts +0 -38
- package/build/exporter/adapters/gatsby/shared/extract-assets.d.ts +0 -7
- package/build/exporter/adapters/gatsby/shared/gatsby-build.d.ts +0 -7
- package/build/exporter/adapters/gatsby/shared/sync-render.d.ts +0 -36
- package/build/exporter/adapters/gatsby/shared/types.d.ts +0 -34
- package/build/exporter/commands/end-render.d.ts +0 -2
- package/build/exporter/commands/prepare-assets-directory.d.ts +0 -2
- package/build/exporter/commands/prepare-domains-render.d.ts +0 -2
- package/build/exporter/commands/reset-render.d.ts +0 -2
- package/build/exporter/commands/start-render.d.ts +0 -2
- package/build/exporter/commands/upload-search-content.d.ts +0 -2
- package/build/exporter/constants/endpoints.d.ts +0 -19
- package/build/exporter/constants/envs.d.ts +0 -31
- package/build/exporter/constants/errors.d.ts +0 -24
- package/build/exporter/services/auth.d.ts +0 -10
- package/build/exporter/services/db.d.ts +0 -4
- package/build/exporter/services/navigation.d.ts +0 -50
- package/build/exporter/services/reference-fields.d.ts +0 -20
- package/build/exporter/services/robots.d.ts +0 -13
- package/build/exporter/services/sites.d.ts +0 -32
- package/build/exporter/services/store.d.ts +0 -15
- package/build/exporter/types/api.d.ts +0 -141
- package/build/exporter/types/global.d.ts +0 -84
- package/build/exporter/types/navigation.d.ts +0 -28
- package/build/exporter/types/pages.d.ts +0 -144
- package/build/exporter/types/render.d.ts +0 -50
- package/build/exporter/types/sites.d.ts +0 -56
- package/build/exporter/types/templates.d.ts +0 -8
- package/build/exporter/utils/api.d.ts +0 -23
- package/build/exporter/utils/artifacts.d.ts +0 -6
- package/build/exporter/utils/brush.d.ts +0 -18
- package/build/exporter/utils/cache.d.ts +0 -30
- package/build/exporter/utils/check-health.d.ts +0 -7
- package/build/exporter/utils/core-utils.d.ts +0 -77
- package/build/exporter/utils/domains.d.ts +0 -13
- package/build/exporter/utils/errors.d.ts +0 -15
- package/build/exporter/utils/folders.d.ts +0 -66
- package/build/exporter/utils/images.d.ts +0 -16
- package/build/exporter/utils/instance.d.ts +0 -21
- package/build/exporter/utils/loggin.d.ts +0 -37
- package/build/exporter/utils/pages.d.ts +0 -34
- package/build/exporter/utils/render.d.ts +0 -49
- package/build/exporter/utils/sites.d.ts +0 -31
- package/build/exporter/utils/store.d.ts +0 -53
- package/start-render.js +0 -5
|
@@ -1,27 +1,50 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fsp from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
+
import { BundlesInconsistencyError } from "../../../constants/errors";
|
|
5
|
+
import { throwError } from "../../../utils/errors";
|
|
6
|
+
import { findFilesBySuffix } from "../../../utils/folders";
|
|
4
7
|
import { verboseLog } from "../../../utils/loggin";
|
|
8
|
+
import { getAssetsDiffBetweenRenders, patchHtmlFile } from "./diff-assets";
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
interface SyncRenderConfig {
|
|
7
11
|
src: string;
|
|
8
12
|
dst: string;
|
|
9
13
|
pagesToCreate: Array<number>;
|
|
10
14
|
pagesToDelete: Array<number>;
|
|
11
15
|
artifactsToCopyToExports: Array<string>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type CopyFilePath = {
|
|
16
|
+
}
|
|
17
|
+
interface CopyFilePath {
|
|
15
18
|
from: string;
|
|
16
19
|
to: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type SyncState = {
|
|
20
|
+
}
|
|
21
|
+
interface SyncState {
|
|
20
22
|
htmlToAdd: Array<CopyFilePath>;
|
|
21
23
|
jsonToAdd: Array<CopyFilePath>;
|
|
22
24
|
htmlToDelete: Array<string>;
|
|
23
25
|
jsonToDelete: Array<string>;
|
|
24
|
-
}
|
|
26
|
+
}
|
|
27
|
+
interface PageInfo {
|
|
28
|
+
id: number;
|
|
29
|
+
composePath: string; // p.ej. '/about-us' o '/'
|
|
30
|
+
htmlPath: string; // p.ej. '/path/to/public/about-us/index.html'
|
|
31
|
+
jsonPath: string; // p.ej. '/path/to/public/page-data/about-us/page-data.json'
|
|
32
|
+
}
|
|
33
|
+
interface GatsbyPageData {
|
|
34
|
+
result: {
|
|
35
|
+
pageContext: {
|
|
36
|
+
id: number;
|
|
37
|
+
fullPath: {
|
|
38
|
+
site: string;
|
|
39
|
+
domain: string;
|
|
40
|
+
domainUrl: string;
|
|
41
|
+
language: string;
|
|
42
|
+
page: string;
|
|
43
|
+
compose: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
25
48
|
|
|
26
49
|
class SyncRender {
|
|
27
50
|
private bundleDir: string;
|
|
@@ -45,43 +68,42 @@ class SyncRender {
|
|
|
45
68
|
this.assetArtifacts = config.artifactsToCopyToExports;
|
|
46
69
|
}
|
|
47
70
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
71
|
+
public async execute() {
|
|
72
|
+
await this.setPagesToDelete();
|
|
73
|
+
await this.setPagesToAdd();
|
|
74
|
+
await this.sync();
|
|
75
|
+
await this.assertAssetsAreValid();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private async assertAssetsAreValid() {
|
|
79
|
+
const isDifferent = await getAssetsDiffBetweenRenders(this.currentRenderDir, this.bundleDir);
|
|
80
|
+
console.log("Comparando assets...");
|
|
81
|
+
console.log("-", this.currentRenderDir);
|
|
82
|
+
console.log("-", this.bundleDir);
|
|
83
|
+
if (isDifferent) {
|
|
84
|
+
throwError(BundlesInconsistencyError);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private async setPagesToDelete() {
|
|
89
|
+
// ¿Por qué se incluyen this.pagesToCreate en las candidatas para borrarse?
|
|
90
|
+
// El set de ids incluye tanto las páginas a borrar como las que se van
|
|
91
|
+
// a crear para manejar correctamente por ejemplo los cambios de slug.
|
|
92
|
+
// Si la página `id=3` tiene slug `slug=about` y despues viene con
|
|
93
|
+
// `slug=about-us` borramos la página `id=3` en el render previo y la
|
|
94
|
+
// volvemos a crear.
|
|
95
|
+
// Resumido lo que pasará es que las páginas que se van a crear se
|
|
96
|
+
// borran previamente por si ha cambiado el slug. Porque el slug hace
|
|
97
|
+
// que se guarden en otro directorio.
|
|
98
|
+
// ¿Qué pasaría si no la borrásemos? que tendríamos las dos páginas
|
|
99
|
+
// `/about/index.html` y `/about-us/index.html`
|
|
100
|
+
const candidateIdsToDelete = new Set<number>([...this.pagesToDelete, ...this.pagesToCreate]);
|
|
101
|
+
const existingPreviousPages = await this.scanPages(this.bundleDir);
|
|
102
|
+
|
|
103
|
+
for (const page of existingPreviousPages) {
|
|
104
|
+
if (candidateIdsToDelete.has(page.id)) {
|
|
105
|
+
this.state.htmlToDelete.push(page.htmlPath);
|
|
106
|
+
this.state.jsonToDelete.push(page.jsonPath);
|
|
85
107
|
}
|
|
86
108
|
}
|
|
87
109
|
|
|
@@ -89,205 +111,166 @@ class SyncRender {
|
|
|
89
111
|
verboseLog(`${this.state.jsonToDelete.length} pages JSON to delete`);
|
|
90
112
|
}
|
|
91
113
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
for (const compose of composePaths) {
|
|
102
|
-
// 1 - leemos el page-data.json de la página para añadir
|
|
103
|
-
// Gatsby crea un directorio `index` para la página raíz `/`
|
|
104
|
-
const normalizedCompose = compose === "/" ? "index" : compose;
|
|
105
|
-
const json = JSON.parse(
|
|
106
|
-
fs.readFileSync(
|
|
107
|
-
path.join(this.currentRenderDir, "page-data", normalizedCompose, "page-data.json"),
|
|
108
|
-
"utf8",
|
|
109
|
-
),
|
|
110
|
-
);
|
|
111
|
-
// 2 - sacamos el id
|
|
112
|
-
const id = json.result.pageContext.id;
|
|
113
|
-
|
|
114
|
-
// 3 - obtenemos el src y dst del HTML
|
|
115
|
-
const htmlFrom = path.join(this.currentRenderDir, compose, "index.html");
|
|
116
|
-
const htmlTo = path.join(this.bundleDir, compose, "index.html");
|
|
117
|
-
// 4 - obtenemos el src/dst del JSON
|
|
118
|
-
const jsonFrom = path.join(
|
|
119
|
-
this.currentRenderDir,
|
|
120
|
-
"page-data",
|
|
121
|
-
normalizedCompose,
|
|
122
|
-
"page-data.json",
|
|
123
|
-
);
|
|
124
|
-
const jsonTo = path.join(this.bundleDir, "page-data", normalizedCompose, "page-data.json");
|
|
125
|
-
|
|
126
|
-
// Solo actuamos en la página si su id está en pagesToCreate
|
|
127
|
-
if (idSet.has(id)) {
|
|
128
|
-
try {
|
|
129
|
-
this.state.htmlToAdd.push({ from: htmlFrom, to: htmlTo });
|
|
130
|
-
this.state.jsonToAdd.push({ from: jsonFrom, to: jsonTo });
|
|
131
|
-
} catch (e) {
|
|
132
|
-
console.log(e);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
114
|
+
private async setPagesToAdd() {
|
|
115
|
+
const candidateIdsToCreate = new Set<number>(this.pagesToCreate);
|
|
116
|
+
const newPages = await this.scanPages(this.currentRenderDir);
|
|
117
|
+
|
|
118
|
+
for (const page of newPages) {
|
|
119
|
+
if (candidateIdsToCreate.has(page.id)) {
|
|
120
|
+
const htmlTo = path.join(this.bundleDir, page.composePath, "index.html");
|
|
121
|
+
const normalizedCompose = page.composePath === "/" ? "index" : page.composePath;
|
|
122
|
+
const jsonTo = path.join(this.bundleDir, "page-data", normalizedCompose, "page-data.json");
|
|
135
123
|
|
|
136
|
-
|
|
137
|
-
|
|
124
|
+
this.state.htmlToAdd.push({ from: page.htmlPath, to: htmlTo });
|
|
125
|
+
this.state.jsonToAdd.push({ from: page.jsonPath, to: jsonTo });
|
|
126
|
+
}
|
|
138
127
|
}
|
|
128
|
+
|
|
129
|
+
verboseLog(`${this.state.htmlToAdd.length} pages HTML to create`);
|
|
130
|
+
verboseLog(`${this.state.jsonToAdd.length} pages JSON to create`);
|
|
139
131
|
}
|
|
140
132
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
sync() {
|
|
146
|
-
// remove html's
|
|
147
|
-
for (const html of this.state.htmlToDelete) {
|
|
133
|
+
private async sync() {
|
|
134
|
+
// Delete...
|
|
135
|
+
const allFilesToDelete = [...this.state.htmlToDelete, ...this.state.jsonToDelete];
|
|
136
|
+
for (const file of allFilesToDelete) {
|
|
148
137
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
138
|
+
// Usar `force: true` para no fallar si el archivo ya no existe.
|
|
139
|
+
await fsp.rm(file, { force: true });
|
|
140
|
+
verboseLog(`Sync (remove) : ${file}`);
|
|
151
141
|
} catch (e) {
|
|
152
|
-
|
|
142
|
+
// El error solo se registraría si es un problema de permisos, etc.
|
|
143
|
+
console.error(`Failed to remove ${file}:`, e);
|
|
153
144
|
}
|
|
154
145
|
}
|
|
155
146
|
|
|
156
|
-
|
|
157
|
-
|
|
147
|
+
await this.restoreWebpackCompilationHash();
|
|
148
|
+
|
|
149
|
+
// Copy...
|
|
150
|
+
const allFilesToAdd = [...this.state.htmlToAdd, ...this.state.jsonToAdd];
|
|
151
|
+
for (const file of allFilesToAdd) {
|
|
158
152
|
try {
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
await fsp.mkdir(path.dirname(file.to), { recursive: true });
|
|
154
|
+
await fsp.copyFile(file.from, file.to);
|
|
155
|
+
verboseLog(`Sync (copy) : ${file.from} -> ${file.to}`);
|
|
161
156
|
} catch (e) {
|
|
162
|
-
console.
|
|
157
|
+
console.error(`Failed to copy ${file.from} to ${file.to}:`, e);
|
|
163
158
|
}
|
|
164
159
|
}
|
|
165
160
|
|
|
166
|
-
//
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
verboseLog(`Sync (copy) : ${html.from} -> ${html.to}`);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// copy json's
|
|
174
|
-
for (const json of this.state.jsonToAdd) {
|
|
175
|
-
fs.mkdirSync(path.dirname(json.to), { recursive: true });
|
|
176
|
-
fs.copyFileSync(json.from, json.to);
|
|
177
|
-
verboseLog(`Sync (copy) : ${json.from} -> ${json.to}`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// update app-data.json (update the webpackCompilationHash)
|
|
181
|
-
this.copyAppDataJsonFile();
|
|
182
|
-
|
|
183
|
-
// copy artifacts
|
|
184
|
-
this.copyDirs();
|
|
185
|
-
|
|
186
|
-
// copy sitemaps
|
|
187
|
-
this.copySitemaps();
|
|
161
|
+
// AVOID TO RESTORE webpackCompilationHash
|
|
162
|
+
// await this.copyAppDataJsonFile();
|
|
163
|
+
await this.copyAssetArtifacts();
|
|
164
|
+
await this.copySitemaps();
|
|
188
165
|
}
|
|
189
166
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const list = fs.readdirSync(dir, { withFileTypes: true });
|
|
167
|
+
private async restoreWebpackCompilationHash() {
|
|
168
|
+
const appDataJson = path.join(this.bundleDir, "page-data", "app-data.json");
|
|
169
|
+
const webpackCompilationHash = JSON.parse(
|
|
170
|
+
await fsp.readFile(appDataJson, "utf8"),
|
|
171
|
+
).webpackCompilationHash;
|
|
172
|
+
console.log(
|
|
173
|
+
"Leyendo el webpackCompilationHash desde",
|
|
174
|
+
appDataJson,
|
|
175
|
+
"=",
|
|
176
|
+
webpackCompilationHash,
|
|
177
|
+
);
|
|
204
178
|
|
|
205
|
-
|
|
206
|
-
const fullPath = path.join(dir, item.name);
|
|
179
|
+
const changedHtmlFilePaths = this.state.htmlToAdd.map(({ from }) => from);
|
|
207
180
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
} else if (item.isFile() && fullPath.endsWith(extension)) {
|
|
211
|
-
results.push(fullPath);
|
|
212
|
-
}
|
|
181
|
+
for (const htmlFilePath of changedHtmlFilePaths) {
|
|
182
|
+
await patchHtmlFile(htmlFilePath, webpackCompilationHash);
|
|
213
183
|
}
|
|
214
|
-
|
|
215
|
-
return results;
|
|
216
184
|
}
|
|
217
185
|
|
|
218
|
-
private
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
// fullPath: "/foo/bar" => "foo/bar"
|
|
231
|
-
// fullPath: "/" => "index"
|
|
232
|
-
return allPageDataJson.map(
|
|
233
|
-
(p) => JSON.parse(fs.readFileSync(p, "utf-8")).result.pageContext.fullPath.compose,
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
private copyAppDataJsonFile() {
|
|
238
|
-
fs.copyFileSync(
|
|
239
|
-
path.join(this.currentRenderDir, "page-data", "app-data.json"),
|
|
240
|
-
path.join(this.bundleDir, "page-data", "app-data.json"),
|
|
241
|
-
);
|
|
242
|
-
verboseLog("Copied app-data.json");
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
private copyDirs() {
|
|
186
|
+
// private async copyAppDataJsonFile() {
|
|
187
|
+
// try {
|
|
188
|
+
// const src = path.join(this.currentRenderDir, "page-data", "app-data.json");
|
|
189
|
+
// const dst = path.join(this.bundleDir, "page-data", "app-data.json");
|
|
190
|
+
// await fsp.copyFile(src, dst);
|
|
191
|
+
// verboseLog("Copied app-data.json");
|
|
192
|
+
// } catch (e) {
|
|
193
|
+
// console.error("Failed to copy app-data.json:", e);
|
|
194
|
+
// }
|
|
195
|
+
// }
|
|
196
|
+
|
|
197
|
+
private async copyAssetArtifacts() {
|
|
246
198
|
for (const assetArtifact of this.assetArtifacts) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
`Copied ${
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
);
|
|
199
|
+
const src = path.join(this.currentRenderDir, assetArtifact);
|
|
200
|
+
const dst = path.join(this.bundleDir, assetArtifact);
|
|
201
|
+
try {
|
|
202
|
+
await fsp.mkdir(path.dirname(dst), { recursive: true });
|
|
203
|
+
await fsp.copyFile(src, dst);
|
|
204
|
+
verboseLog(`Copied artifact: ${assetArtifact}`);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
console.error(`Failed to copy artifact ${src} to ${dst}:`, e);
|
|
207
|
+
}
|
|
257
208
|
}
|
|
258
209
|
}
|
|
259
210
|
|
|
260
|
-
private copySitemaps() {
|
|
261
|
-
/*
|
|
262
|
-
1. buscar directorios que tengan como hijo un `sitemap.xml`
|
|
263
|
-
2. copiar todos los sitemap.xml y sitemap-* a /exports/sites/<domain>/<site>/ borrando previamente los .xmls que existan
|
|
264
|
-
*/
|
|
211
|
+
private async copySitemaps() {
|
|
265
212
|
const renderSrc = path.resolve(this.currentRenderDir);
|
|
266
213
|
const renderDst = path.resolve(this.bundleDir);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
path.basename(xmlFile).startsWith("sitemap-") ||
|
|
275
|
-
path.basename(xmlFile) === "sitemap.xml"
|
|
276
|
-
) {
|
|
277
|
-
fs.rmSync(xmlFile, { force: true });
|
|
214
|
+
|
|
215
|
+
// Primero, elimina los sitemaps existentes en el destino
|
|
216
|
+
const xmlFilesInDst = findFilesBySuffix(renderDst, ".xml");
|
|
217
|
+
for await (const xmlFile of xmlFilesInDst) {
|
|
218
|
+
const basename = path.basename(xmlFile);
|
|
219
|
+
if (basename.startsWith("sitemap-") || basename === "sitemap.xml") {
|
|
220
|
+
await fsp.rm(xmlFile, { force: true });
|
|
278
221
|
}
|
|
279
222
|
}
|
|
280
223
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
224
|
+
// Segundo, copia los nuevos sitemaps desde el origen
|
|
225
|
+
const xmlFilesInSrc = findFilesBySuffix(renderSrc, ".xml");
|
|
226
|
+
for await (const src of xmlFilesInSrc) {
|
|
227
|
+
// Reconstruye la ruta de destino de forma más robusta
|
|
228
|
+
const relativePath = path.relative(renderSrc, src);
|
|
229
|
+
const dst = path.join(renderDst, relativePath);
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
await fsp.mkdir(path.dirname(dst), { recursive: true });
|
|
233
|
+
await fsp.copyFile(src, dst);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
console.error(`Failed to copy sitemap ${src} to ${dst}:`, e);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
285
238
|
|
|
286
|
-
|
|
287
|
-
|
|
239
|
+
verboseLog(`Copied sitemap files.`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Escanea un directorio de build de Gatsby y extrae la información esencial de cada página.
|
|
244
|
+
* Lee cada page-data.json una sola vez para optimizar el rendimiento.
|
|
245
|
+
* @param dir Directorio a escanear (src o dst).
|
|
246
|
+
* @returns Un array con la información de cada página encontrada.
|
|
247
|
+
*/
|
|
248
|
+
private async scanPages(dir: string): Promise<Array<PageInfo>> {
|
|
249
|
+
// Array de paths de page-data.json
|
|
250
|
+
const gatsbyPageDataFiles = findFilesBySuffix(path.join(dir, "page-data"), "page-data.json");
|
|
251
|
+
const pagesFound: Array<PageInfo> = [];
|
|
252
|
+
|
|
253
|
+
for await (const jsonFile of gatsbyPageDataFiles) {
|
|
254
|
+
try {
|
|
255
|
+
const content = JSON.parse(await fsp.readFile(jsonFile, "utf-8")) as GatsbyPageData;
|
|
256
|
+
const id = content.result.pageContext.id;
|
|
257
|
+
const composePath = content.result.pageContext.fullPath.compose;
|
|
258
|
+
// Esto es necesario porque Gatsby convierte la ruta "/" en un
|
|
259
|
+
// directorio llamado "index" en lo que archivos page-data.json
|
|
260
|
+
// se refiere.
|
|
261
|
+
const normalizedCompose = composePath === "/" ? "index" : composePath;
|
|
262
|
+
|
|
263
|
+
pagesFound.push({
|
|
264
|
+
id,
|
|
265
|
+
composePath,
|
|
266
|
+
htmlPath: path.join(dir, composePath, "index.html"),
|
|
267
|
+
jsonPath: path.join(dir, "page-data", normalizedCompose, "page-data.json"),
|
|
268
|
+
});
|
|
269
|
+
} catch (e) {
|
|
270
|
+
console.error(`Error reading or parsing page data from ${jsonFile}:`, e);
|
|
288
271
|
}
|
|
289
|
-
fs.copyFileSync(src, dst);
|
|
290
272
|
}
|
|
273
|
+
return pagesFound;
|
|
291
274
|
}
|
|
292
275
|
}
|
|
293
276
|
|
package/exporter/build.sh
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
|
|
3
3
|
echo "📦 Compiling CX..."
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
tsc --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
|
|
4
|
+
tsgo --project tsconfig.commands.json
|
|
5
|
+
# tsgo --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
|
|
@@ -8,12 +8,14 @@ import path from "node:path";
|
|
|
8
8
|
import { ArtifactError } from "../constants/errors";
|
|
9
9
|
import { AuthService } from "../services/auth";
|
|
10
10
|
import { endSiteRender } from "../services/sites";
|
|
11
|
-
import {
|
|
11
|
+
import { getInstanceDomains } from "../utils/domains";
|
|
12
12
|
import { throwError } from "../utils/errors";
|
|
13
13
|
import { pathExists } from "../utils/folders";
|
|
14
14
|
import { infoLog } from "../utils/loggin";
|
|
15
15
|
import { getRenderMetadataFromDB, getRenderMode, getRenderPathsFromDB } from "../utils/render";
|
|
16
16
|
|
|
17
|
+
const renderByDomains = !!process.env.GRIDDO_RENDER_BY_DOMAINS;
|
|
18
|
+
|
|
17
19
|
async function getRenderReport(options: {
|
|
18
20
|
domain: string;
|
|
19
21
|
exportsSiteDir: string;
|
|
@@ -40,38 +42,65 @@ const sendEndSiteRender = async (report: Report) => {
|
|
|
40
42
|
}
|
|
41
43
|
};
|
|
42
44
|
|
|
43
|
-
async function
|
|
45
|
+
async function endRender() {
|
|
44
46
|
const { buildReportFileName } = await getRenderMetadataFromDB();
|
|
45
47
|
const { __sites } = await getRenderPathsFromDB();
|
|
46
48
|
|
|
47
|
-
const [domain] = process.argv.slice(2);
|
|
48
|
-
const { renderMode } = await getRenderMode(domain);
|
|
49
|
-
|
|
50
|
-
if (renderMode === "IDLE") {
|
|
51
|
-
infoLog(`Skipping build-end for domain ${domain} as it is marked as IDLE.`);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
49
|
await AuthService.login();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
domain
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
if (renderByDomains) {
|
|
51
|
+
const [domain] = process.argv.slice(2);
|
|
52
|
+
const { renderMode } = await getRenderMode(domain);
|
|
53
|
+
|
|
54
|
+
if (renderMode === "IDLE") {
|
|
55
|
+
infoLog(`Skipping build-end for domain ${domain} as it is marked as IDLE.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const report = await getRenderReport({
|
|
60
|
+
domain,
|
|
61
|
+
exportsSiteDir: __sites,
|
|
62
|
+
buildReportFileName,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
infoLog(`Sending ending call to ${domain} sites`);
|
|
66
|
+
|
|
67
|
+
for (const site of report.sites) {
|
|
68
|
+
site.publishHashes = [...new Set(site.publishHashes)];
|
|
69
|
+
site.unpublishHashes = [...new Set(site.unpublishHashes)];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await sendEndSiteRender(report);
|
|
73
|
+
} else {
|
|
74
|
+
console.log("- LEGACY RENDER MODE -");
|
|
75
|
+
const domains = await getInstanceDomains();
|
|
76
|
+
for (const domain of domains) {
|
|
77
|
+
const { renderMode } = await getRenderMode(domain);
|
|
78
|
+
|
|
79
|
+
if (renderMode === "IDLE") {
|
|
80
|
+
infoLog(`Skipping build-end for domain ${domain} as it is marked as IDLE.`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const report = await getRenderReport({
|
|
85
|
+
domain,
|
|
86
|
+
exportsSiteDir: __sites,
|
|
87
|
+
buildReportFileName,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
infoLog(`Sending ending call to ${domain} sites`);
|
|
91
|
+
|
|
92
|
+
for (const site of report.sites) {
|
|
93
|
+
site.publishHashes = [...new Set(site.publishHashes)];
|
|
94
|
+
site.unpublishHashes = [...new Set(site.unpublishHashes)];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
await sendEndSiteRender(report);
|
|
98
|
+
}
|
|
68
99
|
}
|
|
69
|
-
|
|
70
|
-
await sendEndSiteRender(report);
|
|
71
100
|
}
|
|
72
101
|
|
|
73
102
|
async function main() {
|
|
74
|
-
await
|
|
103
|
+
await endRender();
|
|
75
104
|
}
|
|
76
105
|
|
|
77
106
|
main().catch((err) => {
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
import childProcess from "node:child_process";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
6
|
-
import { doLifeCycle } from "../utils/core-utils";
|
|
7
6
|
import { pathExists } from "../utils/folders";
|
|
7
|
+
import { localLog } from "../utils/loggin";
|
|
8
8
|
import { getRenderPathsFromDB } from "../utils/render";
|
|
9
9
|
|
|
10
|
-
async function
|
|
10
|
+
async function prepareAssetsDir() {
|
|
11
11
|
const [domain] = process.argv.slice(2);
|
|
12
12
|
|
|
13
13
|
const { __exports } = await getRenderPathsFromDB({ domain });
|
|
@@ -19,12 +19,12 @@ async function prepareAssetsAction() {
|
|
|
19
19
|
childProcess.execSync(`rm -rf ${domainAssetsDir}`);
|
|
20
20
|
childProcess.execSync(`mv ${assetsDir} ${domainAssetsDir}`);
|
|
21
21
|
} else {
|
|
22
|
-
|
|
22
|
+
localLog("Assets directory not found");
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async function main() {
|
|
27
|
-
await
|
|
27
|
+
await prepareAssetsDir();
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
main().catch((err) => {
|