@griddo/cx 1.75.188 → 1.75.189
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/index.js +1 -1
- package/gatsby-node.ts +3 -4
- package/package.json +119 -119
- package/src/services/store.ts +3 -5
- package/src/types/api.ts +1 -0
- package/src/services/store-with-for-loop.ts +0 -513
- package/src/services/store-with-promise-all.ts +0 -515
package/build/index.js
CHANGED
|
@@ -26,7 +26,7 @@ GFS4: `),console.error(e)});G[K]||(Qo=global[K]||[],ea(G,Qo),G.close=function(e)
|
|
|
26
26
|
\u2502 Access credentials failure \u2502
|
|
27
27
|
\u2502 Check that the login details are correct in your .env file \u2502
|
|
28
28
|
\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F
|
|
29
|
-
`)),process.exit(1)}}},fr=new Rn;var Vu=Z(Cn()),Yu=Z(pt()),Xu=Z(hr());var up=Z(pt()),$u=Z(hr()),lp=Z(Qc()),Hu=Z(Lu());var Bu="1.75.
|
|
29
|
+
`)),process.exit(1)}}},fr=new Rn;var Vu=Z(Cn()),Yu=Z(pt()),Xu=Z(hr());var up=Z(pt()),$u=Z(hr()),lp=Z(Qc()),Hu=Z(Lu());var Bu="1.75.189";$u.default.config();var fp=!!process.env.GRIDDO_BUILD_LOGS&&!!JSON.parse(process.env.GRIDDO_BUILD_LOGS);function Uu(...e){fp&&console.info(...e)}function Gu(e){return new Promise(t=>setTimeout(t,e))}function zu(e,t=3){return(e/1e3).toFixed(t)}function Wu(e){return"site"in e&&e.site?e?.site:void 0}function Ju(){let e=`
|
|
30
30
|
\xB7\xB7
|
|
31
31
|
\xB7\xB7 /
|
|
32
32
|
\xB7\xB7 / //
|
package/gatsby-node.ts
CHANGED
|
@@ -36,9 +36,7 @@ const isMonorepo = !isComponentLibraryEnv;
|
|
|
36
36
|
// onPreInit
|
|
37
37
|
// -----------------------------------------------------------------------------
|
|
38
38
|
export const onPreInit = async () => {
|
|
39
|
-
if (isMonorepo)
|
|
40
|
-
splash();
|
|
41
|
-
}
|
|
39
|
+
if (isMonorepo) splash();
|
|
42
40
|
|
|
43
41
|
initCache();
|
|
44
42
|
prepareStaticFolder();
|
|
@@ -73,8 +71,9 @@ export const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
|
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
console.info(
|
|
76
|
-
`Total page-data.json
|
|
74
|
+
`Total page-data.json size: ${(totalPagesSize / 1024).toFixed(3)}MB`
|
|
77
75
|
);
|
|
76
|
+
|
|
78
77
|
console.log("\n✨ createPages\n");
|
|
79
78
|
};
|
|
80
79
|
|
package/package.json
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
2
|
+
"name": "@griddo/cx",
|
|
3
|
+
"description": "Griddo SSG based on Gatsby",
|
|
4
|
+
"version": "1.75.189",
|
|
5
|
+
"authors": [
|
|
6
|
+
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
|
+
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
8
|
+
"Francis Vega <francis.vega@secuoyas.com>",
|
|
9
|
+
"Gonzalo Hernández <gonzalo.hernandez@secuoyas.com>",
|
|
10
|
+
"Sergio Ródenas <sergio.rodenas@secuoyas.com>",
|
|
11
|
+
"Txema León <txema.leon@secuoyas.com>"
|
|
12
|
+
],
|
|
13
|
+
"license": "UNLICENSED",
|
|
14
|
+
"homepage": "https://griddo.io",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/griddo/griddo"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"griddo-cx": "./index.js"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"start": "gatsby develop -H 0.0.0.0",
|
|
24
|
+
"build": "yarn run build:exporter",
|
|
25
|
+
"build:exporter": "esbuild ./scripts/griddo-exporter.ts --bundle --platform=node --minify --outfile=./build/index.js",
|
|
26
|
+
"build:serve": "IS_SERVE=true gatsby build --prefix-paths && gatsby serve",
|
|
27
|
+
"export": "gatsby build --prefix-paths",
|
|
28
|
+
"clean": "gatsby clean; rm -rf .cache public assets dist build .store",
|
|
29
|
+
"serve": "gatsby serve",
|
|
30
|
+
"format": "prettier --write .",
|
|
31
|
+
"prepare": "yarn run build:exporter",
|
|
32
|
+
"watch:tscheck": "tsc --noEmit --watch"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@babel/core": "^7.21.0",
|
|
36
|
+
"@babel/plugin-proposal-class-properties": "^7.7.4",
|
|
37
|
+
"@babel/preset-env": "^7.14.5",
|
|
38
|
+
"@babel/preset-react": "^7.14.5",
|
|
39
|
+
"@babel/preset-typescript": "^7.16.5",
|
|
40
|
+
"@griddo/core": "^1.75.189",
|
|
41
|
+
"@svgr/webpack": "^5.5.0",
|
|
42
|
+
"babel-loader": "^8.0.6",
|
|
43
|
+
"babel-plugin-styled-components": "^1.10.7",
|
|
44
|
+
"babel-plugin-transform-runtime": "^6.23.0",
|
|
45
|
+
"babel-polyfill": "^6.26.0",
|
|
46
|
+
"branch-name": "^1.0.0",
|
|
47
|
+
"chalk": "^2.4.2",
|
|
48
|
+
"csvtojson": "^2.0.10",
|
|
49
|
+
"dotenv": "^8.1.0",
|
|
50
|
+
"find-up": "^5.0.0",
|
|
51
|
+
"fs-extra": "^9.0.1",
|
|
52
|
+
"gatsby": "^4.8.0",
|
|
53
|
+
"gatsby-plugin-no-sourcemaps": "^4.8.0",
|
|
54
|
+
"gatsby-plugin-polyfill-io": "^1.1.0",
|
|
55
|
+
"gatsby-plugin-provide-react": "^1.0.2",
|
|
56
|
+
"gatsby-plugin-react-helmet": "^5.8.0",
|
|
57
|
+
"gatsby-plugin-react-svg": "^3.1.0",
|
|
58
|
+
"gatsby-plugin-sass": "^5.21.0",
|
|
59
|
+
"gatsby-plugin-styled-components": "^5.8.0",
|
|
60
|
+
"gradient-string": "^2.0.2",
|
|
61
|
+
"html-react-parser": "^1.4.10",
|
|
62
|
+
"js2xmlparser": "^4.0.1",
|
|
63
|
+
"node-sass": "^6.0.0",
|
|
64
|
+
"opn": "^6.0.0",
|
|
65
|
+
"p-limit": "^3.0.0",
|
|
66
|
+
"path-browserify": "^1.0.1",
|
|
67
|
+
"pkg-dir": "^5.0.0",
|
|
68
|
+
"process": "^0.11.10",
|
|
69
|
+
"react-helmet": "^6.0.0"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@griddo/eslint-config-back": "^1.75.189",
|
|
73
|
+
"@types/babel__core": "^7.20.0",
|
|
74
|
+
"@types/babel__preset-env": "^7.9.2",
|
|
75
|
+
"@types/csvtojson": "^2.0.0",
|
|
76
|
+
"@types/eslint": "^7.29.0",
|
|
77
|
+
"@types/fs-extra": "^9.0.13",
|
|
78
|
+
"@types/gradient-string": "^1.1.2",
|
|
79
|
+
"@types/node-sass": "^4.11.3",
|
|
80
|
+
"@types/prettier": "2.7.2",
|
|
81
|
+
"@types/react": "18.0.28",
|
|
82
|
+
"@types/react-dom": "18.0.11",
|
|
83
|
+
"@types/react-helmet": "^6.1.6",
|
|
84
|
+
"@types/webpack": "^5.28.0",
|
|
85
|
+
"eslint": "^7.5.0",
|
|
86
|
+
"eslint-plugin-node": "^11.1.0",
|
|
87
|
+
"eslint-plugin-react": "7.14.3",
|
|
88
|
+
"prettier": "2.0.4"
|
|
89
|
+
},
|
|
90
|
+
"peerDependencies": {
|
|
91
|
+
"axios": "*",
|
|
92
|
+
"react": "*",
|
|
93
|
+
"react-dom": "*"
|
|
94
|
+
},
|
|
95
|
+
"engines": {
|
|
96
|
+
"node": ">=16.17.0"
|
|
97
|
+
},
|
|
98
|
+
"files": [
|
|
99
|
+
".babelrc",
|
|
100
|
+
"build",
|
|
101
|
+
"gatsby-browser.tsx",
|
|
102
|
+
"gatsby-config.ts",
|
|
103
|
+
"gatsby-node.ts",
|
|
104
|
+
"gatsby-ssr.tsx",
|
|
105
|
+
"index.js",
|
|
106
|
+
"scripts",
|
|
107
|
+
"src",
|
|
108
|
+
"static"
|
|
109
|
+
],
|
|
110
|
+
"keywords": [
|
|
111
|
+
"gatsby",
|
|
112
|
+
"griddo",
|
|
113
|
+
"secuoyas",
|
|
114
|
+
"typescript",
|
|
115
|
+
"SSG"
|
|
116
|
+
],
|
|
117
|
+
"publishConfig": {
|
|
118
|
+
"access": "public"
|
|
119
|
+
},
|
|
120
|
+
"gitHead": "d2d62d1804227b1f3a5cc40313454bc903333dcf"
|
|
121
121
|
}
|
package/src/services/store.ts
CHANGED
|
@@ -179,7 +179,7 @@ class StoreService {
|
|
|
179
179
|
await RobotsService.loadRobots();
|
|
180
180
|
|
|
181
181
|
// Array of sites (Promises)
|
|
182
|
-
const
|
|
182
|
+
for (const site of sitesToPublish) {
|
|
183
183
|
// Gets
|
|
184
184
|
const { id: siteId, slug: siteSlug, theme, favicon } = site;
|
|
185
185
|
|
|
@@ -269,6 +269,7 @@ class StoreService {
|
|
|
269
269
|
// Get page data
|
|
270
270
|
const page = await SitesService.getPage(pageId, shouldUpdateSite);
|
|
271
271
|
|
|
272
|
+
// Probably a 404
|
|
272
273
|
if (!page) return;
|
|
273
274
|
|
|
274
275
|
// Update Array of page ids
|
|
@@ -308,7 +309,6 @@ class StoreService {
|
|
|
308
309
|
|
|
309
310
|
// List
|
|
310
311
|
if (page?.mode === "list") {
|
|
311
|
-
// of data items and the `itemsPerPage` prop.
|
|
312
312
|
gatsbyPageObjects = await createGriddoListPages(
|
|
313
313
|
{
|
|
314
314
|
...page, // Revisar la inclusión de este ...page.
|
|
@@ -382,9 +382,7 @@ class StoreService {
|
|
|
382
382
|
);
|
|
383
383
|
|
|
384
384
|
await Promise.all(pagesToRender);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
await Promise.all(promisesOfSitesToPublish);
|
|
385
|
+
}
|
|
388
386
|
} catch (e) {
|
|
389
387
|
const error = e as { message: string };
|
|
390
388
|
|
package/src/types/api.ts
CHANGED
|
@@ -1,513 +0,0 @@
|
|
|
1
|
-
// //
|
|
2
|
-
// ┌───────────────────┐ //
|
|
3
|
-
// │ Page from API │ ∞ loop //
|
|
4
|
-
// └─────────┬─────────┘ //
|
|
5
|
-
// ┌─┼─┐ //
|
|
6
|
-
// navigations //
|
|
7
|
-
// distributors //
|
|
8
|
-
// etc.. //
|
|
9
|
-
// └─┼─┘ //
|
|
10
|
-
// ┌──────────────┼─────────────┐ //
|
|
11
|
-
// ▼ ▼ ▼ //
|
|
12
|
-
// ┌─────────────┐ ┌───────────┐ ┌───────────┐ //
|
|
13
|
-
// │ Single page │ │ Multipage │ │ Listpages │ //
|
|
14
|
-
// └─────────────┘ └───────────┘ └───────────┘ //
|
|
15
|
-
// ▼ ▼ ▼ //
|
|
16
|
-
// └──────┐ | ┌─────┘ //
|
|
17
|
-
// ▼ ▼ ▼ //
|
|
18
|
-
// ┌─────── S T O R E ─────┐ //
|
|
19
|
-
// │ Array of page objects │ //
|
|
20
|
-
// ├─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┤ //
|
|
21
|
-
// │ Build metadata │ //
|
|
22
|
-
// └─────────────────────────┘ //
|
|
23
|
-
|
|
24
|
-
// Types
|
|
25
|
-
import type { BuildProcessData, StoreMode } from "../types/global";
|
|
26
|
-
import type { GatsbyPageObject, PageAdditionalInfo } from "../types/pages";
|
|
27
|
-
import type { Site } from "../types/sites";
|
|
28
|
-
|
|
29
|
-
// External libraries
|
|
30
|
-
import chalk from "chalk";
|
|
31
|
-
import dotenv from "dotenv";
|
|
32
|
-
import fs from "fs";
|
|
33
|
-
import pLimit from "p-limit";
|
|
34
|
-
import path from "path";
|
|
35
|
-
import v8 from "v8";
|
|
36
|
-
|
|
37
|
-
// Services
|
|
38
|
-
import { DistributorService } from "./distributors";
|
|
39
|
-
import { NavigationService } from "./navigation";
|
|
40
|
-
import { RobotsService } from "./robots";
|
|
41
|
-
import { SettingsService } from "./settings";
|
|
42
|
-
import { SitesService } from "./sites";
|
|
43
|
-
|
|
44
|
-
// Utils
|
|
45
|
-
import { version as griddoVersion } from "../../package.json";
|
|
46
|
-
import { createSha256, updatedSiteHash } from "../utils/cache";
|
|
47
|
-
import { deleteSites } from "../utils/folders";
|
|
48
|
-
import {
|
|
49
|
-
createGriddoListPages,
|
|
50
|
-
createGriddoMultiPages,
|
|
51
|
-
createGriddoSinglePage,
|
|
52
|
-
getMultiPageElements,
|
|
53
|
-
getPaginatedPages,
|
|
54
|
-
} from "../utils/pages";
|
|
55
|
-
import { logInfo, walk } from "../utils/shared";
|
|
56
|
-
import { checkSites, getSiteData, unpublishSites } from "../utils/sites";
|
|
57
|
-
|
|
58
|
-
dotenv.config();
|
|
59
|
-
|
|
60
|
-
// Envs
|
|
61
|
-
const API_URL = process.env.API_URL as string;
|
|
62
|
-
const CXBRANCH = process.env.CXBRANCH;
|
|
63
|
-
const REACT_APP_INSTANCE = process.env.GRIDDO_REACT_APP_INSTANCE;
|
|
64
|
-
const GRIDDO_API_CONCURRENCY_COUNT = process.env.GRIDDO_API_CONCURRENCY_COUNT;
|
|
65
|
-
const PUBLIC_API_URL = process.env.PUBLIC_API_URL as string;
|
|
66
|
-
const RENDER_ID = process.env.RENDERID || new Date().valueOf().toString();
|
|
67
|
-
|
|
68
|
-
// Constants shared between Gatsby phases.
|
|
69
|
-
const CREATED_PAGES: Array<number> = [];
|
|
70
|
-
const BUILD_PROCESS_DATA: BuildProcessData = {};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Store service to fetch, process and save temporarily final pages and site
|
|
74
|
-
* data to be consumed by external services (Griddo itself, Gatsby, etc.)
|
|
75
|
-
*
|
|
76
|
-
* It needs to be initialized with a `basePath` to store the files for the
|
|
77
|
-
* `file` mode and the mode itself: `file` or `memory`.
|
|
78
|
-
*
|
|
79
|
-
* The two modes:
|
|
80
|
-
* - File mode will save the final page objects in individual files in the file system.
|
|
81
|
-
* - Memory mode will save the final page objects in an array of objects in memory.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* import { StoreService } from "./store"
|
|
85
|
-
*
|
|
86
|
-
* // Init the store service.
|
|
87
|
-
* StoreService.init("foo/pages", { mode: "file" })
|
|
88
|
-
* // Save the data into files.
|
|
89
|
-
* await StoreService.saveBuildData()
|
|
90
|
-
* // Consume the pages as an interator.
|
|
91
|
-
* const pages = StoreService.getPages()
|
|
92
|
-
*/
|
|
93
|
-
class StoreService {
|
|
94
|
-
static basePath: string;
|
|
95
|
-
static mode: "file" | "memory";
|
|
96
|
-
static pages: Array<GatsbyPageObject> = [];
|
|
97
|
-
static sitesToPublish: Array<Site>;
|
|
98
|
-
static buildProcessData: BuildProcessData;
|
|
99
|
-
static createdPages: Array<number>;
|
|
100
|
-
|
|
101
|
-
// Public methods
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Initialize the Store with a path to store the files in file mode and an option object to set the mode.
|
|
105
|
-
*
|
|
106
|
-
* @param basePath The path to store the page files.
|
|
107
|
-
* @param options An object configuration
|
|
108
|
-
* @param options.mode Store mode
|
|
109
|
-
* @todo Avoid initialize the Store with a `basePath` in memory mode.
|
|
110
|
-
*/
|
|
111
|
-
public static init(basePath: string, options: { mode: StoreMode }) {
|
|
112
|
-
const { mode } = options;
|
|
113
|
-
const griddoCxThreads = parseInt(GRIDDO_API_CONCURRENCY_COUNT || "10");
|
|
114
|
-
const modeString = mode === "file" ? "File mode" : "Memory mode";
|
|
115
|
-
|
|
116
|
-
console.log(`🧶 Processing API page calls with ${griddoCxThreads} threads`);
|
|
117
|
-
console.log(`📦 Griddo Store initialized - ${chalk.italic(modeString)}`);
|
|
118
|
-
|
|
119
|
-
if (mode === "file") {
|
|
120
|
-
this.basePath = basePath;
|
|
121
|
-
this.mode = mode;
|
|
122
|
-
|
|
123
|
-
if (fs.existsSync(basePath)) {
|
|
124
|
-
fs.rmSync(basePath, { recursive: true });
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!fs.existsSync(basePath)) {
|
|
128
|
-
fs.mkdirSync(basePath);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (!fs.existsSync(path.resolve(basePath, "pages"))) {
|
|
132
|
-
fs.mkdirSync(path.resolve(basePath, "pages"));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Save the build data to the Store.
|
|
139
|
-
*/
|
|
140
|
-
public static async saveBuildData() {
|
|
141
|
-
try {
|
|
142
|
-
// Get sites objects to publish and unpublish.
|
|
143
|
-
const { sitesToPublish, sitesToUnpublish } = await checkSites();
|
|
144
|
-
|
|
145
|
-
// The settings will be extracted below in this process.
|
|
146
|
-
await SettingsService.getAll();
|
|
147
|
-
|
|
148
|
-
// If no activity in sites, exit
|
|
149
|
-
if (!(sitesToPublish.length || sitesToUnpublish.length)) {
|
|
150
|
-
console.warn("There are no sites to update");
|
|
151
|
-
|
|
152
|
-
process.exit(0);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Publish and unpublis sites
|
|
156
|
-
console.log(
|
|
157
|
-
chalk.green(
|
|
158
|
-
"\n⬆️ ",
|
|
159
|
-
`(${sitesToPublish.length}) Sites to publish:`,
|
|
160
|
-
sitesToPublish.map(({ name }) => name).join(", "),
|
|
161
|
-
"\n"
|
|
162
|
-
)
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
console.log(
|
|
166
|
-
chalk.red(
|
|
167
|
-
"⬇️ ",
|
|
168
|
-
`(${sitesToUnpublish.length}) Sites to unpublish:`,
|
|
169
|
-
sitesToUnpublish.map(({ name }) => name).join(", "),
|
|
170
|
-
"\n"
|
|
171
|
-
)
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
// Unpublish (API) and delete sites
|
|
175
|
-
await unpublishSites(sitesToUnpublish);
|
|
176
|
-
|
|
177
|
-
// Delete (clean) sites to publish
|
|
178
|
-
await deleteSites([...sitesToPublish]);
|
|
179
|
-
|
|
180
|
-
// Set robots information to use later in the `onPostBuild` phase.
|
|
181
|
-
await RobotsService.loadRobots();
|
|
182
|
-
|
|
183
|
-
// Sites loop
|
|
184
|
-
for (const site of sitesToPublish) {
|
|
185
|
-
// Gets
|
|
186
|
-
|
|
187
|
-
const { id: siteId, slug: siteSlug, theme, favicon } = site;
|
|
188
|
-
|
|
189
|
-
const {
|
|
190
|
-
siteInfo,
|
|
191
|
-
validPagesIds,
|
|
192
|
-
siteHash,
|
|
193
|
-
unpublishHashes,
|
|
194
|
-
siteLangs,
|
|
195
|
-
defaultLang,
|
|
196
|
-
headers,
|
|
197
|
-
footers,
|
|
198
|
-
socials,
|
|
199
|
-
// TODO: Check the false here...
|
|
200
|
-
} = await getSiteData(siteId, false);
|
|
201
|
-
|
|
202
|
-
const {
|
|
203
|
-
cloudinaryName,
|
|
204
|
-
useMetaTitle,
|
|
205
|
-
showBasicMetaRobots,
|
|
206
|
-
avoidHrefLangsOnCanonicals,
|
|
207
|
-
avoidSelfReferenceCanonicals,
|
|
208
|
-
avoidHrefLangXDefault,
|
|
209
|
-
avoidDebugMetas,
|
|
210
|
-
} = SettingsService.settings;
|
|
211
|
-
|
|
212
|
-
// Sets
|
|
213
|
-
|
|
214
|
-
BUILD_PROCESS_DATA[siteId] = {
|
|
215
|
-
siteHash,
|
|
216
|
-
unpublishHashes,
|
|
217
|
-
publishHashes: [],
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const NavService = new NavigationService();
|
|
221
|
-
|
|
222
|
-
// Set `headers` and `footers` to the NavService to use later in this process.
|
|
223
|
-
NavService.navigations = { headers, footers };
|
|
224
|
-
|
|
225
|
-
site.languages = siteLangs;
|
|
226
|
-
|
|
227
|
-
const shouldUpdateSite = updatedSiteHash(siteId, siteHash);
|
|
228
|
-
|
|
229
|
-
const siteScript = siteInfo.siteScript;
|
|
230
|
-
|
|
231
|
-
const siteMetadata = {
|
|
232
|
-
siteUrl: siteInfo.slug,
|
|
233
|
-
title: siteInfo.name,
|
|
234
|
-
favicon,
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const additionalInfo = {
|
|
238
|
-
baseUrl: API_URL,
|
|
239
|
-
publicBaseUrl: PUBLIC_API_URL,
|
|
240
|
-
instance: REACT_APP_INSTANCE,
|
|
241
|
-
siteSlug,
|
|
242
|
-
theme,
|
|
243
|
-
siteMetadata,
|
|
244
|
-
socials,
|
|
245
|
-
siteLangs,
|
|
246
|
-
cloudinaryName,
|
|
247
|
-
griddoVersion,
|
|
248
|
-
siteOptions: {
|
|
249
|
-
useMetaTitle,
|
|
250
|
-
showBasicMetaRobots,
|
|
251
|
-
avoidHrefLangsOnCanonicals,
|
|
252
|
-
avoidSelfReferenceCanonicals,
|
|
253
|
-
avoidHrefLangXDefault,
|
|
254
|
-
avoidDebugMetas,
|
|
255
|
-
},
|
|
256
|
-
BUILD_MODE: CXBRANCH,
|
|
257
|
-
siteScript,
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
logInfo(`${validPagesIds.length} valid pages`);
|
|
261
|
-
|
|
262
|
-
// -------------------------------------------------------------------------
|
|
263
|
-
// Pages loop promise creation
|
|
264
|
-
// -------------------------------------------------------------------------
|
|
265
|
-
// Async function that process every page for one site to use later in the
|
|
266
|
-
// `Promise.all` with pLimit.
|
|
267
|
-
const fetchPageAndSaveToStore = async (pageId: number) => {
|
|
268
|
-
// Here will be store every page returned by the API and processed by
|
|
269
|
-
// Griddo CX.
|
|
270
|
-
let gatsbyPageObjects: Array<GatsbyPageObject> = [];
|
|
271
|
-
|
|
272
|
-
// Get page data
|
|
273
|
-
const page = await SitesService.getPage(pageId, shouldUpdateSite);
|
|
274
|
-
|
|
275
|
-
if (!page) return;
|
|
276
|
-
|
|
277
|
-
// Update Array of page ids
|
|
278
|
-
CREATED_PAGES.push(pageId);
|
|
279
|
-
|
|
280
|
-
// Clone `additionalinfo` to avoid mutation into `pageAdditionalInfo`
|
|
281
|
-
// TODO: Use structuredClone() when node 18 is available.
|
|
282
|
-
const pageAdditionalInfo = JSON.parse(
|
|
283
|
-
JSON.stringify(additionalInfo)
|
|
284
|
-
) as PageAdditionalInfo;
|
|
285
|
-
|
|
286
|
-
// Updated with navigations (header & footer)
|
|
287
|
-
// NavService.getPageNavigations returns { header, footer }
|
|
288
|
-
pageAdditionalInfo.navigations = NavService.getPageNavigations(page);
|
|
289
|
-
|
|
290
|
-
// Content Type Data Query
|
|
291
|
-
// Where the pair `hasDistributorData:true` and `data` prop exists, this
|
|
292
|
-
// function will attach a `queriedItems` prop with the result of the fetch
|
|
293
|
-
// for the data.
|
|
294
|
-
const template = await DistributorService.getDistributorData({
|
|
295
|
-
page,
|
|
296
|
-
cached: !!RENDER_ID,
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// MultiPage Query
|
|
300
|
-
// Where the pair `hasGriddoMultiPage:true` prop exists, this function
|
|
301
|
-
// will process the schema and return a multiPageElemtens array to use
|
|
302
|
-
// in `createGriddoMultipages()`
|
|
303
|
-
const multiPageElements = await getMultiPageElements(template);
|
|
304
|
-
|
|
305
|
-
// -----------------------------------------------------------------------
|
|
306
|
-
// Build page objects
|
|
307
|
-
// -----------------------------------------------------------------------
|
|
308
|
-
// Three types of pages
|
|
309
|
-
// - List with pagination (n pages)
|
|
310
|
-
// - Multi-page module (n pages)
|
|
311
|
-
// - Single (1 page)
|
|
312
|
-
|
|
313
|
-
// List
|
|
314
|
-
if (page?.mode === "list") {
|
|
315
|
-
// of data items and the `itemsPerPage` prop.
|
|
316
|
-
gatsbyPageObjects = await createGriddoListPages(
|
|
317
|
-
{
|
|
318
|
-
...page, // Revisar la inclusión de este ...page.
|
|
319
|
-
// The first page, the one without the `/2, /3, /4, etc..` slug
|
|
320
|
-
page,
|
|
321
|
-
// The other pages
|
|
322
|
-
// In this case `getPaginatedPages` doesn't require the whole page object, just the `template` part.
|
|
323
|
-
// This is because only the `template` prop will be different for each page.
|
|
324
|
-
pages: getPaginatedPages(template),
|
|
325
|
-
// The `template` key with the (maybe) distributor data items queried
|
|
326
|
-
template,
|
|
327
|
-
// Pass all data items
|
|
328
|
-
totalQueriedItems: template.queriedItems,
|
|
329
|
-
// Default site language
|
|
330
|
-
defaultLang,
|
|
331
|
-
},
|
|
332
|
-
pageAdditionalInfo
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// >> Multi-page
|
|
337
|
-
if (multiPageElements) {
|
|
338
|
-
gatsbyPageObjects = await createGriddoMultiPages(
|
|
339
|
-
{
|
|
340
|
-
// The whole page object
|
|
341
|
-
...page,
|
|
342
|
-
// The `template` key with the (maybe) distributor data items queried
|
|
343
|
-
template,
|
|
344
|
-
// Array of object of every element of the MultiPage
|
|
345
|
-
multiPageElements,
|
|
346
|
-
// Default site language
|
|
347
|
-
defaultLang,
|
|
348
|
-
},
|
|
349
|
-
pageAdditionalInfo
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// >> Single template
|
|
354
|
-
if (!multiPageElements && page.mode !== "list") {
|
|
355
|
-
gatsbyPageObjects = [
|
|
356
|
-
await createGriddoSinglePage(
|
|
357
|
-
{
|
|
358
|
-
// The whole page object
|
|
359
|
-
...page,
|
|
360
|
-
// The `template` key with the (maybe) distributor data items queried
|
|
361
|
-
template,
|
|
362
|
-
// Default site language
|
|
363
|
-
defaultLang,
|
|
364
|
-
},
|
|
365
|
-
pageAdditionalInfo
|
|
366
|
-
),
|
|
367
|
-
];
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Update hashes
|
|
371
|
-
BUILD_PROCESS_DATA[siteId].publishHashes.push(page.hash);
|
|
372
|
-
|
|
373
|
-
// Save build data to store
|
|
374
|
-
this.savePages(gatsbyPageObjects); // gatsbyPageObjects is always an array regardless of whether it's just one page
|
|
375
|
-
this.saveSitesToPublish(sitesToPublish);
|
|
376
|
-
this.saveBuildProcessData(BUILD_PROCESS_DATA);
|
|
377
|
-
this.saveCreatedPages(CREATED_PAGES);
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
const griddoCxThreads = parseInt(GRIDDO_API_CONCURRENCY_COUNT || "10");
|
|
381
|
-
|
|
382
|
-
// Create the pLimit array of promises
|
|
383
|
-
const limit = pLimit(griddoCxThreads);
|
|
384
|
-
const pagesToRender = validPagesIds.map((id: number) =>
|
|
385
|
-
limit(() => fetchPageAndSaveToStore(id))
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
await Promise.all(pagesToRender);
|
|
389
|
-
}
|
|
390
|
-
} catch (e) {
|
|
391
|
-
const error = e as { message: string };
|
|
392
|
-
|
|
393
|
-
console.error(error.message);
|
|
394
|
-
|
|
395
|
-
process.exit(1);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Get the pages saved previously from the Store.
|
|
401
|
-
*/
|
|
402
|
-
public static getPages() {
|
|
403
|
-
if (this.mode === "file") {
|
|
404
|
-
return this.getPagesFromFiles();
|
|
405
|
-
} else {
|
|
406
|
-
return this.getPagesFromMemory();
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Save the pages into the Store.
|
|
412
|
-
*
|
|
413
|
-
* @param pages An array of pages to save in the store.
|
|
414
|
-
*/
|
|
415
|
-
public static savePages(pages: Array<GatsbyPageObject>) {
|
|
416
|
-
if (this.mode === "file") {
|
|
417
|
-
this.savePagesToFiles(pages);
|
|
418
|
-
} else {
|
|
419
|
-
this.savePagesToMemory(pages);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Save site to publish data in the Store.
|
|
425
|
-
*
|
|
426
|
-
* @param sites An array of sites to be published.
|
|
427
|
-
*/
|
|
428
|
-
public static saveSitesToPublish(sites: Array<Site>) {
|
|
429
|
-
this.sitesToPublish = sites;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Save the build process data in the Store.
|
|
434
|
-
*
|
|
435
|
-
* @param buildProcessData An object that represents a build process data.
|
|
436
|
-
*/
|
|
437
|
-
public static saveBuildProcessData(buildProcessData: BuildProcessData) {
|
|
438
|
-
this.buildProcessData = buildProcessData;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Save the created pages in the Store.
|
|
443
|
-
*
|
|
444
|
-
* @param pages An array of pages ids.
|
|
445
|
-
*/
|
|
446
|
-
public static saveCreatedPages(pages: Array<number>) {
|
|
447
|
-
this.createdPages = pages;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Get the build metadata from the Store.
|
|
452
|
-
*/
|
|
453
|
-
public static getMetadata() {
|
|
454
|
-
return {
|
|
455
|
-
buildProcessData: this.buildProcessData,
|
|
456
|
-
createdPages: this.createdPages,
|
|
457
|
-
sitesToPublish: this.sitesToPublish,
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Return an iterator with pages read from the file system.
|
|
463
|
-
*/
|
|
464
|
-
private static *getPagesFromFiles() {
|
|
465
|
-
const pagesDirPath = path.resolve(this.basePath, "pages");
|
|
466
|
-
const jsonFilePaths = walk(pagesDirPath).filter(
|
|
467
|
-
(file) => path.extname(file) === ".json"
|
|
468
|
-
);
|
|
469
|
-
|
|
470
|
-
for (const filePath of jsonFilePaths) {
|
|
471
|
-
const page = require(filePath) as GatsbyPageObject;
|
|
472
|
-
page.size = fs.statSync(filePath).size / 1024;
|
|
473
|
-
yield { ...page };
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Get the pages from the Store from the memory.
|
|
479
|
-
*/
|
|
480
|
-
private static getPagesFromMemory() {
|
|
481
|
-
return this.pages;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Save pages to the file system.
|
|
486
|
-
*
|
|
487
|
-
* @param pages An array of final pages to save into the file system.
|
|
488
|
-
*/
|
|
489
|
-
private static savePagesToFiles(pages: Array<GatsbyPageObject>) {
|
|
490
|
-
pages.forEach((pageObject) => {
|
|
491
|
-
const filename = `${createSha256(pageObject.path)}.json`;
|
|
492
|
-
const fileContent = JSON.stringify(pageObject);
|
|
493
|
-
const filePath = path.resolve(this.basePath, "pages", filename);
|
|
494
|
-
fs.writeFileSync(filePath, fileContent);
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Save pages to the memory.
|
|
500
|
-
*
|
|
501
|
-
* @param pages An array of final pages to save into the memory
|
|
502
|
-
*/
|
|
503
|
-
private static savePagesToMemory(pages: Array<GatsbyPageObject>) {
|
|
504
|
-
const pagesWithSize = pages.map((page) => {
|
|
505
|
-
const size = v8.serialize(page).byteLength / 1024;
|
|
506
|
-
|
|
507
|
-
return { ...page, size };
|
|
508
|
-
});
|
|
509
|
-
this.pages.push(...pagesWithSize);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
export { StoreService };
|
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
// //
|
|
2
|
-
// ┌───────────────────┐ //
|
|
3
|
-
// │ Page from API │ ∞ loop //
|
|
4
|
-
// └─────────┬─────────┘ //
|
|
5
|
-
// ┌─┼─┐ //
|
|
6
|
-
// navigations //
|
|
7
|
-
// distributors //
|
|
8
|
-
// etc.. //
|
|
9
|
-
// └─┼─┘ //
|
|
10
|
-
// ┌──────────────┼─────────────┐ //
|
|
11
|
-
// ▼ ▼ ▼ //
|
|
12
|
-
// ┌─────────────┐ ┌───────────┐ ┌───────────┐ //
|
|
13
|
-
// │ Single page │ │ Multipage │ │ Listpages │ //
|
|
14
|
-
// └─────────────┘ └───────────┘ └───────────┘ //
|
|
15
|
-
// ▼ ▼ ▼ //
|
|
16
|
-
// └──────┐ | ┌─────┘ //
|
|
17
|
-
// ▼ ▼ ▼ //
|
|
18
|
-
// ┌─────── S T O R E ─────┐ //
|
|
19
|
-
// │ Array of page objects │ //
|
|
20
|
-
// ├─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┤ //
|
|
21
|
-
// │ Build metadata │ //
|
|
22
|
-
// └─────────────────────────┘ //
|
|
23
|
-
|
|
24
|
-
// Types
|
|
25
|
-
import type { BuildProcessData, StoreMode } from "../types/global";
|
|
26
|
-
import type { GatsbyPageObject, PageAdditionalInfo } from "../types/pages";
|
|
27
|
-
import type { Site } from "../types/sites";
|
|
28
|
-
|
|
29
|
-
// External libraries
|
|
30
|
-
import chalk from "chalk";
|
|
31
|
-
import dotenv from "dotenv";
|
|
32
|
-
import fs from "fs";
|
|
33
|
-
import pLimit from "p-limit";
|
|
34
|
-
import path from "path";
|
|
35
|
-
import v8 from "v8";
|
|
36
|
-
|
|
37
|
-
// Services
|
|
38
|
-
import { DistributorService } from "./distributors";
|
|
39
|
-
import { NavigationService } from "./navigation";
|
|
40
|
-
import { RobotsService } from "./robots";
|
|
41
|
-
import { SettingsService } from "./settings";
|
|
42
|
-
import { SitesService } from "./sites";
|
|
43
|
-
|
|
44
|
-
// Utils
|
|
45
|
-
import { version as griddoVersion } from "../../package.json";
|
|
46
|
-
import { createSha256, updatedSiteHash } from "../utils/cache";
|
|
47
|
-
import { deleteSites } from "../utils/folders";
|
|
48
|
-
import {
|
|
49
|
-
createGriddoListPages,
|
|
50
|
-
createGriddoMultiPages,
|
|
51
|
-
createGriddoSinglePage,
|
|
52
|
-
getMultiPageElements,
|
|
53
|
-
getPaginatedPages,
|
|
54
|
-
} from "../utils/pages";
|
|
55
|
-
import { logInfo, walk } from "../utils/shared";
|
|
56
|
-
import { checkSites, getSiteData, unpublishSites } from "../utils/sites";
|
|
57
|
-
|
|
58
|
-
dotenv.config();
|
|
59
|
-
|
|
60
|
-
// Envs
|
|
61
|
-
const API_URL = process.env.API_URL as string;
|
|
62
|
-
const CXBRANCH = process.env.CXBRANCH;
|
|
63
|
-
const REACT_APP_INSTANCE = process.env.GRIDDO_REACT_APP_INSTANCE;
|
|
64
|
-
const GRIDDO_API_CONCURRENCY_COUNT = process.env.GRIDDO_API_CONCURRENCY_COUNT;
|
|
65
|
-
const PUBLIC_API_URL = process.env.PUBLIC_API_URL as string;
|
|
66
|
-
const RENDER_ID = process.env.RENDERID || new Date().valueOf().toString();
|
|
67
|
-
|
|
68
|
-
// Constants shared between Gatsby phases.
|
|
69
|
-
const CREATED_PAGES: Array<number> = [];
|
|
70
|
-
const BUILD_PROCESS_DATA: BuildProcessData = {};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Store service to fetch, process and save temporarily final pages and site
|
|
74
|
-
* data to be consumed by external services (Griddo itself, Gatsby, etc.)
|
|
75
|
-
*
|
|
76
|
-
* It needs to be initialized with a `basePath` to store the files for the
|
|
77
|
-
* `file` mode and the mode itself: `file` or `memory`.
|
|
78
|
-
*
|
|
79
|
-
* The two modes:
|
|
80
|
-
* - File mode will save the final page objects in individual files in the file system.
|
|
81
|
-
* - Memory mode will save the final page objects in an array of objects in memory.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* import { StoreService } from "./store"
|
|
85
|
-
*
|
|
86
|
-
* // Init the store service.
|
|
87
|
-
* StoreService.init("foo/pages", { mode: "file" })
|
|
88
|
-
* // Save the data into files.
|
|
89
|
-
* await StoreService.saveBuildData()
|
|
90
|
-
* // Consume the pages as an interator.
|
|
91
|
-
* const pages = StoreService.getPages()
|
|
92
|
-
*/
|
|
93
|
-
class StoreService {
|
|
94
|
-
static basePath: string;
|
|
95
|
-
static mode: "file" | "memory";
|
|
96
|
-
static pages: Array<GatsbyPageObject> = [];
|
|
97
|
-
static sitesToPublish: Array<Site>;
|
|
98
|
-
static buildProcessData: BuildProcessData;
|
|
99
|
-
static createdPages: Array<number>;
|
|
100
|
-
|
|
101
|
-
// Public methods
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Initialize the Store with a path to store the files in file mode and an option object to set the mode.
|
|
105
|
-
*
|
|
106
|
-
* @param basePath The path to store the page files.
|
|
107
|
-
* @param options An object configuration
|
|
108
|
-
* @param options.mode Store mode
|
|
109
|
-
* @todo Avoid initialize the Store with a `basePath` in memory mode.
|
|
110
|
-
*/
|
|
111
|
-
public static init(basePath: string, options: { mode: StoreMode }) {
|
|
112
|
-
const { mode } = options;
|
|
113
|
-
const griddoCxThreads = parseInt(GRIDDO_API_CONCURRENCY_COUNT || "10");
|
|
114
|
-
const modeString = mode === "file" ? "File mode" : "Memory mode";
|
|
115
|
-
|
|
116
|
-
console.log(`🧶 Processing API page calls with ${griddoCxThreads} threads`);
|
|
117
|
-
console.log(`📦 Griddo Store initialized - ${chalk.italic(modeString)}`);
|
|
118
|
-
|
|
119
|
-
if (mode === "file") {
|
|
120
|
-
this.basePath = basePath;
|
|
121
|
-
this.mode = mode;
|
|
122
|
-
|
|
123
|
-
if (fs.existsSync(basePath)) {
|
|
124
|
-
fs.rmSync(basePath, { recursive: true });
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!fs.existsSync(basePath)) {
|
|
128
|
-
fs.mkdirSync(basePath);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (!fs.existsSync(path.resolve(basePath, "pages"))) {
|
|
132
|
-
fs.mkdirSync(path.resolve(basePath, "pages"));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Save the build data to the Store.
|
|
139
|
-
*/
|
|
140
|
-
public static async saveBuildData() {
|
|
141
|
-
try {
|
|
142
|
-
// Get sites objects to publish and unpublish.
|
|
143
|
-
const { sitesToPublish, sitesToUnpublish } = await checkSites();
|
|
144
|
-
|
|
145
|
-
// The settings will be extracted below in this process.
|
|
146
|
-
await SettingsService.getAll();
|
|
147
|
-
|
|
148
|
-
// If no activity in sites, exit
|
|
149
|
-
if (!(sitesToPublish.length || sitesToUnpublish.length)) {
|
|
150
|
-
console.warn("There are no sites to update");
|
|
151
|
-
|
|
152
|
-
process.exit(0);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Publish and unpublis sites
|
|
156
|
-
console.log(
|
|
157
|
-
chalk.green(
|
|
158
|
-
"\n⬆️ ",
|
|
159
|
-
`(${sitesToPublish.length}) Sites to publish:`,
|
|
160
|
-
sitesToPublish.map(({ name }) => name).join(", "),
|
|
161
|
-
"\n"
|
|
162
|
-
)
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
console.log(
|
|
166
|
-
chalk.red(
|
|
167
|
-
"⬇️ ",
|
|
168
|
-
`(${sitesToUnpublish.length}) Sites to unpublish:`,
|
|
169
|
-
sitesToUnpublish.map(({ name }) => name).join(", "),
|
|
170
|
-
"\n"
|
|
171
|
-
)
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
// Unpublish (API) and delete sites
|
|
175
|
-
await unpublishSites(sitesToUnpublish);
|
|
176
|
-
|
|
177
|
-
// Delete (clean) sites to publish
|
|
178
|
-
await deleteSites([...sitesToPublish]);
|
|
179
|
-
|
|
180
|
-
// Set robots information to use later in the `onPostBuild` phase.
|
|
181
|
-
await RobotsService.loadRobots();
|
|
182
|
-
|
|
183
|
-
// Sites loop
|
|
184
|
-
const everySite = sitesToPublish.map(async (site) => {
|
|
185
|
-
// Gets
|
|
186
|
-
|
|
187
|
-
const { id: siteId, slug: siteSlug, theme, favicon } = site;
|
|
188
|
-
|
|
189
|
-
const {
|
|
190
|
-
siteInfo,
|
|
191
|
-
validPagesIds,
|
|
192
|
-
siteHash,
|
|
193
|
-
unpublishHashes,
|
|
194
|
-
siteLangs,
|
|
195
|
-
defaultLang,
|
|
196
|
-
headers,
|
|
197
|
-
footers,
|
|
198
|
-
socials,
|
|
199
|
-
// TODO: Check the false here...
|
|
200
|
-
} = await getSiteData(siteId, false);
|
|
201
|
-
|
|
202
|
-
const {
|
|
203
|
-
cloudinaryName,
|
|
204
|
-
useMetaTitle,
|
|
205
|
-
showBasicMetaRobots,
|
|
206
|
-
avoidHrefLangsOnCanonicals,
|
|
207
|
-
avoidSelfReferenceCanonicals,
|
|
208
|
-
avoidHrefLangXDefault,
|
|
209
|
-
avoidDebugMetas,
|
|
210
|
-
} = SettingsService.settings;
|
|
211
|
-
|
|
212
|
-
// Sets
|
|
213
|
-
|
|
214
|
-
BUILD_PROCESS_DATA[siteId] = {
|
|
215
|
-
siteHash,
|
|
216
|
-
unpublishHashes,
|
|
217
|
-
publishHashes: [],
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const NavService = new NavigationService();
|
|
221
|
-
|
|
222
|
-
// Set `headers` and `footers` to the NavService to use later in this process.
|
|
223
|
-
NavService.navigations = { headers, footers };
|
|
224
|
-
|
|
225
|
-
site.languages = siteLangs;
|
|
226
|
-
|
|
227
|
-
const shouldUpdateSite = updatedSiteHash(siteId, siteHash);
|
|
228
|
-
|
|
229
|
-
const siteScript = siteInfo.siteScript;
|
|
230
|
-
|
|
231
|
-
const siteMetadata = {
|
|
232
|
-
siteUrl: siteInfo.slug,
|
|
233
|
-
title: siteInfo.name,
|
|
234
|
-
favicon,
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const additionalInfo = {
|
|
238
|
-
baseUrl: API_URL,
|
|
239
|
-
publicBaseUrl: PUBLIC_API_URL,
|
|
240
|
-
instance: REACT_APP_INSTANCE,
|
|
241
|
-
siteSlug,
|
|
242
|
-
theme,
|
|
243
|
-
siteMetadata,
|
|
244
|
-
socials,
|
|
245
|
-
siteLangs,
|
|
246
|
-
cloudinaryName,
|
|
247
|
-
griddoVersion,
|
|
248
|
-
siteOptions: {
|
|
249
|
-
useMetaTitle,
|
|
250
|
-
showBasicMetaRobots,
|
|
251
|
-
avoidHrefLangsOnCanonicals,
|
|
252
|
-
avoidSelfReferenceCanonicals,
|
|
253
|
-
avoidHrefLangXDefault,
|
|
254
|
-
avoidDebugMetas,
|
|
255
|
-
},
|
|
256
|
-
BUILD_MODE: CXBRANCH,
|
|
257
|
-
siteScript,
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
logInfo(`${validPagesIds.length} valid pages`);
|
|
261
|
-
|
|
262
|
-
// -------------------------------------------------------------------------
|
|
263
|
-
// Pages loop promise creation
|
|
264
|
-
// -------------------------------------------------------------------------
|
|
265
|
-
// Async function that process every page for one site to use later in the
|
|
266
|
-
// `Promise.all` with pLimit.
|
|
267
|
-
const fetchPageAndSaveToStore = async (pageId: number) => {
|
|
268
|
-
// Here will be store every page returned by the API and processed by
|
|
269
|
-
// Griddo CX.
|
|
270
|
-
let gatsbyPageObjects: Array<GatsbyPageObject> = [];
|
|
271
|
-
|
|
272
|
-
// Get page data
|
|
273
|
-
const page = await SitesService.getPage(pageId, shouldUpdateSite);
|
|
274
|
-
|
|
275
|
-
if (!page) return;
|
|
276
|
-
|
|
277
|
-
// Update Array of page ids
|
|
278
|
-
CREATED_PAGES.push(pageId);
|
|
279
|
-
|
|
280
|
-
// Clone `additionalinfo` (to avoid mutation??) into `pageAdditionalInfo`
|
|
281
|
-
// TODO: Use structuredClone() when node 18 is available.
|
|
282
|
-
const pageAdditionalInfo = JSON.parse(
|
|
283
|
-
JSON.stringify(additionalInfo)
|
|
284
|
-
) as PageAdditionalInfo;
|
|
285
|
-
|
|
286
|
-
// Updated with navigations (header & footer)
|
|
287
|
-
// NavService.getPageNavigations returns { header, footer }
|
|
288
|
-
pageAdditionalInfo.navigations = NavService.getPageNavigations(page);
|
|
289
|
-
|
|
290
|
-
// Content Type Data Query
|
|
291
|
-
// Where the pair `hasDistributorData:true` and `data` prop exists, this
|
|
292
|
-
// function will attach a `queriedItems` prop with the result of the fetch
|
|
293
|
-
// for the data.
|
|
294
|
-
const template = await DistributorService.getDistributorData({
|
|
295
|
-
page,
|
|
296
|
-
cached: !!RENDER_ID,
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// MultiPage Query
|
|
300
|
-
// Where the pair `hasGriddoMultiPage:true` prop exists, this function
|
|
301
|
-
// will process the schema and return a multiPageElemtens array to use
|
|
302
|
-
// in `createGriddoMultipages()`
|
|
303
|
-
const multiPageElements = await getMultiPageElements(template);
|
|
304
|
-
|
|
305
|
-
// -----------------------------------------------------------------------
|
|
306
|
-
// Build page objects
|
|
307
|
-
// -----------------------------------------------------------------------
|
|
308
|
-
// Three types of pages
|
|
309
|
-
// - List with pagination (n pages)
|
|
310
|
-
// - Multi-page module (n pages)
|
|
311
|
-
// - Single (1 page)
|
|
312
|
-
|
|
313
|
-
// List
|
|
314
|
-
if (page?.mode === "list") {
|
|
315
|
-
// of data items and the `itemsPerPage` prop.
|
|
316
|
-
gatsbyPageObjects = await createGriddoListPages(
|
|
317
|
-
{
|
|
318
|
-
...page, // Revisar la inclusión de este ...page.
|
|
319
|
-
// The first page, the one without the `/2, /3, /4, etc..` slug
|
|
320
|
-
page,
|
|
321
|
-
// The other pages
|
|
322
|
-
// In this case `getPaginatedPages` doesn't require the whole page object, just the `template` part.
|
|
323
|
-
// This is because only the `template` prop will be different for each page.
|
|
324
|
-
pages: getPaginatedPages(template),
|
|
325
|
-
// The `template` key with the (maybe) distributor data items queried
|
|
326
|
-
template,
|
|
327
|
-
// Pass all data items
|
|
328
|
-
totalQueriedItems: template.queriedItems,
|
|
329
|
-
// Default site language
|
|
330
|
-
defaultLang,
|
|
331
|
-
},
|
|
332
|
-
pageAdditionalInfo
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// >> Multi-page
|
|
337
|
-
if (multiPageElements) {
|
|
338
|
-
gatsbyPageObjects = await createGriddoMultiPages(
|
|
339
|
-
{
|
|
340
|
-
// The whole page object
|
|
341
|
-
...page,
|
|
342
|
-
// The `template` key with the (maybe) distributor data items queried
|
|
343
|
-
template,
|
|
344
|
-
// Array of object of every element of the MultiPage
|
|
345
|
-
multiPageElements,
|
|
346
|
-
// Default site language
|
|
347
|
-
defaultLang,
|
|
348
|
-
},
|
|
349
|
-
pageAdditionalInfo
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// >> Single template
|
|
354
|
-
if (!multiPageElements && page.mode !== "list") {
|
|
355
|
-
gatsbyPageObjects = [
|
|
356
|
-
await createGriddoSinglePage(
|
|
357
|
-
{
|
|
358
|
-
// The whole page object
|
|
359
|
-
...page,
|
|
360
|
-
// The `template` key with the (maybe) distributor data items queried
|
|
361
|
-
template,
|
|
362
|
-
// Default site language
|
|
363
|
-
defaultLang,
|
|
364
|
-
},
|
|
365
|
-
pageAdditionalInfo
|
|
366
|
-
),
|
|
367
|
-
];
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Update hashes
|
|
371
|
-
BUILD_PROCESS_DATA[siteId].publishHashes.push(page.hash);
|
|
372
|
-
|
|
373
|
-
// Save build data to store
|
|
374
|
-
this.savePages(gatsbyPageObjects); // gatsbyPageObjects is always an array regardless of whether it's just one page
|
|
375
|
-
this.saveSitesToPublish(sitesToPublish);
|
|
376
|
-
this.saveBuildProcessData(BUILD_PROCESS_DATA);
|
|
377
|
-
this.saveCreatedPages(CREATED_PAGES);
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
const griddoCxThreads = parseInt(GRIDDO_API_CONCURRENCY_COUNT || "10");
|
|
381
|
-
|
|
382
|
-
// Create the pLimit array of promises
|
|
383
|
-
const limit = pLimit(griddoCxThreads);
|
|
384
|
-
const pagesToRender = validPagesIds.map((id: number) =>
|
|
385
|
-
limit(() => fetchPageAndSaveToStore(id))
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
await Promise.all(pagesToRender);
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
await Promise.all(everySite);
|
|
392
|
-
} catch (e) {
|
|
393
|
-
const error = e as { message: string };
|
|
394
|
-
|
|
395
|
-
console.error(error.message);
|
|
396
|
-
|
|
397
|
-
process.exit(1);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Get the pages saved previously from the Store.
|
|
403
|
-
*/
|
|
404
|
-
public static getPages() {
|
|
405
|
-
if (this.mode === "file") {
|
|
406
|
-
return this.getPagesFromFiles();
|
|
407
|
-
} else {
|
|
408
|
-
return this.getPagesFromMemory();
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Save the pages into the Store.
|
|
414
|
-
*
|
|
415
|
-
* @param pages An array of pages to save in the store.
|
|
416
|
-
*/
|
|
417
|
-
public static savePages(pages: Array<GatsbyPageObject>) {
|
|
418
|
-
if (this.mode === "file") {
|
|
419
|
-
this.savePagesToFiles(pages);
|
|
420
|
-
} else {
|
|
421
|
-
this.savePagesToMemory(pages);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Save site to publish data in the Store.
|
|
427
|
-
*
|
|
428
|
-
* @param sites An array of sites to be published.
|
|
429
|
-
*/
|
|
430
|
-
public static saveSitesToPublish(sites: Array<Site>) {
|
|
431
|
-
this.sitesToPublish = sites;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Save the build process data in the Store.
|
|
436
|
-
*
|
|
437
|
-
* @param buildProcessData An object that represents a build process data.
|
|
438
|
-
*/
|
|
439
|
-
public static saveBuildProcessData(buildProcessData: BuildProcessData) {
|
|
440
|
-
this.buildProcessData = buildProcessData;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Save the created pages in the Store.
|
|
445
|
-
*
|
|
446
|
-
* @param pages An array of pages ids.
|
|
447
|
-
*/
|
|
448
|
-
public static saveCreatedPages(pages: Array<number>) {
|
|
449
|
-
this.createdPages = pages;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Get the build metadata from the Store.
|
|
454
|
-
*/
|
|
455
|
-
public static getMetadata() {
|
|
456
|
-
return {
|
|
457
|
-
buildProcessData: this.buildProcessData,
|
|
458
|
-
createdPages: this.createdPages,
|
|
459
|
-
sitesToPublish: this.sitesToPublish,
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* Return an iterator with pages read from the file system.
|
|
465
|
-
*/
|
|
466
|
-
private static *getPagesFromFiles() {
|
|
467
|
-
const pagesDirPath = path.resolve(this.basePath, "pages");
|
|
468
|
-
const jsonFilePaths = walk(pagesDirPath).filter(
|
|
469
|
-
(file) => path.extname(file) === ".json"
|
|
470
|
-
);
|
|
471
|
-
|
|
472
|
-
for (const filePath of jsonFilePaths) {
|
|
473
|
-
const page = require(filePath) as GatsbyPageObject;
|
|
474
|
-
page.size = fs.statSync(filePath).size / 1024;
|
|
475
|
-
yield { ...page };
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Get the pages from the Store from the memory.
|
|
481
|
-
*/
|
|
482
|
-
private static getPagesFromMemory() {
|
|
483
|
-
return this.pages;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Save pages to the file system.
|
|
488
|
-
*
|
|
489
|
-
* @param pages An array of final pages to save into the file system.
|
|
490
|
-
*/
|
|
491
|
-
private static savePagesToFiles(pages: Array<GatsbyPageObject>) {
|
|
492
|
-
pages.forEach((pageObject) => {
|
|
493
|
-
const filename = `${createSha256(pageObject.path)}.json`;
|
|
494
|
-
const fileContent = JSON.stringify(pageObject);
|
|
495
|
-
const filePath = path.resolve(this.basePath, "pages", filename);
|
|
496
|
-
fs.writeFileSync(filePath, fileContent);
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Save pages to the memory.
|
|
502
|
-
*
|
|
503
|
-
* @param pages An array of final pages to save into the memory
|
|
504
|
-
*/
|
|
505
|
-
private static savePagesToMemory(pages: Array<GatsbyPageObject>) {
|
|
506
|
-
const pagesWithSize = pages.map((page) => {
|
|
507
|
-
const size = v8.serialize(page).byteLength / 1024;
|
|
508
|
-
|
|
509
|
-
return { ...page, size };
|
|
510
|
-
});
|
|
511
|
-
this.pages.push(...pagesWithSize);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
export { StoreService };
|