@griddo/cx 10.4.4 → 10.4.6

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.
@@ -1,7 +1,7 @@
1
1
  import { getGatsbyDomainRunner } from "./utils";
2
2
  import { getInstanceDomains } from "../../utils/domains";
3
3
  import { createBuildData } from "../../utils/download-build-data";
4
- import { clearEmptyDirs } from "../../utils/folders";
4
+ import { clearEmptyDirs, removeMultiPagesFromStore } from "../../utils/folders";
5
5
  import { uploadSearchContentToAPI } from "../../utils/searches";
6
6
  import { doLifeCycle, pause, printExporterLogo } from "../../utils/shared";
7
7
 
@@ -81,6 +81,11 @@ async function runGatsbyAdapter() {
81
81
  await doLifeCycle({
82
82
  name: "Archive",
83
83
  steps: [
84
+ // Elimina las páginas MultiPage del `store`. De este modo nos
85
+ // aseguramos que se vuelven a crear por Gatsby siempre
86
+ // actualizadas.
87
+ removeMultiPagesFromStore, // penalizando optimización...
88
+ () => pause("MultiPages removed from `store`"),
84
89
  () => clearEmptyDirs(),
85
90
  () => pause("Clean empty dirs done!"),
86
91
  runner.removeDisposableArtifacts,
@@ -41,10 +41,6 @@ dotenv.config();
41
41
  /* prettier-ignore */ const PUBLIC_API_URL = process.env.PUBLIC_API_URL as string;
42
42
  /* prettier-ignore */ const RENDER_ID = process.env.GRIDDO_RENDERID || new Date().valueOf().toString();
43
43
 
44
- // Consts
45
- const createdPages: Array<number> = [];
46
- const buildProcessData: BuildProcessData = {};
47
-
48
44
  /**
49
45
  * Fetch, process and save object pages and sites data into the file system to
50
46
  * be consumed by other services (Griddo itself, Adapters, etc.)
@@ -53,6 +49,10 @@ async function createStore(storeDir: string, domain: string) {
53
49
  console.info(`API calls with ${API_CONCURRENCY_COUNT} threads`);
54
50
 
55
51
  try {
52
+ // Vars to save later in the report file
53
+ const createdPages: Array<number> = [];
54
+ const buildProcessData: BuildProcessData = {};
55
+
56
56
  // Get sites objects to publish and unpublish.
57
57
  const { sitesToPublish, sitesToUnpublish } = await checkSites(domain);
58
58
 
@@ -7,6 +7,7 @@ import path from "node:path";
7
7
  import fs from "fs-extra";
8
8
 
9
9
  import { CXRootDir, instanceRootDir, logInfo } from "./shared";
10
+ import { getPageInStoreDir, removePagesFromStore } from "./store";
10
11
  // eslint-disable-next-line node/no-unpublished-import
11
12
  import config from "../../cx.config";
12
13
 
@@ -318,10 +319,26 @@ function createBackup(src: string, suffix = "-BACKUP") {
318
319
  }
319
320
  }
320
321
 
322
+ function isMultiPageId(id: number) {
323
+ return Number.isInteger(id) && id < 0;
324
+ }
325
+
326
+ function removeMultiPagesFromStore() {
327
+ const dirs = config.dirs("");
328
+ const storePath = path.join(dirs.__cx, "store");
329
+ try {
330
+ const multiPageFiles = getPageInStoreDir(storePath).filter(isMultiPageId);
331
+ removePagesFromStore(storePath, multiPageFiles);
332
+ } catch (e) {
333
+ console.info("`store` folder does not exist. Skipping multipage clean up.");
334
+ }
335
+ }
336
+
321
337
  export {
322
338
  clearEmptyDirs,
323
339
  copyArtifacts,
324
340
  deleteSites,
325
341
  moveArtifacts,
326
342
  removeArtifacts,
343
+ removeMultiPagesFromStore,
327
344
  };
@@ -269,11 +269,7 @@ async function createGriddoListPages(
269
269
  defaultLang,
270
270
  };
271
271
 
272
- return await createGriddoPageObject(
273
- paginatedPage,
274
- additionalInfo,
275
- !isFirstPage
276
- );
272
+ return await createGriddoPageObject(paginatedPage, additionalInfo);
277
273
  });
278
274
 
279
275
  return Promise.all(allPages);
@@ -302,7 +298,7 @@ function createGriddoMultiPages(
302
298
  }
303
299
 
304
300
  // Creates each page based on `multiPageElements` from the schema.
305
- const allPages = multiPageElements.map(async (pageElement) => {
301
+ const allPages = multiPageElements.map(async (pageElement, idx) => {
306
302
  // TODO: Use structuredClone() when node 18 is available.
307
303
  const paginatedPage: APIPageObject = JSON.parse(JSON.stringify(cleanPage));
308
304
  const {
@@ -334,6 +330,17 @@ function createGriddoMultiPages(
334
330
  paginatedPage.metaDescription = metaDescription;
335
331
  }
336
332
 
333
+ // Crea un id como número negativo y añadiendo un sufijo para las multipages.
334
+ // Esto es así para marcarlas y posteriormente borrarlas siempre en cada
335
+ // nuevo render desde el Adapter.
336
+ //
337
+ // id de página con hasMultipageTrue: 1546
338
+ // ids de las "sub-páginas": -15460, -15461, -1546n, (-)id(idx)
339
+ //
340
+ // @todo eliminar el concepto multipage de CX, debería ser algo core de
341
+ // Griddo itself: API/AX, que fuesen páginas con sus ids, etc..
342
+ paginatedPage.id = parseInt("-" + paginatedPage.id + idx);
343
+
337
344
  paginatedPage.fullUrl = `${fullUrl}/${rightSectionSlug}`;
338
345
  paginatedPage.fullPath.compose = newCompose;
339
346
  paginatedPage.slug = newCompose;
@@ -243,6 +243,7 @@ export {
243
243
  createStoreDir,
244
244
  getBuildMetadata,
245
245
  getBuildPages,
246
+ getPageInStoreDir,
246
247
  getPagesToCreateOrDelete,
247
248
  removePagesFromStore,
248
249
  savePagesInStore,
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.4.4",
4
+ "version": "10.4.6",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -70,7 +70,7 @@
70
70
  "react-helmet": "^6.0.0"
71
71
  },
72
72
  "devDependencies": {
73
- "@griddo/eslint-config-back": "^10.4.4",
73
+ "@griddo/eslint-config-back": "^10.4.6",
74
74
  "@types/babel__core": "^7.20.0",
75
75
  "@types/babel__preset-env": "^7.9.2",
76
76
  "@types/csvtojson": "^2.0.0",
@@ -117,5 +117,5 @@
117
117
  "publishConfig": {
118
118
  "access": "public"
119
119
  },
120
- "gitHead": "1177d9b185f1b8768e69600651b07fb028d14b47"
120
+ "gitHead": "bf836216af29607748b79d098210379423c6914f"
121
121
  }