@griddo/cx 10.6.15 → 10.6.16
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/build/build-complete.js +24 -24
- package/build/constants/endpoints.d.ts +12 -11
- package/build/constants/envs.d.ts +4 -1
- package/build/constants/index.d.ts +4 -0
- package/build/index.d.ts +5 -2
- package/build/index.js +43 -41
- package/build/registers/api.d.ts +9 -0
- package/build/registers/gatsby.d.ts +9 -0
- package/build/registers/index.d.ts +3 -0
- package/build/reset-render.js +25 -25
- package/build/run-start-render.js +43 -41
- package/build/services/register.d.ts +38 -0
- package/build/start-render.js +43 -41
- package/build/upload-search-content.js +28 -28
- package/build/utils/alerts.d.ts +2 -0
- package/build/utils/core-utils.d.ts +10 -1
- package/build/utils/folders.d.ts +5 -0
- package/build/utils/store.d.ts +4 -4
- package/exporter/adapters/gatsby/index.ts +48 -7
- package/exporter/constants/endpoints.ts +13 -11
- package/exporter/constants/envs.ts +6 -0
- package/exporter/constants/index.ts +8 -0
- package/exporter/index.ts +40 -16
- package/exporter/registers/api.ts +14 -0
- package/exporter/registers/gatsby.ts +14 -0
- package/exporter/registers/index.ts +4 -0
- package/exporter/services/auth.ts +1 -0
- package/exporter/services/register.ts +119 -0
- package/exporter/services/store.ts +29 -19
- package/exporter/utils/alerts.ts +27 -0
- package/exporter/utils/api.ts +18 -1
- package/exporter/utils/core-utils.ts +35 -0
- package/exporter/utils/folders.ts +13 -8
- package/exporter/utils/loggin.ts +3 -3
- package/exporter/utils/sites.ts +19 -3
- package/exporter/utils/store.ts +47 -36
- package/gatsby-node.ts +42 -4
- package/package.json +3 -3
|
@@ -114,6 +114,40 @@ function walk(dir: string) {
|
|
|
114
114
|
return results;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Walk a directory and returns the JSON file absolute paths with one level of depth.
|
|
119
|
+
* Bypass the `metadata` folder.
|
|
120
|
+
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
121
|
+
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
122
|
+
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
123
|
+
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
124
|
+
*/
|
|
125
|
+
function walkStore(dir: string): Array<string> {
|
|
126
|
+
const results: Array<string> = [];
|
|
127
|
+
|
|
128
|
+
// Listamos todas las subcarpetas y evitamos entrar en 'metadata'
|
|
129
|
+
const subdirs = fs.readdirSync(dir).filter((file) => {
|
|
130
|
+
const fullPath = path.join(dir, file);
|
|
131
|
+
return fs.statSync(fullPath).isDirectory() && file !== "metadata";
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Iteramos sobre las subcarpetas
|
|
135
|
+
for (const subdir of subdirs) {
|
|
136
|
+
const subdirPath = path.join(dir, subdir);
|
|
137
|
+
|
|
138
|
+
// Listamos los archivos en cada subcarpeta y filtramos los .json
|
|
139
|
+
const files = fs
|
|
140
|
+
.readdirSync(subdirPath)
|
|
141
|
+
.filter((file) => file.endsWith(".json"));
|
|
142
|
+
|
|
143
|
+
for (const file of files) {
|
|
144
|
+
results.push(path.join(subdirPath, file));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return results;
|
|
149
|
+
}
|
|
150
|
+
|
|
117
151
|
/**
|
|
118
152
|
* Custom delay using the "promise hack",
|
|
119
153
|
*
|
|
@@ -393,4 +427,5 @@ export {
|
|
|
393
427
|
sanitizeAPICacheDir,
|
|
394
428
|
siteList,
|
|
395
429
|
walk,
|
|
430
|
+
walkStore,
|
|
396
431
|
};
|
|
@@ -3,9 +3,8 @@ import path from "node:path";
|
|
|
3
3
|
|
|
4
4
|
import fsx, { MakeDirectoryOptions } from "fs-extra";
|
|
5
5
|
|
|
6
|
-
import { getConfig } from "./core-utils";
|
|
6
|
+
import { getConfig, walkStore } from "./core-utils";
|
|
7
7
|
import { verboseLog } from "./loggin";
|
|
8
|
-
import { getPageInStoreDir, removePagesFromStore } from "./store";
|
|
9
8
|
|
|
10
9
|
const config = getConfig();
|
|
11
10
|
|
|
@@ -196,17 +195,23 @@ function createBackup(src: string, suffix = "-BACKUP") {
|
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
197
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Elimina todas las páginas del store (de todos los sites) cuyo nombre empiece con un guión "-".
|
|
200
|
+
* Estas páginas son "virtuales" y no tienen ids desde API por lo que mantenerlas en el store es un problema cuando se hacen modificaciones en la página "madre".
|
|
201
|
+
* La solución por ahora es borrarlas del store y rehacerlas en todos los renders.
|
|
202
|
+
*/
|
|
203
203
|
async function removeVirtualPagesFromStore() {
|
|
204
204
|
const { __cx } = config.paths();
|
|
205
205
|
const storePath = path.join(__cx, "store");
|
|
206
206
|
|
|
207
207
|
try {
|
|
208
|
-
const
|
|
209
|
-
|
|
208
|
+
const allJsonPageFilesPath = walkStore(storePath);
|
|
209
|
+
|
|
210
|
+
for (const filePath of allJsonPageFilesPath) {
|
|
211
|
+
if (path.basename(filePath).startsWith("-")) {
|
|
212
|
+
fs.unlinkSync(filePath);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
210
215
|
} catch (e) {
|
|
211
216
|
console.info(
|
|
212
217
|
"`store` folder does not exist. Skipping multipage or static list template cleaning.",
|
package/exporter/utils/loggin.ts
CHANGED
|
@@ -69,7 +69,7 @@ function boxLog(
|
|
|
69
69
|
*/
|
|
70
70
|
function buildLog(str: string) {
|
|
71
71
|
if (envs.GRIDDO_BUILD_LOGS) {
|
|
72
|
-
console.
|
|
72
|
+
console.log(str.replace(/(\s)\s+/g, "$1").trim());
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -78,7 +78,7 @@ function buildLog(str: string) {
|
|
|
78
78
|
* @param str The string to be logged.
|
|
79
79
|
*/
|
|
80
80
|
function infoLog(str: string) {
|
|
81
|
-
console.
|
|
81
|
+
console.log(`${kleur.blue("info")} ${str}`);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -86,7 +86,7 @@ function infoLog(str: string) {
|
|
|
86
86
|
* @param str The string to be logged.
|
|
87
87
|
*/
|
|
88
88
|
function successLog(str: string) {
|
|
89
|
-
console.
|
|
89
|
+
console.log(`${kleur.green("success")} ${str}`);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/**
|
package/exporter/utils/sites.ts
CHANGED
|
@@ -62,15 +62,21 @@ async function checkSites(domain: string) {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// Sites with domains as empty arrays are sites that are not from the
|
|
66
|
+
// current domain.
|
|
67
|
+
const validSitesFromCurrentDomain = validSites.filter(
|
|
68
|
+
(site) => site.domains.length > 0,
|
|
69
|
+
);
|
|
70
|
+
|
|
65
71
|
// Save sites object to publish
|
|
66
|
-
const sitesToPublish =
|
|
72
|
+
const sitesToPublish = validSitesFromCurrentDomain.filter((site) =>
|
|
67
73
|
envs.GRIDDO_RENDER_SITE
|
|
68
74
|
? site.id === envs.GRIDDO_RENDER_SITE
|
|
69
|
-
: !!site.isPublished
|
|
75
|
+
: !!site.isPublished,
|
|
70
76
|
);
|
|
71
77
|
|
|
72
78
|
// Save sites object to unpublish
|
|
73
|
-
const sitesToUnpublish =
|
|
79
|
+
const sitesToUnpublish = validSitesFromCurrentDomain.filter(
|
|
74
80
|
(site) => !site.isPublished && site.shouldBeUpdated,
|
|
75
81
|
);
|
|
76
82
|
|
|
@@ -88,7 +94,10 @@ async function checkSites(domain: string) {
|
|
|
88
94
|
* @see https://griddoio.notion.site/Sites-d7bb0b7cb8d24894a5337e1139fc3d09#2019d3255bda4d219c7e19cf28d0c4fe
|
|
89
95
|
*/
|
|
90
96
|
async function unpublishSites(sites: Array<Site>) {
|
|
97
|
+
const { __cx } = config.paths();
|
|
98
|
+
|
|
91
99
|
for (const site of sites) {
|
|
100
|
+
// API
|
|
92
101
|
const buildInfo = await startSiteRender(site.id);
|
|
93
102
|
const { siteHash } = buildInfo;
|
|
94
103
|
const body = {
|
|
@@ -98,6 +107,13 @@ async function unpublishSites(sites: Array<Site>) {
|
|
|
98
107
|
};
|
|
99
108
|
|
|
100
109
|
await endSiteRender(site.id, body);
|
|
110
|
+
|
|
111
|
+
// STORE
|
|
112
|
+
// Remove site directory from the Store
|
|
113
|
+
fs.rmSync(path.join(__cx, "store", site.id.toString()), {
|
|
114
|
+
force: true,
|
|
115
|
+
recursive: true,
|
|
116
|
+
});
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
|
package/exporter/utils/store.ts
CHANGED
|
@@ -8,7 +8,7 @@ import path from "node:path";
|
|
|
8
8
|
|
|
9
9
|
import fsx from "fs-extra";
|
|
10
10
|
|
|
11
|
-
import { getConfig, removeProperties, walk } from "./core-utils";
|
|
11
|
+
import { getConfig, removeProperties, walk, walkStore } from "./core-utils";
|
|
12
12
|
|
|
13
13
|
const config = getConfig();
|
|
14
14
|
|
|
@@ -43,7 +43,8 @@ function* getBuildPagesFromStore<PageType extends GriddoPageObject>(args?: {
|
|
|
43
43
|
const { basePath, withSizeProp } = args || {};
|
|
44
44
|
const { __cx } = config.paths();
|
|
45
45
|
const pagesDirPath = basePath || path.join(__cx, "store");
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
const jsonFilePaths = walkStore(pagesDirPath).filter(
|
|
47
48
|
(file) => path.extname(file) === ".json",
|
|
48
49
|
);
|
|
49
50
|
|
|
@@ -185,22 +186,29 @@ function getPageInStoreDir(basePath: string): Array<number> {
|
|
|
185
186
|
* Save the pages into the file system.
|
|
186
187
|
* @param pages - An array of Griddo page objects to be saved.
|
|
187
188
|
*/
|
|
188
|
-
function savePagesInStore(
|
|
189
|
+
function savePagesInStore(
|
|
190
|
+
siteFolderName: string,
|
|
191
|
+
pages: Array<GriddoPageObject>,
|
|
192
|
+
) {
|
|
189
193
|
const { __cx } = config.paths();
|
|
190
194
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
try {
|
|
196
|
+
pages.forEach((page) => {
|
|
197
|
+
removeProperties(page, ["editorID", "parentEditorID"]);
|
|
198
|
+
const filename = `${page.context.page.id}.json`;
|
|
199
|
+
const filePath = path.join(__cx, "store", siteFolderName, filename);
|
|
200
|
+
fsx.writeJSONSync(filePath, page);
|
|
201
|
+
});
|
|
202
|
+
} catch (e) {
|
|
203
|
+
console.log("ERROR", e);
|
|
204
|
+
}
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
/**
|
|
200
208
|
* Remove files from dir.
|
|
201
209
|
* @param filenames - An array of ids representing file page names.
|
|
202
210
|
*/
|
|
203
|
-
function removePagesFromStore(filenames: Array<number>) {
|
|
211
|
+
function removePagesFromStore(siteDirName: string, filenames: Array<number>) {
|
|
204
212
|
const { __cx } = config.paths();
|
|
205
213
|
|
|
206
214
|
if (filenames.length === 0) {
|
|
@@ -208,7 +216,7 @@ function removePagesFromStore(filenames: Array<number>) {
|
|
|
208
216
|
}
|
|
209
217
|
|
|
210
218
|
filenames.forEach((filename) => {
|
|
211
|
-
const filePath = path.join(__cx, "store", `${filename}.json`);
|
|
219
|
+
const filePath = path.join(__cx, "store", siteDirName, `${filename}.json`);
|
|
212
220
|
try {
|
|
213
221
|
fs.unlinkSync(filePath);
|
|
214
222
|
} catch (error) {
|
|
@@ -226,19 +234,22 @@ function removePagesFromStore(filenames: Array<number>) {
|
|
|
226
234
|
* @param props.changedPages - Array of pages that have been modified in the site.
|
|
227
235
|
* @returns - An object containing the pages to be created and deleted in the site.
|
|
228
236
|
*/
|
|
229
|
-
async function getPagesToCreateOrDelete(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const { changedPages,
|
|
237
|
+
async function getPagesToCreateOrDelete(sitePages: {
|
|
238
|
+
sitesToPublish: Array<Site>;
|
|
239
|
+
validPagesIds: Array<number>;
|
|
240
|
+
changedPages: Array<number>;
|
|
241
|
+
siteDirName: string;
|
|
242
|
+
}) {
|
|
243
|
+
const { __cx } = config.paths();
|
|
244
|
+
const storeDir = path.join(__cx, "store");
|
|
245
|
+
|
|
246
|
+
const { changedPages, validPagesIds, sitesToPublish, siteDirName } =
|
|
247
|
+
sitePages;
|
|
248
|
+
|
|
239
249
|
// Array<ids> de las páginas que están físicamente en el store en el
|
|
240
250
|
// site actual del bucle.
|
|
241
|
-
const
|
|
251
|
+
const siteDirStorePath = path.join(storeDir, siteDirName);
|
|
252
|
+
const pagesInStore = getPageInStoreDir(siteDirStorePath);
|
|
242
253
|
|
|
243
254
|
// Array<ids> que están el `validPagesIds` pero no están por algún
|
|
244
255
|
// motivo en el store. Se incluyen porque deben ser creadas.
|
|
@@ -265,26 +276,26 @@ async function getPagesToCreateOrDelete(
|
|
|
265
276
|
|
|
266
277
|
// 1 - Leer el store
|
|
267
278
|
// 2 - eliminar las páginas que tengan como site uno despublicado o borrado
|
|
268
|
-
const allPagesInStore = getBuildPagesFromStore();
|
|
269
|
-
|
|
270
|
-
const pagesFromInvalidSites: Array<number> = [];
|
|
271
|
-
for await (const page of allPagesInStore) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
279
|
+
// const allPagesInStore = getBuildPagesFromStore();
|
|
280
|
+
|
|
281
|
+
// const pagesFromInvalidSites: Array<number> = [];
|
|
282
|
+
// for await (const page of allPagesInStore) {
|
|
283
|
+
// const pageSite = page.context.page.site;
|
|
284
|
+
// const pageId = page.context.page.id!;
|
|
285
|
+
// // Si el `site.id` de la página no es ninguno de los `sitesToPublish`
|
|
286
|
+
// // añadimos la página a `pagesFromIvalidSites` para borrarla
|
|
287
|
+
// // posteriormente.
|
|
288
|
+
// if (!sitesToPublish.map((site) => site.id).includes(pageSite)) {
|
|
289
|
+
// pagesFromInvalidSites.push(pageId);
|
|
290
|
+
// }
|
|
291
|
+
// }
|
|
281
292
|
|
|
282
293
|
return {
|
|
283
294
|
pagesInStore,
|
|
284
295
|
pagesMissingInStore,
|
|
285
296
|
pagesToDeleteFromStore: [
|
|
286
297
|
...pagesToDeleteFromStore,
|
|
287
|
-
...pagesFromInvalidSites,
|
|
298
|
+
// ...pagesFromInvalidSites,
|
|
288
299
|
],
|
|
289
300
|
pagesToWriteToStore,
|
|
290
301
|
};
|
package/gatsby-node.ts
CHANGED
|
@@ -7,17 +7,22 @@ import {
|
|
|
7
7
|
getBuildPagesFromStore,
|
|
8
8
|
getConfig,
|
|
9
9
|
infoLog,
|
|
10
|
+
insertAlert,
|
|
10
11
|
pageSizeLog,
|
|
11
12
|
verboseLog,
|
|
13
|
+
debugLog,
|
|
12
14
|
} from "./build";
|
|
15
|
+
import { gatsbyRegister } from "./exporter/registers";
|
|
13
16
|
|
|
14
17
|
const griddoBuildLogs = JSON.parse(process.env.GRIDDO_BUILD_LOGS || "false");
|
|
15
18
|
const assetPrefixWithDomain = process.env.SPAWN_ASSET_PREFIX_WITH_DOMAIN;
|
|
19
|
+
const sendAlertActive = JSON.parse(process.env.GRIDDO_ALERT_FEATURE || "false");
|
|
16
20
|
const needsAssetDomainPrefix =
|
|
17
21
|
!!assetPrefixWithDomain && assetPrefixWithDomain !== "";
|
|
18
22
|
|
|
19
23
|
const { __ssg } = getConfig().paths();
|
|
20
24
|
const template = path.join(__ssg, "src/components/template.tsx");
|
|
25
|
+
|
|
21
26
|
const pages = getBuildPagesFromStore<GatsbyPageObject>({
|
|
22
27
|
withSizeProp: griddoBuildLogs,
|
|
23
28
|
});
|
|
@@ -38,14 +43,47 @@ const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
|
|
|
38
43
|
|
|
39
44
|
actions.createPage(page);
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
const path = page.path;
|
|
47
|
+
const id = page.context.id;
|
|
48
|
+
const size = pageSizeLog(Math.round(page.size || 0));
|
|
49
|
+
|
|
50
|
+
if (sendAlertActive && page.size) {
|
|
51
|
+
const pageMaxSizeReached =
|
|
52
|
+
page.size >
|
|
53
|
+
Number.parseInt(process.env.GRIDDO_SSG_MAX_PAGE_SIZE || "524288") /
|
|
54
|
+
1024;
|
|
55
|
+
|
|
56
|
+
if (pageMaxSizeReached) {
|
|
57
|
+
gatsbyRegister.insert("GATSBY_PAGE_SIZE_TOO_BIG", {
|
|
58
|
+
path: page.path,
|
|
59
|
+
size: `${Math.round(page.size)}KB`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
45
63
|
|
|
64
|
+
if (griddoBuildLogs) {
|
|
46
65
|
infoLog(`Creating page ${path} - ${id} - ${size}`);
|
|
47
66
|
}
|
|
48
67
|
}
|
|
68
|
+
|
|
69
|
+
if (sendAlertActive && gatsbyRegister.haveEntries()) {
|
|
70
|
+
const registerContent = gatsbyRegister.get("GATSBY_PAGE_SIZE_TOO_BIG");
|
|
71
|
+
|
|
72
|
+
debugLog("\nRender register report\n");
|
|
73
|
+
debugLog(registerContent);
|
|
74
|
+
debugLog();
|
|
75
|
+
|
|
76
|
+
insertAlert({
|
|
77
|
+
description: "Render register report",
|
|
78
|
+
area: "Griddo",
|
|
79
|
+
level: "W",
|
|
80
|
+
fullData: {
|
|
81
|
+
output: registerContent,
|
|
82
|
+
date: new Date().toISOString(),
|
|
83
|
+
},
|
|
84
|
+
instantNotification: false,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
49
87
|
};
|
|
50
88
|
|
|
51
89
|
export { onCreateWebpackConfig } from "./src/gatsby-node-utils";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/cx",
|
|
3
3
|
"description": "Griddo SSG based on Gatsby",
|
|
4
|
-
"version": "10.6.
|
|
4
|
+
"version": "10.6.16",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@babel/preset-env": "^7.14.5",
|
|
47
47
|
"@babel/preset-react": "^7.14.5",
|
|
48
48
|
"@babel/preset-typescript": "^7.16.5",
|
|
49
|
-
"@griddo/core": "10.6.
|
|
49
|
+
"@griddo/core": "10.6.16",
|
|
50
50
|
"@svgr/webpack": "^5.5.0",
|
|
51
51
|
"babel-loader": "^8.0.6",
|
|
52
52
|
"babel-plugin-transform-runtime": "^6.23.0",
|
|
@@ -114,5 +114,5 @@
|
|
|
114
114
|
"publishConfig": {
|
|
115
115
|
"access": "public"
|
|
116
116
|
},
|
|
117
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "70b2e0f5430ab937321332b83cd48b81303a138a"
|
|
118
118
|
}
|